:root {
  --bg: #f1f5f9; --card: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #f59e0b; --brand-text: #1f1300; --ink: #0f172a; --good: #15803d; --bad: #b91c1c; --blue: #1d4ed8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #131c2e; --text: #e5eaf3; --muted: #94a3b8; --line: #243049; --ink: #020617;
    --good: #4ade80; --bad: #f87171; --blue: #60a5fa;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; padding-bottom: 76px; }
header { position: sticky; top: 0; z-index: 5; background: var(--ink); color: #fff; display: flex; gap: 12px; align-items: center; padding: 10px 16px; }
.logo { font-weight: 800; white-space: nowrap; }
#search-wrap { flex: 1; }
#gsearch { width: 100%; padding: 8px 12px; border-radius: 10px; border: 0; font-size: 15px; }
main { max-width: 900px; margin: 0 auto; padding: 16px; }
nav#tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--ink); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
nav#tabs a { flex: 1; text-align: center; color: #cbd5e1; text-decoration: none; padding: 14px 4px; font-size: 14px; font-weight: 600; }
nav#tabs a.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }
h1 { font-size: 22px; margin: 4px 0 14px; display: flex; align-items: center; gap: 10px; }
h1 .sp { flex: 1; }
h2 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; }
h2 .sp { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row .sp { flex: 1; min-width: 0; }
a.item { display: block; color: inherit; text-decoration: none; }
.title { font-weight: 700; }
.sub { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
button, .btn { font: inherit; font-weight: 700; border: 0; border-radius: 10px; padding: 9px 14px; background: var(--brand); color: var(--brand-text); cursor: pointer; text-decoration: none; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
button.sm { padding: 5px 10px; font-size: 14px; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--line); color: var(--text); white-space: nowrap; }
.pill.new, .pill.estimate, .pill.draft { background: #dbeafe; color: #1e3a8a; }
.pill.scheduled, .pill.sent, .pill.contacted, .pill.quoted { background: #fef3c7; color: #78350f; }
.pill.in_progress { background: #ffedd5; color: #7c2d12; }
.pill.complete, .pill.invoiced { background: #e0e7ff; color: #312e81; }
.pill.paid, .pill.won, .pill.accepted { background: #dcfce7; color: #14532d; }
.pill.lost, .pill.cancelled, .pill.void { background: #fee2e2; color: #7f1d1d; }
.tabsel { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tabsel button { background: var(--card); color: var(--text); border: 1px solid var(--line); white-space: nowrap; }
.tabsel button.on { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
#modal { position: fixed; inset: 0; background: rgba(2, 6, 23, .6); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 18px 16px 24px; }
@media (min-width: 640px) { #modal { align-items: center; } .sheet { border-radius: 16px; } }
label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 10px 0 3px; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text); }
textarea { min-height: 80px; resize: vertical; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.line { display: grid; grid-template-columns: 1fr 56px 90px 30px; gap: 6px; margin-bottom: 6px; }
.right { text-align: right; }
.money { font-variant-numeric: tabular-nums; }
.good { color: var(--good); } .bad { color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.totals { margin-left: auto; width: 240px; }
.totals div { display: flex; justify-content: space-between; padding: 2px 0; }
.totals .grand { font-weight: 800; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.login { max-width: 340px; margin: 18vh auto; text-align: center; }
.print-only { display: none; }
@media print {
  header, nav#tabs, .noprint, h1 button { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .card { border: 0; padding: 0; }
  .print-only { display: block; }
}
