:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1d2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #69A84B;
  --accent-contrast: #ffffff;
  --accent-strong: #588F3F;
  --pos: #15803d;
  --neg: #b91c1c;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --radius: 12px;
  color-scheme: light;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="dark"] {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface-2: #2c2c2c;
  --text: #e8e5e0;
  --muted: #999999;
  --border: #333333;
  --accent: #7CC05E;
  --accent-strong: #69A84B;
  --pos: #4ade80;
  --neg: #f87171;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; letter-spacing: -.02em; }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a { padding: .45rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent); color: var(--accent-contrast); }
.topbar-right { display: flex; gap: .35rem; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 8px; cursor: pointer; font-size: 1.1rem;
  display: inline-flex; align-items: center; justify-content: center;
}

.container { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.r { text-align: right; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.cards { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat { display: flex; flex-direction: column; gap: .25rem; }
.stat-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: .6rem .5rem; border-bottom: 1px solid var(--border); }
.table td { padding: .65rem .5rem; border-bottom: 1px solid var(--border); }
.row-link { cursor: pointer; } .row-link:hover { background: var(--surface-2); }

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-paid { background: rgba(21,128,61,.12); color: var(--pos); }
.badge-sent { background: rgba(105,168,75,.16); color: var(--accent); }
.badge-overdue { background: rgba(185,28,28,.12); color: var(--neg); }
.badge-draft { background: var(--surface-2); color: var(--muted); }
.badge-void { background: var(--surface-2); color: var(--muted); }
.badge-partially_paid { background: rgba(202,138,4,.14); color: #b45309; }
.badge-refunded { background: rgba(124,58,237,.12); color: #6d28d9; }
/* Brighter badge text for the dark (charcoal) theme where the deep amber/purple read too dim. */
[data-theme="dark"] .badge-partially_paid { color: #fbbf24; }
[data-theme="dark"] .badge-refunded { color: #a78bfa; }

/* Forms */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; margin-bottom: .9rem; }
input, select, textarea { font: inherit; padding: .55rem .65rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-2); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .6rem; margin-top: .5rem; }
.line-items input { width: 100%; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  font-weight: 600; font-size: .9rem; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn-primary:hover, .chip.active:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-lg { padding: .85rem 1.6rem; font-size: 1.05rem; }
.btn-group, .filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters { margin-bottom: 1rem; }
.chip { padding: .35rem .8rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: .85rem; }
.chip.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.range { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; }
.range label { margin-bottom: 0; flex-direction: row; align-items: center; gap: .4rem; }

/* Alerts */
.alert { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-ok { background: rgba(21,128,61,.12); color: var(--pos); }
.alert-error { background: rgba(185,28,28,.12); color: var(--neg); }

.totals { margin-top: 1rem; text-align: right; display: flex; flex-direction: column; gap: .25rem; }
.totals .grand { font-size: 1.3rem; font-weight: 700; color: var(--accent); }

/* Auth + pay pages */
.auth-wrap, .pay-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 340px; }
.pay-page { background: var(--bg); }
.pay-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2rem; width: 480px; max-width: 92vw; }

@media (max-width: 720px) {
  .cards, .grid-2 { grid-template-columns: 1fr; }
  .nav { order: 3; width: 100%; }
}

/* Quick-reminder modal + small button */
.btn-sm { padding: .25rem .6rem; font-size: .8rem; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; }
.modal-overlay[hidden] { display: none; }
.modal-box { width: 600px; max-width: 96vw; max-height: 90vh; overflow: auto; }
.modal-box label { display: block; margin: .6rem 0; }
.modal-box input, .modal-box textarea { width: 100%; }

/* Multi-line line-item description fields */
.line-items textarea.item-desc { width: 100%; min-width: 220px; resize: vertical;
  font: inherit; padding: .4rem .5rem; border-radius: 8px; min-height: 2.2rem; line-height: 1.4; }
.line-items td { vertical-align: top; }

/* Signed-in user chip in the top bar */
.topbar-right .who { font-size: .82rem; margin-right: .25rem; opacity: .85; }

/* --- Settings tabs --- */
.tabs { display:flex; flex-wrap:wrap; gap:.4rem; border-bottom:1px solid var(--border); margin:1rem 0 1.4rem; }
.tabs .tab {
  appearance:none; background:transparent; border:0; border-bottom:2px solid transparent;
  color:var(--muted); font:inherit; font-weight:600; padding:.6rem .9rem; cursor:pointer;
  border-radius:8px 8px 0 0;
}
.tabs .tab:hover { color:var(--text); background:var(--surface-2); }
.tabs .tab.active { color:var(--accent); border-bottom-color:var(--accent); }
.tab-panel[hidden] { display:none; }
.tab-panel > fieldset { border:1px solid var(--border); border-radius:10px; padding:1rem; margin-bottom:1.2rem; }
.tab-panel legend { padding:0 .4rem; font-weight:600; }
