:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #09090b;
  --muted: #f4f4f5;
  --muted-fg: #71717a;
  --border: #e4e4e7;
  --selected: #f4f4f5;
  --positive: #15803d;
  --negative: #b91c1c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  --radius: 12px;
  --side: 248px;
  --dot: rgb(0 0 0 / 0.14);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09090b;
  --fg: #fafafa;
  --muted: #18181b;
  --muted-fg: #a1a1aa;
  --border: #27272a;
  --selected: #18181b;
  --positive: #4ade80;
  --negative: #f87171;
  --shadow: none;
  --dot: rgb(255 255 255 / 0.16);
}

@font-face {
  font-family: Geist;
  src: url("/fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 Geist, ui-sans-serif, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}
svg text { font-family: Geist, sans-serif; }
button, a { touch-action: manipulation; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  min-height: 100%;
}
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--bg);
}
.side-top, .brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
.brand span { color: var(--muted-fg); font-weight: 500; }
#theme {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted-fg);
  font-size: 12px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
}
.nav button[aria-pressed="true"] { background: var(--muted); }
.nav .name { font-weight: 600; }
.nav .amt { font-variant-numeric: tabular-nums; color: var(--muted-fg); white-space: nowrap; }
.nav button[aria-pressed="true"] .amt { color: var(--fg); }

.sources { color: var(--muted-fg); font-size: 12px; margin-top: auto; }
.sources summary { cursor: pointer; font-weight: 600; color: var(--fg); display: flex; align-items: center; }
.sources summary::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 99px;
  background: var(--positive);
}
.sources summary[data-state="sync"]::before { background: #eab308; }
.sources ul { list-style: none; padding: 8px 0 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.sources li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sources strong { color: var(--fg); font-weight: 600; }
.sources .err { color: var(--negative); }

main { padding: 28px 32px 48px; max-width: 1240px; min-width: 0; }
.periods {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  margin: 0 0 18px;
}
.periods::-webkit-scrollbar { display: none; }
.periods button {
  flex: none;
  min-height: 36px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 600;
  color: var(--muted-fg);
}
.periods button[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "copy mix"
    "chart chart";
  column-gap: 32px;
  row-gap: 18px;
  align-items: center;
}
.hero-copy { grid-area: copy; min-width: 0; container-type: inline-size; }
.kicker { margin: 0 0 6px; font-weight: 600; color: var(--muted-fg); }
.hero-value {
  margin: 0;
  max-width: 100%;
  font-size: clamp(32px, 8.4cqi, 56px);
  line-height: 0.95;
  font-weight: 600;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.delta { margin: 8px 0 0; min-height: 1.2em; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.delta svg { display: block; }
.delta.up { color: var(--positive); }
.delta.down { color: var(--negative); }
.meters { display: flex; flex-wrap: wrap; gap: 14px 18px; margin-top: 16px; }
.meter { display: flex; align-items: center; gap: 8px; min-width: 0; }
.meter b { display: block; font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: -0.02em; }
.meter span { color: var(--muted-fg); font-size: 11px; font-weight: 600; }
.meter svg { display: block; flex: none; }
.mix { grid-area: mix; display: flex; align-items: center; gap: 12px; min-width: 0; }
.mix svg { width: 148px; height: 148px; flex: none; }
.mix svg path { cursor: pointer; }
.mix ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; width: 132px; min-width: 0; }
.mix button {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  border: 0;
  background: transparent;
  padding: 0;
  width: 100%;
  text-align: left;
  color: var(--muted-fg);
}
.mix button[aria-pressed="true"], .mix button:hover { color: var(--fg); }
.mix .pct { font-variant-numeric: tabular-nums; font-weight: 600; }
.mix .slice-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chart-wrap { grid-area: chart; min-width: 0; }
.weeks {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 22px;
  align-items: end;
  margin-top: 22px;
  min-width: 0;
}
.weeks-stats { display: flex; gap: 18px; padding-bottom: 2px; }
.weeks-stat b {
  display: block;
  font-size: 28px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.weeks-stat span { color: var(--muted-fg); font-size: 11px; font-weight: 600; }
.weeks-stat.up b, .week-col b.up { color: var(--positive); }
.weeks-stat.down b, .week-col b.down { color: var(--negative); }
.week-cols {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  min-width: 0;
}
.week-cols::-webkit-scrollbar { display: none; }
.week-col {
  flex: 1 1 0;
  min-width: 46px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
}
.week-bar {
  height: 64px;
  display: flex;
  align-items: flex-end;
}
.week-bar i {
  display: block;
  width: 100%;
  height: 0;
  background: var(--fg);
  border-radius: 3px 3px 0 0;
}
.week-col.partial .week-bar i {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--fg);
}
.week-col b, .week-col span {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.week-col .week-amt, .week-col span:last-child { color: var(--muted-fg); font-weight: 500; }
.chart {
  position: relative;
  height: 188px;
  border-radius: var(--radius);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 14px 14px;
  background-position: center bottom;
}
.chart svg { display: block; width: 100%; height: 100%; }
.chart .tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: var(--fg);
  color: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transform: translate(-50%, -120%);
}
.chart .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted-fg);
}
.swatch { width: 8px; height: 8px; border-radius: 99px; background: var(--swatch); display: inline-block; }

.table-wrap {
  margin-top: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--bg); z-index: 1; min-width: 180px; }
th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-fg);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 2;
}
th:first-child { z-index: 3; }
th button { border: 0; background: transparent; padding: 0; font: inherit; font-weight: 600; color: inherit; }
th[aria-pressed="true"] { color: var(--fg); box-shadow: inset 0 -2px 0 var(--fg); }
td.selected, th.selected { background: var(--selected); }
th.selected:first-child, td.selected:first-child { background: var(--selected); }
tr.company td { font-weight: 600; }
tr.segment td:first-child { padding-left: 28px; color: var(--muted-fg); font-weight: 500; }
tr.total td { border-top: 2px solid var(--fg); border-bottom: 0; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.share { display: block; height: 2px; margin-top: 6px; background: var(--border); border-radius: 99px; overflow: hidden; width: 92px; }
.share i { display: block; height: 100%; background: var(--fg); border-radius: 99px; }
.partial { color: var(--muted-fg); }
.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 99px;
  background: #eab308;
  vertical-align: 1px;
}
.login-card {
  width: min(360px, calc(100% - 32px));
  margin: 18vh auto 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 4px 0 18px; font-size: 32px; font-weight: 600; letter-spacing: -0.04em; }
.login-card label { display: block; font-weight: 600; margin-bottom: 6px; }
.login-card input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
}
.login-card button {
  margin-top: 12px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
}
.login-error { color: var(--negative); margin: 10px 0 0; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: sticky;
    top: 0;
    z-index: 5;
    height: auto;
    gap: 10px;
    padding: max(12px, env(safe-area-inset-top)) 12px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    margin: 0 -12px;
    padding: 0 12px 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav button {
    width: auto;
    min-width: max-content;
    min-height: 44px;
    flex: none;
    scroll-snap-align: start;
    padding: 8px 12px;
  }
  .sources { display: none; }
  main {
    padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  }
  .periods { margin-bottom: 14px; }
  .periods button { min-height: 40px; padding: 8px 14px; }
  .hero {
    grid-template-columns: 1fr;
    grid-template-areas: "copy" "mix" "chart";
    row-gap: 16px;
  }
  .weeks { grid-template-columns: 1fr; gap: 12px; margin-top: 18px; }
  .weeks-stat b { font-size: 26px; }
  .week-col { flex: 0 0 64px; }
  .hero-value { font-size: clamp(34px, 11cqi, 48px); }
  .mix { justify-self: start; }
  .mix svg { width: 120px; height: 120px; }
  .chart { height: 168px; }
  .table-wrap { margin-inline: -16px; border-radius: 0; border-left: 0; border-right: 0; }
  th:first-child, td:first-child { min-width: 128px; }
  .login-card { margin-top: max(10vh, env(safe-area-inset-top)); }
}
