/* Twinkle Insights — plum & gold, porcelain sheet */

:root {
  color-scheme: light;
  --band: #2a1236;
  --band-2: #3b1a4b;
  --on-band: #fbf6fd;
  --on-band-2: rgba(251, 246, 253, 0.68);
  --on-band-line: rgba(251, 246, 253, 0.14);
  --gold: #e0b45e;
  --gold-ink: #85590f;
  --bg: #ffffff;
  --surface-2: #f5f3f8;
  --ink: #1f1526;
  --ink-2: #5f5468;
  --ink-3: #8b8195;
  --line: #ebe6ef;
  --accent: #6b3584;         /* single-series bars */
  --accent-soft: #e9dff0;
  --good: #1d7a4b;
  --bad: #b23a31;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --s-other: #9b93a3;
  --tabbar: rgba(255, 255, 255, 0.86);
  --radius-sheet: 24px;
  --gutter: 20px;
  --serif: 'Instrument Serif', 'Times New Roman', serif;
  --sans: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --band: #200d2a; --band-2: #2d1439;
    --gold-ink: #e0b45e;
    --bg: #150d1a; --surface-2: #20162a;
    --ink: #f3edf6; --ink-2: #c0b4c9; --ink-3: #8f8399;
    --line: #2c2234;
    --accent: #b98bd0; --accent-soft: #33243f;
    --good: #57c08a; --bad: #ef7d73;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --s-other: #6f6578;
    --tabbar: rgba(21, 13, 26, 0.86);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --band: #200d2a; --band-2: #2d1439; --gold-ink: #e0b45e;
  --bg: #150d1a; --surface-2: #20162a; --ink: #f3edf6; --ink-2: #c0b4c9; --ink-3: #8f8399;
  --line: #2c2234; --accent: #b98bd0; --accent-soft: #33243f; --good: #57c08a; --bad: #ef7d73;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --s-other: #6f6578; --tabbar: rgba(21, 13, 26, 0.86);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--band); }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: linear-gradient(var(--band) 0 40vh, var(--bg) 40vh);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
svg { flex: none; }

/* Wordmark */
.wordmark {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--serif); font-size: 26px; letter-spacing: 0.01em; color: var(--on-band);
}
.wordmark .star { width: 16px; height: 16px; fill: var(--gold); }
.wordmark-lg { font-size: 48px; gap: 12px; }
.wordmark-lg .star { width: 28px; height: 28px; }

/* Login */
.login {
  min-height: 100vh; min-height: 100dvh;
  background: radial-gradient(120% 70% at 50% 0%, var(--band-2), var(--band));
  color: var(--on-band);
  display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + 40px) 28px calc(env(safe-area-inset-bottom) + 40px);
}
.login-inner { width: 100%; max-width: 360px; }
.login-sub { color: var(--on-band-2); margin: 8px 0 40px; font-size: 17px; }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 14px; color: var(--on-band-2); margin-bottom: 6px; }
.field input {
  width: 100%; height: 52px; border-radius: 14px; padding: 0 16px;
  font: inherit; font-size: 17px; color: var(--on-band);
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--on-band-line);
  -webkit-appearance: none; appearance: none;
}
.field input:focus { outline: none; border-color: var(--gold); background: rgba(255, 255, 255, 0.1); }
.field-light span { color: var(--ink-2); }
.field-light input { color: var(--ink); background: var(--surface-2); border-color: var(--line); }
.login-error { min-height: 22px; margin: 0 0 12px; color: #ffb4a8; font-size: 15px; }
.bottom-sheet .login-error { color: var(--bad); }
.btn-gold, .btn-plum, .btn-quiet {
  display: block; width: 100%; height: 52px; border-radius: 14px;
  font-weight: 600; font-size: 17px; text-align: center;
}
.btn-gold { background: var(--gold); color: #2a1236; }
.btn-gold:disabled { opacity: 0.6; }
.btn-plum { background: var(--band); color: var(--on-band); }
.btn-quiet { background: var(--surface-2); color: var(--ink); margin-top: 10px; }
.btn-quiet.danger { color: var(--bad); }

/* Band (header) */
.band {
  background: var(--band);
  color: var(--on-band);
  padding: calc(env(safe-area-inset-top) + 8px) 0 44px;
  position: relative;
  overflow: hidden;
}
.band::after { /* faint star glint behind the figure */
  content: ''; position: absolute; right: -60px; top: 40px; width: 260px; height: 260px;
  background: radial-gradient(closest-side, rgba(224, 180, 94, 0.16), transparent);
  pointer-events: none;
}
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--gutter); height: 48px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--on-band); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: var(--on-band-line); }
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.demo-tag { font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--gold); color: var(--gold); margin-right: 4px; }

.controls { padding: 10px 0 0; }
.branch-pill {
  margin: 0 var(--gutter); display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px 0 12px; border-radius: 99px;
  background: var(--on-band-line); color: var(--on-band); font-weight: 600; font-size: 15px;
}
.branch-pill svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.branch-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.periods {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 14px var(--gutter) 2px; scroll-padding: var(--gutter);
}
.periods::-webkit-scrollbar { display: none; }
.periods button {
  flex: none; height: 32px; padding: 0 14px; border-radius: 99px;
  color: var(--on-band-2); font-size: 15px; font-weight: 500; white-space: nowrap;
  border: 1px solid var(--on-band-line);
}
.periods button[aria-selected="true"] { background: var(--gold); border-color: var(--gold); color: #2a1236; font-weight: 600; }

.hero { padding: 26px var(--gutter) 0; position: relative; z-index: 1; }
.hero-label { margin: 0; color: var(--on-band-2); font-size: 15px; }
.hero-figure {
  margin: 2px 0 0; font-family: var(--serif); font-weight: 400;
  font-size: clamp(52px, 15vw, 72px); line-height: 1.02; letter-spacing: -0.01em;
  font-variant-numeric: lining-nums;
}
.hero-figure .rs { color: var(--gold); font-size: 0.62em; margin-right: 4px; vertical-align: 0.32em; }
.hero-figure .paise { color: var(--on-band-2); font-size: 0.45em; }
.hero-delta { margin: 8px 0 0; font-size: 15px; color: var(--on-band-2); min-height: 22px; }
.hero-delta .chip { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; margin-right: 6px; padding: 2px 8px; border-radius: 99px; }
.hero-delta .up { background: rgba(87, 192, 138, 0.18); color: #8fe3b6; }
.hero-delta .down { background: rgba(239, 125, 115, 0.18); color: #ffb0a8; }
.hero-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); margin: 24px 0 0;
  border-top: 1px solid var(--on-band-line); padding-top: 14px;
}
.hero-stats div + div { border-left: 1px solid var(--on-band-line); padding-left: 12px; }
.hero-stats dt { font-size: 13px; color: var(--on-band-2); }
.hero-stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 600; white-space: nowrap; }

/* Sheet */
.sheet {
  position: relative; margin-top: -24px; background: var(--bg);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 96px);
  min-height: 60vh;
}
.ptr { position: absolute; left: 50%; top: 10px; width: 30px; height: 30px; margin-left: -15px; opacity: 0; display: grid; place-items: center; }
.ptr svg { width: 22px; height: 22px; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; }
.banner { margin: 14px var(--gutter) 0; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); color: var(--ink-2); font-size: 15px; }
.banner.error { color: var(--bad); }

.block { padding: 22px var(--gutter) 24px; }
.block + .block { border-top: 8px solid var(--surface-2); }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.block-head h2 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.link { color: var(--gold-ink); font-weight: 600; font-size: 15px; }
.hint { margin: -6px 0 14px; color: var(--ink-3); font-size: 14px; }
.updated { text-align: center; color: var(--ink-3); font-size: 13px; padding: 4px var(--gutter) 0; }
.empty { color: var(--ink-3); font-size: 15px; padding: 18px 0; text-align: center; }

/* Legend */
.legend { display: flex; gap: 12px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.legend i.prev { background: none; height: 0; border-top: 2px dashed var(--ink-3); border-radius: 0; width: 14px; }

/* Trend chart */
.readout { min-height: 46px; }
.readout .r-date { font-size: 13px; color: var(--ink-3); }
.readout .r-val { font-size: 20px; font-weight: 600; }
.readout .r-prev { font-size: 13px; color: var(--ink-2); margin-left: 6px; font-weight: 400; }
.chart { position: relative; height: 190px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-3); font-size: 11px; font-family: var(--sans); }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { opacity: 0.35; }
.chart .prev-line { fill: none; stroke: var(--ink-3); stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; }

/* Ranked rows */
.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 12px; padding: 11px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row-name { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.row-val { font-weight: 600; text-align: right; }
.row-sub { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--ink-3); font-size: 13px; }
.meter { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.meter b { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.rank { width: 22px; color: var(--ink-3); font-size: 14px; font-weight: 500; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* Branch cards (branches tab) */
.branch-row { display: block; width: 100%; text-align: left; padding: 16px 0; }
.branch-row + .branch-row { border-top: 1px solid var(--line); }
.branch-row:active { background: var(--surface-2); }
.br-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.br-name { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 9px; }
.br-net { font-family: var(--serif); font-size: 30px; line-height: 1.1; margin-top: 4px; font-variant-numeric: lining-nums; }
.br-meta { display: flex; gap: 18px; color: var(--ink-2); font-size: 14px; margin-top: 6px; }
.br-meta b { color: var(--ink); font-weight: 600; }
.change { font-size: 14px; font-weight: 600; white-space: nowrap; }
.change.up { color: var(--good); }
.change.down { color: var(--bad); }
.change.flat { color: var(--ink-3); font-weight: 500; }

/* Payment stack */
.stack { display: flex; height: 14px; border-radius: 99px; overflow: hidden; gap: 2px; background: var(--bg); }
.stack span { display: block; height: 100%; min-width: 3px; }
.pay-legend { margin-top: 12px; }

/* Segmented */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 11px; padding: 3px; margin-bottom: 10px; }
.segmented button { height: 34px; border-radius: 9px; font-size: 15px; font-weight: 500; color: var(--ink-2); }
.segmented button[aria-selected="true"] { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(31, 21, 38, 0.12); }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 4px);
  background: var(--tabbar);
  -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; color: var(--ink-3); font-size: 11px; font-weight: 500; }
.tabbar svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* Bottom sheets */
.scrim { position: fixed; inset: 0; background: rgba(20, 8, 26, 0.45); z-index: 30; }
.bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px var(--gutter) calc(env(safe-area-inset-bottom) + 20px);
  max-height: 80vh; overflow-y: auto;
  animation: sheet-up 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes sheet-up { from { transform: translateY(100%); } }
.grabber { width: 38px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
.bottom-sheet h3 { margin: 0 0 12px; font-size: 19px; }
.options button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 4px; font-size: 17px; text-align: left; }
.options button + button { border-top: 1px solid var(--line); }
.options button[aria-checked="true"]::after { content: ''; margin-left: auto; width: 8px; height: 14px; border: solid var(--accent); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-3px, -3px); }
.range-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.install-steps { padding-left: 20px; margin: 0 0 20px; color: var(--ink-2); }
.install-steps li { margin-bottom: 10px; }
.install-steps strong { color: var(--ink); }
.inline-ico { width: 18px; height: 18px; vertical-align: -3px; fill: none; stroke: var(--s1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Tooltip for tap-to-inspect bars */
.tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  background: var(--ink); color: var(--bg); font-size: 13px; padding: 6px 10px; border-radius: 9px;
  transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap;
}

/* Loading shimmer on numbers */
.loading .hero-figure, .loading .hero-stats dd { opacity: 0.45; transition: opacity 0.2s; }

@media (min-width: 720px) {
  .sheet, .band > * { max-width: 680px; margin-left: auto; margin-right: auto; }
  .sheet { margin-top: -24px; }
  .tabbar { max-width: 680px; margin: 0 auto; border-radius: 20px 20px 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
