:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --card: #ffffff;
  --sidebar: rgba(246, 246, 248, 0.86);
  --fill: rgba(120, 120, 128, 0.12);
  --sep: rgba(60, 60, 67, 0.16);
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.62);
  --label-3: rgba(60, 60, 67, 0.36);
  --accent: #007aff;
  --red: #d70015;
  --green: #248a3d;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --sidebar: rgba(28, 28, 30, 0.86);
    --fill: rgba(118, 118, 128, 0.24);
    --sep: rgba(84, 84, 88, 0.6);
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.62);
    --label-3: rgba(235, 235, 245, 0.32);
    --accent: #0a84ff;
    --red: #ff6961;
    --green: #30d158;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #1c1c1e; --sidebar: rgba(28, 28, 30, 0.86); --fill: rgba(118, 118, 128, 0.24);
  --sep: rgba(84, 84, 88, 0.6); --label: #ffffff; --label-2: rgba(235, 235, 245, 0.62); --label-3: rgba(235, 235, 245, 0.32);
  --accent: #0a84ff; --red: #ff6961; --green: #30d158; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--label); font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased; letter-spacing: -0.01em;
}
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Shell: source list on the left, content on the right; tab bar on phones. */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 20px 12px; display: flex; flex-direction: column; gap: 2px;
  background: var(--sidebar); border-right: 1px solid var(--sep); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.brand { font-weight: 700; font-size: 20px; padding: 4px 10px 18px; }
.sidebar a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--label); font-size: 15px;
}
.sidebar a svg { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sidebar a:hover { background: var(--fill); }
.sidebar a[aria-current="page"] { background: var(--accent); color: #fff; }
.sidebar a[aria-current="page"] svg { stroke: #fff; }
.count { margin-left: auto; font-weight: 400; font-size: 14px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.sidebar a[aria-current="page"] .count { color: rgba(255, 255, 255, 0.85); }

main { padding: 28px clamp(20px, 3vw, 48px) 80px; width: 100%; min-width: 0; outline: none; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 2px; color: var(--label-2); font-size: 15px; }
h1 { margin: 0; font-size: 34px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.refresh {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--label-2);
  font-size: 13px; padding: 8px; min-height: 44px; cursor: pointer; border-radius: 8px;
}
.refresh svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.refresh:hover { color: var(--accent); }
.refresh.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Sections: plain heading + inset grouped list. Spacing carries structure. */
.section { margin-bottom: 34px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 4px 8px; }
h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.015em; }
.section-head .more { font-size: 15px; }
.sub { margin: 0 4px 8px; color: var(--label-2); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 28px; }

.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 52px; position: relative; color: var(--label);
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--sep); }
.row.indent + .row.indent::before { left: 52px; }
a.row:hover, button.row:hover { background: var(--fill); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .d { font-size: 14px; color: var(--label-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .v { font-size: 16px; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.row .age { font-size: 13px; color: var(--label-2); text-align: right; white-space: nowrap; }
.row .chev { width: 8px; height: 13px; flex: none; fill: none; stroke: var(--label-3); stroke-width: 2; stroke-linecap: round; }
.biz { color: var(--label-2); }
.empty { padding: 22px 16px; color: var(--label-2); font-size: 15px; }
.empty b { color: var(--label); font-weight: 600; display: block; margin-bottom: 2px; }

/* Metric tiles: one group of four per business. */
.tiles { margin-bottom: 34px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px 16px 16px; min-width: 0; }
.tile .k { font-size: 14px; color: var(--label-2); }
.tile .n { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; line-height: 1.2; }
.tile .c { font-size: 13px; color: var(--label-2); margin-top: 2px; }
.up { color: var(--green); }
.down { color: var(--red); }

/* Issue rows: tap opens the source, the circle menu acts on it. */
.issue .main { display: block; }
.issue .open { position: absolute; inset: 0; }
.issue .act {
  position: relative; z-index: 1; width: 44px; height: 44px; margin: -6px -10px -6px 0; border: 0; background: none;
  border-radius: 22px; cursor: pointer; color: var(--accent); display: grid; place-items: center;
}
.issue .act:hover { background: var(--fill); }
.issue .act svg { width: 22px; height: 22px; fill: currentColor; }
.issue.done { opacity: 0.45; }
.group-label { margin: 18px 20px 6px; font-size: 13px; color: var(--label-2); }
.group-label:first-child { margin-top: 0; }

.menu {
  margin: 0; inset: auto; border: 0; padding: 6px; min-width: 220px; border-radius: 12px; background: var(--card);
  color: var(--label); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18), 0 0 0 1px var(--sep);
}
.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px;
  font-size: 15px; cursor: pointer; min-height: 44px;
}
.menu button:hover { background: var(--accent); color: #fff; }
.menu hr { border: 0; border-top: 1px solid var(--sep); margin: 4px 6px; }

/* To-dos, Reminders style. */
.check {
  width: 24px; height: 24px; flex: none; border-radius: 50%; border: 1.6px solid var(--label-3); background: none; cursor: pointer;
  display: grid; place-items: center; padding: 0; position: relative;
}
.check::after { content: ""; position: absolute; inset: -10px; }
.check[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.check[aria-checked="true"]::before {
  content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg);
}
.todo.is-done .t { color: var(--label-2); text-decoration: line-through; text-decoration-color: var(--label-3); }
.todo .due { font-size: 13px; color: var(--label-2); }
.todo .due.late { color: var(--red); }
.todo .x { border: 0; background: none; color: var(--label-3); cursor: pointer; width: 44px; height: 44px; margin: -10px -12px -10px 0; border-radius: 22px; }
.todo .x:hover { color: var(--red); background: var(--fill); }
.add { display: flex; gap: 8px; align-items: center; padding: 8px 12px 8px 16px; flex-wrap: wrap; }
.add input[type="text"] { flex: 1 1 200px; border: 0; background: none; padding: 10px 0; font-size: 16px; min-height: 44px; }
.add input[type="text"]:focus { outline: none; }
.add input[type="date"], .add select {
  border: 1px solid var(--sep); background: var(--bg); border-radius: 8px; padding: 6px 8px; font-size: 14px; min-height: 36px;
}
.btn {
  border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
  padding: 0 16px; min-height: 44px; cursor: pointer;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.plain { background: var(--fill); color: var(--accent); }

/* Chart */
.chart { background: var(--card); border-radius: var(--radius); padding: 14px 16px 10px; position: relative; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--label-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart svg { display: block; overflow: visible; }
.chart .grid line { stroke: var(--sep); }
.chart .axis text { fill: var(--label-2); font-size: 11px; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--fill); }
.tip {
  position: absolute; pointer-events: none; background: var(--card); border-radius: 10px; padding: 8px 10px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16), 0 0 0 1px var(--sep); white-space: nowrap; display: none; z-index: 2;
}
.tip b { display: block; font-weight: 600; margin-bottom: 2px; }
.tip span { display: block; color: var(--label-2); }

.status { font-size: 14px; color: var(--label-2); }
.status.ok::before, .status.off::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status.ok::before { background: var(--green); }
.status.off::before { background: var(--label-3); }
.note { color: var(--label-2); font-size: 13px; margin: 8px 4px 0; }
.err { color: var(--red); }

.skeleton { height: 64px; border-radius: var(--radius); background: var(--card); margin-bottom: 12px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: rgba(30, 30, 30, 0.88); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 15px; font-weight: 500;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); transition: opacity 0.2s, transform 0.2s; z-index: 10;
  display: flex; gap: 14px; align-items: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: #64d2ff; font-weight: 600; cursor: pointer; padding: 4px; }

@media (max-width: 1000px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 5; flex-direction: row; justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--sep);
  }
  .brand { display: none; }
  .sidebar a { flex-direction: column; gap: 2px; font-size: 10px; padding: 4px 2px; min-width: 60px; min-height: 48px; color: var(--label-2); }
  .sidebar a svg { width: 24px; height: 24px; stroke: var(--label-2); }
  .sidebar a[aria-current="page"] { background: none; color: var(--accent); }
  .sidebar a[aria-current="page"] svg { stroke: var(--accent); }
  .sidebar .count { display: none; }
  main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 30px; }
  .tile .n { font-size: 22px; }
  .tile { padding: 12px 14px 14px; }
  .row .v { font-size: 15px; }
  .row .age { display: none; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
}

/* Horizontal bars (aging, funnel). */
.hbar { gap: 14px; }
.hbar .hl { width: 104px; flex: none; font-size: 15px; }
.hbar .track { flex: 1; height: 10px; border-radius: 5px; background: var(--fill); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 5px; background: var(--series-1); }
.hbar .v { min-width: 96px; }
.hbar .v .d { font-size: 12px; }
@media (max-width: 760px) { .hbar .hl { width: 84px; font-size: 14px; } .hbar .v { min-width: 76px; } }

/* Full-width dashboard grid: 12 columns on wide screens, one column below 1100px. */
.dash { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 0 24px; align-items: start; }
.dash > * { grid-column: span 12; min-width: 0; }
.dash > .span-3 { grid-column: span 3; } .dash > .span-4 { grid-column: span 4; } .dash > .span-6 { grid-column: span 6; } .dash > .span-8 { grid-column: span 8; }
.stack > .section:last-child { margin-bottom: 34px; }
@media (max-width: 1400px) { .dash > .span-3 { grid-column: span 6; } }
@media (max-width: 1100px) { .dash > .span-3, .dash > .span-4, .dash > .span-6, .dash > .span-8 { grid-column: span 12; } }

/* Business cards on Today: one per business, wraps for any count. */
.biz-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.biz-card { background: var(--card); border-radius: var(--radius); padding: 14px 16px 6px; min-width: 0; }
.biz-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.biz-head a:first-child { color: var(--label); font-weight: 600; font-size: 17px; display: inline-flex; align-items: center; gap: 8px; min-height: 32px; }
.biz-head .more { font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.mini { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin-bottom: 8px; }
.mini .k { font-size: 13px; color: var(--label-2); }
.mini .n { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.mini-chart .chart { padding: 6px 0 0; background: none; }
.biz-card .note { margin: 0 0 8px; }

/* Sidebar groups */
.nav-label { margin: 16px 10px 4px; font-size: 12px; color: var(--label-2); }
.sidebar .dot { margin: 0 5px; }
.phone { display: none !important; }
.more-row { border: 0; background: none; width: 100%; color: var(--accent); cursor: pointer; font-size: 15px; }
.plain-link { color: inherit; }
.btn-link { display: inline-grid; place-items: center; }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 12px; }

/* Reports */
.reports { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 28px; align-items: start; }
.report-nav { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow: auto; }
.report-nav .row { min-height: 44px; padding: 9px 14px; }
.report-nav .row .t { font-size: 15px; }
.report-nav .row.sel { background: var(--accent); }
.report-nav .row.sel .t { color: #fff; }
.report-nav .row.sel .chev { stroke: rgba(255, 255, 255, 0.8); }
.report-body .actions { display: flex; gap: 8px; }
.report-vis { margin-bottom: 16px; }
.table-wrap { background: var(--card); border-radius: var(--radius); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th, table.data td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--sep); white-space: nowrap; }
table.data th { font-weight: 600; font-size: 13px; color: var(--label-2); position: sticky; top: 0; background: var(--card); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 600; border-bottom: 0; }
table.data tbody tr:hover { background: var(--fill); }

/* Ask */
.ask { max-width: 860px; }
.qa { margin-bottom: 18px; }
.qa .q { justify-self: end; background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 18px 18px 4px 18px; margin-left: auto; width: fit-content; max-width: 80%; }
.qa .a { background: var(--card); padding: 12px 16px; border-radius: 18px 18px 18px 4px; margin-top: 8px; max-width: 92%; }
.qa .a p { margin: 0 0 8px; } .qa .a p:last-child { margin: 0; } .qa .a ul { margin: 4px 0 8px; padding-left: 20px; }
.qa .a.pending { color: var(--label-2); animation: pulse 1.2s ease-in-out infinite; }
.qa .a.err { color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip { border: 1px solid var(--sep); background: var(--card); color: var(--accent); border-radius: 18px; padding: 8px 14px; min-height: 44px; font-size: 15px; cursor: pointer; }
.chip:hover { background: var(--fill); }
.ask-form { display: flex; gap: 10px; align-items: flex-end; background: var(--card); border-radius: var(--radius); padding: 10px 10px 10px 16px; margin-top: 12px; }
.ask-form textarea { flex: 1; border: 0; background: none; resize: none; font-size: 16px; line-height: 1.4; padding: 8px 0; min-height: 44px; }
.ask-form textarea:focus { outline: none; }
.ai-form input[type="password"] { flex: 1 1 260px; border: 1px solid var(--sep); background: var(--bg); border-radius: 8px; padding: 8px 10px; min-height: 44px; font-size: 15px; }

.phone-only { display: none; }
@media (max-width: 900px) {
  .reports { grid-template-columns: minmax(0, 1fr); }
  .report-nav { position: static; max-height: none; }
  .reports.picked .report-nav { display: none; }
  .reports:not(.picked) .report-body { display: none; }
  .phone-only { display: inline-flex; align-items: center; min-height: 44px; font-size: 16px; margin-bottom: 4px; }
  .back::before { content: ""; width: 9px; height: 9px; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(45deg); margin-right: 6px; }
}
@media (max-width: 760px) {
  .desk, .nav-label { display: none !important; }
  .phone { display: flex !important; }
  .mini .n { font-size: 18px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .report-body .section-head { flex-wrap: wrap; }
  .ask-form { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@media print {
  .sidebar, .refresh, .actions, .report-nav, .toast { display: none !important; }
  .shell, .reports { display: block; }
  body, .table-wrap, .chart, .list { background: #fff; color: #000; }
}
