/* VAVADA Media Hub — Telegram Mini App. Tokens follow Telegram's theme vars, with own light/dark fallbacks. */

:root {
  color-scheme: light;
  --d-bg: #f0f2f5;
  --d-card: #ffffff;
  --d-text: #14171a;
  --d-hint: #5b636d;
  --d-sep: #e2e5ea;
  --d-accent: #2273d4;
  --d-accent-text: #ffffff;

  /* platform series, fixed order (validated categorical order, light steps) */
  --c0: #257de0; --c1: #f47230; --c2: #00b894; --c3: #f2a600; --c4: #ee7fac; --c5: #008a17;

  --ok: #0aac23; --warn: #f2a600; --bad: #dc3c3d; --idle: #8a919b;
  --ok-text: #157a2b; --warn-text: #8a5a00; --bad-text: #b8292a;
  --grid: rgba(20, 23, 26, .09);
  --track: rgba(20, 23, 26, .08);
  --shadow: 0 6px 24px rgba(10, 20, 40, .16);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --d-bg: #0e1013; --d-card: #1a1d22; --d-text: #eceef1; --d-hint: #9ba2ac; --d-sep: #2b2f36;
    --d-accent: #4c9ef0; --d-accent-text: #0e1013;
    --c0: #338ced; --c1: #e76624; --c2: #00a888; --c3: #d28e05; --c4: #e24d8b; --c5: #0aac23;
    --ok: #0aac23; --warn: #fbb315; --bad: #eb5a5b; --idle: #7c838d;
    --ok-text: #4cd264; --warn-text: #f6bf45; --bad-text: #f37b7c;
    --grid: rgba(236, 238, 241, .1); --track: rgba(236, 238, 241, .1);
    --shadow: 0 8px 28px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --d-bg: #0e1013; --d-card: #1a1d22; --d-text: #eceef1; --d-hint: #9ba2ac; --d-sep: #2b2f36;
  --d-accent: #4c9ef0; --d-accent-text: #0e1013;
  --c0: #338ced; --c1: #e76624; --c2: #00a888; --c3: #d28e05; --c4: #e24d8b; --c5: #0aac23;
  --ok: #0aac23; --warn: #fbb315; --bad: #eb5a5b; --idle: #7c838d;
  --ok-text: #4cd264; --warn-text: #f6bf45; --bad-text: #f37b7c;
  --grid: rgba(236, 238, 241, .1); --track: rgba(236, 238, 241, .1);
  --shadow: 0 8px 28px rgba(0, 0, 0, .55);
}

/* Telegram theme first, own tokens as fallback */
:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--d-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--d-card)));
  --text: var(--tg-theme-text-color, var(--d-text));
  --hint: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, var(--d-hint)));
  --sep: var(--tg-theme-section-separator-color, var(--d-sep));
  --accent: var(--tg-theme-button-color, var(--d-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--d-accent-text));
}
/* Telegram's hint grey is often below 4.5:1; pull it toward the text color. */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --hint: color-mix(in srgb, var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, var(--d-hint))) 72%, var(--text));
    --grid: color-mix(in srgb, var(--text) 10%, transparent);
    --track: color-mix(in srgb, var(--text) 9%, transparent);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
}
main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
main.busy { opacity: .55; transition: opacity .15s; }

/* header */
.top { display: flex; flex-direction: column; gap: 4px; }
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--hint); }
.title { margin: 0; font-size: 28px; line-height: 1.1; font-weight: 700; letter-spacing: -.01em; }
.lead { margin: 6px 0 0; color: var(--hint); max-width: 62ch; }
.lead:empty { display: none; }
.lead b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.daynav {
  margin-top: 10px; display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 12px; padding: 4px; align-self: stretch;
}
.daynav[hidden] { display: none; }
.navbtn {
  flex: 0 0 auto; width: 44px; height: 40px; border: 0; border-radius: 9px;
  background: transparent; color: var(--accent); cursor: pointer; font-size: 16px;
}
.navbtn:hover:not(:disabled) { background: var(--track); }
.navbtn:disabled { color: var(--hint); opacity: .45; cursor: default; }
.daylabel { flex: 1 1 auto; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.daylabel small { display: block; font-weight: 400; font-size: 12px; color: var(--hint); }

/* state / errors */
.state { background: var(--card); border-radius: 14px; padding: 20px 16px; text-align: center; }
.state[hidden] { display: none; }
.state-text { margin: 0; }
.state .retry {
  margin-top: 12px; border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}

/* cards */
.card { background: var(--card); border-radius: 16px; padding: 16px; min-width: 0; }
.sec { display: flex; flex-direction: column; gap: 8px; }
.h2 { margin: 0; font-size: 18px; line-height: 1.25; font-weight: 650; }
.h3 { margin: 12px 0 0; font-size: 15px; font-weight: 600; }
.sub { margin: 0; color: var(--hint); font-size: 13px; }
.empty { margin: 0; color: var(--hint); font-size: 14px; padding: 8px 0; }

/* health pills */
.health { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pill {
  display: grid; grid-template-columns: 10px minmax(0, 1fr); column-gap: 8px; align-items: center; align-content: start;
  background: var(--card); border-radius: 12px; padding: 8px 10px; font-size: 13px; min-width: 0;
}
.pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--idle); }
.pill.ok .dot { background: var(--ok); }
.pill.partial .dot { background: var(--warn); }
.pill.missing .dot { background: var(--bad); }
.pill.waiting .dot { background: transparent; border: 2px solid var(--idle); }
.pill-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-state { grid-column: 2; color: var(--hint); font-size: 12px; line-height: 1.3; }
.pill.partial .pill-state { color: var(--warn-text); }
.pill.missing .pill-state { color: var(--bad-text); }

/* hero */
.hero { display: flex; flex-direction: column; gap: 6px; }
.hero-label { margin: 0; font-size: 14px; font-weight: 400; color: var(--hint); }
.big {
  margin: 0; font-size: clamp(40px, 13vw, 84px); line-height: 1; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.delta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--hint); font-size: 14px; }
.chip {
  display: inline-block; font-weight: 600; font-variant-numeric: tabular-nums; padding: 2px 9px; border-radius: 999px;
  font-size: 13px; background: var(--track); color: var(--text); white-space: nowrap;
}
.chip.up { color: var(--ok-text); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.chip.down { color: var(--bad-text); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.spark { width: 100%; position: relative; }
.spark-hero { height: 76px; margin-top: 6px; }
.spark svg, .chart svg { display: block; overflow: visible; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--card); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-label { margin: 0; font-size: 13px; color: var(--hint); }
.kpi-val { margin: 0; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-note { margin: 0; font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }
.kpi.alert .kpi-val { color: var(--bad-text); }

/* platform cards */
.plats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 4px; }
@media (min-width: 560px) { .health, .plats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.plat {
  border: 1px solid var(--sep); border-radius: 12px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.plat-top { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--hint); min-width: 0; }
.plat-top { align-items: flex-start; line-height: 1.25; }
.plat-top .sw { margin-top: 3px; }
.plat-top span { min-width: 0; overflow-wrap: anywhere; }
.plat-val { margin: 0; font-size: clamp(17px, 5.2vw, 21px); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plat-meta { margin: 0; font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }
.plat-flag { margin: 0; font-size: 12px; color: var(--warn-text); }
.plat-flag.missing { color: var(--bad-text); }
.plat-flag.waiting { color: var(--hint); }
.plat .spark { height: 34px; margin-top: auto; padding-top: 4px; }
.plat .delta { font-size: 12px; }

/* swatches & legend */
.sw { flex: 0 0 auto; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--idle); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--hint); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.b0 { background: var(--c0); } .b1 { background: var(--c1); } .b2 { background: var(--c2); }
.b3 { background: var(--c3); } .b4 { background: var(--c4); } .b5 { background: var(--c5); }
.f0 { fill: var(--c0); } .f1 { fill: var(--c1); } .f2 { fill: var(--c2); }
.f3 { fill: var(--c3); } .f4 { fill: var(--c4); } .f5 { fill: var(--c5); }
.s0 { stroke: var(--c0); } .s1 { stroke: var(--c1); } .s2 { stroke: var(--c2); }
.s3 { stroke: var(--c3); } .s4 { stroke: var(--c4); } .s5 { stroke: var(--c5); }
.fa { fill: var(--accent); } .sa { stroke: var(--accent); } .ba { background: var(--accent); }

/* SVG charts */
.chart { width: 100%; position: relative; min-height: 120px; }
.ax text { fill: var(--hint); font-size: 11px; font-variant-numeric: tabular-nums; }
.ax text.cur { fill: var(--text); font-weight: 600; }
.grid line { stroke: var(--grid); stroke-width: 1; }
.grid line.zero { stroke: var(--hint); stroke-opacity: .5; }
.hl { fill: var(--text); opacity: 0; }
.hl.on { opacity: .07; }
.hit { fill: transparent; cursor: pointer; outline: none; }
.hit:focus-visible { stroke: var(--accent); stroke-width: 2; }
.gapmark { fill: none; stroke: var(--hint); stroke-opacity: .6; stroke-dasharray: 2 3; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { opacity: .13; }
.dot-end { stroke: var(--card); stroke-width: 2; }
.pt-partial { fill: var(--card); stroke-width: 1.5; }
.pt-partial.end { stroke-width: 2; }
.neg { stroke: var(--bad); stroke-width: 1; }
.spark-note { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.spark-note .ring { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--accent); flex: 0 0 auto; }
.marker { stroke: var(--card); stroke-width: 2; opacity: 0; pointer-events: none; }
.marker.on { opacity: 1; }
.guide { stroke: var(--hint); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; pointer-events: none; }
.guide.on { opacity: .8; }

/* top 7 days */
.hbars { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hb { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: baseline; font-size: 14px; }
.hb-name { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.hb-name .sw { margin-top: 5px; }
.hb-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.hb-text span { overflow-wrap: anywhere; }
.hb-text small { color: var(--hint); font-size: 12px; }
.hb-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.hb-track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.hb-fill { height: 100%; border-radius: 4px; min-width: 2px; }

/* heatmap */
.heat-scroll {
  overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  margin-top: 4px; padding-bottom: 4px; scrollbar-width: thin;
}
.heat { display: grid; gap: 2px; font-size: 11px; width: max-content; min-width: 100%; }
.heat-corner, .heat-lab {
  position: sticky; left: 0; z-index: 1; background: var(--card); padding-right: 6px;
}
.heat-lab { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; }
.heat-lab span {
  overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  line-clamp: 2; font-size: 11px; line-height: 1.15; overflow-wrap: anywhere;
}
.heat-day { text-align: center; color: var(--hint); font-variant-numeric: tabular-nums; padding-bottom: 2px; line-height: 1.15; }
.heat-day.cur { color: var(--text); font-weight: 700; }
.cell { position: relative; height: 26px; border-radius: 4px; background: var(--track); cursor: pointer; }
.cell .fill { position: absolute; inset: 0; border-radius: 4px; }
.cell.na { background: transparent; border: 1px dashed color-mix(in srgb, var(--hint) 70%, transparent); }
.cell.zero { background: var(--track); }
.cell.on, .cell:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.heat-key { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 12px; color: var(--hint); margin-top: 4px; }
.heat-key span { display: inline-flex; align-items: center; gap: 6px; }
.ramp { display: inline-flex; gap: 2px; }
.ramp i { width: 14px; height: 10px; border-radius: 2px; background: var(--hint); }
.ramp i:nth-child(1) { opacity: .15; } .ramp i:nth-child(2) { opacity: .35; } .ramp i:nth-child(3) { opacity: .6; } .ramp i:nth-child(4) { opacity: 1; }
.na-key { width: 14px; height: 10px; border-radius: 2px; border: 1px dashed var(--hint); display: inline-block; }

/* budget */
.budget { list-style: none; margin: 0; padding: 0; }
.bud {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px;
  padding: 12px 0; border-top: 1px solid var(--sep); font-variant-numeric: tabular-nums;
}
.bud:first-child { border-top: 0; padding-top: 4px; }
.bud-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; font-size: 14px; }
.bud-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bud-eta { text-align: right; grid-row: 1 / span 2; grid-column: 2; align-self: start; }
.bud-eta strong { display: block; font-size: 16px; white-space: nowrap; }
.bud-eta small { display: block; font-size: 12px; color: var(--hint); white-space: nowrap; }
.bud.risk .bud-eta strong { color: var(--bad-text); }
.bud.unknown .bud-eta strong { color: var(--hint); font-weight: 600; }
.bud-meta { grid-column: 1; margin: 0; font-size: 12px; color: var(--hint); }
.bud-note { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--hint); font-style: italic; }
.bud-track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bud-fill { height: 100%; border-radius: 4px; }
.bud.risk .bud-fill { background: var(--bad); }

/* notes */
.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.note { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 8px; font-size: 14px; }
.note-ic { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; background: var(--track); color: var(--hint); }
.note.signal .note-ic { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn-text); }
.note p { margin: 0; overflow-wrap: anywhere; }
.note b { font-weight: 600; }

.foot { color: var(--hint); font-size: 12px; text-align: center; padding: 4px 0 8px; }
.foot:empty { display: none; }

/* tooltip (fixed; positioned by app.js inside the viewport) */
.tip {
  position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none;
  max-width: min(280px, calc(100vw - 16px)); min-width: 150px;
  background: var(--card); color: var(--text); border: 1px solid var(--sep);
  border-radius: 12px; padding: 8px 10px; box-shadow: var(--shadow);
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.tip[hidden] { display: none; }
.tip-h { font-weight: 650; margin-bottom: 4px; font-size: 13px; }
.tip-r { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 8px; color: var(--hint); line-height: 1.6; }
.tip-r b { color: var(--text); font-weight: 600; text-align: right; white-space: nowrap; }
.tip-r.total { border-top: 1px solid var(--sep); margin-top: 3px; padding-top: 3px; }
.tip-r .sw { width: 8px; height: 8px; }
.tip-r .nosw { width: 8px; }
.tip-n { color: var(--hint); margin-top: 4px; font-style: italic; }

@media (min-width: 700px) {
  .wrap { padding-top: 24px; gap: 16px; }
  .card { padding: 20px; }
  .title { font-size: 34px; }
}
@media (prefers-reduced-motion: no-preference) {
  .hb-fill, .bud-fill { transition: width .4s ease-out; }
}
@media (forced-colors: active) {
  .cell .fill, .hb-fill, .bud-fill, .sw { forced-color-adjust: none; }
}
