: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: "Inter var", "Inter", "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; flex: 1; min-width: 0; }
.nav ul { display: flex; flex-wrap: nowrap; gap: .15rem; list-style: none; margin: 0; padding: 0; }
.nav li { white-space: nowrap; }
.nav a { display: block; padding: .45rem .7rem; 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; align-items: center; gap: .35rem; }
.topbar-right form { display: inline-flex; margin: 0; }
.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: 1200px; 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.8rem; margin: 0; letter-spacing: -.025em; }
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; }
/* Let columns shrink instead of being widened by a long <select> option, and
   truncate the closed control with an ellipsis rather than overflowing. */
.grid-2 > * { min-width: 0; }
select { width: 100%; max-width: 100%; box-sizing: border-box; text-overflow: ellipsis; }
.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 */
/* License banner — pinned above the top navigation */
.license-banner { display: flex; align-items: center; justify-content: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1.25rem; font-size: .92rem; text-align: center;
  background: #B45309; color: #fff; }
.license-banner.locked { background: #B91C1C; }
.license-banner a { color: #fff; text-decoration: underline; font-weight: 600; }
.license-banner .lb-actions { display: inline-flex; gap: .6rem; align-items: center; white-space: nowrap; }
.license-banner .lb-actions button { background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.5);
  border-radius: 6px; padding: .2rem .6rem; font: inherit; font-size: .85rem; cursor: pointer; }
.license-banner .lb-actions button:hover { background: rgba(255,255,255,.3); }

.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) {
  .grid-2 { grid-template-columns: 1fr; }
  .cards  { grid-template-columns: 1fr 1fr; } /* stat cards stay 2-up — denser, less scrolling */
}
@media (max-width: 400px) {
  .cards { grid-template-columns: 1fr; }      /* very narrow phones: one stat per row */
}

/* 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; }

/* Predictive customer combobox (invoice form) */
.combo { position: relative; }
.combo-input { width: 100%; }
.combo-list {
  list-style: none; margin: 4px 0 0; padding: 4px;
  position: absolute; left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto;
}
.combo-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: .95rem; }
.combo-item:hover { background: var(--surface-2); }

/* Horizontal-scroll wrapper for wide tables (e.g. subscriptions) */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > .table { min-width: 720px; }          /* keep columns readable; scroll instead of crush */
.mono-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem;
  color: var(--muted); display: inline-block; max-width: 150px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}

/* Mobile hamburger (hidden on desktop). Uses .nav-toggle.icon-btn so it outranks
   the later `.icon-btn { display: inline-flex }` rule regardless of source order. */
.nav-toggle.icon-btn { display: none; font-size: 1.25rem; }

/* Collapse the primary nav to a dropdown BEFORE it can wrap onto two rows */
@media (max-width: 1024px) {
  .topbar { flex-wrap: wrap; gap: 1rem; }
  .brand { flex: 1; }
  .nav-toggle.icon-btn { display: inline-flex; }
  .nav {
    order: 5; flex: 1 0 100%; width: 100%;
    display: none; margin-top: .5rem;
  }
  .nav.open { display: block; }
  .nav ul { flex-direction: column; gap: .15rem; }
  .nav a { padding: .7rem .85rem; }
}

/* ===== Responsive: phones ===== */
@media (max-width: 760px) {
  .topbar { padding: .6rem .8rem; }
  .brand { font-size: 1.05rem; }
  .topbar-right .who { display: none; }

  .container { padding: 1rem .8rem 3rem; }
  .page-head { margin-bottom: 1rem; }
  h1 { font-size: 1.35rem; }

  /* Tables -> stacked cards. Row labels are added by app.js (data-label). */
  .table { border: 0; }
  .table thead { display: none; }
  .table tbody, .table tr, .table td { display: block; width: auto; }
  .table tr {
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); margin: 0 0 .7rem; padding: .25rem .35rem;
  }
  .table td {
    border: 0; padding: .5rem .55rem; display: flex; gap: 1rem;
    align-items: baseline; justify-content: space-between; text-align: right;
    overflow-wrap: anywhere; word-break: break-word;
  }
  .table td::before {
    content: attr(data-label); text-align: left; flex: 0 0 42%;
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .03em; color: var(--muted);
  }
  /* Cells without a header label (e.g. action buttons): no label, right-aligned */
  .table td:not([data-label]):not([data-fullrow])::before { content: none; }
  .table td:not([data-label]):not([data-fullrow]) { justify-content: flex-end; }
  .table td[data-fullrow] { display: block; text-align: center; }
  .table td[data-fullrow]::before { content: none; }

  /* Wide tables that scroll on desktop should stack here instead */
  .table-wrap { overflow-x: visible; }
  .table-wrap > .table { min-width: 0; }
  .mono-id { max-width: 62vw; }

  /* Let complex cells (clipped names, inline editors, multiple chips) shrink and
     wrap inside the card instead of forcing it wider than the screen. */
  .table td { min-width: 0; flex-wrap: wrap; }
  .table td > * { min-width: 0; max-width: 100%; }
  .table td .cell-clip { max-width: 100%; }
  .table td .inline-edit { flex: 1 1 100%; }
  .table td .inline-edit input[type="text"] { width: auto; flex: 1 1 auto; min-width: 0; max-width: none; }

  /* Line-item editor: stack the field under its label, full width */
  .table.line-items td { display: block; text-align: left; }
  .table.line-items td::before { display: block; margin-bottom: .25rem; flex: none; }
  .table.line-items input, .table.line-items textarea { width: 100% !important; min-width: 0 !important; }

  .form-actions .btn, .btn-group .btn { flex: 1 1 auto; }
  .combo-list { max-height: 50vh; }
}

/* Copy-to-clipboard rows (subscription share links / embed code) */
.copyrow { display: flex; gap: .4rem; align-items: stretch; }
.copyrow input, .copyrow textarea { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
.copyrow textarea { resize: vertical; }
.copyrow .btn { white-space: nowrap; align-self: flex-start; }

/* ===== All checkboxes render as toggle sliders (app-wide, no markup change) ===== */
input[type="checkbox"] {
  -webkit-appearance: none; appearance: none; -moz-appearance: none;
  width: 42px; height: 24px; padding: 0; margin: 0; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  position: relative; cursor: pointer; vertical-align: middle; flex: 0 0 auto;
  transition: background .15s ease, border-color .15s ease;
}
input[type="checkbox"]::before {
  content: ""; position: absolute; top: 50%; left: 3px; transform: translateY(-50%);
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.35); transition: left .15s ease;
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::before { left: 21px; }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="checkbox"]:disabled { opacity: .55; cursor: default; }

/* Segmented window selector (dashboard revenue chart) */
.seg { display:inline-flex; border:1px solid var(--border); border-radius:8px; overflow:hidden; }
.seg-btn { padding:.35rem .7rem; font-size:.85rem; color:var(--muted); text-decoration:none; border-left:1px solid var(--border); background:var(--surface); line-height:1.4; }
.seg-btn:first-child { border-left:0; }
.seg-btn:hover { background:rgba(127,127,127,.08); }
.seg-btn.is-active { background:var(--accent); color:var(--accent-contrast); }

/* Pagination */
.pager { display:flex; justify-content:space-between; align-items:center; gap:1rem; flex-wrap:wrap; margin-top:.85rem; }
.pager-controls { display:flex; align-items:center; gap:.75rem; flex-wrap:wrap; }
.pager-nav { display:flex; align-items:center; gap:.25rem; }
.btn.is-disabled { opacity:.45; pointer-events:none; }

/* Admin dropdown in the primary nav.
   Note: selectors are scoped under .nav so they out-specify the base `.nav ul`
   flex rule — otherwise the submenu would render as a horizontal strip. */
.nav li.nav-group { position: relative; }
.nav .nav-group-btn {
  font: inherit; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .7rem; border: 0; border-radius: 8px;
  background: none; color: var(--muted);
}
.nav .nav-group-btn:hover { background: var(--surface-2); color: var(--text); }
.nav .nav-group-btn.active { background: var(--accent); color: var(--accent-contrast); }
.nav .nav-group-btn .caret { font-size: .65em; opacity: .8; transition: transform .15s; }
.nav .nav-group.open .nav-group-btn .caret { transform: rotate(180deg); }

.nav ul.nav-sub {
  display: none;                 /* hidden until open */
  flex-direction: column;        /* vertical, not the inherited row */
  position: absolute; top: calc(100% + .4rem); right: 0;
  margin: 0; padding: .35rem; gap: .1rem; min-width: 190px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 34px rgba(0,0,0,.16);
}
.nav li.nav-group.open ul.nav-sub { display: flex; }
.nav ul.nav-sub li { width: 100%; }
.nav ul.nav-sub li a {
  display: block; width: 100%; padding: .55rem .8rem; border-radius: 8px;
  color: var(--text); font-weight: 500; white-space: nowrap;
}
.nav ul.nav-sub li a:hover { background: var(--surface-2); }
.nav ul.nav-sub li a.active { background: var(--surface-2); color: var(--accent-strong, var(--accent)); font-weight: 600; }

/* Hover submenus on primary items (Invoices → Recurring, Subscriptions → API Events).
   The parent is a real link; the flyout opens left-aligned under it. */
.nav li.nav-hover > a { display: inline-flex; align-items: center; gap: .35rem; }
.nav li.nav-hover > a .caret { font-size: .65em; opacity: .8; transition: transform .15s; }
.nav li.nav-hover.open > a .caret { transform: rotate(180deg); }
.nav li.nav-hover ul.nav-sub { left: 0; right: auto; }
/* Parent hint when a child page is the current one */
.nav li.nav-hover > a.sub-active { color: var(--text); background: var(--surface-2); }

@media (max-width: 1024px) {
  /* In the collapsed mobile menu, show the admin items inline under the button. */
  .nav .nav-group-btn { display: flex; width: 100%; justify-content: space-between; }
  .nav li.nav-hover > a { display: flex; justify-content: space-between; width: 100%; }
  .nav li.nav-hover > a .caret { display: none; }   /* nothing to open — subs are inline */
  .nav ul.nav-sub {
    position: static; padding: 0 0 0 1rem; min-width: 0;
    border: 0; box-shadow: none; background: none; border-radius: 0;
  }
  .nav li.nav-group ul.nav-sub { display: flex; }  /* always expanded on mobile */
}

/* Dashboard quick date ranges */
.range-bar { display:flex; flex-direction:row; align-items:center; gap:.6rem; flex-wrap:wrap; justify-content:flex-end; }
.range-bar .seg { flex:0 0 auto; }
@media (max-width: 760px) { .range-bar { justify-content:flex-start; } }

/* ---- UX polish: numerals, empty states, labels ---- */
.table td.r, .table th.r { text-align: right; }
.table td, .table th { font-variant-numeric: tabular-nums; }
.empty-state { display: flex; align-items: center; gap: .55rem; color: var(--muted);
  padding: .5rem 0; font-size: .95rem; }
.empty-state.is-good { color: var(--accent-strong, var(--accent)); }
.empty-state .empty-ico { display: inline-flex; align-items: center; justify-content: center;
  width: 1.4rem; height: 1.4rem; border-radius: 50%; background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent-strong, var(--accent)); font-weight: 700; font-size: .85rem; flex: none; }
h2 .lbl, h3 .lbl { font-size: .68rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: .04em; vertical-align: middle; margin-left: .35rem; }

/* ---- Attention dot on nav items ---- */
.nav-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--neg, #c0392b); margin-left: .35rem; vertical-align: middle; }

/* ---- Danger confirm modal (typed confirmation) ---- */
.danger-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.danger-overlay[hidden] { display: none; }
.danger-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 460px; max-width: 96vw; padding: 1.3rem 1.4rem; box-shadow: 0 18px 50px rgba(0,0,0,.28); }
.danger-box h3 { margin: 0 0 .5rem; }
.danger-box p { margin: 0 0 .9rem; color: var(--muted); }
.danger-box input { width: 100%; margin-bottom: 1rem; }
.danger-box .actions { display: flex; justify-content: flex-end; gap: .5rem; }
.btn-danger { background: var(--neg, #c0392b); border-color: var(--neg, #c0392b); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--neg, #c0392b) 85%, black); border-color: color-mix(in srgb, var(--neg, #c0392b) 85%, black); }
.btn-danger[disabled] { opacity: .45; cursor: not-allowed; }

/* ---- Inline edit (e.g. domain on the subscriptions list) ---- */
.inline-edit { display: flex; gap: .25rem; align-items: center; }
.inline-edit input[type="text"] { width: 11rem; max-width: 40vw; padding: .3rem .45rem;
  border: 1px solid var(--border); border-radius: 7px; font-size: .85rem; background: var(--surface); color: var(--text); }
.inline-edit input[type="text"]:focus { outline: 0; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.inline-edit .btn-sm { padding: .3rem .5rem; line-height: 1; }

/* ---- Subscriptions table: keep rows compact so they don't overflow ---- */
.nowrap { white-space: nowrap; }
.cell-clip { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-edit input[type="text"] { width: 8.5rem; }

/* ---- Icon button (gear / manage) ---- */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border: 1px solid var(--border); border-radius: 9px; color: var(--muted); background: var(--surface);
  text-decoration: none; transition: .12s; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---- Row action icons (envelope + gear) ---- */
.row-actions { display: inline-flex; gap: .4rem; justify-content: flex-end; }
button.icon-btn { cursor: pointer; font: inherit; padding: 0; }

/* ---- Slider toggle (authorization switch) ---- */
.switch { display: flex; align-items: center; gap: .6rem; cursor: pointer; font-size: .92rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { position: relative; width: 42px; height: 24px; background: var(--border);
  border-radius: 999px; transition: .15s; flex: 0 0 auto; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff;
  border-radius: 50%; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---- Search bar (invoices / subscriptions) ---- */
.searchbar { display: flex; gap: .5rem; align-items: center; margin: .75rem 0 1rem; flex-wrap: wrap; }
.searchbar input[type="search"] { flex: 1 1 280px; min-width: 200px; padding: .55rem .7rem .55rem 2.4rem;
  border: 1px solid var(--border); border-radius: 10px; font: inherit; color: var(--text);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat .8rem center; }
.searchbar input[type="search"]:focus { outline: 0; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* ---- Dropdown menu (native <details>) — keeps destructive actions out of reach ---- */
.menu { position: relative; display: inline-block; }
.menu > summary { list-style: none; cursor: pointer; user-select: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { background: var(--surface-2, rgba(127,127,127,.08)); }
.menu-pop { position: absolute; right: 0; top: calc(100% + .35rem); z-index: 40;
  min-width: 230px; padding: .35rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(16,24,40,.16); display: flex; flex-direction: column; gap: .15rem; }
.menu-pop form { margin: 0; }
.menu-item { display: block; width: 100%; text-align: left; padding: .5rem .6rem; border: 0;
  border-radius: 7px; background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.menu-item:hover { background: var(--surface-2, rgba(127,127,127,.1)); }
.menu-item-danger { color: var(--neg, #c0392b); }
.menu-item-danger:hover { background: color-mix(in srgb, var(--neg, #c0392b) 12%, transparent); }
@media (max-width: 760px) { .menu-pop { right: auto; left: 0; } }

/* ---- Duplicate customers: banner + one-at-a-time review wizard ---- */
.dup-banner { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; padding: .8rem 1rem; margin-bottom: 1rem; border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: 10px; background: var(--surface); }
.dup-banner-text { display: flex; flex-direction: column; gap: .15rem; }
.dup-review { padding: 1.2rem 1.3rem; }
.dup-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .3rem; }
.dup-reason { font-size: .8rem; color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: .1rem .55rem; }
.dup-keep { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: .4rem 0 .3rem; }
.dup-keep-card { display: flex; gap: .6rem; align-items: flex-start; padding: .8rem .9rem;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; transition: border-color .12s, background .12s; }
.dup-keep-card:hover { background: var(--surface-2, rgba(127,127,127,.06)); }
.dup-keep-card:has(input:checked) { border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent); }
.dup-keep-card input { margin-top: .25rem; }
.dup-keep-body { display: flex; flex-direction: column; gap: .12rem; min-width: 0; }
.dup-keep-top { display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--muted); }
.dup-keep-name { font-weight: 600; word-break: break-word; }
.dup-keep-mail { font-size: .85rem; word-break: break-word; }
.dup-keep-act { font-size: .8rem; }
.dup-keep-note { font-size: .82rem; margin: .1rem 0 .8rem; }
.dup-fields th { font-weight: 600; }
.dup-fields td { vertical-align: top; }
.dup-fields tr.dup-same td { color: var(--muted); }
.dup-opt { display: flex; gap: .45rem; align-items: flex-start; cursor: pointer; padding: .15rem 0; word-break: break-word; }
.dup-opt input { margin-top: .25rem; flex: 0 0 auto; }
.dup-opt:has(input:checked) { font-weight: 500; }
.dup-actions { margin-top: 1rem; }
.dup-skip { margin-top: .6rem; text-align: center; }
@media (max-width: 640px) {
  .dup-keep { grid-template-columns: 1fr; }
  .dup-fields, .dup-fields thead, .dup-fields tbody, .dup-fields tr, .dup-fields th, .dup-fields td { display: block; }
  .dup-fields thead { display: none; }
  .dup-fields tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: .6rem; padding: .4rem .6rem; }
  .dup-fields td::before { content: ""; }
}

/* ============================================================
   Polish pass — tasteful refinement
   ============================================================ */

/* Optional full self-hosting: drop Inter's variable woff2 at
   /assets/fonts/Inter.var.woff2 and uncomment. Until then the stack
   falls back to Inter-if-installed, then Segoe UI / system fonts.
@font-face {
  font-family: "Inter var";
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  src: url("/assets/fonts/Inter.var.woff2") format("woff2");
}
*/

/* Fast, quiet feedback on interactive elements */
a, .btn, .icon-btn, .seg-btn, .nav a, .tab, .table tbody tr,
input, select, textarea, .card {
  transition: background-color .13s ease, border-color .13s ease,
              color .13s ease, box-shadow .13s ease, transform .08s ease;
}

/* Row scannability */
.table tbody tr:hover { background: var(--surface-2); }

/* Tactile press */
.btn:active, .icon-btn:active, .seg-btn:active { transform: scale(.98); }

/* Subtle depth on the primary action */
.btn-primary { box-shadow: 0 1px 2px rgba(16,24,40,.12); }
.btn-primary:hover { box-shadow: 0 2px 5px rgba(16,24,40,.16); }

/* Icon buttons pick up the accent on hover */
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Visible, consistent keyboard focus */
.btn:focus-visible, .icon-btn:focus-visible, .seg-btn:focus-visible,
a:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Brand mark in the topbar */
.brand { display: inline-flex; align-items: center; gap: .5rem; }
.brand-mark { display: inline-flex; flex: 0 0 auto; }

/* Dashboard trend delta chip */
.stat .stat-value { display: inline-flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
/* Net-revenue total + its up-delta use the accent green so they match the
   lighter "Invoices" bars in the revenue chart (which also use --accent). */
.stat-value.pos { color: var(--accent); }
.delta { font-size: .8rem; font-weight: 600; letter-spacing: 0; }
.delta.up { color: var(--accent); }
.delta.down { color: var(--neg); }
.delta.flat { color: var(--muted); }

/* Inline domain editor: muted ghost affordance when empty */
.inline-edit input::placeholder { color: var(--muted); opacity: .8; }

/* ============================================================
   Consistency pass
   ============================================================ */

/* Any label that wraps a checkbox is a toggle row: switch left, text right,
   vertically centred. Fixes views that forgot the inline flex styles. */
label:has(> input[type="checkbox"]) {
  flex-direction: row; align-items: center; gap: .5rem; font-weight: 500;
}

/* First heading inside a card sits flush with the top padding. */
.card > h2:first-child, .card > h3:first-child,
.card > .page-head:first-child h2, .card > .page-head:first-child h3 { margin-top: 0; }

/* Keyboard focus on settings tabs (buttons, so the .btn rule doesn't cover them) */
.tabs .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Small-text utilities (preferred over ad-hoc inline font sizes) */
.small { font-size: .85rem; }
.tiny  { font-size: .78rem; }

/* Forms inside table cells / banners never add phantom margins */
td > form, .lb-actions form { margin: 0; }

/* ---- Sub-tabs inside a settings panel (Email templates) ---- */
.subtabs { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1.1rem; }
.subtabs .chip { cursor: pointer; font: inherit; font-size: .85rem; }
.subtab-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .85; margin-left: .4rem; vertical-align: middle; }
