/* =========================================================================
   ENVSonic Operator Console — Design System v1
   -------------------------------------------------------------------------
   Source of truth for tokens (colour, type, spacing, motion). Loaded AFTER
   the legacy dashboard.css during the migration so new utility classes win
   without disturbing pages that haven't been ported yet. Once every page is
   migrated, dashboard.css can be deleted.
   ========================================================================= */

/* ---------- Fonts (Geist + Geist Mono via Google Fonts) ----------------- */
@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;450;500;550;600;700&family=Geist+Mono:wght@400;450;500&display=swap');

/* ---------- Tokens ------------------------------------------------------ */
:root {
  /* ENVSonic logo palette — used as the brand accent and for per-metric
     splashes (power=orange, voltage=blue, current=green, temp=coral). */
  --brand-green:   125 189 66;   /* logo E */
  --brand-blue:     33 150 243;  /* logo N */
  --brand-orange:  241 136  0;   /* logo V */
  --metric-power:   var(--brand-orange);
  --metric-voltage: var(--brand-blue);
  --metric-current: var(--brand-green);
  --metric-temp:    236 110 53;  /* warm coral, distinct from brand orange */

  /* Brand accent — swapped by JS on brand change */
  --accent:       33 150 243;    /* ENVSonic logo blue */
  --accent-soft:  33 150 243;
  --accent-ink:    8  30  60;

  /* Dark neutrals (default) — near-black with a slight cool cast */
  --bg:        9 10 13;
  --bg-elev:  16 18 22;
  --panel:    20 22 27;
  --panel-2:  26 29 35;
  --border:   34 38 46;
  --border-2: 46 51 61;
  --text:     230 232 236;
  --text-2:   160 166 178;
  --text-3:   115 122 134;

  /* Status — restrained, not screaming */
  --ok:    52 199 132;
  --warn:  234 179 8;
  --err:   239 68 68;
  --sleep: 156 163 175;

  /* Layout chrome dimensions */
  --topbar-h:        56px;
  --sidebar-w:       232px;
  --sidebar-w-coll:  64px;
  --mobile-tab-h:    56px;
  --container-max:   1480px;
  --page-pad-mobile: 16px;
  --page-pad:        24px;

  color-scheme: dark;
}
:root.light {
  --bg:        250 250 249;
  --bg-elev:   255 255 255;
  --panel:     255 255 255;
  --panel-2:   246 247 249;
  --border:    228 230 234;
  --border-2:  212 215 221;
  --text:      18 22 30;
  --text-2:    82 90 104;
  --text-3:    132 140 152;
  --ok:    22 163 99;
  --warn:  202 138 4;
  --err:   220 38 38;
  --sleep: 120 128 140;
  color-scheme: light;
}

/* Brand accent presets (JS reads these via getComputedStyle when needed) */
:root[data-brand="envsonic"]    { --accent: 33 150 243;   --accent-ink:  8 30 60; }
:root[data-brand="hullsonic"]   { --accent: 168 181 198;  --accent-ink: 20 25 35; }

/* ---------- Base -------------------------------------------------------- */
html, body {
  background: rgb(var(--bg));
  color: rgb(var(--text));
  margin: 0;
  padding: 0;
}
body {
  font-family: 'Geist', ui-sans-serif, system-ui, 'Inter', sans-serif;
  font-feature-settings: "ss01", "cv11";
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
*, *::before, *::after { box-sizing: border-box; }

a { color: inherit; text-decoration: none; }
a.link, .link {
  color: rgb(var(--accent));
  transition: opacity .12s ease;
}
a.link:hover { opacity: .82; }

::selection { background: rgb(var(--accent) / 0.35); color: rgb(var(--text)); }

/* ---------- Typography helpers ----------------------------------------- */
.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -0.01em;
}
.mono {
  font-family: 'Geist Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-feature-settings: "tnum";
}
.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgb(var(--text-3));
  font-weight: 500;
}
.muted   { color: rgb(var(--text-2)); }
.muted-2 { color: rgb(var(--text-3)); }
.text-accent { color: rgb(var(--accent)); }

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 26px; line-height: 1.15; }
h2 { font-size: 22px; line-height: 1.2; }
h3 { font-size: 18px; line-height: 1.25; }
h4 { font-size: 15px; line-height: 1.3; font-weight: 550; }

.page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.panel-title { font-size: 14.5px; font-weight: 550; letter-spacing: -0.005em; }

/* ---------- Surfaces --------------------------------------------------- */
.surf {
  background: rgb(var(--panel));
  border: 1px solid rgb(var(--border));
  border-radius: 8px;
}
.surf-2 {
  background: rgb(var(--panel-2));
  border: 1px solid rgb(var(--border));
  border-radius: 8px;
}
.surf-elev {
  background: rgb(var(--bg-elev));
  border: 1px solid rgb(var(--border));
  border-radius: 8px;
}
.rounded-md { border-radius: 6px; }
.rounded-lg { border-radius: 8px; }
.rounded-xl { border-radius: 12px; }
.rounded-full { border-radius: 999px; }

.hairline   { border-color: rgb(var(--border)); }
.hairline-2 { border-color: rgb(var(--border-2)); }
.border-accent { border-color: rgb(var(--accent)); }

/* ---------- Buttons ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px; border-radius: 6px;
  font: 500 13px/1 'Geist', system-ui, sans-serif;
  border: 1px solid rgb(var(--border-2));
  background: rgb(var(--panel));
  color: rgb(var(--text));
  cursor: pointer; white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, transform .15s ease, color .15s ease;
}
.btn:hover    { background: rgb(var(--panel-2)); }
.btn:active   { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost  { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgb(var(--panel-2)); }

.btn-primary {
  background: rgb(var(--accent));
  color: rgb(var(--accent-ink));
  border-color: rgb(var(--accent) / 0.4);
  font-weight: 550;
}
.btn-primary:hover { filter: brightness(1.06); }

.btn-danger {
  background: rgb(var(--err));
  color: white;
  border-color: rgb(var(--err) / 0.4);
}
.btn-danger:hover { filter: brightness(1.06); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; gap: 6px; }
.btn-lg { height: 40px; padding: 0 16px; font-size: 14px; }
.btn-icon { width: 32px; padding: 0; justify-content: center; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Inputs ----------------------------------------------------- */
.input, input[type="text"].input, input[type="email"].input, input[type="password"].input, input[type="search"].input, input[type="number"].input, select.input, textarea.input {
  height: 34px; padding: 0 12px; border-radius: 6px;
  background: rgb(var(--bg-elev));
  border: 1px solid rgb(var(--border));
  color: rgb(var(--text));
  font: 400 13.5px/1 'Geist', system-ui, sans-serif;
  width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea.input { height: auto; padding: 10px 12px; line-height: 1.45; }
.input:focus, .input:focus-visible {
  outline: none;
  border-color: rgb(var(--accent) / 0.55);
  box-shadow: 0 0 0 3px rgb(var(--accent) / 0.18);
}
.input::placeholder { color: rgb(var(--text-3)); }

.label {
  display: block; font-size: 12px; font-weight: 500;
  color: rgb(var(--text-2)); margin-bottom: 6px;
}

/* ---------- Pills ------------------------------------------------------ */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; line-height: 1;
  border: 1px solid rgb(var(--border-2));
  background: rgb(var(--panel-2));
  color: rgb(var(--text-2));
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 999px; }
.pill-lg { height: 26px; padding: 0 10px; font-size: 12.5px; }

/* Status colours */
.c-ok    { color: rgb(var(--ok));    } .bg-ok    { background-color: rgb(var(--ok));    }
.c-warn  { color: rgb(var(--warn));  } .bg-warn  { background-color: rgb(var(--warn));  }
.c-err   { color: rgb(var(--err));   } .bg-err   { background-color: rgb(var(--err));   }
.c-sleep { color: rgb(var(--sleep)); } .bg-sleep { background-color: rgb(var(--sleep)); }

/* ---------- Badge / chip ----------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  background: rgb(var(--panel-2)); border: 1px solid rgb(var(--border));
}

/* ---------- Tables ----------------------------------------------------- */
table.dev {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13.5px;
}
table.dev th {
  text-align: left; font-weight: 500;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: rgb(var(--text-3));
  padding: 10px 12px;
  background: rgb(var(--panel-2));
  border-bottom: 1px solid rgb(var(--border));
  position: sticky; top: 0; z-index: 1;
}
table.dev td {
  padding: 12px;
  border-bottom: 1px solid rgb(var(--border));
  vertical-align: middle;
}
table.dev tr:last-child td { border-bottom: 0; }
table.dev tbody tr { transition: background-color .12s ease; }
table.dev tbody tr:hover { background: rgb(var(--panel-2)); }
table.dev tr.sel { background: rgb(var(--accent) / 0.06); }
table.dev tr.sel:hover { background: rgb(var(--accent) / 0.09); }

/* ---------- Skeleton shimmer ------------------------------------------ */
@keyframes shimmer { 0% { background-position: -200% 0 } 100% { background-position: 200% 0 } }
.sk {
  background: linear-gradient(90deg,
    rgb(var(--panel-2)) 0%,
    rgb(var(--border)) 50%,
    rgb(var(--panel-2)) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
  border-radius: 4px;
}

/* ---------- Form controls --------------------------------------------- */
.cb { /* checkbox */
  appearance: none; width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid rgb(var(--border-2));
  background: rgb(var(--bg-elev));
  display: inline-grid; place-items: center; cursor: pointer;
  transition: background-color .12s, border-color .12s;
  flex-shrink: 0;
}
.cb:checked { background: rgb(var(--accent)); border-color: rgb(var(--accent)); }
.cb:checked::after {
  content: ""; width: 8px; height: 8px;
  background: rgb(var(--accent-ink));
  clip-path: polygon(14% 47%, 0 60%, 39% 100%, 100% 22%, 86% 12%, 39% 73%);
}

.toggle { /* on/off switch */
  width: 28px; height: 16px; border-radius: 999px;
  background: rgb(var(--border-2));
  position: relative; cursor: pointer;
  transition: background-color .15s;
  border: none; padding: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 999px;
  background: rgb(var(--text));
  transition: transform .15s;
}
.toggle.on { background: rgb(var(--accent)); }
.toggle.on::after { transform: translateX(12px); background: rgb(var(--accent-ink)); }

/* ---------- Tabs ------------------------------------------------------- */
.tabs {
  display: flex; gap: 18px; align-items: center;
  border-bottom: 1px solid rgb(var(--border));
}
.tab {
  position: relative; padding: 10px 2px; font-size: 13.5px;
  color: rgb(var(--text-2)); cursor: pointer;
  transition: color .12s;
  background: none; border: 0;
  font-family: inherit;
}
.tab:hover { color: rgb(var(--text)); }
.tab.active { color: rgb(var(--text)); }
.tab.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 1.5px; background: rgb(var(--accent));
}

/* Segmented control (period switcher) */
.seg {
  display: inline-flex; padding: 2px; border-radius: 6px;
  background: rgb(var(--panel-2)); border: 1px solid rgb(var(--border));
  gap: 2px;
}
.seg button {
  font: 500 12px/1 'Geist', system-ui, sans-serif;
  height: 26px; padding: 0 10px; border-radius: 5px;
  background: transparent; color: rgb(var(--text-2));
  border: 0; cursor: pointer;
  transition: background-color .12s, color .12s;
}
.seg button:hover { color: rgb(var(--text)); }
.seg button.active {
  background: rgb(var(--panel));
  color: rgb(var(--text));
}

/* ---------- Sidebar (desktop) ----------------------------------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
  background: rgb(var(--bg));
}
.sidebar-ds {
  display: none;  /* hidden on mobile; bottom tab bar takes its place */
}
@media (min-width: 640px) {
  .sidebar-ds {
    display: flex;
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-right: 1px solid rgb(var(--border));
    background: rgb(var(--bg));
    flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    transition: width .2s cubic-bezier(.2,.6,.3,1);
    z-index: 30;
  }
}
.sidebar-ds.collapsed { width: var(--sidebar-w-coll); }
.sidebar-ds .brand-row {
  height: var(--topbar-h);
  padding: 0 12px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgb(var(--border));
}
.sidebar-ds .brand-row .brand-name {
  font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden;
}
.sidebar-ds.collapsed .brand-row .brand-name { display: none; }

.sidebar-ds nav { padding: 8px; flex: 1; overflow-y: auto; }
.sidebar-ds .nav-section-label {
  padding: 14px 12px 6px; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: rgb(var(--text-3)); font-weight: 500;
}
.sidebar-ds.collapsed .nav-section-label { display: none; }
.navitem {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 6px;
  color: rgb(var(--text-2));
  font-size: 13.5px; font-weight: 450;
  transition: background-color .12s, color .12s;
  cursor: pointer; text-decoration: none;
  margin: 1px 0;
}
.navitem:hover  { background: rgb(var(--panel-2)); color: rgb(var(--text)); }
.navitem.active { background: rgb(var(--panel-2)); color: rgb(var(--text)); }
.navitem.active .ic { color: rgb(var(--accent)); }
.navitem .ic { width: 16px; height: 16px; flex-shrink: 0; color: rgb(var(--text-2)); }
.navitem.active .ic { color: rgb(var(--accent)); }
.sidebar-ds.collapsed .navitem { justify-content: center; padding: 8px 0; }
.sidebar-ds.collapsed .navitem .nav-text { display: none; }
.sidebar-ds .nav-footer {
  padding: 10px; border-top: 1px solid rgb(var(--border));
}

/* ---------- Top bar (desktop + mobile) -------------------------------- */
.topbar {
  height: var(--topbar-h);
  padding: 0 var(--page-pad-mobile);
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgb(var(--border));
  background: rgb(var(--bg));
  position: sticky; top: 0; z-index: 20;
}
@media (min-width: 1024px) {
  .topbar { padding: 0 var(--page-pad); }
}
.topbar .breadcrumb {
  display: none; align-items: center; gap: 6px;
  font-size: 12.5px; color: rgb(var(--text-2));
}
@media (min-width: 768px) { .topbar .breadcrumb { display: flex; } }
.topbar .breadcrumb .sep { color: rgb(var(--text-3)); }
.topbar .search {
  flex: 1; max-width: 520px;
  display: none; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px;
  background: rgb(var(--bg-elev)); border: 1px solid rgb(var(--border));
  border-radius: 6px; color: rgb(var(--text-2));
  margin: 0 auto;
  cursor: text;
  transition: border-color .12s;
}
@media (min-width: 640px) { .topbar .search { display: flex; } }
.topbar .search:focus-within { border-color: rgb(var(--accent) / 0.55); }
.topbar .search input {
  flex: 1; border: 0; background: transparent; outline: none;
  color: rgb(var(--text)); font: 400 13px 'Geist', system-ui, sans-serif;
}
.topbar .search input::placeholder { color: rgb(var(--text-3)); }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.kbd {
  display: inline-flex; align-items: center;
  padding: 1px 5px; border-radius: 4px;
  font: 500 10.5px 'Geist Mono', monospace;
  background: rgb(var(--panel-2)); border: 1px solid rgb(var(--border-2));
  color: rgb(var(--text-3));
}

/* ---------- Brand switcher dropdown ----------------------------------- */
.dropdown {
  position: relative;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: rgb(var(--panel));
  border: 1px solid rgb(var(--border));
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 16px 40px -12px rgb(0 0 0 / 0.45);
  z-index: 100;
  /* Use flex-column explicitly so items always stack vertically, no matter
     what the parent's display rules are. display:block was being inferred
     elsewhere as inline-style under some legacy cascade and the items
     ended up laying out horizontally on open. */
  display: flex !important;
  flex-direction: column !important;
  gap: 1px;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity .14s ease, transform .14s ease, visibility 0s linear .14s;
}
:root.light .dropdown-menu { box-shadow: 0 16px 40px -12px rgb(0 0 0 / 0.12); }
.dropdown.open .dropdown-menu {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  transform: translateY(0) !important;
  transition: opacity .14s ease, transform .14s ease, visibility 0s;
}
/* Belt-and-braces: force each dropdown item to be a full-width row.
   Some legacy CSS targeting .dropdown-item with a different specificity
   could otherwise leave them at auto width and they'd flow inline. */
.dropdown-menu > .dropdown-item,
.dropdown-menu > a.dropdown-item,
.dropdown-menu > button.dropdown-item {
  display: flex !important;
  width: 100% !important;
  flex: 0 0 auto;
}
.dropdown-menu.right { left: auto; right: 0; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px;
  color: rgb(var(--text)); font-size: 13px;
  cursor: pointer; transition: background-color .12s;
  text-decoration: none;
  background: none; border: 0; width: 100%; text-align: left;
  font-family: inherit;
}
.dropdown-item:hover { background: rgb(var(--panel-2)); }
.dropdown-item .ic { width: 15px; height: 15px; color: rgb(var(--text-2)); }
.dropdown-divider { height: 1px; background: rgb(var(--border)); margin: 4px -6px; }
.dropdown-header {
  padding: 8px 10px 6px; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: rgb(var(--text-3));
}

/* ---------- Main content area ----------------------------------------- */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex; flex-direction: column;
  background: rgb(var(--bg));
}
.page {
  flex: 1;
  padding: var(--page-pad-mobile);
  max-width: var(--container-max);
  width: 100%;
  margin: 0 auto;
  animation: pageIn .22s cubic-bezier(.2,.6,.3,1) both;
}
@media (min-width: 1024px) {
  .page { padding: var(--page-pad); }
}
/* Opacity-only fade-in. The previous version animated `transform`
   which some browsers keep as a stacking context after the animation
   completes — that traps position:fixed descendants (modals) inside
   the page element instead of the viewport. */
@keyframes pageIn { from { opacity: 0 } to { opacity: 1 } }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header .h-left { min-width: 0; }
.page-header .h-right { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.page-header .subtitle {
  margin-top: 4px; font-size: 13px; color: rgb(var(--text-2));
}

/* ---------- Card / panel ---------------------------------------------- */
.card {
  background: rgb(var(--panel));
  border: 1px solid rgb(var(--border));
  border-radius: 12px;
  padding: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card-header .panel-title { margin: 0; }

/* Hover-lift card */
.lift {
  transition: transform .18s cubic-bezier(.2,.6,.3,1),
              border-color .18s ease, background-color .18s ease;
}
.lift:hover { transform: translateY(-1px); border-color: rgb(var(--border-2)); }

/* ---------- Grid system (minimal, for porting from Tailwind quickly) -- */
.grid { display: grid; gap: 12px; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (min-width: 640px) {
  .sm-grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .lg-grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lg-grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lg-grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lg-grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .lg-col-span-2 { grid-column: span 2 / span 2; }
  .lg-col-span-3 { grid-column: span 3 / span 3; }
}
.gap-1  { gap: 4px;  }
.gap-2  { gap: 8px;  }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.gap-5  { gap: 20px; }
.gap-6  { gap: 24px; }

/* ---------- Flex helpers --------------------------------------------- */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.items-end    { align-items: flex-end; }
.items-baseline { align-items: baseline; }
.justify-center  { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.flex-1 { flex: 1 1 0%; min-width: 0; }
.flex-none { flex: none; }
.shrink-0 { flex-shrink: 0; }

/* ---------- Spacing utility (4 / 8 / 12 / 16 / 20 / 24 / 32 only) ----- */
.m-0  { margin: 0; }
.mt-0 { margin-top: 0; }   .mt-1 { margin-top: 4px; }   .mt-2 { margin-top: 8px; }   .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 20px; } .mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 20px; } .mb-6 { margin-bottom: 24px; }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

.p-0  { padding: 0; }
.p-2  { padding: 8px; }
.p-3  { padding: 12px; }
.p-4  { padding: 16px; }
.p-5  { padding: 20px; }
.p-6  { padding: 24px; }
.px-2 { padding-left: 8px; padding-right: 8px; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.py-1 { padding-top: 4px; padding-bottom: 4px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.py-3 { padding-top: 12px; padding-bottom: 12px; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }

/* ---------- Sizing helpers ------------------------------------------- */
.w-full { width: 100%; }
.h-full { height: 100%; }
.h-px   { height: 1px; }
.w-px   { width: 1px; }
.min-h-screen { min-height: 100vh; }
.max-w-md   { max-width: 380px; }
.max-w-xl   { max-width: 36rem; }

.hide-on-mobile  { display: none; }
.hide-on-desktop { display: block; }
@media (min-width: 768px) {
  .hide-on-mobile  { display: initial; }
  .hide-on-desktop { display: none; }
}

/* ---------- Mobile bottom tab bar ------------------------------------ */
.mobile-tabs {
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-top: 1px solid rgb(var(--border));
  background: rgb(var(--bg));
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
}
.mobile-tabs a {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  color: rgb(var(--text-2)); font-size: 10.5px; font-weight: 500;
  text-decoration: none;
}
.mobile-tabs a.active { color: rgb(var(--accent)); }
.mobile-tabs a .ic { width: 18px; height: 18px; }
@media (min-width: 640px) { .mobile-tabs { display: none; } }
/* Reserve room at the bottom of the scrollable page so the last items
   aren't hidden behind the fixed tab bar. Only applies on mobile. */
@media (max-width: 639px) {
  .app-main, body { padding-bottom: calc(var(--mobile-tab-h) + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Toasts --------------------------------------------------- */
.toast-stack {
  position: fixed; bottom: 16px; right: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  max-width: calc(100vw - 32px);
}
.toast {
  min-width: 260px; max-width: 360px;
  background: rgb(var(--panel)); border: 1px solid rgb(var(--border));
  border-radius: 8px; padding: 12px 14px;
  font-size: 13px;
  display: flex; align-items: flex-start; gap: 10px;
  box-shadow: 0 14px 40px -10px rgb(0 0 0 / 0.5);
  animation: toastIn .22s cubic-bezier(.2,.7,.2,1) both;
}
:root.light .toast { box-shadow: 0 14px 40px -10px rgb(0 0 0 / 0.14); }
.toast.ok   { border-left: 2px solid rgb(var(--ok)); }
.toast.warn { border-left: 2px solid rgb(var(--warn)); }
.toast.err  { border-left: 2px solid rgb(var(--err)); }
.toast .title { font-weight: 550; }
.toast .body  { color: rgb(var(--text-2)); margin-top: 2px; }
.toast .close { margin-left: auto; cursor: pointer; color: rgb(var(--text-3)); background: none; border: 0; padding: 0; line-height: 1; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- Sparkline / mini chart ----------------------------------- */
.spark { display: block; }
.spark path.line { stroke: rgb(var(--accent)); stroke-width: 1.5; fill: none; }
.spark path.area { fill: rgb(var(--accent) / 0.08); stroke: none; }

/* ---------- Scrollbar ------------------------------------------------ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgb(var(--border-2));
  border-radius: 999px;
  border: 2px solid rgb(var(--bg));
}
::-webkit-scrollbar-thumb:hover { background: rgb(var(--text-3)); }

input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ---------- Login-specific background ------------------------------- */
.login-bg { position: relative; min-height: 100vh; }
.login-bg::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(900px 500px at 80% -10%, rgb(var(--accent) / 0.10), transparent 60%),
    radial-gradient(600px 400px at 0% 100%, rgb(var(--accent) / 0.05), transparent 60%);
}
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 380px;
  margin: 0 auto; padding: 32px 24px;
}

/* ---------- Map placeholder ------------------------------------------ */
.map-grid {
  background-image:
    linear-gradient(rgb(var(--border) / 0.6) 1px, transparent 1px),
    linear-gradient(90deg, rgb(var(--border) / 0.6) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* ---------- Reduced motion ------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =========================================================================
   LEGACY COMPAT LAYER
   -------------------------------------------------------------------------
   Pages that haven't been migrated yet still use the old class names from
   dashboard.css. These rules give those class names a dark-aware,
   token-driven appearance so the visual language is consistent across
   migrated and unmigrated pages. Each rule sets `--primary-bg` / etc. to
   the new token, so legacy CSS that consumes `var(--primary-bg)` lands on
   the correct colour automatically.
   ========================================================================= */

/* Remap legacy tokens to new ones — single source of truth for everything
   that consumes the old var names. */
:root,
:root.light {
  --primary-bg:    rgb(var(--bg));
  --secondary-bg:  rgb(var(--panel));
  --tertiary-bg:   rgb(var(--panel-2));
  --card-bg:       rgb(var(--panel));
  --sidebar-bg:    rgb(var(--bg));
  --header-bg:     rgb(var(--bg));

  --primary-text:   rgb(var(--text));
  --secondary-text: rgb(var(--text-2));
  --accent-text:    rgb(var(--text));
  --muted-text:     rgb(var(--text-3));

  --primary-color: rgb(var(--accent));
  --success-color: rgb(var(--ok));
  --warning-color: rgb(var(--warn));
  --danger-color:  rgb(var(--err));
  --info-color:    rgb(var(--accent));

  --border-color:  rgb(var(--border));
  --hover-bg:      rgb(var(--panel-2));
  --active-bg:     rgb(var(--accent) / 0.10);
  --accent-color:  rgb(var(--accent));
  --accent-hover:  rgb(var(--accent));

  --chart-grid:    rgb(var(--border));
  --chart-text:    rgb(var(--text-2));

  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.25);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.30);
  --shadow-lg: 0 14px 40px -10px rgb(0 0 0 / 0.50);
  --shadow-xl: 0 24px 60px -12px rgb(0 0 0 / 0.55);
}
:root.light {
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.08);
  --shadow-lg: 0 14px 40px -10px rgb(0 0 0 / 0.14);
  --shadow-xl: 0 24px 60px -12px rgb(0 0 0 / 0.16);
}

/* Legacy page-wrappers — bring them onto the new background */
.dashboard-content,
.devices-page,
.alerts-page,
.users-page,
.sites-page,
.settings-page,
.logs-page,
.profile-page {
  color: rgb(var(--text));
}

/* Legacy stat / metric cards → new surface treatment */
.stat-card,
.metric-card,
.summary-card,
.dashboard-card,
.section,
.panel,
.config-card,
.alert-card,
.user-card,
.site-card,
.device-card,
.brand-card,
.fleet-card,
.subscription-card {
  background: rgb(var(--panel)) !important;
  border: 1px solid rgb(var(--border)) !important;
  border-radius: 12px !important;
  box-shadow: none !important;
  color: rgb(var(--text));
}
.stat-card .stat-number,
.metric-card .metric-value,
.dashboard-card h3,
.section-title {
  color: rgb(var(--text)) !important;
}
.stat-label, .metric-label {
  color: rgb(var(--text-3)) !important;
  font-size: 11px !important;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Legacy buttons — kept functional but retoned to the new palette */
.btn-primary, .btn.btn-primary, button.btn-primary {
  background: rgb(var(--accent)) !important;
  color: rgb(var(--accent-ink)) !important;
  border: 1px solid rgb(var(--accent) / 0.4) !important;
  box-shadow: none !important;
}
.btn-primary:hover, .btn.btn-primary:hover, button.btn-primary:hover {
  filter: brightness(1.06);
  background: rgb(var(--accent)) !important;
}
.btn-secondary, .btn.btn-secondary {
  background: rgb(var(--panel-2)) !important;
  color: rgb(var(--text)) !important;
  border: 1px solid rgb(var(--border-2)) !important;
}
.btn-danger {
  background: rgb(var(--err)) !important;
  color: white !important;
  border-color: rgb(var(--err) / 0.4) !important;
}

/* Legacy inputs */
.form-control, input.form-input, textarea.form-input, select.form-input,
.form-group input, .form-group textarea, .form-group select {
  background: rgb(var(--bg-elev)) !important;
  border: 1px solid rgb(var(--border)) !important;
  color: rgb(var(--text)) !important;
  border-radius: 6px !important;
}
.form-control:focus, .form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none !important;
  border-color: rgb(var(--accent) / 0.55) !important;
  box-shadow: 0 0 0 3px rgb(var(--accent) / 0.18) !important;
}

/* Legacy alerts */
.alert {
  background: rgb(var(--panel)) !important;
  border: 1px solid rgb(var(--border)) !important;
  color: rgb(var(--text)) !important;
  border-radius: 8px !important;
}

/* Notification toasts (showNotification helper). Override the legacy
   dashboard.css notification rules so the toast caps its width even
   when the message is long, and uses fixed accent colours that don't
   depend on legacy `--danger-color` / `--success-color` resolving. */
.notification {
  max-width: 360px !important;
  background: rgb(var(--panel)) !important;
  color: rgb(var(--text)) !important;
  border-radius: 10px !important;
  padding: 12px 14px !important;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.35), 0 0 0 1px rgb(var(--border)) !important;
  font-weight: 500;
  white-space: normal;
}
.notification-success { border-left: 3px solid rgb(var(--ok))  !important; }
.notification-error   { border-left: 3px solid rgb(var(--err)) !important; }
.notification-warning { border-left: 3px solid rgb(var(--warn))!important; }
.notification-info    { border-left: 3px solid rgb(var(--accent))!important; }
.alert.alert-error,    .alert-error    { border-left: 2px solid rgb(var(--err)) !important; }
.alert.alert-warning,  .alert-warning  { border-left: 2px solid rgb(var(--warn)) !important; }
.alert.alert-success,  .alert-success  { border-left: 2px solid rgb(var(--ok)) !important; }
.alert.alert-info,     .alert-info     { border-left: 2px solid rgb(var(--accent)) !important; }

/* Legacy tables */
table:not(.dev),
.legacy-table,
.devices-table,
.users-table,
.alerts-table,
.logs-table {
  background: rgb(var(--panel));
  color: rgb(var(--text));
  border-collapse: collapse;
}
table:not(.dev) th,
.legacy-table th,
.devices-table th,
.users-table th,
.alerts-table th,
.logs-table th {
  background: rgb(var(--panel-2)) !important;
  color: rgb(var(--text-3)) !important;
  border-bottom: 1px solid rgb(var(--border)) !important;
  font-weight: 500 !important;
  font-size: 11.5px !important;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
table:not(.dev) td,
.legacy-table td,
.devices-table td,
.users-table td,
.alerts-table td,
.logs-table td {
  background: rgb(var(--panel));
  color: rgb(var(--text));
  border-bottom: 1px solid rgb(var(--border)) !important;
}
table:not(.dev) tr:hover td,
.devices-table tr:hover td,
.users-table tr:hover td,
.alerts-table tr:hover td,
.logs-table tr:hover td {
  background: rgb(var(--panel-2)) !important;
}

/* Legacy badges / pills */
.badge, .label-pill, .status-badge {
  background: rgb(var(--panel-2));
  border: 1px solid rgb(var(--border-2));
  color: rgb(var(--text-2));
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge-success { color: rgb(var(--ok)) !important;   border-color: rgb(var(--ok) / 0.4) !important; }
.badge-warning { color: rgb(var(--warn)) !important; border-color: rgb(var(--warn) / 0.4) !important; }
.badge-danger,
.badge-error   { color: rgb(var(--err)) !important;  border-color: rgb(var(--err) / 0.4) !important; }
.badge-info    { color: rgb(var(--accent)) !important; border-color: rgb(var(--accent) / 0.4) !important; }

/* Empty / loading states */
.empty-state, .loading-state {
  background: rgb(var(--panel-2));
  border: 1px solid rgb(var(--border));
  border-radius: 12px;
  color: rgb(var(--text-2));
}

/* Modals */
.modal-backdrop, .modal-overlay {
  background: rgb(0 0 0 / 0.55) !important;
}
.modal-content, .modal-dialog {
  background: rgb(var(--panel)) !important;
  color: rgb(var(--text)) !important;
  border: 1px solid rgb(var(--border)) !important;
  border-radius: 12px !important;
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.6) !important;
}
/* Self-contained modal sizing + centring override. The legacy
   dashboard.css uses `margin: 10% auto` (block-layout centring) which
   misfires when JS opens the modal with `display:flex`, so the dialog
   lands wherever the page was scrolled. We:
     • Pin the .modal backdrop to a transparent dark full-viewport flex
       centring layer (overriding the legacy background-only rule).
     • Re-declare .modal-content with explicit width clamps + visible
       background + flex column so the header / body / footer don't
       collapse, regardless of which design tokens the page binds. */
.modal {
  position: fixed !important;
  inset: 0 !important;
  width: 100% !important; height: 100% !important;
  background: rgb(0 0 0 / 0.55) !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 20px !important;
  z-index: 1000;
  box-sizing: border-box;
}
.modal .modal-content,
.modal .modal-dialog {
  margin: 0 !important;
  width: 100% !important;
  max-width: 540px !important;
  max-height: calc(100vh - 40px);
  display: flex !important;
  flex-direction: column !important;
  background: rgb(var(--panel)) !important;
  color: rgb(var(--text)) !important;
  border: 1px solid rgb(var(--border)) !important;
  border-radius: 12px !important;
  overflow: hidden;
}
.modal .modal-content.modal-sm  { max-width: 420px !important; }
.modal .modal-content.modal-lg,
.modal .modal-content.modal-large { max-width: 760px !important; }
.modal .modal-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
:root.light .modal, :root.light .modal-content, :root.light .modal-dialog {
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.16) !important;
}

/* Misc text colour catch-alls */
.text-muted, .text-secondary { color: rgb(var(--text-2)) !important; }
.text-light, .text-3 { color: rgb(var(--text-3)) !important; }
.text-primary, .text-link { color: rgb(var(--accent)) !important; }

/* Links that don't carry .link class but appear in legacy content */
a.dropdown-item:hover, a.nav-link:hover { color: rgb(var(--text)); }

/* The legacy CSS sets html { font-size: 16px } which slightly bloats the
   page. Bring it back to the design system's 13.5px baseline for pages
   that lean on the legacy chrome — pages that use .page-anim opt out of
   this so their explicit sizes still apply. */
body { font-size: 13.5px; }

/* Hide the legacy chrome containers entirely — the new index.php replaces
   them but a stray include or AJAX response might re-emit. */
.dashboard-container > .sidebar:not(.sidebar-ds),
.dashboard-container > .main-content > .header:not(.topbar) {
  display: none !important;
}

/* ============================================================
   Legacy page-header retoning — most pages use this pattern:
       <div class="page-header">
           <h2><i class="fas fa-X"></i> Title</h2>
           <p>Subtitle</p>
       </div>
   Restyle it to match the new design system without rewriting markup.
   ============================================================ */
.page-header {
  display: flex !important;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px !important;
  flex-wrap: wrap;
  background: transparent !important;
  padding: 0 !important;
  border: 0 !important;
  box-shadow: none !important;
}
.page-header > div:first-child:not(.h-right):not(.page-actions):not(.h-left),
.page-header > .page-header-content {
  flex: 1; min-width: 0;
}
.page-header h2,
.page-header h1.page-title {
  font-size: 22px !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em !important;
  color: rgb(var(--text)) !important;
  margin: 0 !important;
  line-height: 1.15 !important;
  display: flex !important;
  align-items: center;
  gap: 8px;
  text-transform: none !important;
}
.page-header h2 > i.fas,
.page-header h2 > i.far,
.page-header h2 > i.fab,
.page-header h1 > i.fas,
.page-header h1 > i.far {
  color: rgb(var(--accent));
  font-size: 16px !important;
}
.page-header > p,
.page-header .page-description {
  margin: 4px 0 0 !important;
  font-size: 13px !important;
  color: rgb(var(--text-2)) !important;
  font-weight: 400 !important;
}
.page-header .page-actions,
.page-header > .h-right {
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}

/* Action bar — sits below page-header on a lot of pages with a single CTA */
.action-bar {
  margin-bottom: 16px !important;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Grids that used to be 3-col with chunky cards */
.sites-grid, .users-grid, .device-grid, .alerts-grid,
.metrics-grid, .config-grid {
  display: grid !important;
  gap: 12px !important;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
}

/* Section titles (common across pages) */
.section-header { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-title {
  font-size: 14.5px !important;
  font-weight: 550 !important;
  margin: 0 !important;
  letter-spacing: -0.005em;
  display: flex !important;
  align-items: center;
  gap: 8px;
}
.section-title i.fas, .section-title i.far { color: rgb(var(--accent)); font-size: 14px; }

/* Stats grid (legacy 4-col KPI rows) */
.stats-grid {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 12px !important;
}
@media (min-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr) !important; }
}
.stat-card {
  padding: 16px !important;
  display: flex; align-items: center; gap: 14px;
  border-radius: 12px !important;
}
.stat-card .stat-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgb(var(--panel-2));
  color: rgb(var(--accent));
  display: grid; place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}
.stat-card .stat-icon i { font-size: 16px; }
.stat-card .stat-content { min-width: 0; }
.stat-card .stat-number {
  font-size: 22px !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em !important;
  font-variant-numeric: tabular-nums;
  line-height: 1.1 !important;
  color: rgb(var(--text)) !important;
}
.stat-card .stat-label {
  font-size: 11.5px !important;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgb(var(--text-3)) !important;
  margin-top: 2px;
  font-weight: 500 !important;
}

/* Empty-state defaults (already added higher up, just adjust) */
.empty-state {
  background: rgb(var(--panel)) !important;
  border: 1px solid rgb(var(--border)) !important;
  padding: 48px 24px !important;
  text-align: center !important;
  border-radius: 12px !important;
  color: rgb(var(--text-2)) !important;
}
.empty-state > i.fas,
.empty-state > i.far,
.empty-state .empty-icon i {
  font-size: 32px !important;
  color: rgb(var(--text-3)) !important;
  margin-bottom: 14px;
  display: block;
}
.empty-state h3 {
  font-size: 16px !important;
  font-weight: 550 !important;
  color: rgb(var(--text)) !important;
  margin: 0 0 8px !important;
}
.empty-state p {
  font-size: 13px !important;
  color: rgb(var(--text-2)) !important;
  margin: 0 0 16px !important;
}

/* Forms — labels + inputs */
.form-group {
  margin-bottom: 14px;
}
.form-group label,
.form-label {
  display: block;
  font-size: 12px !important;
  font-weight: 500 !important;
  color: rgb(var(--text-2)) !important;
  margin-bottom: 6px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

/* Tabs (legacy) — bring to the design system look */
.tabs, .tab-list, .tab-buttons {
  display: flex !important;
  gap: 18px !important;
  border-bottom: 1px solid rgb(var(--border)) !important;
  margin-bottom: 16px !important;
  align-items: center;
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  overflow-x: auto;
}
.tab-button, .tab-link, .tabs > a, .tabs > button {
  position: relative !important;
  padding: 10px 2px !important;
  font-size: 13.5px !important;
  color: rgb(var(--text-2)) !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  cursor: pointer;
  font-weight: 450 !important;
  text-decoration: none !important;
  white-space: nowrap;
}
.tab-button:hover, .tab-link:hover, .tabs > a:hover, .tabs > button:hover {
  color: rgb(var(--text)) !important;
  background: transparent !important;
}
.tab-button.active, .tab-link.active, .tabs > a.active, .tabs > button.active {
  color: rgb(var(--text)) !important;
  background: transparent !important;
}
.tab-button.active::after, .tab-link.active::after, .tabs > a.active::after, .tabs > button.active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1.5px;
  background: rgb(var(--accent));
}

/* "Add ..." action button — typical pattern */
.add-action {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  background: rgb(var(--accent)) !important;
  color: rgb(var(--accent-ink)) !important;
  border-radius: 6px;
  font: 550 13px/1 'Geist', system-ui, sans-serif;
  text-decoration: none;
  border: 1px solid rgb(var(--accent) / 0.4);
}

/* Modal sizing */
.modal-content, .modal-dialog {
  max-width: 540px !important;
  width: 92vw;
}
.modal-content.modal-sm { max-width: 420px !important; }
.modal-content.modal-lg, .modal-content.modal-large { max-width: 760px !important; }
.modal-header {
  padding: 16px 20px !important;
  border-bottom: 1px solid rgb(var(--border)) !important;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3, .modal-header h2, .modal-title {
  font-size: 16px !important;
  font-weight: 550 !important;
  margin: 0 !important;
  color: rgb(var(--text)) !important;
}
.modal-body { padding: 20px !important; color: rgb(var(--text)); }
.modal-footer {
  padding: 14px 20px !important;
  border-top: 1px solid rgb(var(--border)) !important;
  display: flex; gap: 8px; justify-content: flex-end;
}
.modal-close {
  background: transparent !important;
  border: 0 !important;
  color: rgb(var(--text-3)) !important;
  font-size: 18px !important;
  cursor: pointer;
  padding: 4px !important;
  line-height: 1;
}
.modal-close:hover { color: rgb(var(--text)) !important; }

/* "Filter row" container patterns */
.filter-controls, .table-controls, .filters-bar {
  background: rgb(var(--panel)) !important;
  border: 1px solid rgb(var(--border)) !important;
  border-radius: 8px !important;
  padding: 12px !important;
  display: flex !important;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px !important;
}
.filter-group {
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  font-size: 12.5px;
}
.filter-group label {
  font-size: 11.5px !important;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgb(var(--text-3)) !important;
  font-weight: 500 !important;
  white-space: nowrap;
}
.filter-group select,
.filter-group input {
  height: 28px !important;
  padding: 0 8px !important;
  font-size: 12.5px !important;
  background: rgb(var(--bg-elev)) !important;
  border: 1px solid rgb(var(--border)) !important;
  color: rgb(var(--text)) !important;
  border-radius: 5px !important;
  width: auto !important;
  min-width: 0;
}
.sort-controls, .pagination-controls {
  display: inline-flex; gap: 8px; align-items: center;
  margin-left: auto;
}

/* Bulk-action toolbar (devices page) */
.bulk-actions-toolbar {
  background: rgb(var(--panel)) !important;
  border: 1px solid rgb(var(--accent) / 0.4) !important;
  box-shadow: 0 0 0 1px rgb(var(--accent) / 0.25) !important;
  border-radius: 8px !important;
  padding: 10px 12px !important;
  margin-bottom: 12px !important;
  display: flex !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  color: rgb(var(--text));
}
.bulk-selection-info { font-size: 13px; color: rgb(var(--text-2)); }
.bulk-action-buttons { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }

/* Sub-page headers some pages use (e.g. settings.php) */
.subsection-title, .panel-heading {
  font-size: 13px !important;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgb(var(--text-3)) !important;
  font-weight: 500 !important;
  margin: 24px 0 10px !important;
}

/* Generic "card" with a header bar */
.card-panel, .card-section {
  background: rgb(var(--panel)) !important;
  border: 1px solid rgb(var(--border)) !important;
  border-radius: 12px !important;
  margin-bottom: 16px;
}
.card-panel-header, .card-section-header {
  padding: 14px 16px;
  border-bottom: 1px solid rgb(var(--border));
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 550;
}
.card-panel-body, .card-section-body { padding: 16px; }

/* ============================================================
   Site detail page — restyles the legacy .site-* / .overview-*
   classes that have no CSS in dashboard.css. Without this block
   the page renders as a vertical stream of unstyled text.
   ============================================================ */
.site-detail-page { max-width: 1280px; display: flex; flex-direction: column; gap: 18px; }
.page-nav { margin-bottom: 0; }

.site-header-card {
    background: rgb(var(--panel));
    border: 1px solid rgb(var(--border));
    border-radius: 12px;
    padding: 18px 20px;
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 18px; flex-wrap: wrap;
}
.site-header-left { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.site-icon {
    display: inline-grid; place-items: center;
    width: 44px; height: 44px; border-radius: 10px;
    background: rgb(var(--accent) / 0.14);
    color: rgb(var(--accent));
    flex-shrink: 0;
}
.site-identity { min-width: 0; }
.site-name {
    margin: 0;
    font: 600 20px/1.2 'Geist', system-ui, sans-serif;
    color: rgb(var(--text));
    letter-spacing: -0.01em;
}
.site-meta-row {
    display: flex; gap: 10px; flex-wrap: wrap;
    margin-top: 6px;
    font-size: 12.5px; color: rgb(var(--text-2));
}
.site-meta-row .meta-item {
    display: inline-flex; align-items: center; gap: 5px;
}
.site-meta-row .badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font: 550 11px 'Geist Mono', monospace;
    text-transform: uppercase; letter-spacing: 0.04em;
    background: rgb(var(--panel-2));
    border: 1px solid rgb(var(--border));
    color: rgb(var(--text-2));
}
.site-description {
    margin: 8px 0 0;
    font-size: 13px; color: rgb(var(--text-2));
    line-height: 1.55;
}
.site-header-right { display: flex; gap: 8px; align-items: center; flex-shrink: 0; flex-wrap: wrap; }
.subscription-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 999px;
    font: 550 11px 'Geist Mono', monospace;
    text-transform: uppercase; letter-spacing: 0.04em;
    background: rgb(var(--panel-2));
    border: 1px solid rgb(var(--border));
    color: rgb(var(--text-2));
}
.subscription-badge.tier-pro,
.subscription-badge.tier-premium { color: rgb(var(--metric-power)); border-color: rgb(var(--metric-power) / 0.4); background: rgb(var(--metric-power) / 0.10); }
.subscription-badge.tier-basic { color: rgb(var(--metric-voltage)); border-color: rgb(var(--metric-voltage) / 0.4); background: rgb(var(--metric-voltage) / 0.10); }

.aggregate-overview { display: flex; flex-direction: column; gap: 12px; }
.aggregate-overview .section-title {
    margin: 0;
    font: 550 14.5px 'Geist', system-ui, sans-serif;
    display: inline-flex; align-items: center; gap: 8px;
    color: rgb(var(--text));
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}
.overview-card {
    background: rgb(var(--panel));
    border: 1px solid rgb(var(--border));
    border-radius: 12px;
    padding: 14px 16px;
    display: flex; gap: 12px; align-items: flex-start;
}
.overview-icon {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px; border-radius: 8px;
    background: rgb(var(--panel-2));
    color: rgb(var(--text-2));
    flex-shrink: 0;
    font-size: 16px;
}
.overview-card.overview-devices     .overview-icon { color: rgb(var(--accent));         background: rgb(var(--accent) / 0.14); }
.overview-card.overview-health      .overview-icon { color: rgb(var(--metric-current)); background: rgb(var(--metric-current) / 0.14); }
.overview-card.overview-temperature .overview-icon { color: rgb(var(--metric-temp));    background: rgb(var(--metric-temp) / 0.14); }
.overview-card.overview-power       .overview-icon { color: rgb(var(--metric-power));   background: rgb(var(--metric-power) / 0.14); }
.overview-card.overview-voltage     .overview-icon { color: rgb(var(--metric-voltage)); background: rgb(var(--metric-voltage) / 0.14); }
.overview-card.overview-errors      .overview-icon { color: rgb(var(--warn));           background: rgb(var(--warn) / 0.14); }
.overview-card.overview-errors.has-errors .overview-icon { color: rgb(var(--err));      background: rgb(var(--err) / 0.14); }
.overview-content { min-width: 0; flex: 1; }
.overview-value {
    font: 600 22px 'Geist Mono', monospace;
    letter-spacing: -0.01em;
    line-height: 1; color: rgb(var(--text));
}
.overview-label {
    font: 500 11px 'Geist', system-ui, sans-serif;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: rgb(var(--text-2));
    margin-top: 4px;
}
.overview-breakdown,
.overview-secondary {
    margin-top: 6px;
    font: 500 11.5px 'Geist Mono', monospace;
    color: rgb(var(--text-2));
    display: flex; gap: 10px; flex-wrap: wrap;
}
.overview-breakdown .status-online,
.overview-breakdown .status-offline {
    display: inline-flex; align-items: center; gap: 4px;
}
.overview-breakdown .status-online  .dot,
.overview-breakdown .status-offline .dot {
    width: 6px; height: 6px; border-radius: 50%; display: inline-block;
}
.overview-breakdown .status-online  .dot { background: rgb(var(--ok)); }
.overview-breakdown .status-offline .dot { background: rgb(var(--sleep)); }
.health-bar {
    display: flex; height: 6px;
    background: rgb(var(--panel-2));
    border-radius: 999px; overflow: hidden;
    margin: 8px 0 6px;
}
.health-bar .health-segment.healthy  { background: rgb(var(--metric-current)); }
.health-bar .health-segment.warning  { background: rgb(var(--warn)); }
.health-bar .health-segment.critical { background: rgb(var(--err)); }
.health-legend {
    display: flex; gap: 10px; flex-wrap: wrap;
    font: 500 11px 'Geist Mono', monospace;
    color: rgb(var(--text-2));
}
.health-legend .legend-item.healthy  { color: rgb(var(--metric-current)); }
.health-legend .legend-item.warning  { color: rgb(var(--warn)); }
.health-legend .legend-item.critical { color: rgb(var(--err)); }

.range-display { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.range-display.compact { font: 600 16px 'Geist Mono', monospace; }
.range-display .range-value { display: flex; flex-direction: column; gap: 2px; }
.range-display .range-value .value {
    font: 600 16px 'Geist Mono', monospace;
    color: rgb(var(--text));
}
.range-display .range-value .label {
    font: 500 10px 'Geist', system-ui, sans-serif;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: rgb(var(--text-3));
}
.range-display .range-min { color: rgb(var(--accent)); }
.range-display .range-max { color: rgb(var(--metric-power)); }
.range-display .range-sep { color: rgb(var(--text-3)); }
.range-display .range-separator { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.range-display .avg-value {
    font: 600 18px 'Geist Mono', monospace;
    color: rgb(var(--text));
}
.range-display .avg-label {
    font: 500 10px 'Geist', system-ui, sans-serif;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: rgb(var(--text-3));
}

.devices-section,
.activity-section,
.info-section {
    background: rgb(var(--panel));
    border: 1px solid rgb(var(--border));
    border-radius: 12px;
    padding: 0;
}
.devices-section .section-header,
.activity-section .section-header,
.info-section .section-header {
    padding: 14px 18px;
    border-bottom: 1px solid rgb(var(--border));
    display: flex; justify-content: space-between; align-items: center;
    gap: 10px; flex-wrap: wrap;
}
.devices-section .section-title,
.activity-section .section-title,
.info-section .section-title {
    margin: 0;
    font: 550 14.5px 'Geist', system-ui, sans-serif;
    color: rgb(var(--text));
    display: inline-flex; align-items: center; gap: 8px;
}
.empty-state {
    padding: 40px 24px;
    text-align: center;
    color: rgb(var(--text-2));
    font-size: 13px;
}
.empty-state i,
.empty-state svg {
    display: block;
    margin: 0 auto 10px;
    color: rgb(var(--text-3));
    opacity: 0.55;
    font-size: 32px;
}
.empty-state h3 {
    margin: 8px 0 4px;
    font: 600 15px 'Geist', system-ui, sans-serif;
    color: rgb(var(--text));
}

/* Site info two-column grid (in info-section body) */
.info-section dl,
.info-section .info-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 8px 16px;
    padding: 16px 18px;
    margin: 0;
    font-size: 13px;
}
.info-section dt,
.info-section .info-label {
    font: 500 12.5px 'Geist', system-ui, sans-serif;
    color: rgb(var(--text-2));
}
.info-section dd,
.info-section .info-value {
    margin: 0;
    color: rgb(var(--text));
}
@media (max-width: 639px) {
    .site-header-card { flex-direction: column; gap: 12px; }
    .site-header-right { width: 100%; justify-content: flex-start; }
    .overview-grid { grid-template-columns: 1fr; }
    .info-section dl,
    .info-section .info-grid { grid-template-columns: 1fr; gap: 4px 0; }
    .info-section dt { margin-top: 8px; }
}

/* Leaflet popup theming so popups blend with the dashboard */
.leaflet-popup-content-wrapper {
    background: rgb(var(--panel));
    color: rgb(var(--text));
    border: 1px solid rgb(var(--border));
    border-radius: 8px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.3);
}
.leaflet-popup-tip { background: rgb(var(--panel)); }
.leaflet-popup-content {
    font-family: 'Geist', system-ui, sans-serif;
    font-size: 12.5px;
    line-height: 1.55;
}
/* ============================================================
   Profile / multi-tab page chrome — retones legacy classes
   used by pages/profile.php so the existing markup gets the
   new look without a full rewrite.
   ============================================================ */
.profile-container { display: flex; flex-direction: column; gap: 16px; }

.profile-tabs {
    display: flex; gap: 4px;
    border-bottom: 1px solid rgb(var(--border));
    padding-bottom: 0;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.profile-tabs .tab-btn {
    padding: 10px 16px;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: rgb(var(--text-2));
    font: 500 13px 'Geist', system-ui, sans-serif;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px;
    transition: color .15s, border-color .15s;
}
.profile-tabs .tab-btn:hover { color: rgb(var(--text)); }
.profile-tabs .tab-btn.active {
    color: rgb(var(--accent));
    border-bottom-color: rgb(var(--accent));
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* .card structure used by profile.php (and a few other pages):
   header / body / footer. Tone each with the surface tokens. */
.tab-content > .card,
.profile-container .card {
    background: rgb(var(--panel)) !important;
    border: 1px solid rgb(var(--border)) !important;
    border-radius: 12px !important;
    overflow: hidden;
    margin-bottom: 14px;
    box-shadow: none !important;
}
.tab-content .card-header,
.profile-container .card-header {
    padding: 14px 18px !important;
    border-bottom: 1px solid rgb(var(--border));
    background: transparent !important;
}
.tab-content .card-header h3,
.profile-container .card-header h3 {
    margin: 0 !important;
    font-size: 14.5px !important;
    font-weight: 550 !important;
    color: rgb(var(--text)) !important;
    display: inline-flex; align-items: center; gap: 8px;
}
.tab-content .card-body,
.profile-container .card-body { padding: 18px !important; color: rgb(var(--text)); }
.tab-content .card-footer,
.profile-container .card-footer {
    padding: 12px 18px !important;
    border-top: 1px solid rgb(var(--border));
    background: transparent !important;
    display: flex; gap: 8px; justify-content: flex-end;
}

/* Form grid + form-group inside profile cards */
.profile-container .form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 18px;
}
@media (max-width: 639px) {
    .profile-container .form-grid { grid-template-columns: 1fr; }
}
.profile-container .form-group { display: flex; flex-direction: column; gap: 4px; }
.profile-container .form-group label {
    font-size: 12.5px;
    font-weight: 500;
    color: rgb(var(--text));
    margin-bottom: 2px;
}
.profile-container .form-group input,
.profile-container .form-group select,
.profile-container .form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid rgb(var(--border));
    border-radius: 6px;
    background: rgb(var(--panel-2));
    color: rgb(var(--text));
    font: 500 13px 'Geist', system-ui, sans-serif;
    box-sizing: border-box;
    transition: border-color .12s, box-shadow .12s;
}
.profile-container .form-group input:disabled {
    color: rgb(var(--text-2));
    cursor: not-allowed;
}
.profile-container .form-group input:focus,
.profile-container .form-group select:focus,
.profile-container .form-group textarea:focus {
    outline: 0;
    border-color: rgb(var(--accent) / 0.55);
    box-shadow: 0 0 0 3px rgb(var(--accent) / 0.18);
}
.profile-container .form-group small {
    color: rgb(var(--text-2));
    font-size: 11.5px;
    margin-top: 2px;
}

/* Profile header section: avatar + name */
.profile-container .profile-header-section {
    display: flex; gap: 18px; align-items: center;
    padding-bottom: 18px; margin-bottom: 18px;
    border-bottom: 1px solid rgb(var(--border));
}
.profile-container .avatar-large {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgb(var(--brand-green)), rgb(var(--brand-blue)));
    color: #fff;
    font: 600 22px 'Geist', system-ui, sans-serif;
    display: grid; place-items: center;
    flex-shrink: 0;
    letter-spacing: 0.04em;
}
.profile-container .profile-meta .username {
    font: 600 16px 'Geist', system-ui, sans-serif;
    color: rgb(var(--text));
}
.profile-container .profile-meta .member-since {
    color: rgb(var(--text-2));
    font-size: 12px; margin-top: 4px;
}
.profile-container .role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font: 550 10.5px 'Geist Mono', monospace;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-top: 4px;
    border: 1px solid rgb(var(--border));
}
.profile-container .role-badge.role-super_admin { color: rgb(var(--metric-power)); border-color: rgb(var(--metric-power) / 0.4); background: rgb(var(--metric-power) / 0.10); }
.profile-container .role-badge.role-admin       { color: rgb(var(--metric-voltage)); border-color: rgb(var(--metric-voltage) / 0.4); background: rgb(var(--metric-voltage) / 0.10); }
.profile-container .role-badge.role-user        { color: rgb(var(--metric-current)); border-color: rgb(var(--metric-current) / 0.4); background: rgb(var(--metric-current) / 0.10); }

/* Password-strength requirements list */
.password-requirements {
    margin-top: 14px;
    padding: 12px 14px;
    background: rgb(var(--panel-2));
    border-radius: 8px;
    border: 1px solid rgb(var(--border));
}
.password-requirements .requirement {
    font-size: 12px;
    line-height: 1.7;
    color: rgb(var(--text-2));
    display: flex; align-items: center; gap: 6px;
}
.password-requirements .requirement.met,
.password-requirements .requirement.valid { color: rgb(var(--ok)); }
.password-requirements .requirement.met i,
.password-requirements .requirement.valid i { color: rgb(var(--ok)); }

/* Login history list */
.login-history { display: flex; flex-direction: column; gap: 6px; }
.login-entry {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border: 1px solid rgb(var(--border));
    border-radius: 8px;
    background: rgb(var(--panel-2));
    font-size: 12.5px;
}
.login-entry .login-status { font-size: 16px; flex-shrink: 0; }
.login-entry.success .login-status { color: rgb(var(--ok)); }
.login-entry.failed  .login-status { color: rgb(var(--err)); }
.login-entry .login-time { font-weight: 500; color: rgb(var(--text)); }
.login-entry .login-info {
    color: rgb(var(--text-2));
    font: 500 11.5px 'Geist Mono', monospace;
}

/* Hover tooltip — attach via data-tip="…" on any element. Multi-line
   tooltips are encouraged: pipe characters (|) in the value become line
   breaks via the (CSS) white-space rules. Pure-CSS, no JS. */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%) translateY(4px);
  background: rgb(var(--panel));
  color: rgb(var(--text));
  border: 1px solid rgb(var(--border-2));
  border-radius: 6px;
  padding: 8px 11px;
  font: 500 12px/1.5 'Geist', system-ui, sans-serif;
  white-space: pre-line;
  width: max-content;
  max-width: 320px;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease, transform .12s ease;
  /* Very high so the tooltip wins over Chart.js canvases and any
     adjacent surface with its own stacking context. */
  z-index: 9000;
  box-shadow: 0 8px 22px rgb(0 0 0 / 0.4);
}
[data-tip]:hover,
[data-tip]:focus-visible {
  /* Promote the hovered element into a high stacking context so the
     tooltip escapes lift cards (which form their own context via
     transform:translateY on hover) and isn't painted under sibling
     content like the big chart. */
  z-index: 9000;
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* Bottom-anchored variant for cards near the top of the viewport */
[data-tip-pos="below"]::after {
  bottom: auto;
  top: calc(100% + 6px);
  transform: translateX(-50%) translateY(-4px);
}
[data-tip-pos="below"]:hover::after { transform: translateX(-50%) translateY(0); }

/* Touch devices: suppress hover tooltips. On phones :hover sticks after a
   tap, so a card's tooltip would render across the next card below it.
   The card's visible label + sub line already carries the same info, and
   the explanatory text was only ever supplementary. */
@media (hover: none) {
  [data-tip]::after,
  [data-tip-pos="below"]::after { display: none !important; }
}

/* ============================================================
   Mobile breakpoint hardening — survives every legacy page on
   narrow viewports. Anything < 640px wide takes these rules.
   ============================================================ */
@media (max-width: 639px) {
  /* Page padding — tighten so content gets to the edges */
  .page { padding: var(--page-pad-mobile) !important; }

  /* Page headers — stack title block above any actions */
  .page-header { flex-direction: column !important; align-items: stretch !important; gap: 12px !important; }
  .page-header .h-right,
  .page-header .page-actions { flex-wrap: wrap; }

  /* All .dev / legacy .table tables scroll horizontally without
     squashing — wrapper-less containment via inline-block trick. */
  .dev, .table {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .dev thead, .table thead { white-space: nowrap; }

  /* Modal full-screen-ish on phones (legacy `.modal-content` rebuilt) */
  .modal-content, .modal-dialog {
    width: 100vw !important; max-width: 100vw !important;
    min-height: 100vh; border-radius: 0 !important;
    margin: 0 !important;
  }
  /* Mobile: pin modal to top so the on-screen keyboard never covers
     the fields. Override the desktop center alignment from above. */
  .modal { align-items: flex-start !important; padding: 12px !important; }
  .modal .modal-content,
  .modal .modal-dialog { max-height: calc(100vh - 24px); }

  /* Two/three/four-up KPI grids → single column */
  .grid.grid-cols-2,
  .grid.sm-grid-cols-2,
  .grid.sm-grid-cols-3,
  .grid.sm-grid-cols-4,
  .grid.sm-grid-cols-5,
  .grid.sm-grid-cols-6,
  .grid.lg-grid-cols-3,
  .grid.lg-grid-cols-4,
  .grid.lg-grid-cols-6 {
    grid-template-columns: 1fr !important;
  }

  /* Device-detail metric cards: opt-out of the single-column collapse.
     Six tiles in one column reads as an endless full-width strip on a
     phone — a 2-column grid keeps the cards compact and the page scannable. */
  .grid.device-metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .grid.device-metric-grid .surf {
    padding: 12px !important;
  }
  .grid.device-metric-grid .surf .num {
    font-size: 20px !important;
  }

  /* Home / overview KPI tiles: same treatment as device-metric-grid — keep
     a tidy 2-column layout on mobile instead of one-tile-per-row strip. */
  .grid.home-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .grid.home-kpi-grid .surf {
    padding: 12px !important;
  }
  .grid.home-kpi-grid .surf .num[style*="28px"],
  .grid.home-kpi-grid .surf .num[style*="font-size:28px"] {
    font-size: 22px !important;
  }

  /* Sidebar — fully hidden when on mobile (the bottom tab bar replaces it) */
  .sidebar-ds { display: none !important; }
  .app-main   { margin-left: 0 !important; }

  /* AI chat slide-over — fill the screen on phones */
  #aiChatPanel { width: 100vw !important; }

  /* AI chat FAB is replaced by the bottom-nav Chat entry on mobile, so
     hide the floating bubble to avoid double-buttons. The nav button is
     wired to open the same panel when one is mounted on the current page. */
  #aiChatToggleBtn { display: none !important; }

  /* KPI tile inside .surf — slightly tighter padding */
  .surf.kpi { padding: 12px 14px !important; }

  /* Form rows in settings sections — labels stack above controls */
  .settings-row { grid-template-columns: 1fr !important; gap: 10px !important; padding: 14px 0 !important; }

  /* Buttons inside header actions wrap onto own row */
  .page-header .btn { flex-shrink: 0; }
}

/* Device detail header — legacy dashboard.css defines this as a single
   horizontal flex row, which collapses the new 4-row layout (breadcrumb /
   title+actions / meta / tabs) into one squashed line. Force the new
   vertical-stack layout and restore the surface chrome. */
.device-detail-header {
  display: block !important;
  align-items: initial !important;
  justify-content: initial !important;
  background: rgb(var(--panel)) !important;
  border: 1px solid rgb(var(--border)) !important;
  border-radius: 12px !important;
  padding: 18px 20px !important;
  box-shadow: none !important;
}
.device-detail-header > .tabs {
  border-bottom: 0;
  padding-bottom: 0;
}
