:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #ffffff;
  --surface-2: #eef4fc;
  --blue: #2a78d6;
  --blue-dark: #184f95;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --good: #0ca30c;
  --bad: #d03b3b;

  /* размеры таблицы площадок — широкие экраны */
  --name-font: 18px;
  --value-font: 15px;
  --header-font: 10px;
  --diff-font: 11px;
  --cell-pad-h: 8px;
  --col-park: 50px;
  --col-ktg: 76px;
  --col-rem: 50px;
}

/* узкие экраны (напр. 1366×768) — плотнее цифры, чтобы название площадки не обрезалось.
   Название площадки НЕ уменьшаем сильнее — экономим место компоновкой цифровых колонок. */
@media (max-width: 1500px) {
  :root {
    --name-font: 16px;
    --value-font: 11px;
    --header-font: 8px;
    --diff-font: 10px;
    --cell-pad-h: 4px;
    --col-park: 32px;
    --col-ktg: 54px;
    --col-rem: 34px;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.hdr {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--grid);
  flex: 0 0 auto;
}
.hdr-left h1 {
  margin: 0;
  font-size: clamp(16px, 1.6vw, 22px);
  color: var(--blue-dark);
  font-weight: 700;
}
.hdr-sub {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 2px;
  text-transform: capitalize;
}
.tabs {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.tab {
  border: 1px solid var(--grid);
  background: var(--surface);
  color: var(--ink-2);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.hdr-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* --- выбор даты/месяца: явно кликабельный "чип" --- */
.picker {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  padding: 7px 10px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  transition: background 0.15s ease;
}
.picker:hover {
  background: #e2edfb;
}
.picker-icon {
  font-size: 15px;
  line-height: 1;
}
.picker-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--blue-dark);
  text-transform: uppercase;
  white-space: nowrap;
}
.picker-caret {
  font-size: 10px;
  color: var(--blue-dark);
  margin-left: 2px;
}
.picker input {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 0;
  border: none;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}
.hidden { display: none !important; }
.updated {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
}

/* ---------- board ---------- */
.board {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: start;
  align-content: start;
  justify-items: stretch;
  gap: 12px;
  padding: 8px 14px 14px;
  overflow: hidden;
}
.loading {
  grid-column: 1 / -1;
  align-self: center;
  justify-self: center;
  color: var(--ink-muted);
  font-size: 15px;
}

.filial {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 12px;
  overflow: hidden;
}

/* --- шапка филиала: название + агрегированные показатели --- */
.filial-title {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: var(--blue-dark);
  color: #fff;
  padding: 14px 10px 14px 14px;
}
.filial-title-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.15;
  min-width: 0;
  flex: 0 1 auto;
}
.filial-title-name div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filial-title-stats {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}
.tstat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 6px;
  padding: 3px 4px;
  min-width: 40px;
}
.tstat-label {
  font-size: 7.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-muted);
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
}
.tstat-value {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---------- таблица площадок ---------- */
.ptable {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.ptable col.col-name { width: auto; }
.ptable col.col-park { width: var(--col-park); }
.ptable col.col-ktg { width: var(--col-ktg); }
.ptable col.col-rem { width: var(--col-rem); }

.ptable thead th {
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--header-font);
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.2;
  padding: 4px 2px;
  border-bottom: 1px solid var(--grid);
}
.ptable thead th.th-name {
  text-align: left;
  padding-left: 8px;
  vertical-align: bottom;
}
.ptable thead th.th-group {
  border-left: 1px solid var(--grid);
}
.ptable thead th.th-sub:nth-child(odd) {
  border-left: 1px solid var(--grid);
}

.ptable tbody td {
  font-size: var(--value-font);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  padding: var(--row-pad, 12px) var(--cell-pad-h);
}
.ptable tbody tr.row-last td {
  border-bottom: 1px solid var(--grid);
}
.ptable tbody td.td-name {
  text-align: left;
  font-weight: 700;
  font-size: var(--name-font);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 8px;
}
.ptable tbody td.val.rem {
  color: var(--ink-2);
  font-weight: 600;
}
.ptable tbody tr.row-main td:nth-child(2),
.ptable tbody tr.row-main td:nth-child(4),
.ptable tbody tr.row-main td:nth-child(6) {
  border-left: 1px solid var(--grid);
}
.ptable tbody tr.row-diff td {
  padding-top: 0;
  padding-bottom: 4px;
}
.ptable tbody td.diff {
  text-align: center;
  font-size: var(--diff-font);
  font-weight: 600;
  color: var(--ink-muted);
}
.ptable tbody td.diff-empty {
  padding: 0;
}

.val-good { color: var(--good); font-weight: 400; }
.val-bad { color: var(--bad); font-weight: 700; }
.val-na { color: var(--ink-muted); font-weight: 400; }

/* ---------- footer legend ---------- */
.legend {
  flex: 0 0 auto;
  display: flex;
  gap: 24px;
  justify-content: center;
  padding: 6px 20px 10px;
  font-size: 12px;
  color: var(--ink-2);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot.good { background: var(--good); }
.dot.bad { background: var(--bad); }
