:root {
  --bg: #0f1418;
  --panel: #171e24;
  --panel-2: #1e272f;
  --line: #2a3640;
  --text: #e8eef2;
  --muted: #93a3ae;
  --accent: #22b8c2;
  --accent-dark: #178089;
  --ok: #2fb35a;
  --warn: #e0a526;
  --bad: #e5524d;
  --blue: #3b5b8c;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

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

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
}
.badge-ok { background: rgba(47, 179, 90, .18); color: #6fdc92; }
.badge-bad { background: rgba(229, 82, 77, .2); color: #ff8a85; }
.badge-unknown { background: var(--panel-2); color: var(--muted); }

.banner {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: rgba(229, 82, 77, .16);
  border: 1px solid rgba(229, 82, 77, .5);
}
.banner.warn { background: rgba(224, 165, 38, .14); border-color: rgba(224, 165, 38, .5); }

/* ---------- Layout ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  padding: 14px 20px 28px;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

.card > h2 { margin-bottom: 12px; }

.card-temp { grid-column: span 4; }
.card-mode { grid-column: span 5; }
.card-setpoints { grid-column: span 3; }
.card-health { grid-column: span 12; }
.card-chart { grid-column: span 12; }
.card-alerts { grid-column: span 12; }
.card-log { grid-column: span 12; }

@media (max-width: 900px) {
  .card-temp, .card-mode, .card-setpoints { grid-column: span 12; }
  .top { padding: 10px 14px; }
  .grid { padding: 10px 14px 24px; }
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* ---------- Temperature ---------- */

.temp-value { font-size: 64px; font-weight: 700; line-height: 1.05; }
.temp-unit { font-size: 24px; color: var(--muted); margin-left: 4px; }

.chip {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .05em;
}
.chip-on { background: var(--ok); color: #04210d; }
.chip-off { background: var(--blue); color: #fff; }
.chip-wait { background: var(--warn); color: #2a1d00; }

/* ---------- Mode ---------- */

.mode-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.mode-buttons button {
  padding: 18px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
}
.mode-buttons button:hover:not(:disabled) { border-color: var(--accent); }
.mode-buttons button.active { background: var(--accent); border-color: var(--accent); color: #04282b; }
.mode-buttons button.pending { outline: 2px dashed var(--warn); outline-offset: 2px; }
.mode-buttons button:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 520px) {
  .mode-buttons { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Setpoints / forms ---------- */

.sp-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sp-row label { color: var(--muted); font-size: 13px; }

input[type="text"], input[type="password"], input[type="number"] {
  width: 110px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #0c1115;
  color: var(--text);
  font: inherit;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.form-error { color: #ff8a85; margin: 8px 0; font-size: 13px; }

button.primary, button.secondary, button.danger {
  padding: 9px 16px;
  border-radius: 6px;
  border: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button.primary { background: var(--accent); color: #04282b; }
button.primary:hover:not(:disabled) { background: #3bd0da; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--bad); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 4px; }
button.link:hover { text-decoration: underline; }

/* ---------- Health ---------- */

.health { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 0; }
.health > div { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.health dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.health dd { margin: 4px 0 0; font-weight: 700; font-size: 17px; }
.health .ok { color: #6fdc92; }
.health .warn { color: #f0c04a; }
.health .bad { color: #ff8a85; }

@media (max-width: 700px) { .health { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Charts ---------- */

.tabs { display: flex; gap: 4px; }
.tabs button {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #04282b; font-weight: 700; }

.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; touch-action: pan-y; }

.chart-wrap .grid-line { stroke: var(--line); stroke-width: 1; }
.chart-wrap .axis-label { fill: var(--muted); font-size: 11px; }
.chart-wrap .series { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart-wrap .band { fill: rgba(47, 179, 90, .16); }
.chart-wrap .sp-on { stroke: #ff8a6a; stroke-dasharray: 5 4; stroke-width: 1.2; }
.chart-wrap .sp-off { stroke: #6fdc92; stroke-dasharray: 5 4; stroke-width: 1.2; }
.chart-wrap .empty { fill: var(--muted); font-size: 14px; text-anchor: middle; }
.chart-wrap .cursor { stroke: var(--muted); stroke-width: 1; }
.chart-wrap .dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }

.tip {
  position: absolute;
  pointer-events: none;
  background: #0c1115;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(-50%, -110%);
}

.legend { margin: 8px 0 0; }
.key { display: inline-block; width: 14px; height: 10px; vertical-align: middle; margin-right: 4px; }
.key-run { background: rgba(47, 179, 90, .5); }
.key-sp { border-top: 2px dashed #ff8a6a; height: 0; }

/* ---------- Log ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.when { white-space: nowrap; color: var(--muted); }
.kind-ok { color: #6fdc92; }
.kind-warn { color: #f0c04a; }
.kind-bad { color: #ff8a85; }

/* ---------- Dialog ---------- */

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 420px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Login ---------- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.login-card h1 { margin-bottom: 4px; }
.login-card form { margin-top: 16px; }
.login-card label { display: block; color: var(--muted); font-size: 13px; margin: 12px 0 4px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 16px; }

/* ---------- Alerts ---------- */

.alerts-status { margin: 0 0 6px; font-weight: 600; }
.alerts-status.ok { color: #6fdc92; }
.alerts-status.bad { color: #ff8a85; }
.alerts-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.alerts-actions[hidden], .alerts-actions button[hidden] { display: none; }