/* AI-Crypto-PRO Dashboard — premium dark, mobile-first (ready for a Telegram Mini App).
 *
 * Chart colors were checked with the data-viz validator:
 *   dark (surfaces #121729 and Telegram #212121):
 *     sources (all pairs):  whale #3987e5, listings #199e70 — CVD ΔE 19.6, normal ΔE 20.9;
 *     importance (ordinal): #1c5cab → #2a78d6 → #5598e7 → #9ec5f4 (lightest step ≥ 2.4:1).
 *   light (Telegram light theme, surface #ffffff):
 *     sources:  #2a78d6, #1baf7a — CVD ΔE 23.1; aqua 2.82:1 -> relief: legend + labels;
 *     importance: #86b6ef → #5598e7 → #256abf → #104281.
 * Blue + violet for the two sources was rejected (normal ΔE 9.8 < 15), so violet
 * stays an interface accent and does not mark data.
 */

:root {
  color-scheme: dark;
  --bg: #070a14;
  --bg-2: #0b1020;
  --surface: #121729;
  --surface-2: #171d33;
  --surface-3: #1d2440;
  --line: #252d4d;
  --line-soft: #1b2240;
  --text: #eef1fb;
  --text-2: #b6bed8;
  --muted: #8089aa;
  --accent: #5b7cff;
  --accent-2: #8b5cf6;
  --accent-grad: linear-gradient(135deg, #4f7cff 0%, #8b5cf6 100%);
  --glow: 0 10px 40px -12px #5b7cff66;

  /* data: identity of the source (validated pair) */
  --src-whale: #3987e5;
  --src-listings: #199e70;
  /* data: importance level (validated ordinal ramp, brighter = more important) */
  --lv-low: #1c5cab;
  --lv-medium: #2a78d6;
  --lv-high: #5598e7;
  --lv-very_high: #9ec5f4;
  --lv-none: #4a5274;

  --row-bg: #0e1428cc;
  --row-hover: #121a33;
  --inset-bg: #0b1020a6;
  --tip-bg: #0d1226f2;
  --track: #ffffff0f;
  --hover: #ffffff08;
  --link-ink: #c7d2fe;
  --band-ink: #6f7899;
  --page-bg:
    radial-gradient(900px 520px at 0% -10%, #1d1a4a 0%, transparent 60%),
    radial-gradient(800px 480px at 100% -5%, #0c2350 0%, transparent 60%),
    var(--bg);

  --ok: #0ca30c;
  --danger: #e66767;
  --warn: #fab219;

  --radius: 18px;
  --radius-sm: 12px;
  --gutter: clamp(16px, 3vw, 48px);
  --maxw: 1360px;           /* below 1500px: one column */
  --header-h: 76px;         /* height of the sticky header (desktop) */
  font-family: Inter, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

/* Light theme: only in Telegram when the user has a light theme.
   Background, surfaces and text then also come from themeParams (app.js). */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5fa;
  --bg-2: #eef1f8;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --surface-3: #f1f3f9;
  --line: #dfe3ee;
  --line-soft: #e9ecf4;
  --text: #0f1222;
  --text-2: #3c4462;
  --muted: #687090;
  --glow: 0 10px 30px -16px #5b7cff80;
  --src-whale: #2a78d6;
  --src-listings: #1baf7a;
  --lv-low: #86b6ef;
  --lv-medium: #5598e7;
  --lv-high: #256abf;
  --lv-very_high: #104281;
  --lv-none: #b5bccd;
  --row-bg: #ffffff;
  --row-hover: #f7f8fc;
  --inset-bg: #f6f7fb;
  --tip-bg: #ffffff;
  --track: #0f12220f;
  --hover: #0f12220a;
  --link-ink: #2f4fd6;
  --band-ink: #8a91aa;
  --page-bg: var(--bg);
}
:root[data-theme="light"] .lvl-very_high .score { box-shadow: none; }
:root[data-theme="light"] .panel { box-shadow: 0 1px 2px #0f122214, 0 10px 28px -20px #0f122240; }
:root[data-theme="light"] .topbar { box-shadow: none; }
:root[data-theme="light"] .timeline .cluster-text { fill: #ffffff; }

* { box-sizing: border-box; }
html, body { margin: 0; }
html {
  -webkit-text-size-adjust: 100%;
  /* Scrolling to an element (anchor, scrollIntoView) stops below the sticky header */
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  min-height: 100vh;
  background: var(--page-bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

code { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; font-size: .9em; color: #a5b4fc; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; border-radius: 8px; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }

/* ---------------------------------------------------------------- demo */

.demo-banner {
  display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; justify-content: center;
  padding: 10px 16px; font-size: 14px;
  background: repeating-linear-gradient(-45deg, #3b2a00, #3b2a00 14px, #4a3500 14px, #4a3500 28px);
  color: #fde68a; border-bottom: 1px solid #a16207; text-align: center;
}
.demo-banner strong { letter-spacing: .06em; }
.badge-demo {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; line-height: 1;
  padding: 4px 8px; border-radius: 999px;
  background: #4a3500; color: #fde68a; border: 1px solid #a16207;
}
body.demo .event { border-style: dashed; border-color: #a1620766; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  /* nearly opaque: content scrolling underneath does not show through the header */
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line-soft);
  box-shadow: 0 8px 24px -16px #000;
}
.topbar .wrap {
  display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; justify-content: space-between;
  padding-top: 14px; padding-bottom: 14px;
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.logo {
  flex: none; width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent-grad); box-shadow: var(--glow);
}
.logo svg { width: 24px; height: 24px; }
h1 { margin: 0; font-size: 21px; font-weight: 750; letter-spacing: -.01em; line-height: 1.15; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; }
.status-pill {
  display: inline-flex; gap: 8px; align-items: center;
  padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
}
.status-pill .muted { font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot-idle { background: var(--muted); }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 4px #0ca30c2e; animation: pulse 2.4s ease-in-out infinite; }
.dot-error { background: var(--danger); box-shadow: 0 0 0 4px #e6676730; }
.dot-demo { background: var(--warn); box-shadow: 0 0 0 4px #fab21930; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px #0ca30c00; } }

.btn {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  min-height: 40px; padding: 8px 16px; border-radius: 12px; border: 1px solid transparent;
  background: var(--accent-grad); color: white; box-shadow: var(--glow);
  transition: filter .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); box-shadow: none; }
.btn-ghost:hover { border-color: var(--accent); filter: none; }
.btn[aria-pressed="true"] { border-color: var(--warn); color: #fde68a; }
.link-btn { font: inherit; background: none; border: 0; color: #fde68a; text-decoration: underline; cursor: pointer; min-height: 32px; }

/* ---------------------------------------------------------------- layout */

.layout { display: grid; gap: 22px; padding-top: 22px; padding-bottom: 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 2px -8px; }
.section-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.005em; }
.section-head p { margin: 0; font-size: 13px; color: var(--muted); }

.panel {
  position: relative;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 0 #ffffff08 inset, 0 20px 40px -28px #000;
}

/* ---------------------------------------------------------------- stat cards */

.cards { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { padding: 20px 20px 18px; overflow: hidden; }
.card::before {
  content: ""; position: absolute; inset: -1px -1px auto -1px; height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--card-accent, var(--accent-grad));
}
.card::after {
  content: ""; position: absolute; width: 220px; height: 220px; right: -90px; top: -110px;
  border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, var(--card-glow, #5b7cff24), transparent 70%);
}
.card-whale { --card-accent: linear-gradient(90deg, #3987e5, #5b7cff); --card-glow: #3987e526; }
.card-listings { --card-accent: linear-gradient(90deg, #199e70, #3987e5); --card-glow: #199e7022; }
.card-ai { --card-accent: var(--accent-grad); --card-glow: #8b5cf62b; }
.card-head { display: flex; gap: 10px; align-items: center; position: relative; z-index: 1; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 650; color: var(--text-2); flex: 1; letter-spacing: .01em; }
.card-icon {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  font-size: 18px; background: var(--surface-3); border: 1px solid var(--line);
}
.metric { display: flex; align-items: baseline; gap: 10px; margin: 16px 0 14px; position: relative; z-index: 1; }
.metric-value { font-size: 44px; font-weight: 780; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric-label { color: var(--muted); font-size: 14px; }
.meter { position: relative; z-index: 1; height: 8px; border-radius: 999px; background: #2a78d62e; overflow: hidden; margin: -4px 0 14px; }
.meter span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent-grad); transition: width .5s ease; }
.kv { margin: 0; display: grid; position: relative; z-index: 1; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.disclaimer { position: relative; z-index: 1; margin: 12px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }

/* ---------------------------------------------------------------- charts */

.analytics { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.chart { padding: 18px 20px 16px; min-width: 0; }
.chart-side { display: grid; gap: 16px; }
.chart-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.chart-head h3 { margin: 0; font-size: 16px; font-weight: 680; }
.chart-head p { margin: 0; font-size: 13px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.swatch-whale { background: var(--src-whale); }
.swatch-listings { background: var(--src-listings); }

.chart-timeline { display: flex; flex-direction: column; }
.timeline { position: relative; width: 100%; height: 240px; flex: 1 1 auto; min-height: 220px; }
.timeline svg { display: block; width: 100%; height: 100%; overflow: visible; }
.timeline .grid { stroke: var(--line); stroke-width: 1; }
.timeline .axis-text { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline .band-text { fill: var(--band-ink); font-size: 11px; }
.timeline .dot-mark { stroke: var(--surface); stroke-width: 2; transition: r .12s ease; pointer-events: none; }
.timeline .dot-whale { fill: var(--src-whale); }
.timeline .dot-listings { fill: var(--src-listings); }
.timeline .stem { stroke-width: 1.5; opacity: .35; }
.timeline .stem-whale { stroke: var(--src-whale); }
.timeline .stem-listings { stroke: var(--src-listings); }
.timeline .now-line { stroke: #a5b4fc; stroke-width: 1; opacity: .45; }
.timeline .now-text { fill: #a5b4fc; font-size: 11px; font-weight: 600; }
.timeline .point-label {
  fill: var(--text-2); font-size: 12px; font-weight: 600;
  paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round;
  pointer-events: none;
}
.timeline .cluster-text { fill: #07101f; font-size: 11px; font-weight: 800; pointer-events: none; }
.timeline .hit { fill: transparent; cursor: pointer; }
.timeline .hit:hover + .dot-mark, .timeline .hit:focus-visible + .dot-mark { r: 9; }
.chart-empty { display: grid; place-items: center; height: 100%; min-height: 120px; color: var(--muted); font-size: 14px; text-align: center; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.bar-row {
  display: grid; grid-template-columns: var(--name-w, 104px) minmax(0, 1fr) 32px; gap: 12px; align-items: center;
  font-size: 14px; border-radius: 10px; padding: 2px 4px; margin: 0 -4px;
}
.bar-row .bar-name { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar-track { height: 12px; display: flex; align-items: center; }
.bar-row .bar-fill { display: block; height: 12px; min-width: 2px; border-radius: 0 4px 4px 0; background: var(--fill, var(--src-whale)); transition: width .45s ease; }
.bar-row .bar-value { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.bar-row.is-zero .bar-value, .bar-row.is-zero .bar-name { color: var(--muted); }
button.bar-row { font: inherit; color: inherit; background: none; border: 0; width: calc(100% + 8px); text-align: left; cursor: pointer; min-height: 32px; }
button.bar-row:hover { background: var(--hover); }
button.bar-row[aria-pressed="true"] { background: #5b7cff1f; box-shadow: inset 0 0 0 1px #5b7cff55; }
#types-chart { --name-w: 148px; }
.fill-low { --fill: var(--lv-low); }
.fill-medium { --fill: var(--lv-medium); }
.fill-high { --fill: var(--lv-high); }
.fill-very_high { --fill: var(--lv-very_high); }
.fill-none { --fill: var(--lv-none); }
.fill-type { --fill: var(--src-whale); }
.chart-note { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 280px;
  padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4;
  background: var(--tip-bg); border: 1px solid var(--line); color: var(--text);
  box-shadow: 0 16px 40px -12px #000c;
}
.tooltip .tt-title { font-weight: 700; margin-bottom: 2px; }
.tooltip .tt-row { color: var(--text-2); }
.tooltip .tt-row + .tt-title { margin-top: 8px; }

/* ---------------------------------------------------------------- feed */

.feed { padding: 18px clamp(14px, 2vw, 22px) 20px; }
.feed-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.feed-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.feed-controls { display: inline-flex; gap: 8px; align-items: center; }
.filter-toggle, .active-filters { display: none; }
.filter-toggle {
  align-items: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  min-height: 40px; padding: 6px 12px; border-radius: 12px; white-space: nowrap;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
}
.filter-toggle svg { width: 18px; height: 18px; color: var(--muted); }
.filter-toggle[aria-expanded="true"] { border-color: var(--accent); }
.filter-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 800; color: white; background: var(--accent-grad);
}
.filter-count[hidden] { display: none; }
.active-filters { flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  min-height: 32px; padding: 4px 10px 4px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--text); border: 1px solid var(--line);
}
.filter-pill-x { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; padding: 14px; border-radius: 14px; background: var(--inset-bg); border: 1px solid var(--line-soft); }
.segmented { display: inline-flex; padding: 3px; gap: 3px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.seg { font: inherit; font-size: 14px; font-weight: 600; min-height: 36px; padding: 6px 14px; border-radius: 9px; background: transparent; color: var(--muted); border: 0; cursor: pointer; }
.seg[aria-pressed="true"] { background: var(--accent-grad); color: white; box-shadow: var(--glow); }
.field { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
.field select, .field input[type="range"] { font: inherit; font-size: 14px; }
.field select {
  min-height: 40px; background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 7px 12px; min-width: 160px;
}
.field-range input { width: 180px; accent-color: var(--accent); min-height: 28px; }
.field output { color: var(--text); font-weight: 700; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; min-height: 36px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); color: var(--muted); border: 1px solid var(--line);
}
.chip.active { color: white; border-color: transparent; background: var(--accent-grad); }
.feed-meta { margin: 14px 2px 10px; font-size: 13px; }

.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.event {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--line-soft); border-radius: 14px;
  background: var(--row-bg);
  transition: border-color .15s ease, background .15s ease;
}
.event:hover { border-color: var(--line); background: var(--row-hover); }
.event.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { border-color: #a5b4fc; box-shadow: 0 0 0 3px #5b7cff40; } }

.score {
  display: grid; place-items: center; align-content: center; gap: 3px;
  width: 56px; height: 56px; border-radius: 14px;
  background: color-mix(in srgb, var(--lvl) 16%, var(--surface));
  border: 2px solid var(--lvl);
}
.score-value { font-size: 21px; font-weight: 800; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.score-label { font-size: 9.5px; line-height: 1; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; text-align: center; }
.lvl-low { --lvl: var(--lv-low); }
.lvl-medium { --lvl: var(--lv-medium); }
.lvl-high { --lvl: var(--lv-high); }
.lvl-very_high { --lvl: var(--lv-very_high); }
.lvl-very_high .score { box-shadow: 0 0 18px -4px #9ec5f4aa; }
.lvl-none { --lvl: var(--lv-none); }

.event-body { min-width: 0; }
.event-top { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; font-size: 13px; }
.type-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line);
  color: var(--text-2); font-weight: 600;
}
.type-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--src-listings); }
.type-chip.type-whale_transfer::before { background: var(--src-whale); }
.asset { font-weight: 750; letter-spacing: .02em; }
.event-time { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.event-summary { margin: 5px 0 4px; font-size: 15px; overflow-wrap: anywhere; }
.event-fact {
  margin: 0 0 7px; font-size: 13px; line-height: 1.45; color: var(--text-2);
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; overflow-wrap: anywhere;
}
.event-fact[hidden] { display: none; }
.event-fact.fact-flow .fact-text { font-variant-numeric: tabular-nums; }
.flow-tag {
  font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  color: var(--text-2); background: var(--surface-3); border: 1px solid var(--line);
}
.flow-tag[hidden] { display: none; }
.flow-tag[data-flow="exchange_internal"], .flow-tag[data-flow="custody_internal"] { border-style: dashed; }
.level-text { display: none; color: var(--text-2); font-weight: 600; }
.score-bar { height: 4px; border-radius: 999px; background: var(--track); overflow: hidden; }
.score-bar span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--lvl, var(--accent)); }
.reasons { margin-top: 6px; font-size: 13px; color: var(--muted); }
.reasons summary { cursor: pointer; width: fit-content; min-height: 24px; color: var(--text-2); }
.reasons summary:hover { color: var(--text); }
.reasons ul { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 2px; }
.reasons .pts { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 700; margin-left: 6px; }
.reasons .pts.neg { color: var(--danger); }
.event-link {
  align-self: start; display: inline-flex; align-items: center; justify-content: center;
  min-height: 34px; padding: 6px 12px; border-radius: 10px;
  color: var(--link-ink); font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap;
  background: var(--surface-3); border: 1px solid var(--line);
}
.event-link:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- empty */

.empty { text-align: center; padding: 36px 16px 28px; }
.empty-art { width: 170px; height: auto; margin-bottom: 8px; animation: spin 18s linear infinite; }
.empty h3 { margin: 6px 0; font-size: 19px; }
.empty p { margin: 6px auto; max-width: 520px; color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.empty-error h3 { color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .empty-art, .dot-ok { animation: none; }
  .meter span, .bar-row .bar-fill { transition: none; }
}

.footer { padding-top: 0; padding-bottom: 28px; font-size: 12px; }

/* ---------------------------------------------------------------- responsive */

/* Large monitors: the content widens and the feed moves into its own column
   beside the statistics and charts, so the screen is not half empty. */
@media (min-width: 1500px) {
  :root { --maxw: min(100%, 1920px); }
  .layout {
    grid-template-columns: minmax(0, 1.6fr) minmax(480px, 1fr);
    grid-template-areas: "cards feed" "head feed" "analytics feed";
    grid-template-rows: auto auto 1fr;
    align-items: start;
  }
  .cards { grid-area: cards; }
  .section-head { grid-area: head; }
  .analytics { grid-area: analytics; }
  .feed {
    grid-area: feed;
    position: sticky; top: calc(var(--header-h) + 16px);
    max-height: calc(100vh - var(--header-h) - 32px);
    display: flex; flex-direction: column;
  }
  .feed > * { flex: none; }
  .feed .event-list { flex: 0 1 auto; overflow-y: auto; min-height: 0; padding-right: 4px; margin-right: -4px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
  .feed #empty-state, .feed #error-state { overflow-y: auto; }
  .timeline { min-height: 300px; }
}
@media (min-width: 2200px) {
  :root { --maxw: 2080px; }
  body { font-size: 17px; }
}

@media (max-width: 1020px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-ai { grid-column: 1 / -1; }
  .analytics { grid-template-columns: minmax(0, 1fr); }
  .chart-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  /* In a Mini App the screen is short: the header scrolls away instead of staying pinned */
  :root { --header-h: 0px; }
  .topbar { position: static; }
  .topbar .wrap { padding-top: 12px; padding-bottom: 12px; gap: 10px; }
  .logo { width: 38px; height: 38px; border-radius: 12px; }
  h1 { font-size: 19px; }
  .status { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .status-pill { grid-column: 1 / -1; white-space: nowrap; overflow: hidden; }
  .status-pill .muted { overflow: hidden; text-overflow: ellipsis; }
  .status .btn { width: 100%; }
  .layout { gap: 18px; padding-top: 16px; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .card { padding: 16px; }
  .metric { margin: 12px 0 10px; }
  .metric-value { font-size: 38px; }
  .chart { padding: 16px; }
  .chart-side { grid-template-columns: minmax(0, 1fr); }
  .timeline { height: 240px; }
  .toolbar { padding: 12px; }
  .toolbar > * { flex: 1 1 100%; }
  .field select, .field-range input { width: 100%; }
  .chips .chip { flex: 1; }
  .segmented { display: flex; }
  .seg { flex: 1; }
  .event { grid-template-columns: 48px minmax(0, 1fr) 36px; gap: 10px; padding: 12px 10px 12px 12px; align-items: start; }
  .score { width: 48px; height: 48px; border-radius: 12px; }
  .score-value { font-size: 18px; }
  .score-label { display: none; }
  .level-text { display: inline; }
  .event-link { width: 36px; height: 36px; min-height: 36px; padding: 0; font-size: 16px; }
  .event-link-text { display: none; }
  .event-time { margin-left: auto; }
}

/* ---------------------------------------------------------------- Telegram Mini App
   body.tma    — opened inside Telegram (or the local preview ?tgpreview=dark|light);
   body.tabbed — one section per screen + bottom tab bar (Telegram or a phone). */

body.tma { background: var(--page-bg); }
body.tma .brand { display: none; }           /* Telegram already shows the app name */
body.tma .topbar { position: static; }
body.tma .footer { display: none; }

.tma-back {
  display: none; align-items: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  min-height: 40px; padding: 8px 12px; border-radius: 12px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
}
body.tma-preview .tma-back:not([hidden]) { display: inline-flex; }

.tabbar { display: none; }
body.tabbed .tabbar {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-soft);
}
.tab {
  display: grid; justify-items: center; gap: 2px;
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  min-height: 52px; padding: 6px 4px; border-radius: 12px; border: 0;
  background: transparent; color: var(--muted);
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--text); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.tab[aria-current="page"] svg { color: var(--accent); }

body.tabbed { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
body.tabbed .layout {
  grid-template-columns: minmax(0, 1fr); grid-template-areas: none; grid-template-rows: none;
  max-width: 760px; padding-top: 14px;
}
body.tabbed .feed { position: static; max-height: none; display: block; }
body.tabbed .feed-head { margin-bottom: 10px; }
body.tabbed .feed-head h2 {  /* the tab bar already says "Стрічка" */
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
body.tabbed .feed-controls { display: flex; width: 100%; }
body.tabbed .feed-controls .segmented { flex: 1 1 auto; min-width: 0; }
body.tabbed .filter-toggle { display: inline-flex; }
body.tabbed .active-filters:not([hidden]) { display: flex; }
body.tabbed .feed:not(.filters-open) .toolbar { display: none; }
body.tabbed .toolbar { margin-bottom: 4px; }
body.tabbed .field-range { display: none; }   /* the ≥ chips cover the same choice */
body.tabbed .feed-meta { margin-top: 4px; }
body.tabbed .seg { flex: 1; padding: 6px 8px; }
@media (max-width: 380px) {
  body.tabbed .filter-toggle { padding: 6px 10px; }
  body.tabbed .filter-toggle-text { display: none; }   /* icon + counter; aria-label keeps the name */
}
body.tabbed .feed .event-list { overflow: visible; }
body.tabbed .cards { grid-template-columns: minmax(0, 1fr); }
body.tabbed .analytics, body.tabbed .chart-side { grid-template-columns: minmax(0, 1fr); }
body.tabbed:not([data-tab="overview"]) [data-tab="overview"],
body.tabbed:not([data-tab="charts"]) [data-tab="charts"],
body.tabbed:not([data-tab="feed"]) [data-tab="feed"] { display: none !important; }
