:root {
  /* Палитра взята из layout.php образовательного портала stemlab.kz — для единого стиля */
  --ac: #1a56db;
  --ac2: #0e3fa1;
  --bg: #f0f4fa;
  --card: #fff;
  --border: #e2e8f4;
  --text: #1e293b;
  --muted: #64748b;

  --ac-green: #065f46;
  --bg-green: #d1fae5;
  --ac-amber: #b45309;
  --bg-amber: #fef3c7;
  /* «Опасность» — тот же цвет, что .btn-danger в components.css портала (#991b1b/#fee2e2) */
  --ac-red: #991b1b;
  --bg-red: #fee2e2;
  --ac-gray: #64748b;
  --bg-gray: #f1f5f9;

  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.num {
  font-family: 'JetBrains Mono', 'SFMono-Regular', monospace;
  font-variant-numeric: tabular-nums;
}

a { color: inherit; }

/* ── Каркас: сайдбар слева + контент справа ─────────────────────── */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
}

.sidebar {
  /* Тот же градиент, что .left-col на основном портале (layout.php) — узнаваемый фирменный стиль */
  width: 230px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0f2460 0%, #1a3a8f 50%, #1e4db7 100%);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: .2px;
  color: #fff;
}

.brand-icon {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  white-space: nowrap;
}
.sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(255,255,255,.15); color: #fff; box-shadow: inset 3px 0 0 #60a5fa; }

.sidebar-auth-slot {
  margin-top: auto;
  font-size: 11.5px;
  color: rgba(255,255,255,.7);
  border-top: 1px solid rgba(255,255,255,.15);
  padding-top: 14px;
}
.sidebar-auth-slot .btn {
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.25);
  color: #fff;
}
.sidebar-auth-slot .btn:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.4); color: #fff; }
.sidebar-auth-slot div { color: #fff; }

.main-content { flex: 1; min-width: 0; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    gap: 14px;
    overflow-x: auto;
  }
  .sidebar-nav { flex-direction: row; }
  .sidebar-auth-slot { display: none; }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}
.badge.online  { background: var(--bg-green); color: var(--ac-green); }
.badge.offline { background: var(--bg-red); color: var(--ac-red); }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px currentColor;
  opacity: .25;
}
.badge.online .dot { animation: pulse 2s infinite; }
@keyframes pulse {
  0%, 100% { opacity: .18; }
  50%      { opacity: .4; }
}

/* ── Контейнер ───────────────────────────────────────────────── */

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-title { font-size: 20px; font-weight: 700; margin: 0; color: var(--text); }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 32px 0 14px;
}
.section-title:first-child { margin-top: 0; }

/* ── Метрики ─────────────────────────────────────────────────── */

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 680px) {
  .metrics { grid-template-columns: 1fr; }
}

.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.metric-card::before {
  content: '';
  position: absolute; inset: 0 0 auto 0;
  height: 3px;
  background: var(--status-color, var(--ac-gray));
}
.metric-card .icon { font-size: 22px; opacity: .9; }
.metric-card .label {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 10px;
  font-weight: 600;
}
.metric-card .value {
  font-size: 34px;
  font-weight: 700;
  margin-top: 2px;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.metric-card .value .unit { font-size: 15px; color: var(--muted); font-weight: 500; }
.metric-card .range { font-size: 12px; color: var(--muted); margin-top: 6px; }

.status-pill {
  position: absolute;
  top: 18px; right: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 4px 9px;
  border-radius: 999px;
}
.status-pill.green  { background: var(--bg-green);  color: var(--ac-green); }
.status-pill.yellow { background: var(--bg-amber); color: var(--ac-amber); }
.status-pill.red    { background: var(--bg-red);    color: var(--ac-red); }
.status-pill.gray   { background: var(--bg-gray);   color: var(--ac-gray); }

.metric-card[data-status="green"]  { --status-color: var(--ac-green); }
.metric-card[data-status="yellow"] { --status-color: var(--ac-amber); }
.metric-card[data-status="red"]    { --status-color: var(--ac-red); }
.metric-card[data-status="gray"]   { --status-color: var(--ac-gray); }

/* ── Карточки общего вида ───────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

/* ── Внутри / на улице — два значения в одной карточке ──────────── */

.dual-value {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 2px;
}
.dual-col.right { text-align: right; }
.metric-card .dual-value .value { font-size: 28px; }
.dual-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-top: 2px;
}

/* ── Режим Авто/Ручной (верх страницы) ─────────────────────────── */

.mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.mode-switch { display: flex; gap: 8px; }

/* ── Климат-контроль: статусы/ручное управление ─────────────────── */

.actuators-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (max-width: 560px) {
  .actuators-grid { grid-template-columns: 1fr; }
}

.actuator-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafcff;
}
.act-icon { font-size: 18px; }
.act-label { font-size: 13.5px; font-weight: 600; color: var(--text); flex: 1; }

.act-state-badge {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-gray);
  color: var(--ac-gray);
}
.act-state-badge.on { background: var(--bg-green); color: var(--ac-green); }
.act-state-badge.off { background: var(--bg-gray); color: var(--ac-gray); }

/* Переключатель-тумблер (iOS-style) — скрыт в авто-режиме, виден в ручном */
.switch { position: relative; width: 38px; height: 22px; flex-shrink: 0; display: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-switch {
  position: absolute; inset: 0; cursor: pointer;
  background: #cbd5e1; border-radius: 999px; transition: background .15s;
}
.slider-switch::before {
  content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider-switch { background: var(--ac); }
.switch input:checked + .slider-switch::before { transform: translateX(16px); }
.switch.active-ui { display: inline-block; }

.slider-item { margin-top: 14px; }
.slider-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.slider-head .act-label { flex: 1; }

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 5px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ac);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(26,86,219,.4);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border: none; border-radius: 50%;
  background: var(--ac); cursor: pointer;
}
input[type="range"]:disabled { opacity: .55; }
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--ac-gray); cursor: default; }

/* ── Реле (оставлено для совместимости стилей истории) ──────────── */

.relay-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.relay-left { display: flex; align-items: center; gap: 14px; }
.relay-icon {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  background: var(--bg-gray); color: var(--ac-gray);
  transition: background .2s, color .2s;
}
.relay-icon.on { background: var(--bg-green); color: var(--ac-green); }
.relay-title { font-weight: 700; font-size: 15px; color: var(--text); }
.relay-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.relay-controls { display: flex; align-items: center; gap: 8px; }
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
}
.btn:hover { border-color: var(--ac); color: var(--ac); }
.btn.primary { background: var(--ac); border-color: var(--ac); color: #fff; }
.btn.primary:hover { background: var(--ac2); border-color: var(--ac2); color: #fff; }
.btn.danger-outline { color: var(--ac-red); border-color: #fca5a5; }
.btn.danger-outline:hover { background: var(--bg-red); border-color: var(--ac-red); }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.active { background: #eaf1ff; border-color: var(--ac); color: var(--ac); }

/* ── График ──────────────────────────────────────────────────── */

.chart-wrap { position: relative; height: 280px; }

/* ── Настройки ───────────────────────────────────────────────── */

details.settings summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
details.settings summary::-webkit-details-marker { display: none; }
details.settings summary .chev { transition: transform .2s; color: var(--muted); }
details.settings[open] summary .chev { transform: rotate(180deg); }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 18px;
}
@media (max-width: 680px) {
  .settings-grid { grid-template-columns: 1fr 1fr; }
}
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.field input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
}
.field input:focus {
  outline: none;
  border-color: var(--ac);
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}

.save-row { display: flex; justify-content: flex-end; margin-top: 16px; gap: 10px; align-items: center; }
.save-hint { font-size: 12px; color: var(--ac-green); opacity: 0; transition: opacity .3s; }
.save-hint.show { opacity: 1; }

/* ── Таблица истории ─────────────────────────────────────────── */

.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters .field { min-width: 150px; }

table.history {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 13.5px;
}
table.history th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
table.history td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
table.history tr:last-child td { border-bottom: none; }
table.history tr:hover td { background: #f8fafc; }

.chip {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.chip.on  { background: var(--bg-green); color: var(--ac-green); }
.chip.off { background: var(--bg-gray); color: var(--ac-gray); }

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

.table-scroll { overflow-x: auto; }

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

/* ── Культура хранения ───────────────────────────────────────────── */

.culture-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 18px;
}
.culture-line b { color: var(--text); }
.culture-line a { font-size: 12.5px; color: var(--ac); text-decoration: none; margin-left: auto; }
.culture-line a:hover { text-decoration: underline; }

.culture-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 760px) {
  .culture-grid { grid-template-columns: repeat(2, 1fr); }
}

.culture-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  position: relative;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.culture-card.active { border-color: var(--ac); background: #f3f7ff; }
.culture-active-badge {
  position: absolute; top: 10px; right: 10px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  background: var(--ac); color: #fff; padding: 3px 7px; border-radius: 999px;
}
.culture-icon { font-size: 32px; }
.culture-name { font-weight: 700; font-size: 14.5px; margin: 8px 0 10px; color: var(--text); }
.culture-range { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.culture-card .btn { width: 100%; margin-top: 12px; }
