/* ==========================================================================
   OWEN Monitoring Dashboard — оформление
   Тёмная «промышленная» тема, адаптивная вёрстка, без внешних зависимостей.
   ========================================================================== */

:root {
  --bg: #080e19;
  --bg-soft: #0b1424;
  --panel: #0f1a2c;
  --panel-2: #142138;
  --panel-3: #1a2a45;
  --border: #1f3049;
  --border-strong: #2c4160;
  --text: #e9eff9;
  --muted: #93a6c0;
  --dim: #64778f;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.14);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.28);
  --font: "Segoe UI", system-ui, -apple-system, "Roboto", "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1100px 600px at 82% -10%, rgba(56, 189, 248, 0.09), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(167, 139, 250, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: none; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

::selection { background: rgba(56, 189, 248, 0.3); }

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

/* ── Загрузка / служебное ─────────────────────────────────────────────────── */

.app-boot { min-height: 100vh; display: grid; place-items: center; }

.boot-screen { display: flex; flex-direction: column; align-items: center; gap: 18px; color: var(--muted); }
.boot-screen p { font-size: 14px; letter-spacing: 0.02em; }

.boot-mark {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.noscript {
  margin: 40px auto;
  max-width: 560px;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--amber);
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: currentColor;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

.loading-block { display: grid; place-items: center; padding: 80px 0; color: var(--muted); gap: 14px; }

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

.shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 16px 18px;
  background: linear-gradient(180deg, rgba(15, 26, 44, 0.96), rgba(10, 18, 31, 0.96));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 20;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.22), rgba(56, 189, 248, 0.04));
  border: 1px solid rgba(56, 189, 248, 0.32);
  color: var(--accent);
  flex: none;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: 0.14em; font-weight: 700; }
.brand-text span { font-size: 11.5px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }

.nav-section {
  margin: 16px 10px 6px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.035); color: var(--text); }

.nav-link.active {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.16), rgba(56, 189, 248, 0.04));
  color: #dff4ff;
  border-color: rgba(56, 189, 248, 0.22);
}

.nav-link .nav-icon { display: inline-flex; color: currentColor; opacity: 0.9; }
.nav-link .nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red);
}

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; }

.user-card { display: flex; align-items: center; gap: 10px; padding: 4px 4px 10px; }
.user-meta { min-width: 0; flex: 1; }
.user-meta strong { display: block; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { display: block; font-size: 11.5px; color: var(--muted); }

.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #082032;
  background: linear-gradient(140deg, #7dd3fc, #38bdf8);
}

.sidebar-actions { display: flex; gap: 6px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); border-color: var(--border); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 62px;
  padding: 10px 28px;
  background: rgba(8, 14, 25, 0.78);
  border-bottom: 1px solid rgba(31, 48, 73, 0.75);
  backdrop-filter: blur(14px);
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.topbar-title { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-sub { font-size: 12px; color: var(--dim); }

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

.topbar-avatar { width: 32px; height: 32px; border: 0; padding: 0; font-size: 11px; border-radius: 9px; cursor: pointer; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(15, 26, 44, 0.6);
  white-space: nowrap;
}

.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.12); }
.live.offline .live-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.12); }

.content { padding: 26px 28px 56px; width: 100%; max-width: 1460px; margin: 0 auto; }

.view { display: flex; flex-direction: column; gap: 22px; animation: view-in 0.22s ease-out; }

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ── Заголовки страниц ────────────────────────────────────────────────────── */

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.page-title { font-size: clamp(22px, 2.4vw, 28px); line-height: 1.2; }
.page-sub { margin-top: 5px; color: var(--muted); font-size: 13.5px; max-width: 760px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.breadcrumbs { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--dim); margin-bottom: 9px; flex-wrap: wrap; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs .sep { color: var(--border-strong); }

.status-line { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-top: 10px; }

/* ── Карточки и KPI ───────────────────────────────────────────────────────── */

.card {
  background: linear-gradient(180deg, rgba(20, 33, 56, 0.72), rgba(13, 23, 39, 0.86));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.card-head h2, .card-head h3 { font-size: 14.5px; font-weight: 650; }
.card-head .sub { font-size: 12px; color: var(--dim); margin-top: 2px; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: 14px; }

.kpi {
  position: relative;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(150deg, rgba(20, 33, 56, 0.9), rgba(12, 21, 36, 0.9));
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: auto -30% -70% auto;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.12), transparent 65%);
  pointer-events: none;
}

.kpi-icon {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.18);
}

.kpi.green .kpi-icon { background: var(--green-soft); color: var(--green); border-color: rgba(52, 211, 153, 0.2); }
.kpi.amber .kpi-icon { background: var(--amber-soft); color: var(--amber); border-color: rgba(251, 191, 36, 0.2); }
.kpi.red .kpi-icon { background: var(--red-soft); color: var(--red); border-color: rgba(248, 113, 113, 0.2); }

.kpi-value { font-size: 27px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi-label { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.kpi-sub { font-size: 11.5px; color: var(--dim); margin-top: 6px; }

/* ── Сетки карточек ───────────────────────────────────────────────────────── */

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.dashboard-split { display: grid; grid-template-columns: minmax(0, 1.85fr) minmax(300px, 1fr); gap: 18px; align-items: start; }

.installation-card { display: flex; flex-direction: column; gap: 14px; padding: 17px 18px; cursor: pointer; transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s; }
.installation-card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.installation-card:focus-visible { outline: 2px solid var(--accent); }

.inst-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.inst-name { font-size: 15.5px; font-weight: 650; }
.inst-address { font-size: 12.5px; color: var(--dim); margin-top: 3px; }
.inst-stats { display: flex; gap: 22px; padding-top: 12px; border-top: 1px solid rgba(31, 48, 73, 0.7); }
.stat-value { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 1px; }
.inst-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12px; color: var(--dim); }

/* ── Бейджи, статусы ──────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.badge.green { background: var(--green-soft); color: var(--green); border-color: rgba(52, 211, 153, 0.24); }
.badge.amber { background: var(--amber-soft); color: var(--amber); border-color: rgba(251, 191, 36, 0.24); }
.badge.red { background: var(--red-soft); color: var(--red); border-color: rgba(248, 113, 113, 0.24); }
.badge.blue { background: var(--accent-soft); color: var(--accent); border-color: rgba(56, 189, 248, 0.24); }
.badge.violet { background: var(--violet-soft); color: var(--violet); border-color: rgba(167, 139, 250, 0.24); }
.badge.gray { background: rgba(148, 163, 184, 0.1); color: var(--muted); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.green { background: var(--green); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12); }
.dot.amber { background: var(--amber); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.12); }
.dot.red { background: var(--red); box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.12); }
.dot.gray { background: var(--dim); box-shadow: 0 0 0 3px rgba(100, 119, 143, 0.12); }
.dot.pulse { animation: dot-pulse 2s ease-in-out infinite; }

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.role-chip { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--violet); background: var(--violet-soft); padding: 3px 8px; border-radius: 6px; }

/* ── Аварии ───────────────────────────────────────────────────────────────── */

.alarm-list { display: flex; flex-direction: column; }
.alarm-item { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid rgba(31, 48, 73, 0.65); }
.alarm-item:last-child { border-bottom: 0; }
.alarm-bar { width: 3px; border-radius: 3px; background: var(--amber); flex: none; }
.alarm-item.critical .alarm-bar { background: var(--red); }
.alarm-body { min-width: 0; flex: 1; }
.alarm-msg { font-size: 13px; line-height: 1.45; color: var(--text); }
.alarm-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11.5px; color: var(--dim); margin-top: 4px; }
.alarm-meta .sep { color: var(--border-strong); }
.alarm-ack { align-self: center; }

/* ── Устройства ───────────────────────────────────────────────────────────── */

.devices-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.device-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(165deg, rgba(20, 33, 56, 0.72), rgba(12, 21, 36, 0.9));
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.device-card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow-soft); }
.device-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.device-name { font-size: 14.5px; font-weight: 650; line-height: 1.35; }
.device-sub { font-size: 11.5px; color: var(--dim); margin-top: 4px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.source-badge { font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); border: 1px solid rgba(56, 189, 248, 0.2); padding: 2px 7px; border-radius: 5px; font-weight: 650; }
.source-badge.modbus { color: var(--violet); background: var(--violet-soft); border-color: rgba(167, 139, 250, 0.2); }
.source-badge.mock { color: var(--muted); background: rgba(148, 163, 184, 0.1); border-color: var(--border); }

.device-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.dm-value { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; letter-spacing: -0.01em; }
.dm-value small { font-size: 11px; color: var(--dim); font-weight: 500; margin-left: 3px; }
.dm-value.critical { color: var(--red); }
.dm-value.warning { color: var(--amber); }
.dm-label { font-size: 11px; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Метрики прибора ──────────────────────────────────────────────────────── */

.metrics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 13px; }

.metric-card {
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(165deg, rgba(20, 33, 56, 0.68), rgba(12, 21, 36, 0.9));
  position: relative;
  overflow: hidden;
}

.metric-card.critical { border-color: rgba(248, 113, 113, 0.42); }
.metric-card.warning { border-color: rgba(251, 191, 36, 0.38); }

.metric-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.metric-label { font-size: 12px; color: var(--muted); }
.metric-time { font-size: 10.5px; color: var(--dim); font-variant-numeric: tabular-nums; }
.metric-value { margin-top: 6px; font-size: 29px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.metric-value.critical { color: var(--red); }
.metric-value.warning { color: var(--amber); }
.metric-unit { font-size: 12.5px; color: var(--dim); font-weight: 500; margin-left: 4px; }
.metric-error { margin-top: 6px; font-size: 11.5px; color: var(--red); }

.gauge { position: relative; height: 5px; border-radius: 99px; background: rgba(148, 163, 184, 0.16); margin-top: 12px; overflow: visible; }
.gauge-fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: linear-gradient(90deg, rgba(56, 189, 248, 0.55), var(--accent)); }
.metric-card.critical .gauge-fill { background: linear-gradient(90deg, rgba(248, 113, 113, 0.55), var(--red)); }
.metric-card.warning .gauge-fill { background: linear-gradient(90deg, rgba(251, 191, 36, 0.55), var(--amber)); }
.gauge-mark { position: absolute; top: -3px; width: 1px; height: 11px; background: rgba(255, 255, 255, 0.35); }
.gauge-mark.alarm { background: var(--red); }
.gauge-mark.warn { background: var(--amber); }
.gauge-scale { display: flex; justify-content: space-between; margin-top: 5px; font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; }

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

.chart-toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.chart-metrics { display: flex; gap: 4px; flex-wrap: wrap; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: 9px; background: rgba(8, 14, 25, 0.55); }
.seg-btn { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 5px 10px; border-radius: 6px; font-weight: 550; }
.seg-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.seg-btn.active { background: var(--accent-soft); color: var(--accent); }

.chart-wrap { position: relative; width: 100%; height: 300px; margin-top: 12px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  min-width: 120px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: rgba(10, 18, 31, 0.96);
  box-shadow: var(--shadow-soft);
  font-size: 12px;
  transform: translate(-50%, -110%);
  opacity: 0;
  transition: opacity 0.12s;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-time { color: var(--dim); font-size: 10.5px; }
.chart-tooltip .tt-value { font-weight: 700; font-size: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 13px; }
.chart-empty[hidden] { display: none; }

.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11px; color: var(--dim); margin-top: 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 2px; border-radius: 2px; background: var(--accent); }
.legend-swatch.warn { background: var(--amber); }
.legend-swatch.alarm { background: var(--red); }

/* ── Информационные списки ────────────────────────────────────────────────── */

.info-list { display: flex; flex-direction: column; }
.info-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid rgba(31, 48, 73, 0.55); font-size: 12.5px; }
.info-row:last-child { border-bottom: 0; }
.info-key { color: var(--dim); }
.info-val { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mono { font-family: var(--mono); font-size: 12px; }

.device-layout { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ── Таблицы ──────────────────────────────────────────────────────────────── */

.table-wrap { width: 100%; overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 650;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: rgba(8, 14, 25, 0.35);
}
.table td { padding: 12px 14px; border-bottom: 1px solid rgba(31, 48, 73, 0.55); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
.table .num { font-variant-numeric: tabular-nums; }
.table .muted { color: var(--dim); }
.table .nowrap { white-space: nowrap; }

.cell-user { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.cell-user .avatar { width: 30px; height: 30px; border-radius: 8px; font-size: 11.5px; }
.cell-user strong { display: block; font-weight: 600; font-size: 13px; }
.cell-user span { display: block; font-size: 11px; color: var(--dim); }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions .icon-btn { width: 30px; height: 30px; }
.row-actions .icon-btn.danger:hover { color: var(--red); border-color: rgba(248, 113, 113, 0.3); background: var(--red-soft); }

/* ── Кнопки ───────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:hover { background: rgba(255, 255, 255, 0.06); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #38bdf8, #0ea5e9); border-color: #0ea5e9; color: #05202e; }
.btn.primary:hover { background: linear-gradient(180deg, #5cc9fa, #16a9e8); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.btn.danger { background: rgba(248, 113, 113, 0.1); border-color: rgba(248, 113, 113, 0.35); color: #fca5a5; }
.btn.danger:hover { background: rgba(248, 113, 113, 0.18); }
.btn.sm { min-height: 30px; padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }

/* ── Формы ────────────────────────────────────────────────────────────────── */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 11px; color: var(--dim); line-height: 1.4; }
.hint { font-size: 11.5px; color: var(--dim); line-height: 1.45; }

.input, .select, .textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(8, 14, 25, 0.66);
  color: var(--text);
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder, .textarea::placeholder { color: #52657c; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.13); }
.textarea { min-height: 84px; resize: vertical; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.select option { background: #0f1a2c; }

.checkbox { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; color: var(--muted); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

.form-error {
  display: none;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: var(--red-soft);
  color: #fecaca;
  font-size: 12.5px;
}
.form-error.visible { display: block; }

.form-section { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 11px; background: rgba(8, 14, 25, 0.32); }
.form-section-title { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); font-weight: 650; }

.password-meter { height: 5px; border-radius: 99px; background: rgba(148, 163, 184, 0.15); overflow: hidden; margin-top: 2px; }
.password-meter span { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--red); transition: width 0.2s, background 0.2s; }

.password-rules { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; font-size: 11.5px; color: var(--dim); }
.password-rules li::before { content: "•"; margin-right: 7px; color: var(--border-strong); }
.password-rules li.ok { color: var(--green); }
.password-rules li.ok::before { content: "✓"; color: var(--green); }

/* ── Вкладки ──────────────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab { padding: 9px 14px; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-row .input { max-width: 280px; }

/* ── Модальные окна ───────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 18px;
  background: rgba(3, 7, 14, 0.72);
  backdrop-filter: blur(4px);
  overflow-y: auto;
  animation: backdrop-in 0.15s ease-out;
}

@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 560px;
  margin: auto;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, #132138, #0d1728);
  box-shadow: var(--shadow);
  animation: modal-in 0.18s ease-out;
}

.modal.lg { max-width: 880px; }
.modal.sm { max-width: 420px; }

@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.99); } to { opacity: 1; transform: none; } }

.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); flex: none; }
.modal-head h2 { font-size: 17px; }
.modal-head p { font-size: 12.5px; color: var(--dim); margin-top: 3px; }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; flex: none; }
.modal-foot .left { margin-right: auto; }

/* ── Уведомления ──────────────────────────────────────────────────────────── */

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 9px; width: min(380px, calc(100vw - 36px)); }
.toast {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: rgba(15, 26, 44, 0.98);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 0.2s ease-out;
}
.toast.success { border-color: rgba(52, 211, 153, 0.4); }
.toast.error { border-color: rgba(248, 113, 113, 0.45); }
.toast .toast-icon { flex: none; margin-top: 1px; }
.toast.success .toast-icon { color: var(--green); }
.toast.error .toast-icon { color: var(--red); }
.toast.info .toast-icon { color: var(--accent); }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Пустые состояния и баннеры ───────────────────────────────────────────── */

.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 46px 20px; text-align: center; color: var(--dim); }
.empty-icon { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; background: rgba(148, 163, 184, 0.08); color: var(--muted); border: 1px solid var(--border); }
.empty h3 { font-size: 15px; color: var(--text); }
.empty p { font-size: 12.5px; max-width: 420px; }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px; font-size: 12.5px; border: 1px solid var(--border); background: rgba(255, 255, 255, 0.02); }
.banner .banner-icon { flex: none; margin-top: 1px; }
.banner.info { border-color: rgba(56, 189, 248, 0.3); background: var(--accent-soft); color: #c9ecff; }
.banner.warning { border-color: rgba(251, 191, 36, 0.3); background: var(--amber-soft); color: #fde68a; }
.banner.error { border-color: rgba(248, 113, 113, 0.35); background: var(--red-soft); color: #fecaca; }

/* ── Авторизация ──────────────────────────────────────────────────────────── */

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(380px, 0.95fr); }

.auth-aside {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 52px clamp(30px, 5vw, 76px);
  border-right: 1px solid var(--border);
  background:
    radial-gradient(700px 500px at 20% 15%, rgba(56, 189, 248, 0.14), transparent 62%),
    radial-gradient(520px 420px at 90% 95%, rgba(167, 139, 250, 0.12), transparent 60%),
    linear-gradient(160deg, #0b1728, #070d17);
  overflow: hidden;
}

.auth-aside::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(56, 189, 248, 0.045) 1px, transparent 1px), linear-gradient(90deg, rgba(56, 189, 248, 0.045) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(circle at 30% 30%, #000 0%, transparent 72%);
  pointer-events: none;
}

.auth-brand { position: relative; display: flex; align-items: center; gap: 13px; }
.auth-brand .brand-mark { width: 46px; height: 46px; }
.auth-brand strong { font-size: 18px; letter-spacing: 0.16em; }
.auth-brand span { display: block; font-size: 11px; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; }

.auth-hero { position: relative; max-width: 520px; }
.auth-hero h1 { font-size: clamp(30px, 3.4vw, 43px); line-height: 1.12; letter-spacing: -0.025em; }
.auth-hero h1 em { font-style: normal; color: var(--accent); }
.auth-hero p { margin-top: 16px; color: var(--muted); font-size: 14.5px; }

.feature-list { position: relative; display: flex; flex-direction: column; gap: 13px; margin: 30px 0 0; padding: 0; list-style: none; }
.feature-list li { display: flex; gap: 11px; font-size: 13px; color: var(--muted); }
.feature-list .f-icon { width: 28px; height: 28px; flex: none; border-radius: 8px; display: grid; place-items: center; background: rgba(56, 189, 248, 0.1); color: var(--accent); border: 1px solid rgba(56, 189, 248, 0.18); }
.feature-list strong { color: var(--text); font-weight: 600; }

.auth-aside-foot { position: relative; font-size: 11.5px; color: var(--dim); }

.auth-panel { display: flex; flex-direction: column; justify-content: center; padding: 40px clamp(22px, 5vw, 64px); }
.auth-card { width: 100%; max-width: 400px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.auth-card h2 { font-size: 24px; }
.auth-card .auth-sub { font-size: 13px; color: var(--muted); margin-top: 5px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-foot { font-size: 11.5px; color: var(--dim); text-align: center; line-height: 1.6; }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 42px; }
.input-wrap .reveal { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: 0; background: transparent; color: var(--dim); border-radius: 7px; display: grid; place-items: center; }
.input-wrap .reveal:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

.auth-alert { display: none; padding: 10px 12px; border-radius: 9px; background: var(--red-soft); border: 1px solid rgba(248, 113, 113, 0.35); color: #fecaca; font-size: 12.5px; }
.auth-alert.visible { display: block; }

.credentials-box { padding: 14px; border-radius: 10px; border: 1px dashed var(--border-strong); background: rgba(8, 14, 25, 0.5); display: flex; flex-direction: column; gap: 10px; }
.credentials-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.credentials-row span { font-size: 11.5px; color: var(--dim); }
.credentials-row code { font-family: var(--mono); font-size: 13.5px; color: var(--accent); overflow-wrap: anywhere; }

/* ── Администрирование: формы и редактор метрик ───────────────────────────── */

.admin-form { display: flex; flex-direction: column; gap: 14px; }

.page-header-left { min-width: 0; }

.metric-rows { display: flex; flex-direction: column; gap: 10px; }

.metric-row {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(8, 14, 25, 0.35);
}

.metric-row-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.metric-row-head strong { font-size: 12px; color: var(--muted); font-weight: 600; }
.metric-row-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric-row .field { gap: 4px; }
.metric-row .field > label { font-size: 10.5px; }
.metric-row .input, .metric-row .select { min-height: 34px; padding: 6px 9px; font-size: 12.5px; }
.metric-row .select { background-position: calc(100% - 14px) 14px, calc(100% - 9px) 14px; }

.params-list { display: flex; flex-direction: column; max-height: 430px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; background: rgba(8, 14, 25, 0.35); }
.param-item { display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; border-bottom: 1px solid rgba(31, 48, 73, 0.6); cursor: pointer; }
.param-item:last-child { border-bottom: 0; }
.param-item:hover { background: rgba(255, 255, 255, 0.025); }
.param-item input { margin-top: 3px; width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.param-main { flex: 1; min-width: 0; }
.param-main strong { display: block; font-size: 12.5px; font-weight: 600; }
.param-main span { display: block; font-size: 11px; color: var(--dim); }
.param-item code { font-family: var(--mono); font-size: 10.5px; color: var(--accent); white-space: nowrap; }

.form-actions { display: flex; gap: 9px; margin-top: 4px; }

.info-list .info-row strong { color: var(--text); font-weight: 600; }

@media (max-width: 900px) {
  .metric-row-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .metric-row-grid { grid-template-columns: 1fr; }
}

/* ── Адаптивность ─────────────────────────────────────────────────────────── */

@media (max-width: 1180px) {
  .dashboard-split, .device-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding: 18px 10px; align-items: center; }
  .brand { padding: 0; }
  .brand-text, .nav-section, .nav-link span:not(.nav-icon), .user-meta, .sidebar-actions { display: none; }
  .nav-link { justify-content: center; width: 44px; height: 42px; padding: 0; }
  .user-card { justify-content: center; padding: 4px 0 10px; }
  .sidebar-footer { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
  .sidebar-actions { display: flex; }
  .content { padding: 22px 20px 48px; }
  .topbar { padding: 10px 20px; }
}

@media (max-width: 820px) {
  .auth { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    height: 62px;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    padding: 6px 8px;
    border-right: 0;
    border-top: 1px solid var(--border);
    background: rgba(10, 18, 31, 0.98);
    z-index: 40;
  }
  .brand, .sidebar-footer, .nav-section { display: none; }
  .nav { flex-direction: row; justify-content: space-around; width: 100%; overflow: visible; }
  .nav-link { flex-direction: column; gap: 3px; width: auto; height: 50px; padding: 4px 10px; font-size: 10px; }
  .nav-link span.nav-label { display: block; }
  .topbar { padding: 9px 14px; }
  .topbar-sub { display: none; }
  .content { padding: 16px 14px 90px; }
  .grid-cards, .devices-grid, .metrics-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 12px 8px 80px; }
  .live { padding: 5px 8px; font-size: 11px; }
}
