/* ============================================================
 * Wiman IoT — operator UI
 * ============================================================
 * Design principles:
 *   - Industrial: dense, information-rich, no decorative noise
 *   - Trustworthy: subdued palette, restrained typography
 *   - Operator-first: high contrast for at-a-glance reading
 *   - Status colors used only for state (green/amber/red/gray)
 *
 * Token system below — every spacing/color/shadow comes from a var.
 * ============================================================ */

:root {
  /* Color — neutrals */
  --bg:           #eef1f4;
  --bg-deep:      #e0e6ec;
  --panel:        #ffffff;
  --panel-soft:   #f7f9fb;
  --panel-deep:   #eef1f4;
  --ink:          #11202d;
  --ink-soft:     #4f5d6c;
  --ink-mute:     #8a96a4;
  --line:         #d8dee4;
  --line-soft:    #ecf0f3;
  --line-strong:  #c1c9d2;

  /* Color — brand */
  --brand:         #0d7d76;
  --brand-dark:    #095049;
  --brand-darker:  #053d38;
  --brand-soft:    #e3f1ef;
  --brand-tint:    #f0f8f7;
  --sidebar-bg:    #0d7d76;
  --sidebar-bg-2:  #0a625c;
  --sidebar-ink:   #ffffff;

  /* Color — status */
  --ok:        #1f9d55;
  --ok-soft:   #d8f1e3;
  --warn:      #b88300;
  --warn-soft: #faedc6;
  --crit:      #c1272d;
  --crit-soft: #fbe1e2;
  --info:      #2a5db0;
  --info-soft: #dde9f7;
  --gray:      #92a0b3;

  /* Color — severity (alarm-only) */
  --sev-critical: #c1272d;
  --sev-major:    #d97706;
  --sev-minor:    #b88300;
  --sev-warning:  #5a7da4;

  /* Spacing scale (4-pt grid) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  /* Shadows */
  --shadow-1: 0 1px 2px rgba(17, 32, 45, 0.05);
  --shadow-2: 0 2px 4px rgba(17, 32, 45, 0.08);
  --shadow-3: 0 4px 12px rgba(17, 32, 45, 0.10);

  /* Radius */
  --radius:    6px;
  --radius-sm: 4px;
  --radius-lg: 10px;

  /* Layout */
  --sidebar-w: 224px;
  --topbar-h:  56px;

  /* Type */
  --font-sans: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

/* ============================================================
 * Reset + base typography
 * ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; color: var(--ink); letter-spacing: -0.005em; }
h1 { font-size: 18px; }
h2 { font-size: 15px; margin: var(--s-5) 0 var(--s-3); }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-soft); margin: var(--s-4) 0 var(--s-2); font-weight: 700; }
p  { margin: 0 0 var(--s-3); }
a  { color: inherit; text-decoration: none; }

code, .code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--line-soft);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--ink);
}

.small  { font-size: 11px; }
.muted  { color: var(--ink-soft); }
.muted.small, .small.muted { color: var(--ink-mute); }
.right { margin-left: auto; }
.num   { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
[x-cloak] { display: none !important; }
.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;
}

/* ============================================================
 * Login
 * ============================================================ */
.page-login {
  background:
    radial-gradient(at 30% 20%, rgba(13,125,118,0.30), transparent 60%),
    radial-gradient(at 80% 80%, rgba(10,98,92,0.40), transparent 60%),
    linear-gradient(135deg, #061722, #0d3b3c);
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.login-wrap { width: 100%; padding: var(--s-6); }
.login-card {
  display: grid; grid-template-columns: 1fr 1fr;
  max-width: 780px; margin: 0 auto;
  background: var(--panel);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.login-card__left {
  background: linear-gradient(160deg, var(--brand), var(--brand-darker));
  color: white; padding: 44px 36px;
  display: flex; flex-direction: column; justify-content: center;
}
.login-mark { font-size: 26px; opacity: 0.9; }
.login-brand { margin: var(--s-3) 0 var(--s-2); font-size: 24px; font-weight: 700; }
.login-tagline { opacity: 0.82; font-size: 13px; margin: 0; }
.login-card__right { padding: 44px 36px; }
.login-h2 { margin: 0 0 var(--s-5); font-size: 20px; }
.login-note { margin: var(--s-3) 0 0; font-size: 11px; color: var(--ink-mute); }

/* ============================================================
 * App shell — sidebar + topbar + content
 * ============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2));
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  box-shadow: 1px 0 0 rgba(0,0,0,0.08);
}
.sidebar__brand {
  padding: 16px 18px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand__mark {
  width: 20px; height: 20px; border-radius: 5px;
  background: white;
  position: relative;
  flex-shrink: 0;
}
.brand__mark::after {
  content: ""; position: absolute; inset: 4px;
  border-radius: 2px; background: var(--brand);
}
.brand__name {
  font-weight: 700; font-size: 14px;
  letter-spacing: 0.01em;
}
.sidebar__nav { flex: 1; padding: var(--s-2) 0 var(--s-4); overflow-y: auto; }
.sidebar__divider {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px 6px;
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  font-weight: 700;
}
.sidebar__divider::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(to right, rgba(255,255,255,0.10), transparent);
}
.sidebar__divider--top { padding-top: 10px; }
.navlink {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 18px 7px 15px;
  color: rgba(255,255,255,0.86);
  font-size: 12px;
  letter-spacing: 0.04em;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.navlink:hover {
  background: rgba(255,255,255,0.06);
  color: #ffffff;
}
.navlink--active {
  background: rgba(0,0,0,0.20);
  border-left-color: white;
  color: #ffffff;
  font-weight: 600;
}
.navlink--sub { padding-left: 32px; font-size: 11px; opacity: 0.85; }
.navlink__label { flex: 1; }
.navlink--disabled { opacity: 0.40; cursor: not-allowed; }
.navlink--disabled:hover { background: transparent; color: rgba(255,255,255,0.86); }
.navlink__tag {
  font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 8px;
  background: rgba(255,255,255,0.14);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 17px; padding: 0 6px;
  background: rgba(0,0,0,0.30); border-radius: 9px;
  font-size: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.nav-badge--critical { background: var(--sev-critical); }
.nav-badge--major    { background: var(--sev-major); }
.nav-badge--minor    { background: var(--sev-minor); }
.nav-badge--warning  { background: var(--sev-warning); }
.sidebar__footer {
  padding: 10px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(0,0,0,0.12);
}
.sidebar__footer .user { font-weight: 600; opacity: 0.95; }
.sidebar__footer .logout { color: rgba(255,255,255,0.65); font-size: 10px; }
.sidebar__footer .logout:hover { color: #fff; text-decoration: underline; }

/* ----- Content + topbar ----- */
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  height: var(--topbar-h);
  padding: 0 var(--s-6);
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4);
}
.topbar__left {
  display: flex; align-items: center; gap: var(--s-3);
  min-width: 0;
}
.topbar__title {
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.crumbs {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-mute);
}
.crumbs a:hover { color: var(--brand); }
.crumbs__sep { color: var(--ink-mute); opacity: 0.6; }
.topbar__right {
  display: flex; align-items: center; gap: var(--s-3);
  font-size: 12px;
}
.sys-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--ok-soft); color: #0a5d2e;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em;
}
.sys-status__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 2px rgba(31,157,85,0.20);
  animation: pulse 2s ease-in-out infinite;
}
.sys-status--degraded { background: var(--warn-soft); color: #7a5500; }
.sys-status--degraded .sys-status__dot { background: var(--warn); box-shadow: 0 0 0 2px rgba(184,131,0,0.25); }
.hello { color: var(--ink-soft); }
.hello b { color: var(--ink); font-weight: 600; letter-spacing: 0.02em; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(31,157,85,0.20); }
  50%      { box-shadow: 0 0 0 6px rgba(31,157,85,0.00); }
}

.page {
  padding: var(--s-5) var(--s-6);
}
.page__inner { max-width: 1480px; margin: 0 auto; }

/* ============================================================
 * Dashboard grid
 * ============================================================ */
.dash { display: flex; flex-direction: column; gap: var(--s-3); }
.dash__row {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--s-3);
}
.dash__col--1  { grid-column: span 1; }
.dash__col--2  { grid-column: span 2; }
.dash__col--3  { grid-column: span 3; }
.dash__col--4  { grid-column: span 4; }
.dash__col--5  { grid-column: span 5; }
.dash__col--6  { grid-column: span 6; }
.dash__col--7  { grid-column: span 7; }
.dash__col--8  { grid-column: span 8; }
.dash__col--9  { grid-column: span 9; }
.dash__col--10 { grid-column: span 10; }
.dash__col--11 { grid-column: span 11; }
.dash__col--12 { grid-column: span 12; }
@media (max-width: 1024px) {
  .dash__row { grid-template-columns: repeat(6, 1fr); }
  .dash__col--4, .dash__col--3, .dash__col--2 { grid-column: span 3; }
  .dash__col--8, .dash__col--6, .dash__col--7 { grid-column: span 6; }
}

/* ============================================================
 * Widgets
 * ============================================================ */
.widget {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-1);
  display: flex; flex-direction: column;
  min-height: 110px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.widget:hover { border-color: var(--line-strong); }
.widget__title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-mute);
  margin-bottom: var(--s-2);
  font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
}

/* Value tile */
.widget--tile { justify-content: space-between; }
.tile__value { display: flex; align-items: baseline; gap: 8px; }
.tile__number {
  font-size: 34px; font-weight: 600; color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
  line-height: 1.05;
}
.tile__unit {
  color: var(--ink-soft); font-size: 13px;
  font-weight: 500;
}
.tile__ts {
  font-size: 10px; color: var(--ink-mute); margin-top: 6px;
  font-variant-numeric: tabular-nums;
  display: flex; align-items: center; gap: 5px;
}
.tile__ts::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--ok); display: inline-block;
  animation: pulse 2s ease-in-out infinite;
}
.tile__value--stale .tile__number { color: var(--gray); }
.tile__value--stale + .tile__ts::before { background: var(--gray); animation: none; }

/* Gauge */
.widget--gauge { align-items: center; padding-bottom: var(--s-2); }
.gauge-host { width: 100%; display: flex; flex-direction: column; align-items: center; }
.gauge__svg { width: 78%; max-width: 200px; height: auto; }
.gauge__track {
  fill: none; stroke: var(--line-soft); stroke-width: 10;
  stroke-linecap: round; pathLength: 100;
}
.gauge__fill {
  fill: none; stroke: var(--ok); stroke-width: 10;
  stroke-linecap: round; pathLength: 100;
  transition: stroke-dasharray 0.4s ease, stroke 0.2s;
}
.gauge--amber   .gauge__fill { stroke: var(--warn); }
.gauge--red     .gauge__fill { stroke: var(--crit); }
.gauge--unknown .gauge__fill { stroke: var(--gray); }
.gauge__value { display: flex; align-items: baseline; gap: 4px; margin-top: 4px; }
.gauge__number {
  font-size: 22px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.gauge__unit { color: var(--ink-soft); font-size: 12px; }
.gauge__ts { font-size: 10px; color: var(--ink-mute); font-variant-numeric: tabular-nums; }
.gauge--stale .gauge__number { color: var(--gray); }

/* Status lamp */
.widget--lamp { justify-content: center; }
.lamp { display: flex; align-items: center; gap: var(--s-3); }
.lamp__dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--gray);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.04);
  flex-shrink: 0;
}
.lamp--green .lamp__dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(31,157,85,0.18), 0 0 14px rgba(31,157,85,0.40);
}
.lamp--amber .lamp__dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(184,131,0,0.18), 0 0 14px rgba(184,131,0,0.40);
}
.lamp--red .lamp__dot {
  background: var(--crit);
  box-shadow: 0 0 0 3px rgba(193,39,45,0.18), 0 0 14px rgba(193,39,45,0.45);
}
.lamp__value { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.lamp__ts { font-size: 10px; color: var(--ink-mute); }
.lamp--stale .lamp__dot { background: var(--gray); box-shadow: 0 0 0 3px rgba(0,0,0,0.04); }
.lamp--inline { display: inline-flex; align-items: center; gap: 6px; }
.lamp--inline .lamp__dot { width: 9px; height: 9px; box-shadow: 0 0 0 2px rgba(0,0,0,0.04); }
.lamp--inline.lamp--green .lamp__dot { box-shadow: 0 0 0 2px rgba(31,157,85,0.20); }
.lamp__label { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; }

/* Data table widget */
.dtable { width: 100%; border-collapse: collapse; font-size: 12px; }
.dtable th {
  text-align: left; color: var(--ink-mute);
  font-weight: 600; padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase; font-size: 9px; letter-spacing: 0.08em;
}
.dtable td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums;
}
.dtable tr:last-child td { border-bottom: 0; }
.dtable__num { text-align: right; }
.dtable__row--stale { color: var(--gray); }

/* Alarm count badge */
.widget--alarm-badge { text-align: center; justify-content: center; }
.alarm-badge__num {
  font-size: 42px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ok);
}
.alarm-badge__breakdown {
  list-style: none; padding: 0; margin: var(--s-2) 0 0;
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
}
.sev {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--line-soft);
  color: var(--ink-soft);
  font-weight: 600;
}
.sev--critical { color: var(--crit);   background: var(--crit-soft); }
.sev--major    { color: #9b5808;       background: var(--warn-soft); }
.alarm-badge__note { font-size: 10px; color: var(--ink-mute); margin-top: 6px; font-style: italic; }

/* Line chart */
.widget--chart { padding-bottom: 6px; }
.chartjs { width: 100%; max-height: 240px; }

/* Error widget */
.widget--error { border-left: 3px solid var(--crit); }
.widget-error strong { color: var(--crit); margin-right: 6px; }
.widget-error span { color: var(--ink-soft); font-size: 12px; }

/* Empty state inside widget */
.empty { text-align: center; padding: 40px 16px; color: var(--ink-mute); }

/* ============================================================
 * Page-head: title + summary stats + actions
 * ============================================================ */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
  color: var(--ink-soft);
  font-size: 13px;
}
.page-head strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.pill--green { background: var(--ok-soft);   color: #0a5d2e; }
.pill--gray  { background: var(--line-soft); color: var(--ink-soft); }
.pill--amber { background: var(--warn-soft); color: #7a5500; }
.pill--red   { background: var(--crit-soft); color: var(--crit); }

/* ============================================================
 * Tables (rtable)
 * ============================================================ */
.rtable {
  width: 100%; border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.rtable th, .rtable td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}
.rtable th {
  background: var(--panel-soft);
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--line);
}
.rtable tbody tr {
  transition: background 0.08s;
}
.rtable tbody tr:hover { background: var(--brand-tint); }
.rtable tbody tr:last-child td { border-bottom: 0; }
.rtable td code {
  background: var(--line-soft);
  font-size: 11.5px;
}
.rtable__num  { text-align: right; font-variant-numeric: tabular-nums; }
.rtable__ts   { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: 12px; }
.rtable__sev  { width: 70px; }
.rtable--compact th, .rtable--compact td { padding: 5px 10px; font-size: 12px; }
.rtable--zebra tbody tr:nth-child(even) { background: var(--panel-soft); }
.rtable--zebra tbody tr:hover { background: var(--brand-tint); }
.row--muted td { color: var(--ink-mute); }

.link { color: var(--info); }
.link:hover { text-decoration: underline; }

/* ============================================================
 * Buttons
 * ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit; font-weight: 600; font-size: 13px;
  background: var(--panel-soft); color: var(--ink);
  transition: background 0.1s, border-color 0.1s, transform 0.05s, color 0.1s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--line-soft); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 3px rgba(13,125,118,0.25); }

.btn--primary {
  background: var(--brand); color: white; border-color: var(--brand);
}
.btn--primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn--secondary {
  background: white; color: var(--ink); border-color: var(--line-strong);
}
.btn--secondary:hover { background: var(--panel-soft); }
.btn--ghost {
  background: transparent; color: var(--ink-soft); border-color: transparent;
}
.btn--ghost:hover { background: var(--line-soft); color: var(--ink); }
.btn--danger {
  background: var(--crit); color: white; border-color: var(--crit);
}
.btn--danger:hover { filter: brightness(1.06); }

.btn--small { height: 26px; padding: 0 9px; font-size: 11px; }
.btn--large { height: 38px; padding: 0 18px; font-size: 14px; }

/* ============================================================
 * Filter bar
 * ============================================================ */
.filter-bar {
  display: flex; gap: var(--s-2); margin-bottom: var(--s-3);
  align-items: stretch;
}
.filter-bar input[type="text"],
.filter-bar input[type="number"] {
  flex: 1; padding: 0 12px;
  height: 32px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: 13px;
  background: var(--panel);
}
.filter-bar input:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(13,125,118,0.12); }
.filter-bar--multi { flex-wrap: wrap; align-items: flex-end; }

/* ============================================================
 * Forms (generic + settings)
 * ============================================================ */
.field { display: block; margin-bottom: var(--s-3); }
.field__label {
  display: block;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--ink-soft); margin-bottom: 5px;
  font-weight: 600;
}
.field input, .field select, .field textarea,
.field--inline input, .field--inline select {
  width: 100%;
  padding: 8px 11px; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel);
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.field input:focus, .field select:focus, .field textarea:focus,
.field--inline input:focus, .field--inline select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13,125,118,0.12);
}
.field--inline { display: flex; flex-direction: column; gap: 4px; }
.field--inline select[multiple] { min-width: 320px; min-height: 120px; }
.form-error {
  background: var(--crit-soft); color: var(--crit);
  padding: 8px 12px; border-radius: var(--radius-sm);
}

/* ============================================================
 * Cards
 * ============================================================ */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-3);
  box-shadow: var(--shadow-1);
}
.card__header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--line-soft);
}
.card--narrow  { max-width: 720px; }
.card--summary .gw-detail__imei {
  font-size: 15px; font-weight: 600;
  background: var(--line-soft); padding: 3px 8px; border-radius: 3px;
  font-family: var(--font-mono);
}

/* KV display list */
.kv {
  display: grid; grid-template-columns: 150px 1fr;
  gap: 6px 18px;
  margin: 0; font-size: 13px;
}
.kv dt { color: var(--ink-soft); font-size: 12px; }
.kv dd { margin: 0; }

.code-block {
  background: #1a1f29; color: #d4d8df;
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 11.5px; overflow-x: auto;
  font-family: var(--font-mono);
}

/* Messages */
.msg {
  padding: 9px 13px; border-radius: var(--radius-sm); margin-bottom: var(--s-2);
  font-size: 13px; border-left: 3px solid transparent;
}
.msg--success { background: var(--ok-soft);   color: #0a5d2e;     border-color: var(--ok); }
.msg--warning { background: var(--warn-soft); color: #7a5500;     border-color: var(--warn); }
.msg--error   { background: var(--crit-soft); color: var(--crit); border-color: var(--crit); }
.msg--info    { background: var(--info-soft); color: var(--info); border-color: var(--info); }

/* Trend page controls */
.trend-controls {
  display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end;
  margin-bottom: var(--s-3);
  padding: var(--s-3);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* ============================================================
 * Alarms — severity chips, badges, alarm rows, state pills
 * ============================================================ */
.sev-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sev-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--panel); color: var(--ink-soft);
  border: 1px solid var(--line);
  transition: border-color 0.1s, color 0.1s, background 0.1s;
}
.sev-chip b {
  font-variant-numeric: tabular-nums;
  background: var(--line-soft); padding: 0 6px; border-radius: 8px;
}
.sev-chip:hover { border-color: var(--brand); color: var(--brand); }
.sev-chip--active { background: var(--brand); color: white; border-color: var(--brand); }
.sev-chip--active b { background: rgba(255,255,255,0.25); color: white; }
.sev-chip--critical { color: var(--sev-critical); border-color: var(--sev-critical); }
.sev-chip--critical.sev-chip--active { background: var(--sev-critical); color: white; }
.sev-chip--major    { color: var(--sev-major); border-color: var(--sev-major); }
.sev-chip--major.sev-chip--active { background: var(--sev-major); color: white; }
.sev-chip--minor    { color: var(--sev-minor); border-color: var(--sev-minor); }
.sev-chip--minor.sev-chip--active { background: var(--sev-minor); color: white; }
.sev-chip--warning  { color: var(--sev-warning); border-color: var(--sev-warning); }
.sev-chip--warning.sev-chip--active { background: var(--sev-warning); color: white; }

.sev-badge {
  display: inline-block;
  padding: 3px 9px; border-radius: 3px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--line-soft); color: var(--ink-soft);
}
.sev-badge--critical { background: var(--sev-critical); color: white; }
.sev-badge--major    { background: var(--sev-major);    color: white; }
.sev-badge--minor    { background: var(--sev-minor);    color: white; }
.sev-badge--warning  { background: var(--sev-warning);  color: white; }

.state-pill {
  display: inline-block;
  padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.state-pill--firing  { background: var(--crit);      color: white; }
.state-pill--pending { background: var(--warn);      color: white; }
.state-pill--acked   { background: var(--line-soft); color: var(--ink-soft); }

.rtable--alarms tbody tr { border-left: 3px solid transparent; }
.alarm-row--critical { border-left-color: var(--sev-critical); }
.alarm-row--major    { border-left-color: var(--sev-major); }
.alarm-row--minor    { border-left-color: var(--sev-minor); }
.alarm-row--warning  { border-left-color: var(--sev-warning); }
.alarm-row--acked    { opacity: 0.75; }
.alarm-row--pending  td { background: rgba(184,131,0,0.04); }

.event-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
.event-tag--raised       { background: var(--crit-soft); color: var(--crit); }
.event-tag--cleared      { background: var(--ok-soft);   color: var(--ok); }
.event-tag--acked        { background: var(--info-soft); color: var(--info); }
.event-tag--auto_cleared { background: var(--line-soft); color: var(--ink-soft); }

.inline-ack { display: inline-flex; align-items: center; gap: 6px; position: relative; }
.inline-ack__pop {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px;
  display: flex; gap: 6px; align-items: center;
  z-index: 20;
  box-shadow: var(--shadow-3);
  white-space: nowrap;
}
.inline-ack__pop input {
  width: 200px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 3px;
}

/* ============================================================
 * Empty state cards (full-page)
 * ============================================================ */
.empty-state {
  text-align: center; padding: 40px 16px;
}
.empty-state__lamp { display: inline-flex; padding: 12px; }
.empty-state h3 {
  margin: 10px 0 4px; font-size: 16px; color: var(--ink);
  text-transform: none; letter-spacing: 0;
}

/* ============================================================
 * Device cards (FRONTEND devices index)
 * ============================================================ */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s-3);
}
.device-card {
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s-4);
  box-shadow: var(--shadow-1);
  color: inherit;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.05s;
}
.device-card:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-3);
}
.device-card:active { transform: translateY(1px); }
.device-card__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.device-card__type {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-mute);
  background: var(--line-soft);
  padding: 3px 8px; border-radius: 3px;
}
.device-card--energy_meter .device-card__type { color: #0a7a4a; background: var(--ok-soft); }
.device-card--dg          .device-card__type { color: #8c4316; background: var(--warn-soft); }
.device-card--transformer .device-card__type { color: #214a82; background: var(--info-soft); }
.device-card--compressor  .device-card__type { color: #b34244; background: var(--crit-soft); }
.device-card__title {
  font-size: 15px; font-weight: 600; color: var(--ink);
  margin-bottom: 2px;
}
.device-card__sub {
  font-size: 11px; color: var(--ink-soft);
  margin-bottom: var(--s-3);
  word-break: break-all;
}
.device-card__sub code {
  background: transparent; padding: 0; font-size: 11px;
}
.device-card__foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: auto;
  padding-top: var(--s-2);
  border-top: 1px solid var(--line-soft);
}
.device-card__count {
  font-size: 11px; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.device-card__arrow {
  font-size: 16px; color: var(--brand); font-weight: 600;
}

/* Device dashboard top bar */
.device-detail__bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  margin-bottom: var(--s-3);
  font-size: 12px;
}
.device-detail__meta { display: flex; gap: 10px; align-items: center; }
.device-detail__meta code { font-size: 12px; }
.device-detail__actions { display: flex; gap: 6px; }

/* ============================================================
 * Settings form (device/gateway editors)
 * ============================================================ */
.settings-wrap { max-width: 920px; }
.settings-form { display: flex; flex-direction: column; gap: var(--s-3); }

.settings-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.settings-card__header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px;
  padding: 11px 18px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}
.settings-card__header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-transform: none;
}
.settings-card__hint { font-size: 11px; color: var(--ink-mute); }
.settings-card__hint--link { color: var(--info); }
.settings-card__hint--link:hover { text-decoration: underline; }

.kv-form {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 8px 18px;
  padding: 14px 18px;
  margin: 0;
  font-size: 13px;
}
.kv-form dt {
  color: var(--ink-soft);
  font-size: 12px;
  padding-top: 2px;
}
.kv-form dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.kv-form dd code { font-size: 12.5px; }

.form-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 8px 18px;
  padding: 14px 18px;
  border-top: 1px solid var(--line-soft);
}
.form-row:first-of-type { border-top: 0; }
.form-row__label {
  padding-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.form-row__label--check {
  display: flex; align-items: center; gap: 8px;
  padding-top: 0;
}
.form-row__label--check input { transform: scale(1.1); }
.form-row__input { display: flex; flex-direction: column; gap: 4px; }
.settings-form input[type="text"],
.settings-form input[type="number"],
.settings-form textarea,
.settings-form select {
  width: 100%;
  padding: 8px 11px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.settings-form input:focus,
.settings-form textarea:focus,
.settings-form select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13,125,118,0.12);
}
.settings-form textarea { resize: vertical; min-height: 72px; }
.form-row__help { font-size: 11px; color: var(--ink-mute); line-height: 1.45; }
.form-row__error {
  font-size: 11px; color: var(--crit);
  background: var(--crit-soft);
  padding: 4px 8px; border-radius: 3px;
}
.form-row--split { grid-template-columns: 1fr 1fr; }
.form-row--split > div > .form-row__label {
  padding-top: 0; display: block; margin-bottom: 6px;
}

.settings-actions {
  position: sticky; bottom: 0;
  padding: var(--s-3) 0 0;
  display: flex; justify-content: flex-end; gap: 8px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

/* ============================================================
 * Stage 5.7 — Parameter Profile suggestions
 * Device settings: slot-grid · slot-card
 * Map-unmapped:    quickpick chips
 * ============================================================ */

/* slot-grid: 2-column responsive list of canonical params per device-type */
.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  padding: 12px 14px;
}
.slot-grid__footer {
  padding: 10px 18px;
  font-size: 11px;
  background: var(--panel-soft);
  border-top: 1px solid var(--line-soft);
}
.slot-grid__footer code {
  background: transparent;
  font-size: 10.5px;
  color: var(--ink-mute);
}

.slot-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: var(--panel);
  display: flex; flex-direction: column;
  gap: 6px;
  min-height: 70px;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.slot-card--mapped {
  border-left: 3px solid var(--ok);
  background: #f8fcfa;
}
.slot-card--unmapped {
  border-left: 3px solid var(--line);
  border-style: dashed;
  background: var(--panel-soft);
  opacity: 0.92;
}
.slot-card--unmapped:hover {
  border-color: var(--brand);
  opacity: 1;
  box-shadow: var(--shadow-1);
}
.slot-card__head { display: flex; align-items: flex-start; gap: 6px; }
.slot-card__status {
  font-size: 14px; line-height: 1;
  color: var(--ok);
  flex-shrink: 0;
  padding-top: 2px;
}
.slot-card--unmapped .slot-card__status { color: var(--ink-mute); }
.slot-card__title { flex: 1; min-width: 0; }
.slot-card__name {
  font-size: 12.5px; font-weight: 600;
  color: var(--ink);
}
.slot-card__slug {
  display: block;
  font-size: 10px;
  color: var(--ink-mute);
  background: transparent;
  padding: 0;
  margin-top: 1px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.slot-card__body {
  padding-left: 22px;
  font-size: 11.5px;
}
.slot-card__from {
  display: flex; align-items: center; gap: 6px;
  color: var(--ink-soft);
}
.slot-card__from code {
  background: var(--ok-soft);
  color: #0a5d2e;
  font-weight: 600;
}
.slot-card__edit {
  margin-left: auto;
  color: var(--ink-mute);
  text-decoration: none;
  font-size: 13px;
  padding: 0 4px;
}
.slot-card__edit:hover { color: var(--brand); }
.slot-card__suggested-key {
  font-size: 10px;
  color: var(--ink-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-card__suggested-key code {
  background: transparent;
  padding: 0;
  font-size: 10px;
  color: var(--ink-mute);
}
.slot-card__pick {
  display: inline-block;
  margin-top: 2px;
  padding: 3px 8px;
  background: var(--brand);
  color: white;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 600;
  text-decoration: none;
}
.slot-card__pick:hover { background: var(--brand-dark); }

/* Quick-pick chips inside the map-unmapped page */
.quickpick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px;
}
.quickpick__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11.5px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, transform 0.05s;
}
.quickpick__chip:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.quickpick__chip:active { transform: translateY(1px); }
.quickpick__chip--active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
.quickpick__chip--active .quickpick__unit { color: rgba(255,255,255,0.85); }
.quickpick__slot {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
}
.quickpick__unit {
  color: var(--ink-mute);
  font-size: 10px;
  padding: 1px 5px;
  background: var(--line-soft);
  border-radius: 3px;
}

/* ============================================================
 * Tag-mapping editor — compact source strip + equation preview +
 * caret toggle (advanced collapsible) + danger zone
 * ============================================================ */
.src-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  font-size: 12px;
}
.src-strip__label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  margin-right: 4px;
}
.src-strip__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink);
}
.src-strip__chip i {
  font-style: normal;
  color: var(--ink-mute);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.src-strip__chip code {
  background: transparent;
  padding: 0;
  font-size: 11px;
}
.src-strip__chip--field {
  background: #fff8d6;
  border-color: #f1d877;
}
.src-strip__chip--field code { color: #6f4d00; font-weight: 600; }
.src-strip__spacer { flex: 1; }
.src-strip__live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: var(--ok-soft);
  color: #0a5d2e;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.src-strip__live b { font-variant-numeric: tabular-nums; }
.src-strip__live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px rgba(31,157,85,0.6);
  animation: pulse 2s ease-in-out infinite;
}
.src-strip__live--stale {
  background: var(--line-soft);
  color: var(--ink-mute);
  font-weight: 500;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.6; transform: scale(1.2); }
}

/* Tag key — non-editable but copyable */
.tag-key-chip {
  display: inline-block;
  padding: 5px 10px;
  background: var(--panel-soft);
  border: 1px dashed var(--line);
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--ink);
  user-select: all;
}

/* Equation preview */
.eq-preview {
  margin: 8px 18px 14px;
  padding: 12px 14px;
  background: #fafcfb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.eq-preview__title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  margin-bottom: 8px;
}
.eq-preview__line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}
.eq-preview__raw {
  padding: 4px 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink-soft);
}
.eq-preview__var {
  padding: 4px 9px;
  background: var(--info-soft);
  color: var(--info);
  border: 1px solid var(--info);
  border-radius: 4px;
  font-weight: 600;
}
.eq-preview__op { color: var(--ink-mute); font-weight: 700; }
.eq-preview__result {
  margin-left: auto;
  padding: 4px 12px;
  background: var(--brand);
  color: white;
  border-radius: 4px;
  font-size: 16px;
}
.eq-preview__result b { font-weight: 700; }
.eq-preview__result .muted { color: rgba(255,255,255,0.7); margin-left: 4px; font-size: 12px; }
.eq-preview__note {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-mute);
  font-style: italic;
}

/* Caret for collapsible cards */
.settings-card__header--toggle {
  cursor: pointer;
  user-select: none;
}
.settings-card__header--toggle:hover { background: var(--line-soft); }
.caret {
  display: inline-block;
  margin-right: 6px;
  color: var(--ink-mute);
  transition: transform 0.15s ease;
}
.caret--open { transform: rotate(90deg); color: var(--brand); }

/* Danger card */
.settings-card--danger { border-color: var(--crit-soft); }
.settings-card--danger .settings-card__header {
  background: #fff5f5;
  border-bottom-color: var(--crit-soft);
}
.settings-card--danger .settings-card__header .danger {
  color: var(--crit);
}
.danger-body {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.danger-body p { margin: 0; font-size: 13px; line-height: 1.55; }
.danger-form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.danger-form .form-row__label { padding-top: 0; }
.danger-form input[type="text"] {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  width: 140px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.danger-form input[type="text"]:focus {
  border-color: var(--crit);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(193,39,45,0.15);
}
.btn--danger {
  background: var(--crit);
  color: white;
  border: 1px solid var(--crit);
  padding: 7px 14px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12.5px;
}
.btn--danger:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn--danger:not(:disabled):hover { background: #a01f24; }

/* ============================================================
 * Build-info pill in topbar — boot · tpl · now
 * Tiny diagnostic so the owner can tell whether a deploy actually
 * shipped new code (tpl changed) vs just bounced the process (boot only).
 * ============================================================ */
.build-pill {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  background: #15202b;
  color: #d4d8df;
  border-radius: 999px;
  padding: 3px 4px;
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-right: var(--s-3);
  user-select: none;
}
.build-pill__seg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  position: relative;
  white-space: nowrap;
}
.build-pill__seg + .build-pill__seg::before {
  content: "·";
  position: absolute;
  left: -1px;
  color: rgba(255,255,255,0.25);
  font-size: 12px;
  top: 50%;
  transform: translateY(-52%);
}
.build-pill__seg i {
  font-style: normal;
  color: #f3b94a;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.build-pill__seg:last-child i { color: #6fcf97; }
.build-pill__seg:first-child i { color: #f3b94a; }
.build-pill__seg:nth-child(2) i { color: #5bb6ff; }

@media (max-width: 1180px) {
  .build-pill { font-size: 10px; }
  .build-pill__seg { padding: 3px 7px; }
}
@media (max-width: 900px) {
  .build-pill__seg:nth-child(-n+2) { display: none; }
}

/* ============================================================
 * Responsive — three tiers
 *   ≤ 1180px : tighten label column + card padding (sidebar still 224px)
 *   ≤  960px : stack labels on top of inputs (sidebar still 224px)
 *   ≤  900px : sidebar collapses to icon-only 64px (last resort)
 * ============================================================ */

/* Tier 1 — most desktops with the platform open in a half-screen window */
@media (max-width: 1180px) {
  .settings-wrap { max-width: 100%; }
  .kv-form,
  .form-row { grid-template-columns: 160px 1fr; gap: 6px 14px; padding: 12px 14px; }
  .settings-card__header { padding: 9px 14px; }
  .settings-card__header { flex-wrap: wrap; }
  .settings-card__hint { flex-basis: 100%; }
  .form-row__label { padding-top: 7px; font-size: 11.5px; }
  .settings-form input[type="text"],
  .settings-form input[type="number"],
  .settings-form textarea,
  .settings-form select { padding: 7px 10px; font-size: 12.5px; }
  .form-row__help { line-height: 1.4; }
}

/* Tier 2 — narrow content area: stack labels above inputs */
@media (max-width: 960px) {
  .kv-form,
  .form-row { grid-template-columns: 1fr; gap: 4px 0; padding: 10px 14px; }
  .form-row__label { padding-top: 0; }
  .form-row--split { grid-template-columns: 1fr 1fr; gap: 10px; }
  .settings-card__header h2 { font-size: 12.5px; }
  .settings-form { gap: var(--s-2); }
  .settings-actions { padding-bottom: var(--s-3); }
}

/* Tier 3 — true narrow viewport: sidebar collapses to icons */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 64px 1fr; }
  .sidebar__brand .brand__name,
  .sidebar__divider,
  .navlink__label { display: none; }
  .navlink { justify-content: center; padding: 10px 0; position: relative; }
  .navlink--sub { padding-left: 0; }
  .nav-badge { position: absolute; top: 4px; right: 6px; }
  .sidebar__footer { padding: 8px 4px; font-size: 9px; }
  .sidebar__footer .logout { display: none; }
  .topbar { padding: 0 var(--s-3); }
  .page { padding: var(--s-3); }
  .form-row--split { grid-template-columns: 1fr; }
}

/* ============================================================
 * Topology page — FDM-style communication tree
 * server → broker → gateways → slaves
 * ============================================================ */

.topo {
  display: flex; flex-direction: column; align-items: center;
  gap: 0;
  padding: var(--s-4) 0;
}

.topo__tier {
  display: flex; gap: var(--s-4); flex-wrap: wrap; justify-content: center;
  width: 100%;
}
.topo__tier--gateways { gap: var(--s-5); align-items: flex-start; }

.topo__node {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--s-3) var(--s-4) var(--s-4);
  box-shadow: var(--shadow-2);
  text-align: center;
  min-width: 220px;
  position: relative;
  display: flex; flex-direction: column; align-items: center;
}
.topo__node--server { border-color: #3a4a5c; }
.topo__node--broker { border-color: var(--brand); }
.topo__node--gateway { min-width: 280px; max-width: 360px; text-align: left; align-items: stretch; }
.topo__node--gateway.is-online  { box-shadow: 0 0 0 1px rgba(31,157,85,0.3), var(--shadow-2); }
.topo__node--gateway.is-offline { opacity: 0.85; border-color: var(--line-strong); }

.topo__icon { margin-bottom: 6px; line-height: 0; }
.topo__icon--gw { align-self: center; }

.topo__node-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.topo__node-type {
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  font-weight: 700; color: var(--ink-mute);
}

.topo__title {
  font-size: 14px; font-weight: 600; color: var(--ink);
  margin-bottom: 4px;
  display: block;
}
.topo__title:hover { color: var(--brand); }
.topo__sub {
  font-size: 11px; color: var(--ink-soft);
  margin-bottom: var(--s-2);
  line-height: 1.5;
}
.topo__sub code { font-size: 11px; }
.topo__chips {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 2px;
  justify-content: center;
}
.topo__node--gateway .topo__chips { justify-content: flex-start; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 10px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.chip--warn { background: var(--warn-soft); color: #7a5500; border-color: transparent; }
.chip__dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gray); flex-shrink: 0;
}
.chip__dot--green { background: var(--ok); box-shadow: 0 0 0 2px rgba(31,157,85,0.18); }

/* Vertical connectors between tiers */
.topo__connector {
  width: 2px;
  height: 32px;
  background: linear-gradient(to bottom, var(--brand), var(--line-strong));
  margin: 0 auto;
  position: relative;
}
.topo__connector::after {
  content: ""; position: absolute; left: -3px; bottom: -1px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 2px var(--panel);
}

/* Horizontal bus line above gateway row */
.topo__bus {
  position: relative;
  width: 80%; max-width: 1100px;
  height: 2px;
  background: var(--brand);
  margin: var(--s-3) 0 var(--s-3);
}
.topo__bus::before, .topo__bus::after {
  content: ""; position: absolute; top: -3px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand);
}
.topo__bus::before { left: -4px; }
.topo__bus::after  { right: -4px; }
.topo__bus-label {
  position: absolute; left: 50%; top: -22px;
  transform: translateX(-50%);
  background: var(--panel);
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--ink-soft);
}

/* RS485 rail under each gateway */
.topo__rs485 {
  position: relative;
  margin: var(--s-4) -8px var(--s-3);
  height: 2px;
  background: #4f5d6c;
  border-radius: 1px;
}
.topo__rs485::before, .topo__rs485::after {
  content: ""; position: absolute; top: -3px;
  width: 8px; height: 8px; border-radius: 50%;
  background: #4f5d6c;
}
.topo__rs485::before { left: -4px; }
.topo__rs485::after  { right: -4px; }
.topo__rs485-label {
  position: absolute; left: 12px; top: -22px;
  background: var(--panel);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
}

/* Slave devices fanning out under a gateway */
.topo__slaves {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.topo__slave {
  display: flex; flex-direction: column; align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  text-align: center;
  color: inherit;
  transition: border-color 0.1s, transform 0.05s, background 0.1s;
}
.topo__slave:hover { border-color: var(--brand); background: var(--brand-tint); }
.topo__slave:active { transform: translateY(1px); }
.topo__slave--energy_meter { border-top: 3px solid var(--ok); }
.topo__slave--dg           { border-top: 3px solid var(--warn); }
.topo__slave--transformer  { border-top: 3px solid var(--info); }
.topo__slave--compressor   { border-top: 3px solid var(--crit); }
.topo__slave--temp         { border-top: 3px solid #b34244; }
.topo__slave--flow         { border-top: 3px solid #2a8b8b; }
.topo__slave--generic      { border-top: 3px solid var(--gray); }

.topo__slave-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  margin-bottom: 4px;
  font-size: 9px;
}
.topo__slave-sid {
  font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft);
}
.topo__slave-icon { margin-bottom: 4px; line-height: 0; }
.topo__slave-title {
  font-size: 11px; font-weight: 600; color: var(--ink);
  margin-bottom: 2px;
  line-height: 1.2;
}
.topo__slave-sub {
  font-size: 9px; color: var(--ink-mute);
  line-height: 1.3;
}

/* Bullet list inside a settings-card */
.settings-list {
  padding: 14px 18px 14px 38px;
  margin: 0;
  font-size: 12.5px;
  color: var(--ink);
  line-height: 1.6;
}
.settings-list li { margin: 2px 0; }
.settings-list code { font-size: 11.5px; }
.settings-list em { color: var(--brand); font-style: normal; font-weight: 600; }

/* Compact row actions (edit/toggle/delete buttons in tables) */
.rtable__actions {
  white-space: nowrap;
  text-align: right;
}
.rtable__actions form,
.rtable__actions .btn {
  vertical-align: middle;
  margin-left: 2px;
}

/* ============================================================================
 * Stage 9 — Tenancy-specific styles + global compact pass
 * (appended to wiman.css after Stage 5.7)
 *
 * COMPACT PASS rationale:
 *   - Settings forms had too much vertical whitespace (40-50% wasted)
 *   - Inputs stretched edge-to-edge on wide screens — hard to scan
 *   - Section headers + cards had heavy padding
 * Tightening rules below apply to ALL settings pages (tenancy + Stage 5.6),
 * so device_settings.html / gateway_settings.html benefit automatically.
 * ========================================================================== */


/* ---------- Compact settings cards (global override) -------------------- */

.settings-wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: var(--s-3, 12px) var(--s-2, 8px);
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3, 12px);
}

.settings-card {
  background: #fff;
  border: 1px solid var(--border, #e6e9ec);
  border-radius: var(--radius, 8px);
  box-shadow: var(--shadow-1, 0 1px 3px rgba(0,0,0,.04));
  padding: var(--s-2, 8px) var(--s-4, 16px) var(--s-3, 12px);
}

.settings-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3, 12px);
  padding: var(--s-2, 8px) 0 var(--s-2, 8px);
  margin: 0 0 var(--s-2, 8px);
  border-bottom: 1px solid var(--border-soft, #f0f2f4);
}

.settings-card__header h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .045em;
  text-transform: uppercase;
  margin: 0;
  color: var(--text, #1d2226);
}

.settings-card__hint {
  font-size: 11.5px;
  color: var(--muted, #7a8086);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

/* ---------- Compact form rows ------------------------------------------- */

.form-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: var(--s-2, 8px) var(--s-3, 12px);
  align-items: start;
  padding: var(--s-1, 4px) 0;
  margin: 0;
}

.form-row + .form-row {
  border-top: none;        /* no internal dividers — too noisy */
  padding-top: var(--s-2, 8px);
}

.form-row__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text, #1d2226);
  padding-top: 6px;                /* aligns label with input baseline */
  margin: 0;
  line-height: 1.4;
}

.form-row__label--check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-top: 0;
  font-weight: 500;
  font-size: 13px;
}

.form-row__label--check input[type="checkbox"] {
  margin: 0;
}

.form-row__input {
  min-width: 0;
}

.form-row__input .form-control,
.form-row__input .form-select,
.form-row__input input[type="text"],
.form-row__input input[type="email"],
.form-row__input input[type="number"],
.form-row__input input[type="date"],
.form-row__input input[type="password"],
.form-row__input select,
.form-row__input textarea {
  max-width: 480px;
  width: 100%;
  padding: 6px 10px;
  font-size: 13.5px;
  line-height: 1.5;
  border: 1px solid var(--border, #d5d9dd);
  border-radius: var(--radius-sm, 4px);
  background: #fff;
  color: var(--text, #1d2226);
  transition: border-color .12s ease, box-shadow .12s ease;
}

.form-row__input input:focus,
.form-row__input select:focus,
.form-row__input textarea:focus {
  outline: none;
  border-color: var(--saga-darkest, #347f8c);
  box-shadow: 0 0 0 3px rgba(52, 127, 140, .12);
}

.form-row__input textarea {
  max-width: 600px;
  resize: vertical;
  min-height: 60px;
}

.form-row__help {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted, #7a8086);
  line-height: 1.5;
  max-width: 600px;
}

.form-row__error {
  margin-top: 3px;
  font-size: 12px;
  color: #b51a1a;
  font-weight: 500;
}

/* ---------- Compact split row (2-col side-by-side) ---------------------- */

.form-row--split {
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2, 8px) var(--s-4, 16px);
}

.form-row--split > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row--split .form-row__label {
  padding-top: 0;
}

.form-row--split .form-control,
.form-row--split input,
.form-row--split select,
.form-row--split textarea {
  max-width: none;     /* let split inputs fill their half */
}

/* ---------- Three-up rows (e.g. SMS / Email / Monthly checkboxes) ------- */

.form-row--triple {
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--s-2, 8px) var(--s-3, 12px);
}

/* ---------- Field placeholders look softer ------------------------------ */

.form-row__input ::placeholder {
  color: #adb2b8;
  font-size: 13px;
}

/* ---------- Settings actions bar (sticky bottom) ------------------------ */

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2, 8px);
  padding: var(--s-3, 12px) var(--s-4, 16px);
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(245,247,249,0) 0%, rgba(245,247,249,1) 35%);
  margin: var(--s-2, 8px) calc(-1 * var(--s-2, 8px)) 0;
}

/* ---------- KV form (read-only field pairs) ----------------------------- */

.kv-form {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 4px var(--s-3, 12px);
  margin: 0;
  padding: var(--s-1, 4px) 0;
}

.kv-form dt {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted, #7a8086);
  padding-top: 2px;
  line-height: 1.5;
}

.kv-form dd {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text, #1d2226);
}


/* ---------- Responsive collapse ----------------------------------------- */

@media (max-width: 720px) {
  .form-row,
  .kv-form {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .form-row__label,
  .kv-form dt {
    padding-top: 0;
    font-weight: 600;
  }
  .form-row--split,
  .form-row--triple {
    grid-template-columns: 1fr;
  }
}


/* ============================================================================
 * TENANCY-specific bits (home tiles + state pills + help section)
 * ========================================================================== */

/* ---------- Tenancy home tiles ----------------------------------------- */

.tenancy-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-3, 12px);
  margin: var(--s-3, 12px) 0 var(--s-4, 16px);
  max-width: 920px;
}

.tenancy-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--s-3, 12px) var(--s-2, 8px);
  background: #fff;
  border: 1px solid var(--border, #e6e9ec);
  border-radius: var(--radius, 8px);
  box-shadow: var(--shadow-1, 0 1px 3px rgba(0,0,0,.04));
  color: inherit;
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

.tenancy-tile:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2, 0 3px 10px rgba(0,0,0,.08));
  border-color: var(--saga-mint, #3eb6a1);
}

.tenancy-tile__icon {
  font-size: 22px;
  line-height: 1;
  margin-bottom: 4px;
  opacity: .85;
}

.tenancy-tile__count {
  font-size: 26px;
  font-weight: 600;
  color: var(--saga-darkest, #347f8c);
  line-height: 1.1;
}

.tenancy-tile__label {
  margin-top: 4px;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text, #1d2226);
}

.tenancy-tile__hint {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted, #7a8086);
}

/* ---------- Help section + page intro ---------------------------------- */

.tenancy-help {
  margin: var(--s-4, 16px) 0;
  padding: var(--s-3, 12px) var(--s-4, 16px);
  background: #fff;
  border: 1px solid var(--border, #e6e9ec);
  border-radius: var(--radius, 8px);
  box-shadow: var(--shadow-1, 0 1px 3px rgba(0,0,0,.04));
  max-width: 920px;
}

.tenancy-help h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted, #7a8086);
  margin: 0 0 6px;
}

.tenancy-help h2:not(:first-child) {
  margin-top: var(--s-3, 12px);
}

.topology-tree {
  margin: 0;
  padding: 10px 12px;
  background: var(--saga-pale, #f5fbf9);
  border: 1px solid var(--saga-mint-2, #c8eae3);
  border-radius: var(--radius-sm, 4px);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  overflow-x: auto;
  color: var(--text, #1d2226);
}

.workflow {
  margin: 0;
  padding-left: 22px;
  line-height: 1.5;
  font-size: 13px;
}

.workflow li {
  margin: 2px 0;
}

.workflow strong {
  color: var(--saga-darkest, #347f8c);
}

.page-intro {
  margin: 4px 0 var(--s-3, 12px);
  max-width: 720px;
  line-height: 1.5;
}

.page-intro .muted {
  color: var(--muted, #7a8086);
  font-size: 13px;
}

/* ---------- State pill variants used by tenancy lists ------------------ */

.state-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  line-height: 1.5;
  white-space: nowrap;
}

.state-pill--ok     { background: #e6f6ef; color: #0a7c3e; }
.state-pill--info   { background: #e6f0fa; color: #1959a8; }
.state-pill--brand  { background: var(--saga-pale, #ddf3ee); color: var(--saga-darkest, #347f8c); }
.state-pill--muted  { background: #eef0f2; color: #6b7178; }
.state-pill--danger { background: #fdecea; color: #b51a1a; }

/* ---------- Sidebar sub-divider ---------------------------------------- */

.sidebar__divider--sub {
  margin-top: var(--s-2, 8px);
  opacity: .55;
  font-size: 10px;
  letter-spacing: .12em;
}

/* ---------- Mobile tweaks ---------------------------------------------- */

@media (max-width: 720px) {
  .tenancy-tiles {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .tenancy-tiles {
    grid-template-columns: 1fr;
  }
}
/* ============================================================================
 * Gateway tabbed dashboard — single page per gateway, slaves as tabs.
 * Matches the AKS Cold Storage layout (Location tabs + green/yellow cards).
 * Appended to wiman.css after the Stage 9 tenancy block.
 * ========================================================================== */

.gw-dash {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 var(--s-2, 8px);
}

/* ---------- Status strip ----------------------------------------------- */

.gw-dash__strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3, 12px);
  padding: var(--s-2, 8px) var(--s-3, 12px);
  margin: var(--s-2, 8px) 0 var(--s-3, 12px);
  background: #fff;
  border: 1px solid var(--border, #e6e9ec);
  border-radius: var(--radius, 8px);
  font-size: 12.5px;
}

.gw-dash__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #f3f5f7;
  font-weight: 600;
  letter-spacing: .04em;
  font-size: 11.5px;
}

.gw-dash__lamp {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.gw-dash__lamp--online   { background: #2ecc71; box-shadow: 0 0 0 3px rgba(46,204,113,.18); }
.gw-dash__lamp--offline  { background: #e74c3c; box-shadow: 0 0 0 3px rgba(231,76,60,.18); }
.gw-dash__lamp--unknown  { background: #95a5a6; box-shadow: 0 0 0 3px rgba(149,165,166,.18); }

.gw-dash__meta {
  font-size: 12.5px;
  color: var(--text, #1d2226);
}

/* ---------- Slave tabs (the "Location 1 | 2 | 3 …" row) ---------------- */

.slave-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  border-bottom: 2px solid var(--border, #e6e9ec);
  margin: 0 0 var(--s-3, 12px);
  background: #fff;
  border-top-left-radius: var(--radius, 8px);
  border-top-right-radius: var(--radius, 8px);
  overflow-x: auto;
}

.slave-tab {
  background: none;
  border: 0;
  padding: var(--s-3, 12px) var(--s-4, 16px);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--muted, #7a8086);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;            /* overlap the parent's border-bottom */
  transition: color .12s ease, border-color .12s ease, background .12s ease;
  white-space: nowrap;
}

.slave-tab:hover {
  color: var(--text, #1d2226);
  background: rgba(52, 127, 140, 0.05);
}

.slave-tab--active {
  color: var(--saga-darkest, #347f8c);
  border-bottom-color: var(--saga-darkest, #347f8c);
}

/* ---------- Slave panel (only active is visible) ----------------------- */

.slave-panel {
  display: none;
  animation: fadeIn .12s ease-in;
}
.slave-panel--active {
  display: block;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

.slave-panel__footer {
  margin-top: var(--s-3, 12px);
  padding-top: var(--s-2, 8px);
  border-top: 1px dashed var(--border, #e6e9ec);
}

/* ---------- Cards inside a panel (Temperature + Humidity style) -------- */

.storage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--s-4, 16px);
  margin-top: var(--s-2, 8px);
}

.storage-card {
  background: #fff;
  border: 1px solid var(--border, #e6e9ec);
  border-radius: var(--radius, 8px);
  overflow: hidden;
  box-shadow: var(--shadow-1, 0 1px 3px rgba(0,0,0,.05));
  transition: transform .12s ease, box-shadow .12s ease;
}

.storage-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2, 0 4px 12px rgba(0,0,0,.08));
}

.storage-card__head {
  padding: 14px 18px;
  font-weight: 600;
  letter-spacing: .04em;
  font-size: 14px;
  text-transform: uppercase;
  color: #fff;
  text-align: center;
  background: var(--saga-darkest, #347f8c);
}

/* Card colors by parameter kind (kind set server-side) */
.storage-card--temperature .storage-card__head { background: #43a047; }   /* green */
.storage-card--humidity    .storage-card__head { background: #c0ca33; }   /* lime/yellow */
.storage-card--pressure    .storage-card__head { background: #1976d2; }   /* blue */
.storage-card--flow        .storage-card__head { background: #00897b; }   /* teal */
.storage-card--voltage     .storage-card__head { background: #ef6c00; }   /* orange */
.storage-card--current     .storage-card__head { background: #ad1457; }   /* magenta */
.storage-card--power       .storage-card__head { background: #5e35b1; }   /* purple */
.storage-card--generic     .storage-card__head { background: var(--saga-darkest, #347f8c); }

.storage-card__body {
  padding: 28px 18px 18px;
  text-align: center;
  background: #fff;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Override the default tile__value layout inside our storage cards
   so the number is BIG and the unit subtle, matching the screenshot. */
.storage-card__body .tile__value {
  font-size: 38px;
  font-weight: 700;
  color: var(--text, #1d2226);
  line-height: 1.1;
  letter-spacing: -.02em;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.storage-card__body .tile__number {
  font-variant-numeric: tabular-nums;
}

.storage-card__body .tile__unit {
  font-size: 16px;
  font-weight: 500;
  color: var(--muted, #7a8086);
  text-transform: lowercase;
}

.storage-card__body .tile__value--stale {
  color: var(--muted, #95a5a6);
  opacity: .55;
}

.storage-card__body .tile__ts {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted, #95a5a6);
  letter-spacing: .04em;
}

/* ---------- Empty state ------------------------------------------------ */

.empty-state {
  padding: var(--s-5, 24px);
  text-align: center;
  background: #fff;
  border: 1px dashed var(--border, #d5d9dd);
  border-radius: var(--radius, 8px);
  color: var(--muted, #7a8086);
  margin: var(--s-3, 12px) 0;
}

/* ---------- Mobile ----------------------------------------------------- */

@media (max-width: 720px) {
  .storage-cards {
    grid-template-columns: 1fr;
  }
  .slave-tab {
    padding: var(--s-2, 8px) var(--s-3, 12px);
    font-size: 11.5px;
  }
  .gw-dash__strip {
    gap: var(--s-2, 8px);
    font-size: 11.5px;
  }
}

/* ============================================================
 * Stat tiles — fleet summary row (used on /registry/devices/)
 * ============================================================ */
.stat-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 0 0 1.25rem;
}
.stat-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  position: relative;
  box-shadow: 0 1px 2px rgba(15, 32, 45, 0.04);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-tile:hover {
  box-shadow: 0 4px 8px rgba(15, 32, 45, 0.08);
  transform: translateY(-1px);
}
.stat-tile__num {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  letter-spacing: -0.02em;
}
.stat-tile__label {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.stat-tile--ok { border-left: 3px solid var(--ok); }
.stat-tile--ok .stat-tile__num { color: var(--ok); }
.stat-tile--warn { border-left: 3px solid var(--warn); }
.stat-tile--warn .stat-tile__num { color: var(--warn); }
.stat-tile--crit { border-left: 3px solid var(--crit); }
.stat-tile--crit .stat-tile__num { color: var(--crit); }

/* ============================================================
 * Page jump-nav — sticky section navigation on long settings pages
 * ============================================================ */
.page-jumpnav {
  position: sticky;
  top: 56px; /* below the topbar */
  z-index: 10;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px 8px;
  margin: 0 0 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(15, 32, 45, 0.05);
}
.page-jumpnav a {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--panel-soft);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 4px;
  transition: background 0.1s ease, color 0.1s ease;
}
.page-jumpnav a:hover {
  background: var(--brand-soft);
  color: var(--brand);
}
.page-jumpnav a.danger {
  color: var(--crit);
  background: var(--crit-soft);
}
.page-jumpnav a.danger:hover {
  background: var(--crit);
  color: var(--panel);
}

/* Scroll-margin so section headers don't hide under the sticky topbar
 * + jumpnav when clicked from a jump-link. */
[id^="sec-"] { scroll-margin-top: 120px; }

/* ============================================================
 * Polished device card refinements
 * ============================================================ */
.device-card {
  transition: box-shadow 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}
.device-card:hover {
  box-shadow: 0 6px 16px rgba(15, 32, 45, 0.12);
  transform: translateY(-2px);
  border-color: var(--brand-soft);
}
.device-card__title {
  font-weight: 600;
  letter-spacing: -0.01em;
}
.device-card__sub code {
  background: var(--panel-soft);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* DASHBOARD_FACE_CSS — global time-range picker, sparkline, trend arrow, source badge */

.range-picker {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; margin: 0 0 14px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 1px 3px rgba(15,32,45,.05);
}
.range-picker__label {
  font-size: 11.5px; color: var(--ink-soft); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.range-picker__chips {
  display: inline-flex; gap: 6px; border-radius: 6px;
  background: #f1f5f9; padding: 3px; border: 1px solid #e2e8f0;
}
.range-chip {
  border: 0; padding: 6px 14px; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); background: transparent; border-radius: 4px;
  cursor: pointer; transition: background 0.12s ease, color 0.12s ease;
}
.range-chip:hover { background: rgba(20,184,166,0.08); color: var(--brand); }
.range-chip.active {
  background: var(--brand); color: #fff;
  box-shadow: 0 1px 3px rgba(15,118,110,.25);
}
.range-picker__source {
  font-size: 11.5px; color: var(--ink-soft); margin-left: auto;
  font-family: ui-monospace, Menlo, monospace; font-weight: 500;
}

/* Source badge on charts */
.chart__source-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  vertical-align: middle;
}

/* Sparkline area on value tile */
.tile__spark {
  width: 100%; height: 42px;
  margin-top: 6px;
  position: relative;
}
.tile__spark svg { width: 100%; height: 100%; display: block; }

/* Trend arrow next to value */
.tile__trend {
  margin-left: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  font-family: ui-monospace, Menlo, monospace;
  vertical-align: 2px;
}
.tile__trend[data-trend="up"]   { color: #047857; }
.tile__trend[data-trend="down"] { color: #b91c1c; }
.tile__trend[data-trend="flat"] { color: #64748b; }

/* ============================================================
 * DASHBOARD_GRID_POLISH — phone breakpoint + improved widget hover
 * ============================================================ */

/* Widget lift + softer shadow on hover */
.widget {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.widget:hover {
  border-color: var(--brand-soft, #5eead4);
  box-shadow: 0 6px 14px rgba(15, 32, 45, 0.08);
  transform: translateY(-1px);
}

/* Phone breakpoint (≤640 px) — collapse to single column */
@media (max-width: 640px) {
  .dash { gap: 10px; }
  .dash__row { grid-template-columns: 1fr; gap: 10px; }
  .dash__col--1, .dash__col--2, .dash__col--3,
  .dash__col--4, .dash__col--5, .dash__col--6,
  .dash__col--7, .dash__col--8, .dash__col--9,
  .dash__col--10, .dash__col--11, .dash__col--12 {
    grid-column: span 1;
  }
  .widget {
    min-height: 88px;
    padding: 10px 12px;
    border-radius: 8px;
  }
  .tile__number { font-size: 30px; }
  .widget__title { font-size: 9px; letter-spacing: 0.06em; }
  .widget--chart { height: 200px !important; }
  /* Range picker compacts gracefully */
  .range-picker { padding: 8px 12px; gap: 8px; }
  .range-picker__source { display: none; }
}

/* Small tablet (641-820px) — keep 6 cols but tighter */
@media (min-width: 641px) and (max-width: 820px) {
  .dash { gap: 10px; }
  .dash__row { gap: 10px; }
  .widget { min-height: 100px; padding: 10px 14px; }
  .tile__number { font-size: 30px; }
}

/* Make the sparkline slot collapse on phones so number stays prominent */
@media (max-width: 480px) {
  .tile__spark { display: none; }
}

/* DASHBOARD_FACE_TILE_ROW — trend arrow sits beside the value */
.tile__row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px;
}
.tile__swap { flex: 1; min-width: 0; }
.tile__row .tile__trend {
  font-size: 20px; font-weight: 700;
  flex: 0 0 auto;
  line-height: 1;
  margin-left: 4px;
  font-family: ui-monospace, Menlo, monospace;
}


/* ============================================================
   SIDEBAR_COLLAPSIBLE_BLOCK -- Stripe-style collapsible rail.
   Toggle button at top-right of sidebar collapses to 64px icon-only.
   ============================================================ */

.sidebar {
  transition: width 180ms ease;
}

.sidebar__brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand__logo {
  height: 24px;
  width: auto;
  flex-shrink: 0;
}
.brand__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-toggle {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: rgba(255,255,255,0.10);
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: background 120ms ease, transform 180ms ease;
}
.sb-toggle:hover { background: rgba(255,255,255,0.20); }
.sb-toggle svg { width: 14px; height: 14px; }

.navlink {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  position: relative;
}
.navlink__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}
.navlink:hover .navlink__icon { opacity: 1; }
.navlink--active .navlink__icon { opacity: 1; }
.navlink__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.nav-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.4;
}
.nav-badge--critical { background:#7f1d1d; color:#fecaca; }
.nav-badge--major    { background:#9a3412; color:#fed7aa; }
.nav-badge--minor    { background:#854d0e; color:#fde68a; }
.nav-badge--warning  { background:#374151; color:#e5e7eb; }

/* ─── COLLAPSED STATE ─────────────────────────────────────── */

.sidebar--collapsed { width: 64px; }
.sidebar--collapsed .brand__name { display: none; }
.sidebar--collapsed .sidebar__divider { display: none; }
.sidebar--collapsed .navlink__label { display: none; }
.sidebar--collapsed .navlink__tag { display: none; }
.sidebar--collapsed .nav-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 9px;
  padding: 0 4px;
  line-height: 1.3;
}
.sidebar--collapsed .navlink {
  justify-content: center;
  padding: 10px 0;
}
.sidebar--collapsed .navlink--sub { padding-left: 0; }
.sidebar--collapsed .sb-toggle svg { transform: rotate(180deg); }
.sidebar--collapsed .sidebar__footer .user { display: none; }
.sidebar--collapsed .sidebar__footer .logout { display: none; }
.sidebar--collapsed .sidebar__footer {
  padding: 8px 4px;
  text-align: center;
}

/* Native tooltip when collapsed shows the title= attribute */
.sidebar--collapsed .navlink { cursor: pointer; }

/* Content shifts when sidebar collapses */
.sidebar--collapsed + .content { /* no extra rule needed -- flex layout handles it */ }


/* ============================================================
   GLOSSY_DASHBOARD_BLOCK -- premium widget surface polish.
   Appended at end so cascade wins over earlier .widget rules.
   ============================================================ */

/* Subtle radial-gradient page backdrop instead of flat grey */
body .content,
body .dash-page,
body main.content {
  background:
    radial-gradient(1200px 600px at 0% -10%, rgba(20,184,166,0.06), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(14,165,233,0.05), transparent 65%),
    #f5f7fa;
}

/* Cards: bigger radius, layered shadow, gradient surface, smooth lift */
.widget {
  border-radius: 16px;
  border: 1px solid rgba(15,23,42,0.06);
  background:
    linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
  box-shadow:
    0 1px 2px rgba(15,23,42,0.04),
    0 8px 24px -10px rgba(15,23,42,0.10);
  padding: 16px 18px;
  min-height: 140px;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  position: relative;
  overflow: hidden;
}
.widget::before {
  /* glossy highlight strip across the top */
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg,
    transparent, rgba(20,184,166,0.45), transparent);
  pointer-events: none;
}
.widget:hover {
  transform: translateY(-2px);
  border-color: rgba(20,184,166,0.30);
  box-shadow:
    0 2px 4px rgba(15,23,42,0.05),
    0 14px 32px -10px rgba(15,23,42,0.16),
    0 0 0 1px rgba(20,184,166,0.15);
}

/* Title row: brand-accent left stripe + tighter spacing */
.widget__title {
  font-size: 10.5px;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: #475569;
  padding-left: 10px;
  position: relative;
  margin-bottom: 10px;
}
.widget__title::before {
  content: "";
  position: absolute;
  left: 0; top: 1px; bottom: 1px;
  width: 3px;
  background: linear-gradient(180deg, #0f766e, #14b8a6);
  border-radius: 2px;
}

/* Value tile: bigger number, crisper letter-spacing */
.tile__row {
  align-items: center;
  gap: 6px;
}
.tile__number {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.022em;
  line-height: 1.0;
  color: #0f172a;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tile__unit {
  font-size: 14px;
  color: #64748b;
  font-weight: 500;
  margin-left: 4px;
  align-self: flex-end;
  padding-bottom: 6px;
}
.tile__trend {
  font-size: 18px;
  font-weight: 800;
  opacity: 0.85;
}
.tile__trend[data-trend="up"]   { color: #047857; }
.tile__trend[data-trend="down"] { color: #b91c1c; }
.tile__trend[data-trend="flat"] { color: #14b8a6; }

/* Sparkline: brighter area fill */
.tile__spark {
  height: 46px;
  margin-top: 8px;
  opacity: 0.95;
}

/* Status lamp: bigger dot + glow + breathing pulse on green */
.widget--lamp { justify-content: center; align-items: center; }
.lamp { gap: 14px; }
.lamp__dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  position: relative;
}
.lamp--green .lamp__dot {
  background: radial-gradient(circle at 35% 35%, #4ade80, #16a34a);
  box-shadow:
    0 0 0 3px rgba(34,197,94,0.18),
    0 0 16px 2px rgba(34,197,94,0.45);
  animation: lampPulseGreen 2.4s ease-in-out infinite;
}
.lamp--amber .lamp__dot {
  background: radial-gradient(circle at 35% 35%, #fbbf24, #d97706);
  box-shadow:
    0 0 0 3px rgba(245,158,11,0.18),
    0 0 14px 2px rgba(245,158,11,0.45);
}
.lamp--red .lamp__dot {
  background: radial-gradient(circle at 35% 35%, #f87171, #dc2626);
  box-shadow:
    0 0 0 3px rgba(239,68,68,0.20),
    0 0 18px 3px rgba(239,68,68,0.55);
  animation: lampPulseRed 1.4s ease-in-out infinite;
}
.lamp--stale .lamp__dot {
  background: radial-gradient(circle at 35% 35%, #cbd5e1, #94a3b8);
  box-shadow: 0 0 0 3px rgba(100,116,139,0.10);
  animation: none;
}
.lamp__value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
@keyframes lampPulseGreen {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34,197,94,0.18), 0 0 16px 2px rgba(34,197,94,0.45); }
  50%      { box-shadow: 0 0 0 5px rgba(34,197,94,0.10), 0 0 22px 4px rgba(34,197,94,0.60); }
}
@keyframes lampPulseRed {
  0%, 100% { box-shadow: 0 0 0 3px rgba(239,68,68,0.20), 0 0 18px 3px rgba(239,68,68,0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(239,68,68,0.10), 0 0 26px 5px rgba(239,68,68,0.75); }
}

/* Gauge: gradient arc + softer track */
.gauge__svg { width: 84%; max-width: 220px; }
.gauge__track {
  stroke: rgba(15,23,42,0.06);
  stroke-width: 11;
}
.gauge__value {
  stroke-width: 11;
  stroke: url(#wm-gauge-gradient);
  filter: drop-shadow(0 1px 2px rgba(15,118,110,0.30));
}
.gauge__pct {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

/* Inject a gradient defs at the body level via ::before pseudo-element trick.
   (Actual gradient defs need to be in SVG; this fallback ensures the
    --primary stroke still renders even if defs id isn't present.) */
.gauge__value:not([stroke^="url"]) {
  stroke: #14b8a6;
}

/* Empty / loading state polish */
.tile__value:empty::before,
.lamp__value:empty::before {
  content: "—";
  color: #cbd5e1;
  font-size: 32px;
  font-weight: 500;
}

/* Dashboard meta strip + topbar lift */
.meta-strip {
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(240,253,250,0.95) 0%, rgba(220,252,231,0.65) 100%);
  border: 1px solid rgba(20,184,166,0.25);
  box-shadow: 0 2px 8px -2px rgba(20,184,166,0.18);
}

/* Better empty placeholders for tiles with no data */
.widget .tile__row:has(.tile__number:empty) .tile__number::before,
.widget .tile__row:has(.tile__swap:empty) .tile__number::before {
  content: "—";
  color: #cbd5e1;
}


/* ============================================================
   PREMIUM_TIER_2_BLOCK -- glassmorphism + per-metric color +
   entry animation + refined typography. Appended after GLOSSY.
   ============================================================ */

/* Richer page backdrop: more saturated gradient, no flat zones */
body .content,
body .dash-page,
body main.content {
  background:
    radial-gradient(1400px 700px at -5% -15%, rgba(20,184,166,0.10), transparent 55%),
    radial-gradient(1200px 600px at 105% 115%, rgba(14,165,233,0.08), transparent 60%),
    radial-gradient(800px 400px at 50% 50%, rgba(15,118,110,0.03), transparent 70%),
    linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

/* Cards: frosted glass + bigger radius + premium shadow stack */
.widget {
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.85) 0%, rgba(250,251,252,0.75) 100%);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
  border: 1px solid rgba(255,255,255,0.6);
  box-shadow:
    0 1px 1px rgba(15,23,42,0.04),
    0 2px 6px rgba(15,23,42,0.04),
    0 16px 40px -14px rgba(15,23,42,0.12),
    inset 0 1px 0 rgba(255,255,255,0.8);
  padding: 18px 20px 16px;
  min-height: 150px;
  animation: cardEntry 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 220ms ease,
              border-color 220ms ease;
}
.widget:hover {
  transform: translateY(-3px) scale(1.005);
  box-shadow:
    0 2px 4px rgba(15,23,42,0.05),
    0 4px 10px rgba(15,23,42,0.06),
    0 24px 48px -16px rgba(15,23,42,0.18),
    inset 0 1px 0 rgba(255,255,255,0.9);
  border-color: rgba(20,184,166,0.35);
}

/* Staggered card entry for that "load orchestrated" feel */
@keyframes cardEntry {
  0%   { opacity: 0; transform: translateY(14px) scale(0.985); }
  100% { opacity: 1; transform: translateY(0)    scale(1); }
}
.widget:nth-child(1)  { animation-delay: 0ms; }
.widget:nth-child(2)  { animation-delay: 40ms; }
.widget:nth-child(3)  { animation-delay: 80ms; }
.widget:nth-child(4)  { animation-delay: 120ms; }
.widget:nth-child(5)  { animation-delay: 160ms; }
.widget:nth-child(6)  { animation-delay: 200ms; }
.widget:nth-child(7)  { animation-delay: 240ms; }
.widget:nth-child(8)  { animation-delay: 280ms; }
.widget:nth-child(9)  { animation-delay: 320ms; }
.widget:nth-child(10) { animation-delay: 360ms; }
.widget:nth-child(n+11) { animation-delay: 400ms; }

/* Per-metric color stripe on the title accent */
.widget__title {
  font-size: 11px;
  letter-spacing: 0.14em;
  font-weight: 800;
  color: #475569;
  padding-left: 12px;
  margin-bottom: 12px;
}
.widget__title::before {
  width: 4px;
  border-radius: 3px;
  background: linear-gradient(180deg, #0f766e, #14b8a6, #2dd4bf);
  box-shadow: 0 0 8px -1px rgba(20,184,166,0.4);
}
.widget--gauge .widget__title::before {
  background: linear-gradient(180deg, #0369a1, #0ea5e9, #38bdf8);
  box-shadow: 0 0 8px -1px rgba(14,165,233,0.45);
}
.widget--lamp .widget__title::before {
  background: linear-gradient(180deg, #7c2d12, #f59e0b, #fbbf24);
  box-shadow: 0 0 8px -1px rgba(245,158,11,0.45);
}

/* Tile numbers: bigger, bolder, refined */
.tile__number {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: -0.028em;
  line-height: 1.0;
  background: linear-gradient(180deg, #0f172a 0%, #334155 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 1px 0 rgba(15,23,42,0.04);
}
.tile__unit {
  font-size: 15px;
  font-weight: 600;
  color: #64748b;
  padding-bottom: 8px;
}
.tile__trend {
  font-size: 20px;
  font-weight: 900;
}

/* Sparkline: gradient fill from color → transparent (not flat alpha) */
.tile__spark {
  height: 52px;
  margin-top: 10px;
  position: relative;
}
.tile__spark svg polyline {
  filter: drop-shadow(0 1px 2px rgba(15,23,42,0.10));
}

/* Status lamp upgrade: concentric ripple + smoother gradients */
.lamp__dot {
  width: 26px;
  height: 26px;
  position: relative;
}
.lamp__dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0;
  pointer-events: none;
}
.lamp--green .lamp__dot {
  background: radial-gradient(circle at 32% 32%, #6ee7b7 0%, #10b981 50%, #047857 100%);
  color: #10b981;
}
.lamp--green .lamp__dot::after {
  animation: lampRipple 2.2s ease-out infinite;
}
.lamp--amber .lamp__dot {
  background: radial-gradient(circle at 32% 32%, #fcd34d 0%, #f59e0b 50%, #b45309 100%);
  color: #f59e0b;
}
.lamp--red .lamp__dot {
  background: radial-gradient(circle at 32% 32%, #fca5a5 0%, #ef4444 50%, #991b1b 100%);
  color: #ef4444;
}
.lamp--red .lamp__dot::after {
  animation: lampRipple 1.2s ease-out infinite;
}
@keyframes lampRipple {
  0%   { transform: scale(0.9); opacity: 0.7; }
  100% { transform: scale(2.0); opacity: 0;   }
}
.lamp__value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.018em;
  background: linear-gradient(180deg, #0f172a, #334155);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Gauge polish */
.gauge__svg { width: 86%; max-width: 230px; }
.gauge__track { stroke: rgba(15,23,42,0.05); stroke-width: 12; }
.gauge__value {
  stroke-width: 12;
  stroke: #0ea5e9;
  filter: drop-shadow(0 2px 4px rgba(14,165,233,0.35));
}
.gauge__pct {
  font-size: 30px;
  font-weight: 800;
  background: linear-gradient(180deg, #0369a1, #0ea5e9);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Meta strip: glass + brand glow */
.meta-strip {
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(240,253,250,0.85) 0%, rgba(220,252,231,0.55) 100%);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(20,184,166,0.30);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.8) inset,
    0 6px 20px -6px rgba(20,184,166,0.25);
  padding: 10px 16px;
}

/* Topbar lift */
.topbar {
  background: rgba(255,255,255,0.65);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(15,23,42,0.06);
}

/* Active alarms / count badges: pill with brand shimmer */
.nav-badge {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: #fff;
  box-shadow: 0 2px 6px -2px rgba(220,38,38,0.55);
}

/* Buttons polish */
.btn--primary {
  background: linear-gradient(180deg, #0f766e 0%, #115e59 100%);
  box-shadow: 0 2px 6px -2px rgba(15,118,110,0.45);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.btn--primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -2px rgba(15,118,110,0.55);
}


/* ============================================================
   DARK_MODE_PALETTE_BLOCK -- toggleable dark theme with
   per-metric color + icon chips + compact sizing.
   Activated via <html data-theme="dark">. Light stays default.
   ============================================================ */

/* Per-metric CSS variables (apply in BOTH themes, color tweaked per theme) */
.widget[data-metric=status]   { --m-color: #22c55e; --m-icon: "\26A0"; }
.widget[data-metric=signal]   { --m-color: #38bdf8; --m-icon: "\1F4F6"; }
.widget[data-metric=counter]  { --m-color: #a78bfa; --m-icon: "\1F522"; }
.widget[data-metric=di]       { --m-color: #22d3ee; --m-icon: "\26A1"; }
.widget[data-metric=do]       { --m-color: #fbbf24; --m-icon: "\1F50C"; }
.widget[data-metric=voltage]  { --m-color: #fde047; --m-icon: "\26A1"; }
.widget[data-metric=current]  { --m-color: #fb923c; --m-icon: "\1F50B"; }
.widget[data-metric=power]    { --m-color: #f59e0b; --m-icon: "\1F4A1"; }
.widget[data-metric=temp]     { --m-color: #f87171; --m-icon: "\1F321"; }
.widget[data-metric=humidity] { --m-color: #67e8f9; --m-icon: "\1F4A7"; }
.widget[data-metric=pressure] { --m-color: #93c5fd; --m-icon: "\1F32A"; }
.widget[data-metric=analog]   { --m-color: #c4b5fd; --m-icon: "\1F4CA"; }
.widget[data-metric=flow]     { --m-color: #06b6d4; --m-icon: "\1F30A"; }
.widget[data-metric=generic]  { --m-color: #14b8a6; --m-icon: "\1F4CC"; }

/* Title icon chip (works in both themes) */
.widget__title { padding-left: 32px; min-height: 22px; position: relative; }
.widget__title::after {
  content: var(--m-icon);
  position: absolute;
  left: 8px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px;
  font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px;
  background: color-mix(in srgb, var(--m-color, #14b8a6) 18%, transparent);
  color: var(--m-color, #14b8a6);
}

/* Title accent stripe uses metric color */
.widget__title::before {
  background: linear-gradient(180deg, var(--m-color, #14b8a6), color-mix(in srgb, var(--m-color, #14b8a6) 60%, transparent)) !important;
  box-shadow: 0 0 8px -1px color-mix(in srgb, var(--m-color, #14b8a6) 50%, transparent) !important;
}

/* Compact tile sizing (overrides earlier premium tier 2) */
.widget {
  min-height: 122px;
  padding: 14px 16px 12px;
  border-radius: 14px;
}
.tile__number { font-size: 36px; }
.tile__spark { height: 38px; margin-top: 6px; }
.lamp__dot { width: 22px; height: 22px; }
.lamp__value { font-size: 20px; }

/* ----- DARK THEME ----- */
html[data-theme="dark"] {
  --ink: #e6edf7;
  --ink-soft: #cfe1ff;
  --ink-mute: #8a99b6;
  --line: rgba(255,255,255,.08);
  --line-strong: rgba(255,255,255,.18);
  --panel: #0f1830;
}
html[data-theme="dark"] body .content,
html[data-theme="dark"] body .dash-page,
html[data-theme="dark"] body main.content {
  background:
    radial-gradient(1400px 700px at -5% -15%, rgba(34,211,238,0.10), transparent 55%),
    radial-gradient(1200px 600px at 105% 115%, rgba(167,139,250,0.10), transparent 60%),
    linear-gradient(135deg, #070b14 0%, #0a1228 100%);
  color: #e6edf7;
}
html[data-theme="dark"] .widget {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border: 1px solid rgba(255,255,255,0.07);
  box-shadow:
    0 1px 1px rgba(0,0,0,0.35),
    0 12px 30px -12px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.05);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
html[data-theme="dark"] .widget:hover {
  border-color: color-mix(in srgb, var(--m-color, #14b8a6) 35%, transparent);
  box-shadow:
    0 1px 1px rgba(0,0,0,0.35),
    0 16px 36px -14px rgba(0,0,0,0.65),
    0 0 0 1px color-mix(in srgb, var(--m-color, #14b8a6) 25%, transparent),
    inset 0 1px 0 rgba(255,255,255,0.07);
}
html[data-theme="dark"] .widget__title { color: #cfe1ff; }
html[data-theme="dark"] .tile__number {
  background: linear-gradient(180deg, #e6edf7 0%, #cfe1ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
html[data-theme="dark"] .tile__unit { color: #8a99b6; }
html[data-theme="dark"] .tile__ts { color: #5e6e8c; }
html[data-theme="dark"] .lamp__value {
  background: linear-gradient(180deg, #e6edf7, #cfe1ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
html[data-theme="dark"] .meta-strip {
  background: linear-gradient(180deg, rgba(15,23,42,0.65), rgba(15,23,42,0.45));
  border: 1px solid rgba(34,211,238,0.18);
  color: #cfe1ff;
}
html[data-theme="dark"] .gauge__track { stroke: rgba(255,255,255,0.07); }
html[data-theme="dark"] .topbar {
  background: rgba(15,23,42,0.65);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
html[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #070b14 0%, #0a1228 100%) !important;
  border-right: 1px solid rgba(255,255,255,0.05);
}

/* Theme toggle button styling (works both themes) */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid rgba(15,23,42,0.12);
  background: rgba(255,255,255,0.7);
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  margin-right: 10px;
  transition: background 120ms ease, transform 120ms ease;
}
.theme-toggle:hover { background: rgba(20,184,166,0.10); transform: scale(1.05); }
html[data-theme="dark"] .theme-toggle {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.10);
  color: #fde047;
}
html[data-theme="dark"] .theme-toggle:hover { background: rgba(255,255,255,0.10); }


/* ============================================================
   DARK_MODE_POLISH_BLOCK -- fine-tune dim/low-contrast pieces
   that the first dark-mode patcher missed.
   Light theme untouched.
   ============================================================ */

/* ---- Range picker (top-of-dashboard time bar) ---- */
html[data-theme="dark"] .range-picker {
  background: rgba(15,23,42,0.55);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
html[data-theme="dark"] .range-picker__label { color: #cfe1ff; }
html[data-theme="dark"] .range-picker__source { color: #94a3b8; }
html[data-theme="dark"] .range-picker__chips {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}
html[data-theme="dark"] .range-chip {
  color: #cbd5e1;
}
html[data-theme="dark"] .range-chip:hover {
  background: rgba(34,211,238,0.12);
  color: #67e8f9;
}
html[data-theme="dark"] .range-chip.active {
  background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
  color: #fff;
  box-shadow: 0 1px 3px rgba(2,132,199,0.5);
}

/* ---- Chart "1-MIN AGG" source badge ---- */
html[data-theme="dark"] .chart__source-badge {
  color: #94a3b8;
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.10);
}

/* ---- Alarm-badge severity pills (was cream/pink bleed) ---- */
html[data-theme="dark"] .sev--critical {
  color: #fca5a5;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.30);
}
html[data-theme="dark"] .sev--major {
  color: #fbbf24;
  background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.30);
}
html[data-theme="dark"] .sev--minor {
  color: #67e8f9;
  background: rgba(14,165,233,0.12);
  border: 1px solid rgba(14,165,233,0.30);
}
html[data-theme="dark"] .sev--warning {
  color: #fcd34d;
  background: rgba(234,179,8,0.12);
  border: 1px solid rgba(234,179,8,0.30);
}

/* ---- Generic pills used elsewhere ---- */
html[data-theme="dark"] .pill--red,
html[data-theme="dark"] .pill--crit {
  background: rgba(239,68,68,0.14);
  color: #fca5a5;
}
html[data-theme="dark"] .pill--amber,
html[data-theme="dark"] .pill--warn {
  background: rgba(245,158,11,0.14);
  color: #fbbf24;
}
html[data-theme="dark"] .pill--green,
html[data-theme="dark"] .pill--ok {
  background: rgba(34,197,94,0.14);
  color: #86efac;
}

/* ---- Data table rows (Reg1, Reg10, etc.) ---- */
html[data-theme="dark"] .data-table {
  color: #e6edf7;
}
html[data-theme="dark"] .data-table thead {
  background: rgba(255,255,255,0.04) !important;
}
html[data-theme="dark"] .data-table thead th {
  color: #cfe1ff !important;
  border-bottom: 1px solid rgba(255,255,255,0.10);
}
html[data-theme="dark"] .data-table tbody td {
  color: #cbd5e1;
  border-bottom-color: rgba(255,255,255,0.06) !important;
}
html[data-theme="dark"] .data-table tbody tr:hover {
  background: rgba(255,255,255,0.03);
}
html[data-theme="dark"] .data-table code,
html[data-theme="dark"] .data-table b {
  color: #67e8f9;
}

/* ---- Tile trend arrow ---- */
html[data-theme="dark"] .tile__trend { color: #8a99b6; }
html[data-theme="dark"] .tile__trend[data-trend="up"]   { color: #34d399; }
html[data-theme="dark"] .tile__trend[data-trend="down"] { color: #f87171; }
html[data-theme="dark"] .tile__trend[data-trend="flat"] { color: #67e8f9; }

/* ---- Topbar (title, hello, build-pill) ---- */
html[data-theme="dark"] .topbar__title { color: #e6edf7; }
html[data-theme="dark"] .hello { color: #cfe1ff; }
html[data-theme="dark"] .hello b { color: #fff; }
html[data-theme="dark"] .build-pill {
  background: rgba(255,255,255,0.06);
  color: #cfe1ff;
  border: 1px solid rgba(255,255,255,0.08);
}
html[data-theme="dark"] .build-pill i { color: #94a3b8; }

/* ---- Sidebar navlinks ---- */
html[data-theme="dark"] .sidebar .navlink {
  color: #cfe1ff;
}
html[data-theme="dark"] .sidebar .navlink:hover {
  background: rgba(255,255,255,0.06);
  color: #67e8f9;
}
html[data-theme="dark"] .sidebar .navlink.navlink--active,
html[data-theme="dark"] .sidebar .sidebar__link--active {
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%) !important;
  color: #fff !important;
  box-shadow: 0 4px 12px -4px rgba(13,148,136,0.55);
}
html[data-theme="dark"] .sidebar__brand {
  background: rgba(255,255,255,0.04) !important;
  color: #67e8f9;
}
html[data-theme="dark"] .sidebar-section,
html[data-theme="dark"] .sidebar__section,
html[data-theme="dark"] .sidebar__group-title {
  color: #64748b;
}

/* ---- Sparkline svg fill polish in dark ---- */
html[data-theme="dark"] .tile__spark svg polyline {
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.45));
}

/* ---- Cards / sections that use bare background:#fff ---- */
html[data-theme="dark"] .card {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border: 1px solid rgba(255,255,255,0.06);
  color: #e6edf7;
}
html[data-theme="dark"] .card h1,
html[data-theme="dark"] .card h2,
html[data-theme="dark"] .card h3 { color: #67e8f9; }
html[data-theme="dark"] .card p,
html[data-theme="dark"] .card li,
html[data-theme="dark"] .card span { color: #cbd5e1; }

/* ---- Forms ---- */
html[data-theme="dark"] input[type=text],
html[data-theme="dark"] input[type=number],
html[data-theme="dark"] input[type=search],
html[data-theme="dark"] input[type=email],
html[data-theme="dark"] input[type=password],
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: rgba(255,255,255,0.04);
  color: #e6edf7;
  border-color: rgba(255,255,255,0.10);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #64748b; }

/* ---- Inline labels (subtle text, small caps) ---- */
html[data-theme="dark"] label b,
html[data-theme="dark"] label strong { color: #cfe1ff; }

/* ---- Empty placeholders / stale markers (large "—") ---- */
html[data-theme="dark"] .tile__value:empty::before,
html[data-theme="dark"] .lamp__value:empty::before { color: #475569; }

/* ---- Lamp dot "stale" state ---- */
html[data-theme="dark"] .lamp--stale .lamp__dot {
  background: radial-gradient(circle at 35% 35%, #475569, #334155);
}

/* ---- Builder palette + grid (when in dark mode) ---- */
html[data-theme="dark"] .dbld-bar {
  background: rgba(15,23,42,0.65);
  border-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .dbld-bar strong { color: #67e8f9; }
html[data-theme="dark"] .dbld-palette {
  background: rgba(15,23,42,0.65);
  border-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .dbld-palette h3 { color: #67e8f9; }
html[data-theme="dark"] .dbld-pal-item {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.10);
  color: #cfe1ff;
}
html[data-theme="dark"] .dbld-pal-item small { color: #94a3b8; }
html[data-theme="dark"] .grid-stack {
  background: repeating-linear-gradient(0deg,#0a1228,#0a1228 39px,rgba(255,255,255,0.04) 39px,rgba(255,255,255,0.04) 40px);
  border-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .grid-stack-item-content {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border-color: rgba(255,255,255,0.10);
  color: #cbd5e1;
}
html[data-theme="dark"] .dbld-card-head {
  background: rgba(255,255,255,0.04);
  border-bottom-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .dbld-card-title { color: #e6edf7; }
html[data-theme="dark"] .dbld-card-tag { color: #94a3b8; }
html[data-theme="dark"] .dbld-card-type { color: #67e8f9; }
html[data-theme="dark"] .dbld-modal {
  background: linear-gradient(180deg, #0f1830, #111c38);
  color: #e6edf7;
  box-shadow: 0 20px 60px -10px rgba(0,0,0,0.7);
}
html[data-theme="dark"] .dbld-modal h2 { color: #67e8f9; }


/* ============================================================
   DARK_SIDEBAR_ICONS_BLOCK -- boost icon visibility in dark
   ============================================================ */

/* Brighter, thicker icon strokes in dark mode (both expanded + collapsed) */
html[data-theme="dark"] .sidebar .navlink svg,
html[data-theme="dark"] .sidebar .sb-toggle svg {
  stroke: #a5f3fc;
  stroke-width: 2.1;
  opacity: 0.95;
}
html[data-theme="dark"] .sidebar .navlink:hover svg {
  stroke: #ecfeff;
  opacity: 1;
}
html[data-theme="dark"] .sidebar .navlink.navlink--active svg,
html[data-theme="dark"] .sidebar .sidebar__link--active svg {
  stroke: #ffffff;
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(34,211,238,0.5));
}

/* In collapsed mode the icon IS the entire link target -- give it a
   subtle background ring on hover for better affordance */
html[data-theme="dark"] .sidebar--collapsed .navlink {
  border-radius: 8px;
}
html[data-theme="dark"] .sidebar--collapsed .navlink:hover {
  background: rgba(34,211,238,0.10);
}
html[data-theme="dark"] .sidebar--collapsed .navlink.navlink--active,
html[data-theme="dark"] .sidebar--collapsed .sidebar__link--active {
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%) !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10),
              0 4px 12px -4px rgba(13,148,136,0.65);
}

/* Sidebar toggle (chevron) — make the arrow clearly visible */
html[data-theme="dark"] .sb-toggle {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.10);
  color: #a5f3fc;
}
html[data-theme="dark"] .sb-toggle:hover {
  background: rgba(34,211,238,0.15);
  color: #ecfeff;
}

/* Light mode parity tweak: don't change anything (no override) */


/* ============================================================
   DARK_SIDEBAR_ICONS_V2_BLOCK -- icons use currentColor; set
   the LINK color, not the svg stroke. Bumps opacity too.
   ============================================================ */

html[data-theme="dark"] .sidebar .navlink {
  color: #a5f3fc;
}
html[data-theme="dark"] .sidebar .navlink .navlink__label {
  color: #cfe1ff;
}
html[data-theme="dark"] .sidebar .navlink .navlink__icon {
  opacity: 1;
  color: #67e8f9;
}
html[data-theme="dark"] .sidebar .navlink:hover {
  color: #ecfeff;
  background: rgba(34,211,238,0.10);
}
html[data-theme="dark"] .sidebar .navlink:hover .navlink__icon {
  color: #ecfeff;
}
html[data-theme="dark"] .sidebar .navlink.navlink--active,
html[data-theme="dark"] .sidebar .sidebar__link--active {
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px -4px rgba(13,148,136,0.55);
}
html[data-theme="dark"] .sidebar .navlink.navlink--active .navlink__icon,
html[data-theme="dark"] .sidebar .sidebar__link--active .navlink__icon {
  color: #ffffff;
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(255,255,255,0.4));
}

/* Section headers (FRONTEND / BACKEND / INFRA labels) */
html[data-theme="dark"] .sidebar .sidebar__section,
html[data-theme="dark"] .sidebar .sidebar-section,
html[data-theme="dark"] .sidebar .sidebar__group-title,
html[data-theme="dark"] .sidebar h4,
html[data-theme="dark"] .sidebar h5 {
  color: #64748b !important;
}

/* Collapsed-rail specific */
html[data-theme="dark"] .sidebar--collapsed .navlink {
  justify-content: center;
}
html[data-theme="dark"] .sidebar--collapsed .navlink .navlink__icon {
  width: 20px;
  height: 20px;
}

/* Brand mark + sb-toggle chevron */
html[data-theme="dark"] .sidebar__brand,
html[data-theme="dark"] .brand__mark {
  color: #67e8f9;
}
html[data-theme="dark"] .sb-toggle {
  color: #a5f3fc;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
}
html[data-theme="dark"] .sb-toggle:hover {
  color: #ecfeff;
  background: rgba(34,211,238,0.18);
}

/* Footer (admin / change pw / sign out) */
html[data-theme="dark"] .sidebar__footer { color: #cbd5e1; }
html[data-theme="dark"] .sidebar__footer a { color: #a5f3fc; }
html[data-theme="dark"] .sidebar__footer a:hover { color: #ecfeff; }


/* ============================================================
   APP_SHELL_COLLAPSED_GRID_BLOCK -- when sidebar collapses,
   shrink the parent grid track so content reclaims the space.
   Uses :has() (Chrome/Safari/Firefox 121+).
   ============================================================ */
.app-shell:has(.sidebar.sidebar--collapsed) {
  grid-template-columns: 64px 1fr;
}


/* ============================================================
   SIDEBAR_GROUPS_CSS_BLOCK -- collapsible <details>/<summary>
   navigation groups
   ============================================================ */

.navgroup { margin: 2px 0; }
.navgroup > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.navgroup > summary::-webkit-details-marker { display: none; }

.navgroup__head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--sidebar-ink, #cfe1ff);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background 120ms ease, color 120ms ease;
}
.navgroup__head:hover { background: rgba(20,184,166,0.10); color: var(--brand, #0d9488); }
.navgroup__head .navlink__label { flex: 1; }

.navgroup__chev {
  transition: transform 180ms ease;
  opacity: 0.55;
  flex-shrink: 0;
}
.navgroup[open] > summary .navgroup__chev { transform: rotate(90deg); opacity: 0.9; }

.navgroup__items {
  display: flex; flex-direction: column; gap: 1px;
  padding-left: 8px;
  margin-top: 2px;
  margin-bottom: 6px;
  border-left: 1px dashed rgba(15,23,42,0.08);
  margin-left: 18px;
}

.navgroup__items .navlink--sub {
  padding: 6px 10px 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
}
.navgroup__items .navlink--sub .navlink__icon {
  width: 15px; height: 15px;
  opacity: 0.75;
}

/* When sidebar is collapsed: hide group heads, force-show items as icons */
.sidebar--collapsed .navgroup > summary { display: none; }
.sidebar--collapsed .navgroup > .navgroup__items {
  display: flex !important;
  border-left: none !important;
  padding-left: 0 !important;
  margin-left: 0 !important;
}
.sidebar--collapsed .navgroup__items .navlink--sub {
  padding: 10px 0;
  justify-content: center;
  font-size: 0;             /* hides labels at the icon-rail level too */
}
.sidebar--collapsed .navgroup__items .navlink--sub .navlink__icon {
  width: 18px; height: 18px;
}
.sidebar--collapsed .navlink--footer { margin-top: auto; }

/* Dark-mode tweaks */
html[data-theme="dark"] .navgroup__head { color: #a5f3fc; }
html[data-theme="dark"] .navgroup__head:hover {
  background: rgba(34,211,238,0.10);
  color: #ecfeff;
}
html[data-theme="dark"] .navgroup__items {
  border-left-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .navgroup__items .navlink--sub { color: #cbd5e1; }
html[data-theme="dark"] .navgroup__items .navlink--sub:hover { color: #ecfeff; }
html[data-theme="dark"] .navgroup__items .navlink--sub.navlink--active {
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
  color: #fff;
}


/* ============================================================
   SIDEBAR_SPACING_BLOCK -- breathable rail
   ============================================================ */

/* Pinned top-level links: more vertical space, bigger icons */
.sidebar .navlink {
  padding: 10px 14px 10px 16px;
  font-size: 13px;
  gap: 12px;
  margin: 1px 6px;
  border-radius: 6px;
  /* override the original heavy left-border accent for non-active items */
  border-left: 0;
}
.sidebar .navlink--active {
  border-left: 0;
  background: linear-gradient(135deg, var(--brand, #0d9488) 0%, #0f766e 100%);
  color: #fff;
  box-shadow: 0 2px 8px -2px rgba(13,148,136,0.45);
}
.sidebar .navlink__icon {
  width: 20px;
  height: 20px;
}

/* Group rows */
.sidebar .navgroup {
  margin: 4px 0;
}
.sidebar .navgroup__head {
  padding: 10px 14px 10px 16px;
  gap: 12px;
  margin: 1px 6px;
}
.sidebar .navgroup__head .navlink__icon {
  width: 20px;
  height: 20px;
}

/* Sub-items inside groups: slightly smaller than parents but still legible */
.sidebar .navgroup__items {
  margin-top: 4px;
  margin-bottom: 8px;
  padding-left: 6px;
  margin-left: 22px;
  gap: 2px;
}
.sidebar .navgroup__items .navlink--sub {
  padding: 7px 10px 7px 12px;
  font-size: 12.5px;
  gap: 10px;
  margin: 0;
}
.sidebar .navgroup__items .navlink--sub .navlink__icon {
  width: 17px;
  height: 17px;
}

/* Footer-pinned (Django admin) */
.sidebar .navlink--footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-bottom: 10px;
}

/* Collapsed rail keeps its own compact spacing (don't let the new
   margins push icons off-center) */
.sidebar--collapsed .navlink,
.sidebar--collapsed .navgroup__items .navlink--sub {
  margin: 2px 8px;
  padding: 10px 0;
}
.sidebar--collapsed .navlink__icon,
.sidebar--collapsed .navgroup__items .navlink--sub .navlink__icon {
  width: 22px;
  height: 22px;
}


/* ============================================================
   DARK_MODE_SWEEPER_BLOCK -- catch-all dark-mode overrides for
   inline-styled elements across the whole platform.
   ============================================================ */

/* ---------- WHITE / NEAR-WHITE BACKGROUNDS ---------- */
html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"],
html[data-theme="dark"] [style*="background:#FFFFFF"],
html[data-theme="dark"] [style*="background: #FFFFFF"],
html[data-theme="dark"] [style*="background:#ffffff"],
html[data-theme="dark"] [style*="background: #ffffff"],
html[data-theme="dark"] [style*="background: white"],
html[data-theme="dark"] [style*="background:white"] {
  background: #0f1830 !important;
  color: #e6edf7;
}

/* ---------- SLATE-50 / SLATE-100 ---------- */
html[data-theme="dark"] [style*="background:#f8fafc"],
html[data-theme="dark"] [style*="background: #f8fafc"],
html[data-theme="dark"] [style*="background:#f1f5f9"],
html[data-theme="dark"] [style*="background: #f1f5f9"],
html[data-theme="dark"] [style*="background:#fafbfc"],
html[data-theme="dark"] [style*="background: #fafbfc"] {
  background: rgba(255,255,255,0.04) !important;
  color: #e6edf7;
}

/* ---------- SLATE-200 (heavier elevation) ---------- */
html[data-theme="dark"] [style*="background:#e2e8f0"],
html[data-theme="dark"] [style*="background: #e2e8f0"] {
  background: rgba(255,255,255,0.08) !important;
}

/* ---------- STATUS-COLOR PASTELS (soft) ---------- */
/* GREEN tints */
html[data-theme="dark"] [style*="background:#dcfce7"],
html[data-theme="dark"] [style*="background: #dcfce7"],
html[data-theme="dark"] [style*="background:#d1fae5"],
html[data-theme="dark"] [style*="background: #d1fae5"],
html[data-theme="dark"] [style*="background:#f0fdfa"],
html[data-theme="dark"] [style*="background: #f0fdfa"],
html[data-theme="dark"] [style*="background:#ccfbf1"],
html[data-theme="dark"] [style*="background: #ccfbf1"] {
  background: rgba(34,197,94,0.12) !important;
  color: #86efac !important;
}

/* RED tints */
html[data-theme="dark"] [style*="background:#fee2e2"],
html[data-theme="dark"] [style*="background: #fee2e2"],
html[data-theme="dark"] [style*="background:#fef2f2"],
html[data-theme="dark"] [style*="background: #fef2f2"],
html[data-theme="dark"] [style*="background:#fbe1e2"],
html[data-theme="dark"] [style*="background: #fbe1e2"],
html[data-theme="dark"] [style*="background:#fce7f3"],
html[data-theme="dark"] [style*="background: #fce7f3"] {
  background: rgba(239,68,68,0.12) !important;
  color: #fca5a5 !important;
}

/* AMBER tints */
html[data-theme="dark"] [style*="background:#fef3c7"],
html[data-theme="dark"] [style*="background: #fef3c7"],
html[data-theme="dark"] [style*="background:#fffbeb"],
html[data-theme="dark"] [style*="background: #fffbeb"],
html[data-theme="dark"] [style*="background:#faedc6"],
html[data-theme="dark"] [style*="background: #faedc6"] {
  background: rgba(245,158,11,0.12) !important;
  color: #fbbf24 !important;
}

/* BLUE tints */
html[data-theme="dark"] [style*="background:#dbeafe"],
html[data-theme="dark"] [style*="background: #dbeafe"],
html[data-theme="dark"] [style*="background:#bfdbfe"],
html[data-theme="dark"] [style*="background: #bfdbfe"] {
  background: rgba(14,165,233,0.12) !important;
  color: #93c5fd !important;
}

/* PURPLE / PINK accents */
html[data-theme="dark"] [style*="background:#fce7f3"],
html[data-theme="dark"] [style*="background: #fce7f3"] {
  background: rgba(217,70,239,0.12) !important;
  color: #f0abfc !important;
}

/* ---------- DARK TEXT ON ASSUMED-LIGHT BG → LIGHT TEXT ---------- */
html[data-theme="dark"] [style*="color:#0f172a"],
html[data-theme="dark"] [style*="color: #0f172a"],
html[data-theme="dark"] [style*="color:#1e293b"],
html[data-theme="dark"] [style*="color: #1e293b"],
html[data-theme="dark"] [style*="color:#374151"],
html[data-theme="dark"] [style*="color: #374151"] {
  color: #e6edf7 !important;
}

/* MID-SLATE → SOFT SLATE */
html[data-theme="dark"] [style*="color:#475569"],
html[data-theme="dark"] [style*="color: #475569"],
html[data-theme="dark"] [style*="color:#64748b"],
html[data-theme="dark"] [style*="color: #64748b"],
html[data-theme="dark"] [style*="color:#7a8086"],
html[data-theme="dark"] [style*="color: #7a8086"] {
  color: #cbd5e1 !important;
}

/* LIGHT-SLATE → MUTED */
html[data-theme="dark"] [style*="color:#94a3b8"],
html[data-theme="dark"] [style*="color: #94a3b8"],
html[data-theme="dark"] [style*="color:#cbd5e1"],
html[data-theme="dark"] [style*="color: #cbd5e1"],
html[data-theme="dark"] [style*="color:#e2e8f0"],
html[data-theme="dark"] [style*="color: #e2e8f0"] {
  color: #94a3b8 !important;
}

/* ---------- BRAND TEAL → BRIGHTER CYAN (dark needs more contrast) ---------- */
html[data-theme="dark"] [style*="color:#0f766e"],
html[data-theme="dark"] [style*="color: #0f766e"],
html[data-theme="dark"] [style*="color:#0d9488"],
html[data-theme="dark"] [style*="color: #0d9488"],
html[data-theme="dark"] [style*="color:#0a7c3e"],
html[data-theme="dark"] [style*="color: #0a7c3e"] {
  color: #67e8f9 !important;
}

/* Status text colors stay vivid */
html[data-theme="dark"] [style*="color:#166534"],
html[data-theme="dark"] [style*="color: #166534"],
html[data-theme="dark"] [style*="color:#15803d"],
html[data-theme="dark"] [style*="color: #15803d"] {
  color: #86efac !important;
}
html[data-theme="dark"] [style*="color:#991b1b"],
html[data-theme="dark"] [style*="color: #991b1b"],
html[data-theme="dark"] [style*="color:#b91c1c"],
html[data-theme="dark"] [style*="color: #b91c1c"],
html[data-theme="dark"] [style*="color:#dc2626"],
html[data-theme="dark"] [style*="color: #dc2626"] {
  color: #fca5a5 !important;
}
html[data-theme="dark"] [style*="color:#854d0e"],
html[data-theme="dark"] [style*="color: #854d0e"],
html[data-theme="dark"] [style*="color:#92400e"],
html[data-theme="dark"] [style*="color: #92400e"],
html[data-theme="dark"] [style*="color:#78350f"],
html[data-theme="dark"] [style*="color: #78350f"],
html[data-theme="dark"] [style*="color:#b45309"],
html[data-theme="dark"] [style*="color: #b45309"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] [style*="color:#1e40af"],
html[data-theme="dark"] [style*="color: #1e40af"] {
  color: #93c5fd !important;
}

/* ---------- LIGHT BORDERS → SUBTLE DARK ---------- */
html[data-theme="dark"] [style*="border:1px solid #e2e8f0"],
html[data-theme="dark"] [style*="border: 1px solid #e2e8f0"],
html[data-theme="dark"] [style*="border-color:#e2e8f0"],
html[data-theme="dark"] [style*="border-color: #e2e8f0"],
html[data-theme="dark"] [style*="border-bottom:1px solid #e2e8f0"],
html[data-theme="dark"] [style*="border-bottom: 1px solid #e2e8f0"],
html[data-theme="dark"] [style*="border-top:1px solid #e2e8f0"],
html[data-theme="dark"] [style*="border-top: 1px solid #e2e8f0"],
html[data-theme="dark"] [style*="border:1px solid #cbd5e1"],
html[data-theme="dark"] [style*="border: 1px solid #cbd5e1"],
html[data-theme="dark"] [style*="border-color:#cbd5e1"],
html[data-theme="dark"] [style*="border-color: #cbd5e1"] {
  border-color: rgba(255,255,255,0.10) !important;
}

/* ---------- GENERIC SECTIONS / CARDS / PANELS ---------- */
html[data-theme="dark"] section.card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .surface,
html[data-theme="dark"] .table-wrap {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  color: #e6edf7;
  border-color: rgba(255,255,255,0.08);
}

/* ---------- TABLES (non-inline) ---------- */
html[data-theme="dark"] table {
  color: #e6edf7;
}
html[data-theme="dark"] table thead {
  background: rgba(255,255,255,0.04);
}
html[data-theme="dark"] table thead th {
  color: #cfe1ff;
  border-bottom: 1px solid rgba(255,255,255,0.10);
}
html[data-theme="dark"] table tbody tr {
  border-bottom-color: rgba(255,255,255,0.06);
}
html[data-theme="dark"] table tbody td {
  color: #cbd5e1;
}
html[data-theme="dark"] table tbody tr:hover {
  background: rgba(255,255,255,0.03);
}

/* ---------- FORMS ---------- */
html[data-theme="dark"] input[type=text],
html[data-theme="dark"] input[type=number],
html[data-theme="dark"] input[type=email],
html[data-theme="dark"] input[type=password],
html[data-theme="dark"] input[type=search],
html[data-theme="dark"] input[type=tel],
html[data-theme="dark"] input[type=url],
html[data-theme="dark"] input[type=date],
html[data-theme="dark"] input[type=datetime-local],
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background: rgba(255,255,255,0.04) !important;
  color: #e6edf7 !important;
  border-color: rgba(255,255,255,0.10) !important;
}
html[data-theme="dark"] input:focus,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] select:focus {
  border-color: rgba(34,211,238,0.45) !important;
  outline: none;
  box-shadow: 0 0 0 3px rgba(34,211,238,0.18);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #64748b !important;
}
html[data-theme="dark"] label,
html[data-theme="dark"] .form-label {
  color: #cbd5e1;
}
html[data-theme="dark"] label b,
html[data-theme="dark"] label strong {
  color: #cfe1ff;
}

/* Disabled / readonly */
html[data-theme="dark"] input[disabled],
html[data-theme="dark"] input[readonly],
html[data-theme="dark"] textarea[disabled],
html[data-theme="dark"] select[disabled] {
  background: rgba(255,255,255,0.02) !important;
  color: #64748b !important;
  cursor: not-allowed;
}

/* ---------- CODE / KBD / PRE ---------- */
html[data-theme="dark"] code,
html[data-theme="dark"] kbd,
html[data-theme="dark"] pre,
html[data-theme="dark"] tt,
html[data-theme="dark"] samp {
  background: rgba(255,255,255,0.05) !important;
  color: #67e8f9 !important;
  border-color: rgba(255,255,255,0.08) !important;
}
html[data-theme="dark"] pre {
  padding: 10px;
  border-radius: 6px;
}

/* ---------- HR + DIVIDERS ---------- */
html[data-theme="dark"] hr {
  border-color: rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.06);
}

/* ---------- BUTTONS (non-primary) ---------- */
html[data-theme="dark"] button:not(.btn--primary):not(.dbld-btn--primary):not(.dbld-btn--danger):not(.theme-toggle):not(.sb-toggle):not(.snip-btn) {
  background: rgba(255,255,255,0.05);
  color: #cfe1ff;
  border-color: rgba(255,255,255,0.10);
}
html[data-theme="dark"] button:not(.btn--primary):not(.dbld-btn--primary):not(.dbld-btn--danger):not(.theme-toggle):not(.sb-toggle):not(.snip-btn):hover {
  background: rgba(255,255,255,0.10);
  color: #ecfeff;
}
html[data-theme="dark"] .btn,
html[data-theme="dark"] .btn--ghost {
  background: rgba(255,255,255,0.05);
  color: #cfe1ff;
  border-color: rgba(255,255,255,0.10);
}

/* ---------- LINKS ---------- */
html[data-theme="dark"] a:not(.navlink):not(.btn):not(.btn--primary):not(.dbld-btn) {
  color: #67e8f9;
}
html[data-theme="dark"] a:not(.navlink):not(.btn):not(.btn--primary):not(.dbld-btn):hover {
  color: #a5f3fc;
}

/* ---------- HEADINGS ---------- */
html[data-theme="dark"] h1, html[data-theme="dark"] h2,
html[data-theme="dark"] h3, html[data-theme="dark"] h4,
html[data-theme="dark"] h5, html[data-theme="dark"] h6 {
  color: #e6edf7;
}
html[data-theme="dark"] .page-head h1,
html[data-theme="dark"] .page__title { color: #e6edf7; }

/* ---------- LISTS ---------- */
html[data-theme="dark"] ul, html[data-theme="dark"] ol {
  color: #cbd5e1;
}
html[data-theme="dark"] dl dt { color: #cfe1ff; }
html[data-theme="dark"] dl dd { color: #cbd5e1; }

/* ---------- BREADCRUMBS / SMALL TEXT ---------- */
html[data-theme="dark"] .breadcrumbs,
html[data-theme="dark"] .crumbs,
html[data-theme="dark"] small,
html[data-theme="dark"] .small,
html[data-theme="dark"] .text-muted {
  color: #94a3b8;
}

/* ---------- PILLS / CHIPS (cover what main DARK_MODE_POLISH missed) ---------- */
html[data-theme="dark"] .pill,
html[data-theme="dark"] .chip {
  border-color: rgba(255,255,255,0.10);
}

/* ---------- STAT CARDS (the 2/2/2 Gateways/Online/Slaves Total cards) ---------- */
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .stats-card,
html[data-theme="dark"] .summary-card,
html[data-theme="dark"] .kpi-card {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border-color: rgba(255,255,255,0.08);
  color: #e6edf7;
}

/* ---------- MODAL / DIALOG (generic) ---------- */
html[data-theme="dark"] dialog,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .modal__content,
html[data-theme="dark"] [role="dialog"] {
  background: linear-gradient(180deg, #0f1830, #111c38);
  color: #e6edf7;
  border-color: rgba(255,255,255,0.10);
}

/* ---------- DROPDOWN / DATALIST results (browser-styled, limited) ---------- */
html[data-theme="dark"] option {
  background: #0f1830;
  color: #e6edf7;
}

/* ---------- DEVICE/GATEWAY/CLIENT CARDS (auto-detect by class) ---------- */
html[data-theme="dark"] .device-card,
html[data-theme="dark"] .gateway-card,
html[data-theme="dark"] .client-card,
html[data-theme="dark"] .master-card,
html[data-theme="dark"] .user-card,
html[data-theme="dark"] .row-card {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%) !important;
  border-color: rgba(255,255,255,0.08) !important;
  color: #e6edf7;
}

/* ---------- MESSAGE BANNERS (info/success/error/warning) ---------- */
html[data-theme="dark"] .msg--info,
html[data-theme="dark"] .alert--info,
html[data-theme="dark"] .banner--info {
  background: rgba(14,165,233,0.12) !important;
  color: #93c5fd !important;
  border-color: rgba(14,165,233,0.30) !important;
}
html[data-theme="dark"] .msg--success,
html[data-theme="dark"] .alert--success,
html[data-theme="dark"] .banner--success {
  background: rgba(34,197,94,0.12) !important;
  color: #86efac !important;
  border-color: rgba(34,197,94,0.30) !important;
}
html[data-theme="dark"] .msg--warning,
html[data-theme="dark"] .alert--warning,
html[data-theme="dark"] .banner--warning {
  background: rgba(245,158,11,0.12) !important;
  color: #fbbf24 !important;
  border-color: rgba(245,158,11,0.30) !important;
}
html[data-theme="dark"] .msg--error,
html[data-theme="dark"] .alert--error,
html[data-theme="dark"] .banner--error,
html[data-theme="dark"] .msg--danger {
  background: rgba(239,68,68,0.12) !important;
  color: #fca5a5 !important;
  border-color: rgba(239,68,68,0.30) !important;
}

/* ---------- TAB STRIPS ---------- */
html[data-theme="dark"] .tabs__tab,
html[data-theme="dark"] .tab-nav__item {
  color: #94a3b8;
  border-bottom-color: transparent;
}
html[data-theme="dark"] .tabs__tab:hover,
html[data-theme="dark"] .tab-nav__item:hover {
  color: #cfe1ff;
}
html[data-theme="dark"] .tabs__tab.is-active,
html[data-theme="dark"] .tab-nav__item.is-active,
html[data-theme="dark"] .tab-nav__item--active {
  color: #67e8f9;
  border-bottom-color: #0ea5e9;
}

/* ---------- FOOTER / NOTES / HINTS ---------- */
html[data-theme="dark"] .hint,
html[data-theme="dark"] .note,
html[data-theme="dark"] footer.note,
html[data-theme="dark"] .help-text {
  color: #94a3b8;
}

/* ---------- KEEP page body color sane wherever a stray .content is used ---------- */
html[data-theme="dark"] .content,
html[data-theme="dark"] .page,
html[data-theme="dark"] main.content {
  color: #e6edf7;
}


/* ============================================================
   DARK_AUTOBOX_BLOCK -- dark mode for the per-device AUTO-BOX
   dashboard (gw-dash strip, slave tabs, storage cards).
   ============================================================ */

/* Status strip ("ONLINE · Slaves · Last packet") */
html[data-theme="dark"] .gw-dash__strip {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border-color: rgba(255,255,255,0.08);
  color: #e6edf7;
}
html[data-theme="dark"] .gw-dash__chip {
  background: rgba(255,255,255,0.06);
  color: #cfe1ff;
}
html[data-theme="dark"] .gw-dash__meta { color: #cbd5e1; }

/* Slave tabs ("LOCATION-1 | 2 | …") banner */
html[data-theme="dark"] .slave-tabs {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border-bottom-color: rgba(255,255,255,0.12);
}
html[data-theme="dark"] .slave-tab { color: #94a3b8; }
html[data-theme="dark"] .slave-tab:hover {
  color: #ecfeff;
  background: rgba(34,211,238,0.08);
}
html[data-theme="dark"] .slave-tab--active {
  color: #67e8f9;
  border-bottom-color: #0ea5e9;
}
html[data-theme="dark"] .slave-panel__footer {
  border-top-color: rgba(255,255,255,0.10);
  color: #94a3b8;
}

/* Storage cards (the metric tiles) */
html[data-theme="dark"] .storage-card {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border-color: rgba(255,255,255,0.08);
  box-shadow: 0 1px 1px rgba(0,0,0,0.35), 0 10px 26px -14px rgba(0,0,0,0.55);
}
html[data-theme="dark"] .storage-card:hover {
  box-shadow: 0 1px 1px rgba(0,0,0,0.35), 0 14px 30px -14px rgba(0,0,0,0.65);
  border-color: rgba(34,211,238,0.25);
}

/* Card BODY (was #fff) -> dark; the value text -> light */
html[data-theme="dark"] .storage-card__body {
  background: transparent;
}
html[data-theme="dark"] .storage-card__body .tile__value,
html[data-theme="dark"] .storage-card__body .tile__number {
  color: #e6edf7;
}
html[data-theme="dark"] .storage-card__body .tile__unit { color: #94a3b8; }
html[data-theme="dark"] .storage-card__body .tile__value--stale { color: #64748b; }
html[data-theme="dark"] .storage-card__body .tile__ts { color: #64748b; }

/* Card headers keep their vivid metric colors, but the GENERIC one used a
   muted saga-teal -- brighten its text a touch for dark */
html[data-theme="dark"] .storage-card__head { color: #ffffff; }

/* Empty-state panel */
html[data-theme="dark"] .empty-state {
  background: linear-gradient(180deg, #0f1830 0%, #111c38 100%);
  border-color: rgba(255,255,255,0.08);
  color: #cbd5e1;
}

/* Layout-picker select in the toolbar */
html[data-theme="dark"] .tile-grid + * select,
html[data-theme="dark"] .gw-dash select {
  background: rgba(255,255,255,0.05);
  color: #e6edf7;
  border-color: rgba(255,255,255,0.10);
}


/* CW_FIT_TO_PAGE_BLOCK -- scale a custom widget to fit the viewport (keeps aspect) */
html.cw-fit .custom-widget {
  min-height: 0 !important;
  max-width: min(100%, calc((100vh - 175px) * var(--cw-ar, 1.6)));
  margin-left: auto;
  margin-right: auto;
}
.cw-fit-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; border: 1px solid #cbd5e1; background: #fff; color: #475569;
  border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.cw-fit-toggle:hover { background: #f1f5f9; }
.cw-fit-toggle.is-on { background: #0d9488; color: #fff; border-color: #0d9488; }
html[data-theme="dark"] .cw-fit-toggle { background: rgba(255,255,255,.05); color: #cbd5e1; border-color: rgba(255,255,255,.12); }
html[data-theme="dark"] .cw-fit-toggle.is-on { background: #0d9488; color: #fff; }
