/* Тёмная тема по макету «Тренды — Telegram Mini App». Цвета задаются здесь и нигде больше. */
:root {
  color-scheme: dark;
  --bg: #111315;
  --bg-sheet: #16191C;
  --bg-backdrop: #0A0B0C;
  --card: #181B1E;
  --card-border: #23272B;
  --control: #1A1D20;
  --control-border: #262A2E;
  --control-active: #2A2F33;
  --chip: #1E2225;
  --divider: #22262A;
  --nav: #14171A;
  --text: #E8E6E1;
  --text-2: #C9CCC8;
  --text-3: #9AA09B;
  --text-4: #868C88;
  --bar: #3A4045;
  --bar-recent: #4C5358;
  --accent: #8FB8A4;
  --accent-soft: rgba(143, 184, 164, 0.16);
  --accent-ink: #111315;
  --down: #E0A288;
  --danger: #E08A80;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.4 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; text-align: inherit; }
button:disabled { cursor: default; opacity: 0.45; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
h1, h2 { margin: 0; text-wrap: balance; }
input, select { font: inherit; color: var(--text); }
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Каркас: прокручиваемая область + нижнее меню */
.app { height: 100%; display: flex; flex-direction: column; }
main {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 16px;
}
.nav {
  flex: 0 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--nav); border-top: 1px solid var(--divider);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 48px; font-size: 11px; color: var(--text-4);
}
.nav a[aria-current="page"] { color: var(--accent); font-weight: 500; }

/* Шапка экрана */
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.head-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.title { font-size: 28px; line-height: 34px; font-weight: 600; letter-spacing: -0.02em; }
.title-sm { font-size: 20px; line-height: 26px; font-weight: 600; }
.sub { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--text-3); }
.badge {
  padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--text-3);
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
}
.icon-btn {
  width: 44px; height: 44px; flex: 0 0 auto; border-radius: 14px;
  background: var(--control); border: 1px solid var(--control-border);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.icon-btn .dot { position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* Переключатель периода */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px;
  border-radius: 14px; background: var(--control); border: 1px solid var(--control-border);
}
.seg button { height: 36px; border-radius: 10px; font-size: 14px; color: var(--text-3); text-align: center; }
.seg button[aria-pressed="true"] { background: var(--control-active); color: var(--text); font-weight: 500; }

/* Карточки */
.card { padding: 16px; border-radius: 20px; background: var(--card); border: 1px solid var(--card-border); display: flex; flex-direction: column; gap: 8px; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kpi { padding: 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--card-border); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--text-3); }
.kpi-value { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.kpi-note { font-size: 12px; color: var(--text-4); }

.eyebrow { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); font-weight: 500; }
.hero { gap: 6px; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.hero-name { font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.hero-num { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: 0 0 auto; text-align: right; }
.big { font-size: 28px; line-height: 32px; font-weight: 600; color: var(--accent); }
.big.down { color: var(--down); }
.muted { font-size: 13px; color: var(--text-3); }
.faint { font-size: 12px; color: var(--text-4); }
.spark-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-4); }
.chev { color: var(--text-4); }

/* Секции и списки */
.section { display: flex; flex-direction: column; gap: 8px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 2px; }
.section-title { font-size: 17px; font-weight: 600; }
.link-btn { font-size: 13px; color: var(--text-3); min-height: 32px; }
.list { border-radius: 20px; background: var(--card); border: 1px solid var(--card-border); padding: 4px 14px; display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 6px 0; border-bottom: 1px solid var(--divider); width: 100%; }
.row:last-child { border-bottom: 0; }
.rank { width: 20px; flex: 0 0 auto; font-size: 13px; color: var(--text-4); }
.row-text { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-name { font-size: 15px; overflow-wrap: anywhere; }
.row-val { flex: 0 0 auto; min-width: 52px; text-align: right; font-size: 14px; font-weight: 600; color: var(--accent); }
.row-val.down { color: var(--down); }
.row-val.flat { color: var(--text-2); }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 12px; border-radius: 16px; background: var(--card); border: 1px solid var(--card-border); min-height: 84px; }
.tile-name { font-size: 13px; line-height: 17px; overflow-wrap: anywhere; }
.tile-val { font-size: 16px; font-weight: 600; color: var(--accent); }
.tile-val.down { color: var(--down); }
.tile-val.flat { color: var(--text-2); }

/* Столбики по периодам */
.bars { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); align-items: end; height: 140px; border-bottom: 1px solid var(--control-border); padding-top: 20px; }
.bar-col { display: flex; justify-content: center; position: relative; height: 100%; align-items: flex-end; }
.bar { width: 22px; max-width: 70%; border-radius: 5px 5px 0 0; background: var(--bar); min-height: 2px; }
.bar.recent { background: var(--bar-recent); }
.bar.now { background: var(--accent); }
.bar.none { background: transparent; border: 1px dashed var(--control-border); border-bottom: 0; height: 24px; }
.bar-label { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 600; white-space: nowrap; }
.bar-axis { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); font-size: 10px; color: var(--text-4); text-align: center; }
.bar-axis .now { color: var(--text-2); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 40px; padding: 0 14px; border-radius: 12px; display: inline-flex; align-items: center; gap: 8px; font-size: 14px; background: var(--chip); color: var(--text-2); cursor: pointer; }
.chip.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; box-shadow: inset 0 0 0 1px var(--accent); }
.chip.off { opacity: 0.45; cursor: default; }

/* Пустые и служебные состояния */
.empty { padding: 28px 20px; border-radius: 20px; background: var(--card); border: 1px dashed var(--control-border); text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.empty-title { font-size: 16px; font-weight: 600; }
.center-screen { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 32px 24px; text-align: center; }
.code { font-size: 22px; font-weight: 600; letter-spacing: 0.04em; padding: 10px 16px; border-radius: 14px; background: var(--control); border: 1px solid var(--control-border); }
.skeleton { border-radius: 20px; background: linear-gradient(90deg, var(--card) 0%, #1D2124 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* Кнопки действий */
.btn { height: 52px; border-radius: 16px; font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--divider); color: var(--text-2); font-weight: 500; font-size: 15px; }
.footer-bar { flex: 0 0 auto; padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--chip); background: var(--bg); }

/* Шторка фильтров */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(10, 11, 12, 0.72); display: flex; flex-direction: column; justify-content: flex-end; }
.sheet { max-height: 88%; display: flex; flex-direction: column; background: var(--bg-sheet); border-radius: 28px 28px 0 0; border-top: 1px solid var(--control-border); }
.sheet-handle { display: flex; justify-content: center; padding-top: 8px; }
.sheet-handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--bar); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 4px; }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 22px; }
.sheet-foot { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--divider); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 10px; font-size: 13px; color: var(--text-3); }
.hint { font-size: 12px; color: var(--text-4); margin-top: 8px; }

/* Админка */
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-3); }
.input { height: 44px; padding: 0 12px; border-radius: 12px; background: var(--control); border: 1px solid var(--control-border); }
.input:focus { outline: none; border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.role { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--text-3); }
.role.admin { background: var(--accent-soft); color: var(--accent); }
.row-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.small-btn { min-height: 36px; padding: 0 10px; border-radius: 10px; background: var(--chip); font-size: 13px; color: var(--text-2); }
.small-btn.danger { color: var(--danger); }
.error { font-size: 13px; color: var(--danger); }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 30; padding: 12px 14px; border-radius: 14px; background: var(--control-active); color: var(--text); font-size: 14px; text-align: center; }
