:root {
  --charcoal: #3a3a3a;
  --charcoal-soft: #5c5c5c;
  --cream: #faf8f5;
  --paper: #ffffff;
  --line: #e4e0da;
  --green: #2f7a4f;
  --amber: #b8862f;
  --red: #b8433a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--charcoal);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
}

header.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

header.brand .wordmark {
  font-family: Georgia, 'Times New Roman', serif;
  letter-spacing: 3px;
  font-size: 22px;
  font-weight: 400;
}

header.brand .subtitle {
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--charcoal-soft);
  text-transform: uppercase;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

h1, h2, h3 {
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 400;
}

a { color: inherit; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card .label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--charcoal-soft);
}

.stat-card .value {
  font-size: 26px;
  margin-top: 6px;
  font-family: Georgia, serif;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}

th {
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--charcoal-soft);
  background: #f4f1ec;
}

tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7f5f0; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge.active { background: #e6f2e9; color: var(--green); }
.badge.payment_failed { background: #fbeee7; color: var(--red); }
.badge.on_hold { background: #f5ece0; color: var(--amber); }
.badge.archived { background: #eef1f5; color: #4a5568; }
.badge.succeeded { background: #e6f2e9; color: var(--green); }
.badge.failed { background: #fbeee7; color: var(--red); }
.badge.processing, .badge.pending { background: #eef1f5; color: #4a5568; }
.badge.refunded { background: #eef1f5; color: #4a5568; }
.badge.outstanding { background: #fbeee7; color: var(--red); }
.badge.partially_paid { background: #f5ece0; color: var(--amber); }
.badge.paid { background: #e6f2e9; color: var(--green); }
.badge.void { background: #eef1f5; color: #4a5568; text-decoration: line-through; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 10px;
}

input[type="text"], input[type="number"], select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13.5px;
  background: var(--paper);
}

button {
  padding: 8px 16px;
  border-radius: 7px;
  border: 1px solid var(--charcoal);
  background: var(--charcoal);
  color: var(--paper);
  font-size: 13.5px;
  cursor: pointer;
}

button.secondary {
  background: var(--paper);
  color: var(--charcoal);
}

button:hover { opacity: 0.85; }

.back-link {
  font-size: 13px;
  color: var(--charcoal-soft);
  text-decoration: none;
  margin-bottom: 14px;
  display: inline-block;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card .row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.card .row:last-child { border-bottom: none; }
.card .row .k { color: var(--charcoal-soft); }

section { margin-bottom: 28px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: none; align-items: center; justify-content: center; z-index: 50;
  padding: 24px 12px;
  overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--paper); border-radius: var(--radius); padding: 24px;
  width: 420px; max-width: 90vw;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.modal label { display: block; font-size: 12px; color: var(--charcoal-soft); margin: 10px 0 4px; }
.modal input, .modal select { width: 100%; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.empty { color: var(--charcoal-soft); padding: 24px; text-align: center; }

/* Custom alert/confirm dialogs (replace native browser popups) */
.ui-dialog-message { font-size: 14px; line-height: 1.5; color: var(--charcoal); }

/* Toasts */
#ui-toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.ui-toast {
  background: var(--charcoal); color: var(--paper);
  padding: 11px 16px; border-radius: 8px; font-size: 13.5px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 320px;
}
.ui-toast.show { opacity: 1; transform: translateY(0); }
.ui-toast-error { background: var(--red); }
.ui-toast-success { background: var(--green); }

/* Logo */
header.brand { display: flex; align-items: center; gap: 12px; }
header.brand img.logo { height: 46px; width: auto; }
header.brand .brand-text { display: flex; flex-direction: column; }

/* Login page */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--cream);
}
.login-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 36px 34px; width: 360px; max-width: 90vw;
  text-align: center;
}
.login-card img.logo { width: 110px; height: auto; margin-bottom: 6px; }
.login-card h1 { font-size: 18px; margin: 4px 0 22px; letter-spacing: 1px; }
.login-card label { display: block; font-size: 12px; color: var(--charcoal-soft); margin: 14px 0 4px; text-align: left; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 20px; padding: 10px; }
.login-card .recaptcha-wrap { margin-top: 16px; display: flex; justify-content: center; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 16px; }

/* Stripe Payment Element container */
#payment-element-wrap { margin: 14px 0; }
