:root {
  --bg: #f7f6f3; --card: #ffffff; --tile: #efeee9; --row: #f3f2ee;
  --text: #141413; --text2: #5e5d59; --muted: #8f8d86;
  --border: rgba(20, 20, 19, .10); --border2: rgba(20, 20, 19, .20);
  --accent: #1f63c9; --accent-bg: #e3edfb;
  --good: #17733a; --good-bg: #e2f2e6; --bad: #b3261e; --bad-bg: #fbe7e6;
  --warn: #7a5200; --warn-bg: #fbf0d6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --card: #1c1c1b; --tile: #222220; --row: #1f1f1d;
    --text: #efeee9; --text2: #c2c0b6; --muted: #8f8d86;
    --border: rgba(255, 255, 255, .10); --border2: rgba(255, 255, 255, .20);
    --accent: #79aaf2; --accent-bg: #1b2a40;
    --good: #6fcf8a; --good-bg: #15301e; --bad: #f28b82; --bad-bg: #3b1a18;
    --warn: #ecc46a; --warn-bg: #3a2e12;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
h1 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.boot { text-align: center; margin-top: 30vh; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.ttl p { margin: 2px 0 0; font-size: 12px; }
.range { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range button, .dates {
  font: inherit; font-size: 13px; color: var(--text2); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 11px; cursor: pointer;
}
.range button.on, .dates.on { background: var(--accent-bg); color: var(--accent); border-color: transparent; }
.range .refresh { display: inline-flex; align-items: center; justify-content: center; padding: 6px 10px; }
.refresh svg { width: 16px; height: 16px; }
.refresh.busy svg { animation: spin 1s linear infinite; }
.refresh.busy { color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.dates { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; cursor: default; }
.dates input { font: inherit; font-size: 13px; color: inherit; background: transparent; border: 0; padding: 3px 0; min-width: 0; width: 118px; }
.dates input::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; }

.note { font-size: 13px; border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; background: var(--warn-bg); color: var(--warn); }

.sec { font-size: 12px; font-weight: 500; color: var(--muted); margin: 16px 0 6px; }
.grid5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--tile); border-radius: 10px; padding: 11px 13px 12px; min-width: 0; }
.tile .l { font-size: 12px; color: var(--text2); }
.tile .n { font-size: 24px; font-weight: 600; letter-spacing: -.01em; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .m { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 2px; }
.good { color: var(--good) !important; }
.bad { color: var(--bad) !important; }

/* Phone: the funnel becomes a list, one line per step (count left, cost right). */
.fl { display: none; background: var(--tile); border-radius: 12px; padding: 2px 14px; }
.fl-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.fl-row:last-child { border-bottom: 0; }
.fl-l, .fl-r { min-width: 0; }
.fl-r { text-align: right; }
.fl .l { font-size: 12px; color: var(--text2); display: block; }
.fl .n { font-size: 20px; font-weight: 600; display: block; }
.fl .m { font-size: 12px; color: var(--muted); display: block; }

.tablewrap { margin-top: 20px; overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 13px; }
th { font-weight: 500; font-size: 12px; color: var(--text2); text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--border2); white-space: nowrap; }
td { text-align: right; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); z-index: 1; }
td small { display: block; font-size: 11px; color: var(--muted); }
td.nm { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
tr.tot td { background: var(--row); font-weight: 600; }
tr.src td { font-weight: 600; padding-top: 13px; }
tr.sub td.nm { padding-left: 22px; color: var(--text2); }
tr.sub td.nm .raw { color: var(--muted); font-size: 11px; display: block; }
td.cpa { font-weight: 600; }
td.cpa.good { background: var(--good-bg); }
td.cpa.bad { background: var(--bad-bg); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.legend { font-size: 12px; color: var(--muted); margin: 10px 2px 0; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin: 0 4px 0 10px; }
.legend .sw:first-child { margin-left: 0; }

.lock { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.lockcard { width: 100%; max-width: 320px; display: grid; gap: 8px; }
.lockcard h1 { margin-bottom: 10px; }
.lockcard input[type=password] { font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border2); background: var(--card); color: var(--text); }
.lockcard button { font: inherit; font-weight: 600; padding: 10px 12px; border-radius: 8px; border: 0; background: var(--text); color: var(--bg); cursor: pointer; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 0; }

@media (max-width: 760px) {
  .wrap { padding-top: 14px; }
  .top { flex-direction: column; align-items: stretch; }
  .range button { flex: 1 1 auto; }
  .dates { flex: 1 1 100%; justify-content: center; }
  .dates input { width: 50%; text-align: center; }
  #kpi .grid5, #kpi .sec { display: none; }
  .fl { display: block; }
  #money.grid5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #money .tile:last-child { grid-column: 1 / -1; }
  .tile .n { font-size: 21px; }
  /* Narrow sticky name column so more metric columns fit while swiping. */
  table { min-width: 620px; font-size: 12.5px; }
  th, td { padding: 8px 6px; }
  th:first-child, td.nm { white-space: normal; width: 96px; min-width: 96px; max-width: 96px; font-size: 12px; line-height: 1.3; }
  tr.sub td.nm { padding-left: 10px; }
  tr.sub td.nm .raw { display: none; }
  .dot { margin-right: 4px; }
  .range .refresh { flex: 0 0 auto; }
}
