/* Тёмная тема в духе интерфейса ChatGPT: тёмный сайдбар, нейтральные панели,
   тонкие границы, крупные скругления и минимум цвета — цвет только у данных. */

:root {
  color-scheme: dark;
  --bg: #212121;
  --sidebar: #171717;
  --panel: #1e1e1e;
  --panel-2: #2a2a2a;
  --hover: #2a2a2a;
  --line: #333333;
  --line-strong: #424242;
  --text: #ececec;
  --muted: #9b9b9b;
  --muted-2: #777777;

  --accent: #10a37f;
  --good: #34d399;
  --fair: #fbbf24;
  --moderate: #fb923c;
  --poor: #f87171;
  --bad: #c084fc;

  --radius: 14px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--panel-2);
  border-radius: 5px;
  padding: 1px 5px;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── каркас ─────────────────────────────────────────────── */

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

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

main {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 28px 40px;
}

/* ── сайдбар ────────────────────────────────────────────── */

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 12px;
}

.logo {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--sidebar);
  font-weight: 700;
  font-size: 15px;
  display: grid;
  place-items: center;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: 11.5px;
  color: var(--muted-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-caption {
  font-size: 11px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item:hover {
  background: #222222;
  color: var(--text);
}

.nav-item.active {
  background: #2f2f2f;
  color: var(--text);
}

.nav-item.active svg {
  opacity: 1;
}

.nav-item.disabled {
  color: var(--muted-2);
  cursor: default;
  opacity: 0.55;
}

.nav-item.disabled:hover {
  background: none;
  color: var(--muted-2);
}

.nav-item em {
  margin-left: auto;
  font-style: normal;
  font-size: 10.5px;
  color: var(--muted-2);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 6px;
}

.side-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px;
  border-top: 1px solid var(--line);
}

.conn {
  display: flex;
  align-items: center;
  gap: 10px;
}

.conn-text {
  display: flex;
  flex-direction: column;
  font-size: 12.5px;
}

.conn-text small {
  color: var(--muted-2);
  font-size: 11px;
}

.side-note {
  font-size: 11px;
  color: var(--muted-2);
}

.logout {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted-2);
  font: inherit;
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
}

.logout:hover {
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
  flex-shrink: 0;
}

.dot.online {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15);
}

.dot.offline {
  background: var(--poor);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.12);
}

/* ── верхняя полоса ─────────────────────────────────────── */

.topbar {
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(33, 33, 33, 0.88);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.crumb {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.crumb span {
  margin: 0 6px;
  color: var(--muted-2);
}

.crumb b {
  color: var(--text);
  font-weight: 500;
}

.meta {
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── секции ─────────────────────────────────────────────── */

.section {
  margin-bottom: 22px;
  scroll-margin-top: 70px;
}

.section-head,
.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.section-head {
  margin-bottom: 14px;
}

h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 12.5px;
}

/* ── AQI ────────────────────────────────────────────────── */

.aqi {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 24px;
  margin-bottom: 14px;
}

.aqi.good {
  border-left: 3px solid var(--good);
}
.aqi.fair {
  border-left: 3px solid var(--fair);
}
.aqi.moderate {
  border-left: 3px solid var(--moderate);
}
.aqi.poor {
  border-left: 3px solid var(--poor);
}
.aqi.bad {
  border-left: 3px solid var(--bad);
}

.aqi-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  min-width: 160px;
}

.aqi-label {
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted-2);
}

.aqi-value {
  font-size: 56px;
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.aqi-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.aqi-side b {
  font-weight: 600;
}

.aqi-side .muted {
  font-size: 12px;
  color: var(--muted-2);
}

.aqi-scale {
  position: relative;
  display: flex;
  gap: 2px;
  height: 6px;
  width: 100%;
  min-width: 240px;
  max-width: 380px;
  margin: 8px 0 4px;
}

.aqi-scale .seg {
  height: 100%;
  border-radius: 999px;
  opacity: 0.75;
}

.seg.good {
  background: var(--good);
}
.seg.fair {
  background: var(--fair);
}
.seg.moderate {
  background: var(--moderate);
}
.seg.poor {
  background: var(--poor);
}
.seg.bad {
  background: var(--bad);
}

.aqi-marker {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--panel);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

/* ── карточки значений ──────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 10px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.12s ease;
}

.card:hover {
  border-color: var(--line-strong);
}

.card .label {
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.card .value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.card .value small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-2);
  margin-left: 4px;
}

.card .note {
  font-size: 12px;
  color: var(--muted);
  margin-top: auto;
}

.card.good {
  border-left: 3px solid var(--good);
}
.card.fair {
  border-left: 3px solid var(--fair);
}
.card.moderate {
  border-left: 3px solid var(--moderate);
}
.card.poor {
  border-left: 3px solid var(--poor);
}
.card.bad {
  border-left: 3px solid var(--bad);
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid transparent;
}

.badge.muted {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border-color: var(--line);
}
.badge.good {
  background: rgba(52, 211, 153, 0.12);
  color: var(--good);
  border-color: rgba(52, 211, 153, 0.25);
}
.badge.fair {
  background: rgba(251, 191, 36, 0.12);
  color: var(--fair);
  border-color: rgba(251, 191, 36, 0.25);
}
.badge.moderate {
  background: rgba(251, 146, 60, 0.12);
  color: var(--moderate);
  border-color: rgba(251, 146, 60, 0.25);
}
.badge.poor {
  background: rgba(248, 113, 113, 0.12);
  color: var(--poor);
  border-color: rgba(248, 113, 113, 0.25);
}
.badge.bad {
  background: rgba(192, 132, 252, 0.12);
  color: var(--bad);
  border-color: rgba(192, 132, 252, 0.25);
}

/* ── панели ─────────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  margin-bottom: 14px;
  scroll-margin-top: 66px;
}

.panel-head {
  align-items: center;
  margin-bottom: 10px;
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tabs {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.tabs button {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.tabs button:hover {
  color: var(--text);
}

.tabs button.active {
  background: #3a3a3a;
  color: var(--text);
}

select,
.device-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font: inherit;
  font-size: 12.5px;
}

.btn {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: #333333;
}

.chart {
  width: 100%;
  height: 320px;
}

.chart-block + .chart-block {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.chart-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.chart-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.chart-head span {
  font-size: 11.5px;
  color: var(--muted-2);
}

/* Карточки над графиками: те же, что были в «Сейчас», плюс цветная метка
   ряда. Клик по карточке скрывает и возвращает ряд. */
.chart-cards {
  margin: 12px 0 6px;
}

.chart-cards .card {
  min-height: 96px;
  cursor: pointer;
}

.chart-cards .card.off {
  opacity: 0.4;
}

.card-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 7px;
  transform: translateY(-1px);
}

#diag {
  margin-top: 10px;
}

/* Атрибут hidden должен побеждать display:flex у .chips и .aqi. */
[hidden] {
  display: none !important;
}

.empty {
  padding: 40px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ── таблица ────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  margin: 0 -18px -14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

thead th {
  text-align: right;
  font-weight: 500;
  color: var(--muted-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

thead th:first-child,
tbody td:first-child {
  text-align: left;
}

tbody td {
  text-align: right;
  padding: 8px 18px;
  border-bottom: 1px solid #2a2a2a;
  color: var(--text);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #262626;
}

/* ── чипы диагностики ───────────────────────────────────── */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  color: var(--muted);
}

.chip b {
  color: var(--text);
  font-weight: 500;
}

/* ── ошибка и подвал ────────────────────────────────────── */

.error {
  margin: 14px 28px 0;
  padding: 10px 14px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(248, 113, 113, 0.08);
  color: var(--poor);
  font-size: 13px;
}

footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.6;
}

/* ── скроллбары ─────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: #3a3a3a;
  border-radius: 999px;
  border: 2px solid var(--bg);
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ── адаптив ────────────────────────────────────────────── */

@media (max-width: 880px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }

  .side-brand {
    display: none;
  }

  .topbar {
    display: none;
  }

  .side-nav {
    flex-direction: row;
    gap: 4px;
  }

  .side-caption,
  .side-bottom {
    display: none;
  }

  .nav-item {
    white-space: nowrap;
    padding: 7px 9px;
    font-size: 12.5px;
  }

  .nav-item svg {
    display: none;
  }

  .nav-item.disabled {
    display: none;
  }

  .meta {
    display: none;
  }

  main {
    padding: 18px 16px 32px;
  }

  .aqi {
    gap: 18px;
    padding: 16px 18px;
    overflow: hidden;
  }

  .aqi-side {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }

  .aqi-scale {
    min-width: 0;
    width: 100%;
  }

  .aqi-value {
    font-size: 46px;
  }

  .chart {
    height: 240px;
  }

  .panel {
    padding: 14px 14px 12px;
  }

  .table-wrap {
    margin: 0 -14px -12px;
  }

  .error {
    margin: 12px 16px 0;
  }
}

/* ── графики диагностики ────────────────────────────────── */

#diag {
  margin-top: 12px;
}

.diag-charts {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.diag-chart {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.diag-chart > summary {
  position: relative;
  padding: 9px 12px 9px 26px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text);
  list-style: none;
}

/* Штатный маркер <details> на macOS рисуется по-разному (а в headless —
   вообще не рисуется), поэтому рисуем свой треугольник. */
.diag-chart > summary::-webkit-details-marker {
  display: none;
}

.diag-chart > summary::before {
  content: '▸';
  position: absolute;
  left: 10px;
  top: 8px;
  font-size: 11px;
  color: var(--muted-2);
}

.diag-chart[open] > summary::before {
  content: '▾';
}

.diag-chart > summary em {
  margin-left: 8px;
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted-2);
}

.diag-chart[open] > summary {
  border-bottom: 1px solid var(--line);
}

.chart-sm {
  height: 240px;
}
