/* TruFit Dashboard. One dark theme, one type scale, a 4px spacing grid. */
:root {
  color-scheme: dark;
  /* surfaces */
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1d2129;
  --line: #262b34;
  --line-soft: #1f232b;
  /* ink */
  --text: #eceef2;
  --text-2: #aab1bd;
  --muted: #7d8592;
  /* status (fixed meaning, always shown with a label) */
  --good: #0ca30c;
  --bad: #e5484d;
  --bad-bg: rgba(229, 72, 77, 0.12);
  --idle: #6b7280;
  /* chart series, fixed order: insurance, cash, contact, other */
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #6b7280;
  --accent: #3987e5;

  /* type scale */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 16px;
  --fs-lg: 22px;
  --fs-xl: 36px;

  /* spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --gutter: 24px;
  --radius: 12px;
  --max: 1200px;
}
@media (max-width: 640px) {
  :root { --gutter: 16px; --fs-lg: 20px; --fs-xl: 30px; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-base)/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }

/* top bar and tabs */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.bar {
  max-width: var(--max); margin: 0 auto; padding: var(--s-4) var(--gutter) var(--s-3);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
}
.brand { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-md); font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-weight: 500; }
.mark { width: 20px; height: 20px; border-radius: 6px; background: var(--accent); position: relative; }
.mark::before, .mark::after { content: ""; position: absolute; background: #fff; border-radius: 2px; }
.mark::before { left: 5px; right: 5px; top: 6px; height: 2.5px; }
.mark::after { left: 8.75px; width: 2.5px; top: 6px; bottom: 4px; }
.fetched { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }

.tabs {
  max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--s-2);
}
.tab {
  appearance: none; border: 0; background: none; color: inherit; font: inherit; cursor: pointer;
  text-align: left; padding: var(--s-2) var(--s-3) var(--s-3); border-radius: 8px 8px 0 0;
  position: relative; min-width: 0;
}
.tab:hover { background: var(--surface); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-name { display: block; font-size: var(--fs-base); font-weight: 600; color: var(--text-2); }
.tab[aria-selected="true"] .tab-name { color: var(--text); }
.tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 2px;
  background: var(--text); border-radius: 2px;
}
.tab-state { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.is-problem .tab-state { color: var(--bad); font-weight: 500; }
.tab.is-ok .tab-state { color: var(--text-2); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--idle); }
.dot.ok { background: var(--good); }
.dot.problem { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.dot.waiting, .dot.not_connected { background: transparent; border: 1.5px solid var(--idle); }

.tab-name .dot { display: none; width: 6px; height: 6px; }
/* Phones: all five tabs fit; the dot sits before the name and the section header spells the status out. */
@media (max-width: 640px) {
  .tabs { gap: 0; padding: 0 calc(var(--gutter) - var(--s-2)); }
  .tab { padding: var(--s-2) var(--s-2) var(--s-3); text-align: center; }
  .tab-name { font-size: var(--fs-sm); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
  .tab-state { display: none; }
  .tab-name .dot { display: inline-block; }
  .tab[aria-selected="true"]::after { left: var(--s-2); right: var(--s-2); }
  .head { gap: var(--s-1); margin-bottom: var(--s-4); }
}

.notice {
  max-width: var(--max); margin: var(--s-4) auto 0; padding: var(--s-3) var(--s-4);
  border-radius: 8px; background: var(--bad-bg); color: var(--text); font-size: var(--fs-sm);
  width: calc(100% - 2 * var(--gutter));
}

/* sections */
main.wrap { padding-top: var(--s-6); padding-bottom: 64px; }
.loading { color: var(--muted); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
h1 { font-size: var(--fs-lg); line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; margin: 0; }
.sub { margin: var(--s-1) 0 0; color: var(--text-2); display: flex; align-items: center; gap: var(--s-2); }
.sub.problem { color: var(--bad); font-weight: 500; }
.stamp { color: var(--muted); font-size: var(--fs-xs); }

.card { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); }
.card + .card, .stats + .card { margin-top: var(--s-4); }
.stats > .card, .stores > .card { margin-top: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; padding: var(--s-5) var(--s-5) 0; }
.card-title { font-size: var(--fs-md); font-weight: 600; margin: 0; }
.card-body { padding: var(--s-4) var(--s-5) var(--s-5); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }
.stat { padding: var(--s-5); }
.stat-label { color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; }
.stat-value { font-size: var(--fs-xl); line-height: 1.1; font-weight: 600; letter-spacing: -0.02em; margin-top: var(--s-2); font-variant-numeric: tabular-nums; }
.stat-note { margin-top: var(--s-2); color: var(--muted); font-size: var(--fs-xs); }
.stat-note .up { color: var(--text-2); }
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-2); }
  .stat { padding: var(--s-4) var(--s-3); }
  .stat-label { font-size: var(--fs-xs); }
  .stat-note { display: none; }
}

/* legend and chart */
.legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart { width: 100%; height: 260px; display: block; }
.chart text { fill: var(--muted); font-size: 12px; font-family: inherit; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line-soft); stroke-width: 1; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .col.dim { opacity: 0.45; }
@media (max-width: 640px) { .chart { height: 200px; } }

.tip {
  position: fixed; z-index: 10; pointer-events: none; min-width: 168px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: var(--s-2) var(--s-3); font-size: var(--fs-sm); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.tip-title { font-weight: 600; margin-bottom: var(--s-1); }
.tip-row { display: flex; align-items: center; gap: var(--s-2); color: var(--text-2); }
.tip-row span:nth-child(2) { flex: 1; }
.tip-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* tables */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--line); }
.table td { padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .muted { color: var(--muted); }
.table tr.is-problem td { background: var(--bad-bg); }
.status { display: inline-flex; align-items: center; gap: var(--s-2); white-space: nowrap; }
.warn { display: block; color: var(--muted); font-size: var(--fs-xs); margin-top: 2px; }
@media (max-width: 720px) {
  .table.stack thead { display: none; }
  .table.stack tr { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line-soft); }
  .table.stack tr:last-child { border-bottom: 0; }
  .table.stack td { padding: 0; border: 0; background: none; }
  .table.stack td[data-k="check"] { font-weight: 500; }
  .table.stack td[data-k="detail"], .table.stack td[data-k="since"] { grid-column: 1 / -1; color: var(--text-2); font-size: var(--fs-sm); }
  .table.stack td[data-k="since"] { color: var(--muted); font-size: var(--fs-xs); }
  .table.stack tr.is-problem { background: var(--bad-bg); }
  .table.stack tr.is-problem td { background: none; }
}

details.daily { border-top: 1px solid var(--line-soft); }
details.daily summary { cursor: pointer; padding: var(--s-4) var(--s-5); color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; list-style: none; }
details.daily summary::-webkit-details-marker { display: none; }
details.daily summary::before { content: "›"; display: inline-block; width: 1em; transition: transform 0.15s; }
details.daily[open] summary::before { transform: rotate(90deg); }
details.daily .table-scroll { max-height: 360px; overflow: auto; border-top: 1px solid var(--line-soft); }

/* store cards (reviews) */
.stores { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s-4); }
.store-name { font-weight: 600; font-size: var(--fs-md); }
.store-rating { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.02em; margin-top: var(--s-2); line-height: 1.1; }
.store-rating small { font-size: var(--fs-base); color: var(--muted); font-weight: 500; margin-left: var(--s-1); letter-spacing: 0; }
.store-facts { display: flex; gap: var(--s-5); margin-top: var(--s-3); color: var(--text-2); font-size: var(--fs-sm); }
.store-facts b { color: var(--text); font-variant-numeric: tabular-nums; }
.store-facts .bad b, .store-facts .bad { color: var(--bad); }

/* not connected yet */
.empty { padding: 56px var(--s-5); text-align: center; }
.empty-icon { width: 40px; height: 40px; margin: 0 auto var(--s-4); border-radius: 50%; border: 1.5px dashed var(--idle); }
.empty-title { font-size: var(--fs-md); font-weight: 600; }
.empty-text { color: var(--text-2); margin: var(--s-2) auto 0; max-width: 420px; }
