/* NaqviX Invoicing — app shell.
   Tokens and constraints come from docs/BRAND.md. The invoice document styles
   itself (public/invoice.js) and deliberately does not inherit from here. */

:root {
  --ink: #131316;
  --ink-2: #33333d;
  --muted: #55555f;
  --accent: #2b1fd4;
  --accent-2: #5b4ef0;
  --accent-soft: #eeedfd;
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --line: #e6e6ec;
  --line-2: #d8d8e2;
  --ok: #0e8a5f;
  --ok-soft: #e6f5ef;
  --warn: #b45309;
  --warn-soft: #fdf3e7;
  --danger: #c0342b;
  --danger-soft: #fbecea;

  --r-sm: 8px;
  --r: 10px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(19, 19, 22, .04), 0 8px 24px rgba(19, 19, 22, .06);
  --shadow-lg: 0 2px 8px rgba(19, 19, 22, .06), 0 24px 60px rgba(19, 19, 22, .14);

  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Outfit', 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --nav-w: 246px;
  --t: 140ms ease;
  --t-panel: 220ms cubic-bezier(.2, .7, .3, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f7f7fa;
    --ink-2: #e2e2ea;
    --muted: #c2c2d0;
    --accent: #8b80ff;
    --accent-2: #a79dff;
    --accent-soft: #201d3a;
    --bg: #0d0d10;
    --surface: #17171b;
    --surface-2: #1c1c21;
    --line: #33333d;
    --line-2: #44444f;
    --ok: #34d399;
    --ok-soft: #10261e;
    --warn: #fbbf24;
    --warn-soft: #2a1f10;
    --danger: #f87171;
    --danger-soft: #2a1513;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    --shadow-lg: 0 2px 8px rgba(0, 0, 0, .5), 0 24px 60px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ink: #f7f7fa;
  --ink-2: #e2e2ea;
  --muted: #c2c2d0;
  --accent: #8b80ff;
  --accent-2: #a79dff;
  --accent-soft: #201d3a;
  --bg: #0d0d10;
  --surface: #17171b;
  --surface-2: #1c1c21;
  --line: #33333d;
  --line-2: #44444f;
  --ok: #34d399;
  --ok-soft: #10261e;
  --warn: #fbbf24;
  --warn-soft: #2a1f10;
  --danger: #f87171;
  --danger-soft: #2a1513;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, .5), 0 24px 60px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }
img { max-width: 100%; }
[hidden] { display: none !important; }

h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -.015em;
  margin: 0;
  line-height: 1.2;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.num { font-variant-numeric: tabular-nums; }

/* ---------------- boot ---------------- */

.booting { display: grid; place-items: center; min-height: 100dvh; }
.boot-star { width: 40px; height: 40px; fill: var(--accent); animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .boot-star { animation: none; } }

/* ---------------- login ---------------- */

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 520px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

.login-card {
  width: min(100%, 400px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 34px 30px;
}

.login-card .brand-mark { display: block; height: 34px; margin: 0 auto 22px; object-fit: contain; }
.login-card h1 { font-size: 20px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13.5px; margin: 6px 0 24px; }

/* ---------------- app frame ---------------- */

.app-frame { display: flex; min-height: 100dvh; }

.sidebar {
  width: var(--nav-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}

.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.sidebar .brand img,
.topbar img { height: 22px; object-fit: contain; }
/* Two real wordmark files (ink for light, white for dark) rather than an
   invert filter — the filter mangled the indigo dot. */
.brand-swap { display: inline-flex; align-items: center; }
.brand-swap .logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-swap .logo-light { display: none; }
  :root:not([data-theme="light"]) .brand-swap .logo-dark { display: block; }
}
:root[data-theme="dark"] .brand-swap .logo-light { display: none; }
:root[data-theme="dark"] .brand-swap .logo-dark { display: block; }
:root[data-theme="light"] .brand-swap .logo-light { display: block; }
:root[data-theme="light"] .brand-swap .logo-dark { display: none; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--r);
  color: var(--ink-2);
  font-size: 14.5px;
  font-weight: 500;
  transition: background var(--t), color var(--t);
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link svg { width: 18px; height: 18px; flex: none; stroke-width: 1.7; }
.nav-sep { height: 1px; background: var(--line); margin: 12px 8px; }
.nav-foot { margin-top: auto; padding-top: 12px; }

.who {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line);
}
.who .avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; font-family: var(--display);
}
.who .meta { min-width: 0; }
.who .meta b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .meta span { font-size: 11px; color: var(--muted); text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar img { height: 22px; object-fit: contain; }

.page { padding: 26px 30px 60px; max-width: 1240px; width: 100%; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-head h1 { font-size: 25px; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- bottom nav (mobile) ---------------- */

.tabbar { display: none; }

/* ---------------- controls ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--r);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), border-color var(--t), transform var(--t), opacity var(--t);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; stroke-width: 1.8; }

/* Primary button inverts against the page: ink on light, near-white on dark. */
.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fbfbfd;
}
.btn-primary:hover { background: #000; border-color: #000; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { color: #0d0d10; }
  :root:not([data-theme="light"]) .btn-primary:hover { background: #fff; border-color: #fff; }
}
:root[data-theme="dark"] .btn-primary { color: #0d0d10; }
:root[data-theme="dark"] .btn-primary:hover { background: #fff; border-color: #fff; }
:root[data-theme="light"] .btn-primary { color: #fbfbfd; }
:root[data-theme="light"] .btn-primary:hover { background: #000; border-color: #000; }

.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: var(--line-2); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-block { width: 100%; }

.field { margin-bottom: 15px; }
.field > label,
.label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: 6px;
}
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14.5px;
  transition: border-color var(--t), box-shadow var(--t);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%2371717f' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.row { display: grid; gap: 14px; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: repeat(3, 1fr); }
.row-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 720px) { .row-2, .row-3, .row-4 { grid-template-columns: 1fr; } }

.check {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; cursor: pointer;
}

/* segmented choice cards — used by the invoice wizard */
.choices { display: grid; gap: 10px; }
.choices-2 { grid-template-columns: 1fr 1fr; }
.choices-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) { .choices-2, .choices-3 { grid-template-columns: 1fr; } }

.choice {
  text-align: left;
  padding: 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--surface);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color var(--t), background var(--t), transform var(--t);
}
.choice:hover { border-color: var(--accent); transform: translateY(-1px); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice b { display: block; font-family: var(--display); font-size: 15px; font-weight: 600; }
.choice span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }

/* ---------------- cards, tables, states ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-head h2 { font-size: 16px; }
.card-tight { padding: 0; overflow: hidden; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 18px;
}
.stat .label { margin-bottom: 8px; }
.stat .value { font-family: var(--display); font-size: 25px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .foot { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
/* The highlighted stat is a solid panel, so its colours are pinned rather than
   taken from --ink: that token inverts in dark mode and turned this card into
   white-on-white. Light keeps the ink panel; dark switches to brand indigo,
   which reads clearly against the dark surface. */
.stat.accent {
  background: linear-gradient(135deg, #131316, #2a2a35);
  border-color: transparent;
  color: #fff;
}
.stat.accent .value { color: #fff; }
.stat.accent .label,
.stat.accent .foot { color: rgba(255, 255, 255, .68); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stat.accent {
    background: linear-gradient(135deg, #2b1fd4, #5b4ef0);
  }
}
:root[data-theme="dark"] .stat.accent {
  background: linear-gradient(135deg, #2b1fd4, #5b4ef0);
}
:root[data-theme="light"] .stat.accent {
  background: linear-gradient(135deg, #131316, #2a2a35);
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  padding: 11px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background var(--t); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: var(--surface-2); }
table.data .right { text-align: right; }
/* Invoice numbers and dates should never wrap mid-value on desktop. */
@media (min-width: 761px) {
  table.data td.num, table.data td.nowrap { white-space: nowrap; }
}
table.data .strong { font-weight: 600; }
table.data .sub { display: block; font-size: 12px; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  text-transform: capitalize; white-space: nowrap;
}
.pill::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill-draft { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill-sent { background: var(--accent-soft); color: var(--accent); }
.pill-partial { background: var(--warn-soft); color: var(--warn); }
.pill-paid { background: var(--ok-soft); color: var(--ok); }
.pill-overdue { background: var(--danger-soft); color: var(--danger); }
.pill-cancelled { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.pill-admin { background: var(--ink); color: var(--bg); }
.pill-employee { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }

.empty { text-align: center; padding: 54px 20px; color: var(--muted); }
.empty svg { width: 34px; height: 34px; opacity: .35; margin-bottom: 12px; stroke-width: 1.5; }
.empty h3 { font-size: 16px; color: var(--ink); margin-bottom: 6px; }
.empty p { font-size: 13.5px; margin: 0 0 18px; }

.searchbar { position: relative; flex: 1; min-width: 190px; max-width: 340px; }
.searchbar input { padding-left: 36px; }
.searchbar svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--muted); pointer-events: none; stroke-width: 1.8;
}
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filters select { width: auto; min-width: 150px; }

/* ---------------- wizard ---------------- */

.wizard { max-width: 900px; }
.steps { display: flex; gap: 6px; margin-bottom: 24px; flex-wrap: wrap; }
.step-dot {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface);
}
.step-dot i {
  font-style: normal; width: 18px; height: 18px; border-radius: 50%;
  background: var(--line); color: var(--muted);
  display: grid; place-items: center; font-size: 10.5px; font-weight: 700;
}
.step-dot.done { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.step-dot.done i { background: var(--accent); color: #fff; }
.step-dot.current { color: var(--ink); border-color: var(--ink); }
.step-dot.current i { background: var(--ink); color: var(--bg); }
@media (max-width: 640px) {
  .step-dot span { display: none; }
  .step-dot { padding: 6px; }
}

.wizard-foot {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line);
}

/* line item editor */
.items-editor { display: flex; flex-direction: column; gap: 10px; }
.item-row {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  padding: 13px;
  display: grid;
  gap: 10px;
  /* Six cells: description, qty, unit, rate, amount, remove. The amount column
     must be wide enough for large PKR figures such as "Rs 14,650,000". */
  grid-template-columns: 1fr 78px 92px 118px 132px 40px;
  align-items: start;
}
.item-row .amt {
  align-self: center; text-align: right; font-weight: 600;
  font-variant-numeric: tabular-nums; font-size: 14.5px; padding-top: 22px;
  min-width: 0; overflow-wrap: anywhere;
}
.item-row .drop { align-self: center; padding-top: 18px; }
@media (max-width: 860px) {
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .desc-cell { grid-column: 1 / -1; }
  .item-row .amt { text-align: left; padding-top: 0; }
  .item-row .drop { padding-top: 0; justify-self: end; }
}

.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: color var(--t), border-color var(--t), background var(--t);
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.icon-btn svg { width: 15px; height: 15px; stroke-width: 1.8; }

/* typeahead */
.typeahead { position: relative; }
.ta-list {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  max-height: 260px; overflow-y: auto; padding: 5px;
}
.ta-item {
  padding: 9px 11px; border-radius: var(--r-sm); cursor: pointer;
  font-size: 14px; display: block; width: 100%; text-align: left;
  background: none; border: 0; color: inherit; font-family: inherit;
}
.ta-item:hover, .ta-item.active { background: var(--accent-soft); color: var(--accent); }
.ta-item small { display: block; color: var(--muted); font-size: 12px; }
.ta-item:hover small, .ta-item.active small { color: inherit; opacity: .75; }

/* totals summary */
.totals-box { margin-left: auto; width: min(100%, 330px); font-size: 14.5px; }
.totals-box .line { display: flex; justify-content: space-between; padding: 7px 0; color: var(--ink-2); }
.totals-box .line span:last-child { font-variant-numeric: tabular-nums; }
.totals-box .grand {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line);
  font-family: var(--display); font-size: 20px; font-weight: 600;
}
.totals-box .grand span:last-child { font-variant-numeric: tabular-nums; }

/* ---------------- invoice viewer ---------------- */

.viewer-bar {
  position: sticky; top: 0; z-index: 25;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.viewer-bar .spacer { flex: 1; }
.viewer-stage { padding: 24px 16px 90px; display: flex; justify-content: center; }

/* ---------------- modal ---------------- */

.modal-back {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(19, 19, 22, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade var(--t-panel);
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: min(100%, 560px);
  max-height: 88dvh;
  display: flex; flex-direction: column;
  animation: rise var(--t-panel);
}
.modal.wide { width: min(100%, 800px); }
@keyframes rise { from { transform: translateY(12px) scale(.99); opacity: 0; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 15px 20px; border-top: 1px solid var(--line);
}
@media (max-width: 600px) {
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-height: 94dvh; border-radius: var(--r-lg) var(--r-lg) 0 0; animation: sheet var(--t-panel); }
  @keyframes sheet { from { transform: translateY(100%); } }
  .modal-foot { padding-bottom: max(15px, env(safe-area-inset-bottom)); }
}

/* ---------------- toasts ---------------- */

.toasts {
  position: fixed; z-index: 200; left: 50%; transform: translateX(-50%);
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(92vw, 420px);
}
.toast {
  background: var(--ink); color: var(--bg);
  padding: 11px 16px; border-radius: var(--r);
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--t-panel);
  max-width: 100%;
}
:root[data-theme="dark"] .toast { background: #f2f2f5; color: #0d0d10; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ---------------- responsive frame ---------------- */

@media (max-width: 900px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .page { padding: 18px 16px 96px; }
  .page-head h1 { font-size: 21px; }

  .tabbar {
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; border-radius: var(--r-sm);
    font-size: 10.5px; font-weight: 500; color: var(--muted);
  }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a.active { color: var(--accent); }
  .tabbar svg { width: 21px; height: 21px; stroke-width: 1.7; }
  .viewer-stage { padding: 14px 8px 96px; }
}


/* ---------------- mobile: data tables become cards ---------------- */
/* Admin screens are table-heavy; horizontal scrolling on a phone is unusable.
   Each row becomes a card and each cell carries its column name, injected as
   data-label by stackTables() in app.js so no markup has to repeat it. */
@media (max-width: 760px) {
  .card-tight .table-wrap { overflow-x: visible; padding: 10px; }
  table.data { border-collapse: separate; border-spacing: 0; }
  table.data thead { display: none; }
  table.data tbody,
  table.data tr,
  table.data td { display: block; width: 100%; }

  table.data tr {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    padding: 4px 14px;
    margin-bottom: 10px;
  }
  table.data tbody tr:last-child { margin-bottom: 0; }
  table.data tbody tr.clickable:hover { background: var(--surface-2); }

  table.data td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    text-align: right;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  table.data tr td:last-child { border-bottom: 0; }
  table.data td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    text-align: left;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--muted);
  }
  /* Cells with no column name (action buttons) span the full width. */
  table.data td[data-label=""]::before { content: none; }
  table.data td[data-label=""] { justify-content: flex-end; }
  table.data .sub { display: block; text-align: right; }

  /* The settings screen is a long form — give it room. */
  .card { padding: 16px; }
  .page-head { margin-bottom: 16px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .modal-body { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat .value { font-size: 20px; }
  .viewer-bar { gap: 6px; padding: 10px 12px; }
  .viewer-bar .btn { flex: 0 0 auto; }
}

@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr; }
}

/* Paid marker in the invoice list */
.paid-tick {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 600; color: var(--ok); white-space: nowrap;
}
.paid-tick svg { width: 15px; height: 15px; stroke-width: 2.2; }
.mark-paid { white-space: nowrap; }
.mark-paid:hover { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }

/* ---------------- theme toggle ---------------- */
.theme-toggle { flex: none; }
.theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: block; }
}
:root[data-theme="dark"] .theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: block; }
:root[data-theme="light"] .theme-toggle .i-sun { display: block; }
:root[data-theme="light"] .theme-toggle .i-moon { display: none; }

@media print {
  .sidebar, .topbar, .tabbar, .viewer-bar, .toasts { display: none !important; }
  .page, .viewer-stage { padding: 0 !important; }
  body { background: #fff; }
}
