:root {
  color-scheme: dark;
  --bg: #061019;
  --bg-soft: #0a1822;
  --panel: #0d1c27;
  --panel-2: #102433;
  --line: #1b3344;
  --line-soft: #142837;
  --text: #e8f2f8;
  --muted: #89a3b6;
  --muted-2: #638096;
  --accent: #4cc9f0;
  --accent-2: #7ae582;
  --amber: #f4c95d;
  --red: #ff6b6b;
  --blue: #78a6ff;
  --purple: #b79cff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 600px at 8% -8%, rgba(22, 97, 128, 0.28), transparent 65%),
    radial-gradient(900px 600px at 100% 4%, rgba(25, 82, 58, 0.18), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; background: #0a1a24; border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }
svg { display: block; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.sep { color: var(--muted-2); }

.ambient {
  position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.65), transparent 75%);
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(6, 16, 25, 0.82);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 auto;
  border-radius: 13px; color: #06212b;
  background: linear-gradient(145deg, #7ae582, #4cc9f0);
  box-shadow: 0 0 24px rgba(76, 201, 240, 0.28);
}
.brand-mark svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.brand-copy { display: grid; line-height: 1.15; }
.brand-copy strong { font-size: 18px; letter-spacing: -0.02em; }
.brand-copy span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.13em; }

.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.device-picker select {
  min-width: 190px; max-width: 280px;
  color: var(--text); background: #0b1a24; border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 34px 9px 12px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.device-picker select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Pills and buttons */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line); color: var(--muted); background: #0a1721;
  font-size: 12px; font-weight: 600;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 9px currentColor; }
.pill.online { color: var(--accent-2); border-color: rgba(122, 229, 130, 0.32); background: rgba(25, 77, 48, 0.25); }
.pill.offline { color: var(--red); border-color: rgba(255, 107, 107, 0.3); background: rgba(83, 25, 25, 0.22); }
.pill.neutral { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px;
  color: #04121a; background: linear-gradient(180deg, #67d8f7, #42b9dc);
  font-weight: 700; font-size: 14px;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn.ghost { color: var(--text); background: #0e202c; border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: #2e5268; background: #122836; }
.btn.danger { color: #ffb5b5; border-color: rgba(255, 107, 107, 0.35); background: rgba(83, 25, 25, 0.25); }
.btn.danger:hover:not(:disabled) { background: rgba(112, 33, 33, 0.4); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.full { width: 100%; }
.btn:focus-visible, .icon-btn:focus-visible, .mode-btn:focus-visible, .range-tabs button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Layout */
.shell { width: min(1440px, 94vw); margin: 0 auto; padding: 22px 0 40px; }
.dashboard { display: grid; gap: 16px; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 16px; margin-bottom: 16px;
  border: 1px solid rgba(244, 201, 93, 0.28); border-radius: var(--radius-sm);
  background: rgba(94, 72, 18, 0.18); color: #f6dfa3; font-size: 14px;
}
.banner strong { color: #ffe8a8; }

/* Hero */
.hero {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 24px;
  padding: 26px 28px; border: 1px solid var(--line); border-radius: var(--radius);
  background:
    radial-gradient(700px 220px at 12% 0%, rgba(76, 201, 240, 0.1), transparent 70%),
    linear-gradient(145deg, #0d1e2a, #0a1721 68%);
  box-shadow: var(--shadow);
}
.hero-kicker { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.hero-title { display: flex; align-items: center; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
.hero-title h1 { font-size: clamp(24px, 3.2vw, 38px); line-height: 1.1; letter-spacing: -0.035em; }
.hero .muted { margin-top: 8px; max-width: 720px; }

.mode-badge {
  display: inline-grid; place-items: center; min-width: 72px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 9px;
  font: 800 13px/1 var(--mono); letter-spacing: 0.12em;
}
.mode-badge.is-auto { color: #9cf3a5; border-color: rgba(122, 229, 130, 0.35); background: rgba(29, 90, 51, 0.28); }
.mode-badge.is-manual { color: #a9c8ff; border-color: rgba(120, 166, 255, 0.38); background: rgba(38, 65, 117, 0.3); }
.mode-badge.is-off { color: #ffc0c0; border-color: rgba(255, 107, 107, 0.36); background: rgba(96, 29, 29, 0.28); }

.hero-facts { display: grid; grid-template-columns: repeat(3, minmax(105px, 1fr)); gap: 10px; margin: 0; }
.hero-facts div { padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: 11px; background: rgba(5, 15, 22, 0.45); }
.hero-facts dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }
.hero-facts dd { margin: 4px 0 0; font-weight: 700; font-size: 13px; white-space: nowrap; }

/* Status strip */
.status-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.status-tile {
  position: relative; overflow: hidden;
  padding: 16px 17px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: linear-gradient(160deg, #0e202c, #0a1721);
  transition: border-color 0.2s ease, background 0.2s ease;
}
.status-tile::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 3px;
  background: var(--line); opacity: 0.8;
}
.status-tile.is-on { border-color: rgba(122, 229, 130, 0.35); }
.status-tile.is-on::after { background: var(--accent-2); box-shadow: 0 0 18px var(--accent-2); }
.status-tile.is-warn { border-color: rgba(244, 201, 93, 0.4); }
.status-tile.is-warn::after { background: var(--amber); }
.status-tile.is-danger { border-color: rgba(255, 107, 107, 0.4); }
.status-tile.is-danger::after { background: var(--red); }
.tile-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.tile-light { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.status-tile.is-on .tile-light { background: var(--accent-2); box-shadow: 0 0 12px var(--accent-2); }
.status-tile.is-warn .tile-light { background: var(--amber); box-shadow: 0 0 12px var(--amber); }
.status-tile.is-danger .tile-light { background: var(--red); box-shadow: 0 0 12px var(--red); }
.status-tile strong { display: block; margin-top: 11px; font-size: 24px; letter-spacing: -0.03em; line-height: 1; }
.status-tile small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }

/* Metrics */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.metric { padding: 14px 15px; border: 1px solid var(--line-soft); border-radius: 12px; background: rgba(11, 25, 34, 0.8); }
.metric > span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.metric strong { display: block; margin-top: 6px; font: 700 22px/1.1 var(--mono); letter-spacing: -0.04em; }
.metric small { display: block; margin-top: 5px; color: var(--muted-2); font-size: 11px; }

/* Cards */
.card {
  padding: 20px 22px; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(170deg, rgba(15, 33, 45, 0.92), rgba(9, 22, 31, 0.92));
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.2);
}
.card h2 { font-size: 18px; letter-spacing: -0.02em; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; flex-wrap: wrap; }
.card-head > div:first-child { min-width: 0; }
.card-head .muted { font-size: 12.5px; margin-top: 3px; }

/* Charts */
.charts-card { display: grid; gap: 16px; }
.range-tabs { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #0a1721; }
.range-tabs button { border: 0; border-radius: 7px; padding: 6px 12px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.range-tabs button:hover { color: var(--text); }
.range-tabs button.active { color: #07202a; background: var(--accent); }
.chart-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.chart { padding: 12px 12px 6px; border: 1px solid var(--line-soft); border-radius: 12px; background: rgba(5, 14, 21, 0.5); }
.chart figcaption { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.chart .chart-now { color: var(--text); font-family: var(--mono); font-size: 12px; letter-spacing: 0; text-transform: none; }
.chart canvas { display: block; width: 100%; height: 150px; }
.chart-note { color: var(--muted-2); font-size: 12px; }

/* Two-column */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.mode-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.mode-btn {
  display: grid; gap: 4px; text-align: left; padding: 13px 14px;
  color: var(--text); background: #0b1923; border: 1px solid var(--line); border-radius: 11px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.mode-btn:hover:not(:disabled) { border-color: #2d556c; transform: translateY(-1px); }
.mode-btn strong { font-size: 13px; letter-spacing: 0.06em; }
.mode-btn span { color: var(--muted); font-size: 11.5px; }
.mode-btn.active { border-color: rgba(76, 201, 240, 0.55); background: rgba(22, 76, 96, 0.3); box-shadow: inset 0 0 0 1px rgba(76, 201, 240, 0.15); }
.mode-btn[data-mode="off"].active { border-color: rgba(255, 107, 107, 0.5); background: rgba(89, 28, 28, 0.28); }

.note { margin-top: 14px; color: var(--muted); font-size: 12px; }
.warn-note { color: #e9c77a; }

.override-row {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  padding: 13px 0; border-bottom: 1px solid var(--line-soft);
}
.override-row:last-of-type { border-bottom: 0; }
.override-copy { display: grid; gap: 2px; }
.override-copy strong { font-size: 14px; }
.override-copy span { color: var(--muted); font-size: 12px; }
.inline-fields { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.compact { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.compact input { width: 58px; padding: 6px 7px; }
.inline-fields input {
  color: var(--text); background: #08151e; border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px;
}

.threshold-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.threshold-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.threshold-grid label.check { display: flex; align-items: center; gap: 9px; min-height: 39px; padding-top: 15px; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 13px; }
.threshold-grid input[type="number"] {
  width: 100%; color: var(--text); background: #08151e; border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 11px; font-family: var(--mono); font-size: 14px;
}
.threshold-grid input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto; }
.unit { color: var(--muted-2); font-size: 10px; letter-spacing: 0; text-transform: none; }
.actions-row { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

/* Tables */
.table-wrap { margin-top: 14px; overflow-x: auto; }
.commands-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 680px; }
.commands-table th { padding: 9px 10px; text-align: left; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; border-bottom: 1px solid var(--line); }
.commands-table td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.commands-table tr:last-child td { border-bottom: 0; }
.commands-table .mono { font-family: var(--mono); font-size: 11.5px; color: #b9cedd; word-break: break-word; }
.status-badge { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.status-badge.pending { color: #ffe2a1; background: rgba(110, 82, 19, 0.35); }
.status-badge.sent { color: #b7d6ff; background: rgba(35, 72, 121, 0.4); }
.status-badge.completed { color: #a9efb2; background: rgba(31, 91, 51, 0.4); }
.status-badge.failed, .status-badge.expired { color: #ffb3b3; background: rgba(103, 31, 31, 0.4); }

/* Architecture */
.architecture-card { display: flex; align-items: flex-start; gap: 16px; }
.arch-icon { display: grid; place-items: center; width: 46px; height: 46px; flex: 0 0 auto; border-radius: 12px; color: var(--accent); background: rgba(76, 201, 240, 0.1); border: 1px solid rgba(76, 201, 240, 0.22); }
.arch-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.architecture-card p { margin-top: 5px; color: var(--muted); font-size: 13px; max-width: 1050px; }

/* Empty state */
.empty-state {
  width: min(680px, 100%); margin: 8vh auto; padding: 38px 34px; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(160deg, #0d1f2b, #091620);
  box-shadow: var(--shadow);
}
.empty-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 18px; border-radius: 18px; color: var(--accent); background: rgba(76, 201, 240, 0.1); border: 1px solid rgba(76, 201, 240, 0.25); }
.empty-icon svg { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.empty-state h1 { font-size: 26px; letter-spacing: -0.03em; }
.empty-state p { margin-top: 12px; color: var(--muted); }

/* Footer */
.footer { display: flex; justify-content: space-between; gap: 14px; width: min(1440px, 94vw); margin: 0 auto; padding: 0 0 26px; color: var(--muted-2); font-size: 11.5px; }
.footer span:last-child { text-align: right; }

/* Dialog */
.login-dialog {
  width: min(420px, 92vw); padding: 0; color: var(--text);
  border: 1px solid var(--line); border-radius: 18px; background: #0c1b26;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
}
.login-dialog::backdrop { background: rgba(2, 8, 13, 0.72); backdrop-filter: blur(5px); }
.login-dialog form { padding: 22px; display: grid; gap: 14px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dialog-head h2 { font-size: 24px; margin-top: 4px; letter-spacing: -0.03em; }
.eyebrow { color: var(--accent); font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em; font-weight: 800; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #0b1923; font-size: 20px; line-height: 1; }
.icon-btn:hover { color: var(--text); border-color: #31536a; }
.login-dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.login-dialog input[type="password"] {
  width: 100%; padding: 11px 12px; color: var(--text); background: #08141d;
  border: 1px solid var(--line); border-radius: 10px;
}
.form-error { min-height: 18px; color: var(--red); font-size: 12.5px; }
.dialog-note { color: var(--muted-2); font-size: 11.5px; text-align: center; }

/* Toast */
.toast {
  position: fixed; z-index: 50; right: 20px; bottom: 20px;
  max-width: min(430px, calc(100vw - 40px));
  padding: 12px 15px; border: 1px solid var(--line); border-radius: 11px;
  color: var(--text); background: #10232f; box-shadow: var(--shadow);
  font-size: 13px; opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: rgba(122, 229, 130, 0.4); }
.toast.err { border-color: rgba(255, 107, 107, 0.45); }
.noscript { position: fixed; inset: auto 20px 20px; padding: 14px; background: #4a1d1d; color: #fff; border-radius: 10px; }

/* Responsive */
@media (max-width: 1100px) {
  .status-strip { grid-template-columns: repeat(2, 1fr); }
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .threshold-grid { grid-template-columns: repeat(3, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .hero { align-items: flex-start; flex-direction: column; }
  .hero-facts { width: 100%; grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; justify-content: flex-start; }
  .device-picker { flex: 1 1 200px; }
  .device-picker select { width: 100%; max-width: none; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .threshold-grid { grid-template-columns: repeat(2, 1fr); }
  .mode-buttons { grid-template-columns: 1fr; }
  .override-row { align-items: flex-start; flex-direction: column; gap: 10px; }
  .inline-fields { justify-content: flex-start; }
  .hero { padding: 20px; }
  .hero-facts { grid-template-columns: 1fr 1fr; }
  .footer { flex-direction: column; gap: 5px; }
  .footer span:last-child { text-align: left; }
  .banner { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 460px) {
  .status-strip, .metrics, .threshold-grid { grid-template-columns: 1fr 1fr; }
  .status-tile strong { font-size: 20px; }
  .metric strong { font-size: 18px; }
  .card { padding: 16px; }
  .hero-facts { grid-template-columns: 1fr; }
}
