/* ==========================================================================
   Bizmania Assistant — светлая дизайн-система (новая тема, этап 2)
   Токены → база → каркас (сайдбар / нижняя навигация) → компоненты → таблицы.
   Тёмный «остров» котировок — в terminal.css (загружается после).
   ========================================================================== */

/* ---- Inter (self-hosted variable) ---- */
@font-face {
  font-family: 'Inter Variable'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url('../fonts/inter-cyrillic-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F;
}
@font-face {
  font-family: 'Inter Variable'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url('../fonts/inter-cyrillic-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116;
}
@font-face {
  font-family: 'Inter Variable'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url('../fonts/inter-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: 'Inter Variable'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url('../fonts/inter-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

/* ---- Токены ---- */
:root {
  --font-sans: 'Inter Variable', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef1f6;
  --row-alt: #fafbfd;

  --border: #e5e9f0;
  --border-2: #d6dce6;

  --text: #0f172a;
  --text-2: #3f4a5a;
  --text-3: #6b7688;
  --text-muted: #98a2b3;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eaf1ff;
  --accent-ring: rgba(37, 99, 235, .22);

  --success: #15a34a; --success-soft: #e7f7ee;
  --warning: #d97706; --warning-soft: #fef3c7;
  --danger: #e11d48;  --danger-soft: #ffe4ea;

  --radius-xs: 6px;
  --radius-sm: 9px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -14px rgba(16, 24, 40, .22);
  --shadow-md: 0 10px 30px -14px rgba(16, 24, 40, .3);

  --sidebar-w: 252px;
  --tabbar-h: 60px;
  --focus: 0 0 0 3px var(--accent-ring);
}

/* Задел под тёмную тему (включается позже через data-theme="dark" на <html>). */
:root[data-theme="dark"] {
  --bg: #0b0e14;
  --surface: #131722;
  --surface-2: #171b26;
  --surface-3: #1e222d;
  --row-alt: #151925;
  --border: #242a38;
  --border-2: #313849;
  --text: #e6e9ef;
  --text-2: #b9c0cd;
  --text-3: #8b93a3;
  --text-muted: #6b7280;
  --accent-soft: #16233d;
}

/* ---- База ---- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.card h3, .card > h2 { margin: 0 0 10px; }
a { color: var(--accent); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
.numeric, td, th { font-variant-numeric: tabular-nums; }

/* Иконки (инлайн-SVG спрайт) */
.ic { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 15px; height: 15px; }
.ic-lg { width: 22px; height: 22px; }

/* ---- Каркас ---- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* Сайдбар (десктоп) */
.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px 14px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand__mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #60a5fa);
  color: #fff; font-size: 16px; font-weight: 800; box-shadow: var(--shadow-xs);
}
.brand__name { font-size: 14.5px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.brand__sub { display: block; font-size: 11.5px; font-weight: 500; color: var(--text-muted); letter-spacing: 0; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-cap {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); padding: 14px 10px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  border: none; background: transparent; border-radius: var(--radius-sm);
  color: var(--text-2); font-family: inherit; font-size: 13.5px; font-weight: 550;
  text-align: left; cursor: pointer; transition: background .14s, color .14s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 650; }
.nav-item .ic { color: var(--text-3); }
.nav-item.active .ic { color: var(--accent); }

.sidebar-foot { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.admin-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13px; font-weight: 550; text-decoration: none;
}
.admin-link:hover { background: var(--surface-2); color: var(--text); }
.app-version { font-size: 11.5px; color: var(--text-muted); padding: 0 10px; }

/* Контент */
.main { min-width: 0; padding: 0 26px 40px; }
.tab { display: none; }
.tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.page-header { display: flex; align-items: flex-start; gap: 10px; padding: 22px 0 10px; margin-bottom: 2px; }
.page-header__text { min-width: 0; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; margin-top: 1px; flex: 0 0 auto;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text-2);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
}
.icon-btn:hover:not(:disabled) { background: var(--accent-soft); border-color: #c7d2fe; color: var(--accent-hover); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.page-header h1 { font-size: 21px; font-weight: 700; letter-spacing: -.02em; }
.page-sub { font-size: 13px; color: var(--text-3); margin: 3px 0 0; }

/* Нижняя навигация (мобайл) */
.tabbar { display: none; }
.app-version--mobile { display: none; }

/* ---- Карточки ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.topgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.topcard { margin-bottom: 0; }
.topcard h3 { font-size: 14px; margin: 0 0 10px; }

/* ---- Подсказки / текст ---- */
.hint { font-size: 12.5px; color: var(--text-3); line-height: 1.5; margin-bottom: 12px; }
.hint b { color: var(--text-2); }
#info { font-size: 13px; color: var(--text-3); }
.muted { color: var(--text-muted); }
.pos { color: var(--success); font-weight: 650; }
.neg { color: var(--danger); font-weight: 650; }
.chart-legend { font-size: 12px; color: var(--text-3); margin-top: 8px; }

/* ---- Контролы ---- */
.controls { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; align-items: flex-start; }
.controls label { display: block; font-size: 11.5px; color: var(--text-3); font-weight: 600; margin-bottom: 3px; }
.controls label + br { display: none; }

/* «Тест»: селект города, стрелки и «Обновить» — на одной высоте */
.controls--test > div { display: flex; flex-direction: column; align-items: flex-start; }
.controls--test select { display: block; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-top: 0; }
select, input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"] {
  padding: 6px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 13px; max-width: 280px;
  transition: border-color .15s, box-shadow .15s;
}
select:hover, input:hover { border-color: #b9c2d0; }
select:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }

.checkbox-group { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; min-height: 30px; }
.checkbox-group label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; margin: 0; font-weight: 500; }
.checkbox-group input { cursor: pointer; accent-color: var(--accent); width: 15px; height: 15px; flex: 0 0 auto; }

.segmented {
  display: inline-flex; border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface); flex-wrap: wrap;
}
.segmented label { position: relative; margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; padding: 5px 12px; font-size: 13px; font-weight: 550; color: var(--text-2);
  cursor: pointer; border-right: 1px solid var(--border); white-space: nowrap; line-height: 1.35;
  transition: background .14s, color .14s;
}
.segmented label:last-child span { border-right: none; }
.segmented label:hover span { background: var(--surface-2); }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

/* ---- Кнопки ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--border-2); background: var(--surface);
  color: var(--text-2); border-radius: var(--radius-sm); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 550; margin-top: 10px;
  transition: background .14s, border-color .14s, color .14s;
}
.btn:hover { background: var(--accent-soft); border-color: #c7d2fe; color: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-right { float: right; }
.ta-left { text-align: left; }

/* ---- Бейджи / чипы ---- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 4px 12px; font-size: 13px; color: var(--text-2);
}
.chip b { color: var(--text); }
.badge { display: inline-block; padding: 1px 8px; border-radius: var(--radius-pill); font-weight: 650; }
.badge--ok { background: var(--success-soft); color: #166534; }
.badge--warn { background: var(--warning-soft); color: #92400e; }
.badge--bad { background: var(--danger-soft); color: #991b1b; }

/* ---- Таблицы данных ---- */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: right; }
th { background: var(--surface-2); position: sticky; top: 0; z-index: 2; white-space: normal; font-weight: 650; color: var(--text-2); border-bottom-color: var(--border-2); }
td { white-space: nowrap; }
td:first-child, th:first-child { text-align: left; }
td:first-child { white-space: normal; word-break: break-word; min-width: 140px; }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--accent-soft); }
.wrap { overflow-x: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); }
.wrap > table { border-radius: inherit; }

/* Вторая строка заголовков липнет под первой (top задаёт pinHeaderSecondRows) */
thead tr:nth-child(2) th { z-index: 1; }

/* Закреплённый узкий столбец с иконкой при горизонтальной прокрутке */
.sticky-icon tbody td:first-child {
  position: sticky; left: 0; z-index: 2; background: var(--surface);
  width: 40px; min-width: 40px; max-width: 40px; text-align: center; white-space: nowrap; padding: 2px 4px;
  box-shadow: 2px 0 4px -3px rgba(16, 24, 40, .3);
}
.sticky-icon tbody tr:nth-child(even) td:first-child { background: var(--row-alt); }
.sticky-icon tbody tr:hover td:first-child { background: var(--accent-soft); }
.sticky-icon tbody td:nth-child(2) { text-align: left; min-width: 140px; white-space: normal; word-break: break-word; }
.sticky-icon thead tr:first-child th:first-child {
  position: sticky; left: 0; z-index: 3; background: var(--surface-2);
  width: 40px; min-width: 40px; box-shadow: 2px 0 4px -3px rgba(16, 24, 40, .3);
}

/* Иконки товаров */
.icon-inline { width: 24px; height: 24px; vertical-align: middle; margin-right: 6px; border-radius: 4px; }
.icon-cell { width: 24px; height: 24px; display: block; margin: auto; }

/* Мир → Регион: поставщик */
.wr-sup-name { white-space: nowrap; }
.wr-sup-sub { font-size: 11px; font-weight: 400; }

/* ---- Аномалии: кликабельная строка → график цен ---- */
#anomBody tr.anom-nav { cursor: pointer; }
#anomBody tr.anom-nav:hover,
#anomBody tr.anom-nav:nth-child(even):hover { background: var(--accent-soft); }

/* Десктоп: длинные колонки (название и описание) переносятся по строкам,
   чтобы таблица укладывалась по ширине экрана без горизонтального скролла. */
#anomTable td.ac-name { white-space: normal; word-break: break-word; }
#anomTable td.ac-context { white-space: normal; word-break: break-word; text-align: left; min-width: 180px; }
#anomTable td.ac-when { white-space: nowrap; }

/* Бейдж степени интереса */
.interest {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 8px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 650; line-height: 1.5; white-space: nowrap;
}
.interest__dot { width: 7px; height: 7px; border-radius: var(--radius-pill); background: currentColor; }
.interest--high { background: var(--danger-soft); color: #be123c; }
.interest--med { background: var(--warning-soft); color: #b45309; }
.interest--low { background: #fef9c3; color: #a16207; }
.interest-dot { display: inline-block; width: 8px; height: 8px; border-radius: var(--radius-pill); margin-right: 7px; vertical-align: middle; }
.interest-dot--high { background: #e11d48; }
.interest-dot--med { background: #f59e0b; }
.interest-dot--low { background: #eab308; }

/* Поля ввода внутри таблиц */
table input[type="number"] { width: 76px; padding: 4px 6px; }

/* ---- График цен: шапка и легенда-пилюли ---- */
canvas { max-height: 420px; }
.graph-head { display: flex; flex-direction: column; gap: 12px; }
.graph-head__id { display: flex; align-items: center; gap: 12px; }
.graph-head__icon { width: 36px; height: 36px; border-radius: 8px; flex: 0 0 auto; }
.graph-head__title { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.graph-head__sub { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }

/* Кнопки перехода из «Графика цен» в отраслевые вкладки */
.graph-nav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.graph-nav__label { font-size: 12px; color: var(--text-3); font-weight: 600; }
.graph-nav .btn { width: auto; }
.btn-sm { padding: 5px 10px; font-size: 12px; margin-top: 0; }

/* Кликабельные строки-витрины и подсветка перехода */
.nav-row { cursor: pointer; }
.row-flash td { animation: rowflash 1.6s ease; }
@keyframes rowflash { 0%, 100% { background: transparent; } 20%, 60% { background: var(--accent-soft); } }

/* Всплывающее меню выбора вкладки (режим «Полная») */
.nav-menu { position: absolute; z-index: 80; min-width: 210px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.nav-menu__title { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 650; padding: 0 2px; }
.nav-menu .btn { margin-top: 0; justify-content: flex-start; }

.chart-legend { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.legend-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-pill);
  font-family: inherit; font-size: 12px; font-weight: 550; color: var(--text-2); cursor: pointer;
  transition: opacity .14s, background .14s;
}
.legend-pill:hover { background: var(--surface-2); }
.legend-pill .dot { width: 9px; height: 9px; border-radius: var(--radius-pill); background: var(--text-muted); }
.legend-pill.off { opacity: .45; }

/* ---- Вкладка «Экспериментально»: карточки городов ---- */
.exp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(370px, 1fr)); gap: 16px; }
.city-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 12px;
}
.city-card__head { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 4px 8px; }
.city-card__title { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.city-card__region { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.city-kpis { gap: 6px; }
.city-kpis .chip { font-size: 12px; padding: 3px 10px; }
.city-block { display: flex; flex-direction: column; gap: 8px; }
.city-block__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.city-block__name { font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.city-chart { height: 140px; }
.city-chart canvas { max-height: none; }
.mini-seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: var(--radius-pill); overflow: hidden; }
.mini-seg button { border: none; background: transparent; color: var(--text-3); font-family: inherit; font-size: 11.5px; font-weight: 600; padding: 4px 10px; cursor: pointer; }
.mini-seg button.active { background: var(--accent-soft); color: var(--accent-hover); }
.city-block--ind summary { cursor: pointer; font-size: 12.5px; font-weight: 650; color: var(--text-2); list-style: none; }
.city-block--ind summary::-webkit-details-marker { display: none; }
.city-block--ind summary::before { content: '▸ '; color: var(--text-muted); }
.city-block--ind[open] summary::before { content: '▾ '; }
.ind-bars { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; min-width: 0; }
.ind-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 12px; }
.ind-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ind-track { height: 8px; background: var(--surface-3); border-radius: var(--radius-pill); overflow: hidden; }
.ind-fill { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--accent); }
.ind-fill.pos { background: var(--success); }
.ind-fill.neg { background: var(--danger); }
.ind-val { font-variant-numeric: tabular-nums; color: var(--text-2); min-width: 64px; text-align: right; }
.ind-val.pos { color: var(--success); }
.ind-val.neg { color: var(--danger); }
.city-about { font-size: 12px; }
.city-about__soon { color: var(--text-muted); }
.city-more { display: flex; flex-direction: column; gap: 12px; }
.city-more-btn { display: none; }

/* Шапка карточки города — кликабельна */
.city-card__head { cursor: pointer; }
.city-card__head:hover .city-card__title { color: var(--accent-hover); }
.city-card__sub { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 3px; font-size: 12.5px; color: var(--text-3); }
.city-meta { display: inline-flex; align-items: center; gap: 5px; }
.city-meta .ic { color: var(--text-muted); }
.city-card__more { margin-left: auto; color: var(--accent); font-weight: 650; display: none; align-items: center; gap: 3px; }
.city-card__head:hover .city-card__more { display: inline-flex; }

/* ---- Вкладка «Тест»: город ---- */
.city-hero { display: flex; flex-direction: column; gap: 14px; }
.city-hero__title { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.city-hero__meta { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; position: relative; min-height: 84px; }
.kpi--click { cursor: pointer; }
.kpi--click:hover { border-color: #c7d2fe; }
.kpi__label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 650; }
.kpi__val { font-size: 18px; font-weight: 700; letter-spacing: -.01em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi__sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.kpi__val, .kpi__sub { transition: opacity .18s; }
.kpi__chart { position: absolute; left: 10px; right: 10px; top: 30px; bottom: 8px; opacity: 0; transition: opacity .18s; pointer-events: none; }
.kpi.open .kpi__val, .kpi.open .kpi__sub { opacity: 0; }
.kpi.open .kpi__chart { opacity: 1; }

/* Подсказка под интерактивным графиком бюджета */
.test-hint { font-size: 11px; color: var(--text-muted); margin-top: 6px; }
#testBudgetChart { cursor: pointer; }

.test-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.test-sec { margin-bottom: 0; display: flex; flex-direction: column; min-width: 0; }
.test-sec--circ { grid-column: 1 / -1; }
.test-sec h3 { margin: 0 0 10px; }
.test-sec__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.test-sec__head h3 { margin: 0; }
.city-chart--tall { height: 220px; }
.test-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.test-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 650; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.test-table td { padding: 6px; border-bottom: 1px solid var(--border); }
.test-table .tl { text-align: left; color: var(--text-2); }
.test-table .tr { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.test-table tr:last-child td { border-bottom: none; }
.test-total td { font-weight: 700; border-top: 1px solid var(--border-2); }
.test-table--det td { font-size: 12px; padding: 4px 6px; }

.tax-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.tax-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; text-align: center; }
.tax-tile__v { font-size: 18px; font-weight: 700; }
.tax-tile__l { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.circ-cat { border-bottom: 1px solid var(--border); min-width: 0; }
.circ-cat:last-child { border-bottom: none; }
.ind-row--click { cursor: pointer; border-radius: var(--radius-xs); padding: 3px 4px; }
.ind-row--click:hover { background: var(--accent-soft); }
.circ-det { padding: 0 4px; min-width: 0; }
.circ-det:empty { display: none; }

/* ---- Адаптив ---- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 0 16px calc(var(--tabbar-h) + 28px); }

  /* Нижний бар: горизонтально скроллится, все разделы, без «Ещё» */
  .tabbar {
    display: flex; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    min-height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, .94); backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--border);
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .tabbar::-webkit-scrollbar { display: none; }
  .tabbar-item {
    flex: 0 0 auto; min-width: 70px; scroll-snap-align: center;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: none; background: none; cursor: pointer; color: var(--text-3);
    font-family: inherit; font-size: 10.5px; font-weight: 550; padding: 8px 12px;
  }
  .tabbar-item .ic { width: 21px; height: 21px; stroke-width: 1.8; }
  .tabbar-item.active { color: var(--accent); }

  .app-version--mobile { display: block; text-align: center; margin: 20px 0 0; }

  .exp-grid { grid-template-columns: 1fr; }
  .test-grid { grid-template-columns: minmax(0, 1fr); }
  .city-hero__title { font-size: 19px; }
  .city-card { padding: 14px; }
  .city-more { display: none; }
  .city-card.open .city-more { display: flex; }
  .city-more-btn { display: inline-flex; align-self: stretch; justify-content: center; margin-top: 0; }
  .ind-row { grid-template-columns: 86px minmax(0, 1fr) auto; }

  .page-header { padding: 16px 0 12px; }
  .page-header h1 { font-size: 19px; }
}

@media (max-width: 720px) {
  .card { padding: 14px; border-radius: var(--radius); }
  .controls { gap: 8px; margin: 9px 0; }
  .controls > div { flex: 1 1 100%; }
  .controls label { margin-bottom: 2px; }
  .controls select,
  .controls input:not([type="checkbox"]):not([type="radio"]),
  select,
  input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"] {
    max-width: none; width: 100%;
  }
  .checkbox-group input { width: 15px; height: 15px; max-width: 15px; }
  .topgrid { grid-template-columns: 1fr; }
  .btn { width: 100%; justify-content: center; }
  .btn-right { float: none; }

  /* Кнопки графика на мобильном: подпись сверху, кнопки — в одну строку */
  .graph-nav { gap: 6px; }
  .graph-nav__label { width: 100%; }
  .graph-nav .btn { flex: 1 1 0; width: auto; justify-content: center; padding: 6px 8px; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }

  /* Детальная таблица товарооборота на мобильном: прячем «Произведено» и «Цена»
     и фиксируем раскладку, чтобы таблица гарантированно влезала по ширине */
  .test-table--det { table-layout: fixed; }
  .test-table--det .col-prod,
  .test-table--det .col-price { display: none; }
  .test-table--det th, .test-table--det td { padding: 4px 4px; }
  .test-table--det td { font-size: 11px; }
  .test-table--det .tl { width: 34%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* «Тест» на мобильном: «Прочее» — 2 колонки с переносом значения,
     «Бюджет» — без «% от общего», с «Δ%» и фиксированной раскладкой */
  .test-sec .test-table .tl { overflow-wrap: anywhere; }
  .test-table--kv td:nth-child(3) { display: none; }
  .test-table--kv td:nth-child(2) { white-space: normal; overflow-wrap: anywhere; }
  .test-table--budget { table-layout: fixed; }
  .test-table--budget td:nth-child(4) { display: none; }
  .test-table--budget td:nth-child(1) { width: 46%; }
  .test-table--budget td:nth-child(2) { width: 22%; }
  .test-table--budget td:nth-child(3) { width: 32%; }

  /* Аномалии: таблица превращается в карточки, кликабельность сохраняется */
  .wrap-cards { max-height: none; overflow: visible; border: none; }
  #anomTable thead { display: none; }
  #anomTable, #anomTable tbody, #anomTable td { display: block; width: auto; }
  #anomTable { border: none; }
  #anomTable tr {
    display: grid; grid-template-columns: 1fr auto auto; gap: 4px 9px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    margin-bottom: 10px; padding: 11px 13px 10px; box-shadow: var(--shadow-xs);
  }
  #anomTable tbody tr:nth-child(even) { background: var(--surface); }
  #anomTable tr.anom-nav:hover { background: var(--accent-soft); }
  #anomTable td { border: none; padding: 0; text-align: left; white-space: normal; }
  #anomTable td:first-child { min-width: 0; }
  #anomTable td::before {
    content: attr(data-label); display: block;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); font-weight: 650; margin-bottom: 1px;
  }
  /* Шапка карточки: дата-время · период · интерес */
  #anomTable td.ac-when { grid-column: 1; grid-row: 1; align-self: center; font-size: 12.5px; font-weight: 650; color: var(--text-2); }
  #anomTable td.ac-period {
    grid-column: 2; grid-row: 1; align-self: center; justify-self: end;
    background: var(--surface-3); border-radius: var(--radius-pill);
    padding: 1px 9px; font-size: 11.5px; font-weight: 650; color: var(--text-3);
  }
  #anomTable td.ac-interest { grid-column: 3; grid-row: 1; align-self: center; justify-self: end; }
  /* Основное: город · товар — крупно и жирно */
  #anomTable td.ac-name { grid-row: 2; grid-column: 1 / -1; padding-top: 5px; font-size: 15.5px; font-weight: 650; color: var(--text); line-height: 1.35; }
  #anomTable td.ac-change { grid-row: 3; grid-column: 1 / -1; font-size: 15px; font-weight: 700; }
  #anomTable td.ac-context { grid-row: 4; grid-column: 1 / -1; color: var(--text-3); font-size: 12.5px; }
  #anomTable td.ac-when::before, #anomTable td.ac-period::before,
  #anomTable td.ac-interest::before, #anomTable td.ac-context::before { content: none; }
  /* Индикатор интереса в карточке — ненавязчивая точка без подписи и фона */
  #anomTable .interest { background: none; padding: 0; }
  #anomTable .interest__label { display: none; }
  #anomTable .interest__dot { width: 9px; height: 9px; }
  #anomTable tr.anom-empty { display: block; padding: 12px; }
  #anomTable tr.anom-empty td::before { content: none; }

  /* ===== Мир → Регион: таблица превращается в карточки ===== */
  #wrTable thead { display: none; }
  #wrTable, #wrTable tbody, #wrTable td { display: block; width: auto; }
  #wrTable { border: none; }
  #wrTable tr {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    margin-bottom: 10px; padding: 12px 13px; box-shadow: var(--shadow-xs);
  }
  #wrTable tbody tr:nth-child(even) { background: var(--surface); }
  #wrTable td {
    border: none; padding: 0; text-align: left; white-space: normal;
    min-width: 0; max-width: none; position: static; box-shadow: none; background: transparent;
  }
  #wrTable td::before {
    content: attr(data-label); display: block;
    font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); font-weight: 650; margin-bottom: 2px;
  }
  #wrTable .wr-sup-name { white-space: normal; }
  #wrTable td.wr-ico { grid-column: 1; grid-row: 1; align-self: center; }
  #wrTable td.wr-ico .icon-cell { margin: 0; }
  #wrTable td.wr-name { grid-column: 2 / -1; grid-row: 1; align-self: center; font-size: 15.5px; font-weight: 650; color: var(--text); line-height: 1.35; }
  /* Мировой поставщик */
  #wrTable td.wr-wsup { grid-column: 1 / -1; grid-row: 2; padding-top: 8px; border-top: 1px solid var(--border); }
  #wrTable td.wr-wsup::before { content: 'Мировой поставщик'; color: var(--accent); }
  #wrTable td.wr-wprice { grid-column: 1; grid-row: 3; }
  #wrTable td.wr-wq { grid-column: 2; grid-row: 3; }
  #wrTable td.wr-wr { grid-column: 3; grid-row: 3; }
  #wrTable td.wr-wstock { grid-column: 4; grid-row: 3; }
  /* Региональный поставщик */
  #wrTable td.wr-gsup { grid-column: 1 / -1; grid-row: 4; padding-top: 10px; border-top: 1px solid var(--border); }
  #wrTable td.wr-gsup::before { content: 'Региональный поставщик'; color: var(--success); }
  #wrTable td.wr-gprice { grid-column: 1; grid-row: 5; }
  #wrTable td.wr-gq { grid-column: 2; grid-row: 5; }
  #wrTable td.wr-gr { grid-column: 3; grid-row: 5; }
  /* Расчёт (выделенный блок) */
  #wrTable td.wr-q, #wrTable td.wr-sale, #wrTable td.wr-pct {
    grid-row: 6; margin-top: 4px; padding: 8px 10px;
    background: var(--accent-soft); border-radius: var(--radius-sm);
  }
  #wrTable td.wr-q { grid-column: 1 / 3; }
  #wrTable td.wr-sale { grid-column: 3; }
  #wrTable td.wr-pct { grid-column: 4; }
  #wrTable td.wr-q input { width: 100%; }
  #wrTable td.wr-q::before, #wrTable td.wr-sale::before, #wrTable td.wr-pct::before { color: #3b5bdb; }
  #wrTable td.wr-pct b { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
