/* INFILITH BMS — Web Portal (v5.37 instrument language, mirrors the app kit) */
:root {
  --bg: #0B0F17;
  --card: #101720;
  --card2: #141C28;
  --border: #232C3B;
  --divider: #1A2230;
  --text: #E7ECF3;
  --muted: #8C97A8;
  --dim: #5A6575;
  --neon: #E5FF00;
  --neon-light: #EFFF66;
  --neon-glow: rgba(229, 255, 0, 0.2);
  --blue: #5B9CF8;
  --cyan: #06B6D4;
  --amber: #F5B544;
  --red: #F05252;
  --purple: #A855F7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- Loading / sign-in ---------- */
.center-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
}

.loader {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid var(--divider);
  border-top-color: var(--neon);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--muted); font-size: 14px; }

.signin-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
}

.logo { width: 28px; height: 28px; display: block; }
.logo-lg { width: 84px; height: 84px; margin: 0 auto 14px; }

.signin-title {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.5px;
}
.t-white { color: var(--text); }
.t-neon { color: var(--neon); }
.signin-sub { margin: 0 0 26px; color: var(--muted); font-size: 14px; }
.signin-hint { margin: 22px 0 0; color: var(--dim); font-size: 12px; line-height: 1.5; }

/* ---------- Get the app (QR + download) — web-only promo on the signin card ---------- */
.getapp { margin: 0 0 26px; }
.getapp-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  color: var(--neon);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2.6px;
}
.getapp-divider::before, .getapp-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.qr-frame {
  display: inline-flex;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  line-height: 0;
}
.qr-frame svg { width: 156px; height: 156px; display: block; }
.getapp-cap { margin: 10px 0 12px; color: var(--muted); font-size: 12.5px; }
.getapp-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--neon);
  font-size: 14.5px;
  font-weight: 800;
  text-decoration: none;
}
.getapp-link:hover { color: var(--neon-light); text-decoration: underline; }
.getapp-link svg { flex: none; }
.getapp-note { margin: 8px 0 0; color: var(--dim); font-size: 11px; }

.error {
  margin: 16px 0 0;
  color: var(--red);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Buttons (v5.37 instrument hierarchy) ------------------------
   PRIMARY = brand fill on dark text; DEFAULT = elevated surface + hairline;
   GHOST = no fill, muted. All uppercase, letterspaced, tight radius. */
.btn-neon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: var(--neon);
  color: #0A0C04;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  border: 1px solid var(--neon);
  border-radius: 10px;
  padding: 11px 20px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn-neon:hover { background: var(--neon-light); border-color: var(--neon-light); }
.btn-neon:disabled {
  background: var(--card2);
  border-color: var(--border);
  color: var(--dim);
  cursor: default;
}
.btn-lg { width: 100%; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 8px 13px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.btn-ghost:hover { color: var(--text); border-color: var(--dim); }

/* ---------- Top bar (v5.37 instrument chrome) ----------------------------
   Mirrors the app's mock header: brand dot + micro INFILITH mark on the
   left, a flat uppercase tab strip in the centre (active tab lit by brand
   accent + a 2px top border), and the account chip on the right. Hairline
   bottom border only — no glow, no blur. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  gap: 18px;
  flex-wrap: wrap;
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* Left: brand dot + micro INFILITH lockup, right-padded before the tabs. */
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px 4px;
  border-right: 1px solid var(--divider);
  padding-right: 18px;
}
.brand .logo { display: block; width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.8px;
  color: var(--text);
  text-transform: uppercase;
}
.brand-sub {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 2.4px;
  color: var(--dim);
  text-transform: uppercase;
}

/* Centre: flat uppercase tab strip — no pill, active lit like the app nav. */
.tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}
.tab-btn {
  position: relative;
  background: transparent;
  border: none;
  border-top: 2px solid transparent;
  color: var(--dim);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 16px 15px 14px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--neon);
  border-top-color: var(--neon);
}

/* Right: account chip — role badge over a dim email line. */
.userchip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0 12px 18px;
  border-left: 1px solid var(--divider);
}
.u-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; line-height: 1.2; }
.u-email {
  font-size: 11px;
  font-family: Consolas, "Courier New", monospace;
  color: var(--dim);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-badge {
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 5px;
  border: 1px solid;
}
.role-ADMIN { color: var(--neon); border-color: rgba(229,255,0,.5); background: rgba(229,255,0,.1); }
.role-DEALER { color: var(--cyan); border-color: rgba(6,182,212,.5); background: rgba(6,182,212,.1); }
/* v5.23: field-service role — dealer-blue family, distinct hue. */
.role-TECHNICIAN { color: #a78bfa; border-color: rgba(167,139,250,.5); background: rgba(167,139,250,.1); }
.role-CUSTOMER { color: var(--muted); border-color: var(--border); background: var(--card2); }

/* ---------- v5.23 pack identity (manufacturer + production date) ------- */
.pack-meta .meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 16px;
}
.meta-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.meta-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.meta-src { text-transform: none; letter-spacing: 0; opacity: .75; }
.meta-value { font-size: 13.5px; color: var(--text); overflow-wrap: anywhere; }
.meta-input {
  background: var(--card2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 13px; font-family: inherit; max-width: 100%;
}
.meta-input:focus { outline: none; border-color: var(--cyan); }

/* ---------- v5.23 per-technician rights toggles (Users table) ---------- */
.tech-rights { display: flex; flex-direction: column; gap: 4px; }
.tech-right { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); cursor: pointer; }
.tech-right input { accent-color: var(--cyan); }

/* ---------- v5.66 control grants (Users → Controls, all 12 types) -------
 * Two-column grid so a DEALER/TECHNICIAN row stays scannable; the four
 * dangerous controls (SET_EEPROM / CALIBRATE_CELLS / CLEAR_RTC_DATA /
 * FACTORY_RESTORE) are tinted red with a ⚠ prefix in the label. */
.tech-rights-grid { display: grid; grid-template-columns: repeat(2, minmax(140px, 1fr)); gap: 3px 12px; }
.tech-right-danger { color: var(--red); }
.tech-right-danger input { accent-color: var(--red); }

/* Read-only grant (Hardware refresh without Hardware parameters): locked
 * parameter fields in Configure → Parameters. */
.ctrl-field-ro { opacity: .62; }
.ctrl-field-ro .ctrl-input:disabled { cursor: not-allowed; }

/* ---------- Banner ---------- */
.banner {
  margin: 14px 22px 0;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.5;
  background: rgba(240, 82, 82, 0.12);
  border: 1px solid rgba(240, 82, 82, 0.45);
  color: #FCA5A5;
}
.banner.info {
  background: rgba(6, 182, 212, 0.1);
  border-color: rgba(6, 182, 212, 0.4);
  color: #67E8F9;
}

/* ---------- View ---------- */
.view { padding: 22px; max-width: 1440px; margin: 0 auto; }

.view-head { display: flex; align-items: baseline; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.view-title { font-size: 17px; font-weight: 800; margin: 0; }
.view-sub { font-size: 12.5px; color: var(--dim); }

.empty {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 46px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Battery cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.batt-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.batt-card.stale { opacity: 0.78; }
/* v5.54 fix ("Configure tab is not visible after clicking it"): the Configure
 * sheet inside the card is position:fixed — the .stale opacity above creates a
 * stacking context that traps it, so every later sibling card and the z-20
 * header painted OVER the panel. The card hosting an open panel renders at
 * full opacity, releasing the trap so the fixed sheet (z-90) wins the stack. */
.batt-card.panel-open, .batt-card:has(.config-overlay) { opacity: 1; }

.batt-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  border-radius: 10px;
}
.batt-head:focus-visible { outline: 2px solid var(--cyan); outline-offset: 4px; }
.batt-name { font-size: 15.5px; font-weight: 800; margin: 0; overflow-wrap: anywhere; }
.batt-owner { font-size: 12px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.batt-dealer { font-size: 11.5px; color: var(--dim); margin-top: 2px; overflow-wrap: anywhere; }

/* Collapsible card: summary line always visible, full detail on tap. */
.batt-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}
.batt-details { display: none; }
.batt-card.expanded .batt-details { display: flex; flex-direction: column; gap: 14px; }
.batt-chev {
  display: inline-block;
  margin-left: 8px;
  font-size: 12px;
  color: var(--dim);
  transition: transform .2s ease;
}
.batt-card.expanded .batt-chev { transform: rotate(180deg); }

/* ---------- Controls tab (admin) ---------- */
.ctrl-card .batt-head { cursor: pointer; }
.ctrl-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}
.ctrl-section { border-top: 1px dashed var(--divider); padding-top: 12px; }
.ctrl-hint { font-size: 11.5px; color: var(--muted); margin: -4px 0 10px; line-height: 1.45; }
.ctrl-section-title {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 8px;
}
.ctrl-mos-row { display: flex; gap: 18px; flex-wrap: wrap; }
.ctrl-mos { display: flex; align-items: center; gap: 6px; }
.ctrl-mos-label { font-size: 12px; font-weight: 800; color: var(--muted); min-width: 40px; }
.ctrl-btn {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .5px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--muted);
  cursor: pointer;
}
.ctrl-btn:hover:not(:disabled) { color: var(--text, #E2E8F0); border-color: var(--dim); }
.ctrl-btn.ctrl-btn-on {
  color: var(--neon);
  border-color: rgba(229,255,0,.5);
  background: rgba(229,255,0,.12);
}
.ctrl-btn:disabled { cursor: default; }
.ctrl-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ctrl-field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); min-width: 0; }
/* v5.63: "Function configuration" flags — one checkbox per register-0x2D
 * bit (JBDTools renders the same twelve as checkboxes). */
.ctrl-flag { flex-direction: row; align-items: center; gap: 7px; min-height: 26px; }
.ctrl-flag input { width: 15px; height: 15px; accent-color: var(--neon); cursor: pointer; flex: none; }
.ctrl-flag input:disabled { cursor: not-allowed; opacity: .6; }
/* Sub-groups inside the hardware-parameters section (JBDTools-style grouping) */
.ctrl-subgroup { margin-top: 12px; }
.ctrl-subgroup-title {
  font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}
.ctrl-input {
  width: 100%;
  padding: 7px 9px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text, #E2E8F0);
}
.ctrl-input:focus { outline: none; border-color: var(--neon); box-shadow: 0 0 0 2px rgba(229,255,0,.15); }
.ctrl-apply { margin-top: 10px; }
.ctrl-assign { display: flex; gap: 8px; align-items: stretch; }
.ctrl-select {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  font-size: 12.5px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text, #E2E8F0);
}
.ctrl-select:focus { outline: none; border-color: var(--cyan); }
.ctrl-danger .ctrl-section-title { color: var(--red); }
.link-select { max-width: 190px; }
.bday-input { max-width: 130px; }

/* v5.13: automated wishes strip under the topbar (time-of-day + events) */
.greeting-line {
  padding: 9px 20px;
  font-size: 13px;
  color: var(--text, #E2E8F0);
  background: rgba(229, 255, 0, 0.07);
  border-bottom: 1px solid rgba(229, 255, 0, 0.18);
}

/* Warranty editor grid */
.wiz-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1.1px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid;
  white-space: nowrap;
}
.pill-online { color: var(--neon); border-color: rgba(229,255,0,.45); background: rgba(229,255,0,.1); }
.pill-offline { color: var(--dim); border-color: var(--border); background: var(--card2); }
.pill-charging { color: var(--neon); border-color: rgba(229,255,0,.45); background: rgba(229,255,0,.1); }
.pill-discharging { color: var(--cyan); border-color: rgba(6,182,212,.45); background: rgba(6,182,212,.1); }
.pill-idle { color: var(--muted); border-color: var(--border); background: var(--card2); }
.pill-stale { color: var(--amber); border-color: rgba(245,181,68,.45); background: rgba(245,181,68,.1); }
.pill-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* SOC */
.soc-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
/* SOC — hero number in the instrument's mono data face (app DataXL) */
.soc-value { font-family: Consolas, "Courier New", monospace; font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: -1px; }
/* socColor() classes — colored SOC number + collapsed summary value */
.soc-value.neon, .batt-summary .neon { color: var(--neon); }
.soc-value.amber, .batt-summary .amber { color: var(--amber); }
.soc-value.red, .batt-summary .red { color: var(--red); }
.soc-ah { font-family: Consolas, "Courier New", monospace; font-size: 12px; color: var(--muted); font-weight: 600; padding-bottom: 5px; }

/* v5.37 — full SOC ring, matching the app's RingGauge. Pure CSS: a
   conic-gradient track fills 0..var(--soc) in the state colour, a dark disc
   masks the centre, and the mono value + Ah sit on top. No JS change. */
.soc-ring {
  --soc: 0;
  --arc: var(--neon);
  position: relative;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, var(--card) 78%, transparent 79% 100%),
    conic-gradient(from -90deg, var(--arc) calc(var(--soc) * 1%), var(--divider) 0);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: none;
}
.soc-ring.neon { --arc: var(--neon); }
.soc-ring.amber { --arc: var(--amber); }
.soc-ring.red { --arc: var(--red); }
.soc-ring .soc-ring-val {
  font-family: Consolas, "Courier New", monospace;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1px;
}
.soc-ring .soc-ring-val.neon { color: var(--neon); }
.soc-ring .soc-ring-val.amber { color: var(--amber); }
.soc-ring .soc-ring-val.red { color: var(--red); }
.soc-ring .soc-ring-sub {
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
}
/* Headline row: ring on the left, state + flow stacked to the right. */
.soc-ring-row { display: flex; align-items: center; gap: 16px; }
.soc-ring-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.soc-track {
  height: 9px;
  border-radius: 99px;
  background: var(--divider);
  overflow: hidden;
}
.soc-fill { height: 100%; border-radius: 99px; transition: width 0.6s ease; }
.soc-high { background: var(--neon); }
.soc-mid { background: var(--amber); }
.soc-low { background: var(--red); }

/* metrics */
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric {
  background: var(--card2);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 9px 10px;
  min-width: 0;
}
.metric-label { font-size: 9.5px; font-weight: 700; letter-spacing: 0.7px; color: var(--dim); text-transform: uppercase; }
.metric-value { font-family: Consolas, "Courier New", monospace; font-size: 14.5px; font-weight: 700; margin-top: 3px; overflow-wrap: anywhere; }
.metric-value.neon { color: var(--neon); }
.metric-value.cyan { color: var(--cyan); }
.metric-value.amber { color: var(--amber); }
.metric-value.red { color: var(--red); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  padding: 3.5px 8px;
  border-radius: 6px;
  border: 1px solid;
}
.chip-on { color: var(--neon); border-color: rgba(229,255,0,.4); background: rgba(229,255,0,.08); }
.chip-off { color: var(--dim); border-color: var(--border); background: transparent; }
.chip-danger { color: var(--red); border-color: rgba(240,82,82,.45); background: rgba(240,82,82,.1); }
.chip-info { color: var(--cyan); border-color: rgba(6,182,212,.4); background: rgba(6,182,212,.08); }
.chip-plain { color: var(--muted); border-color: var(--border); background: var(--card2); }

.batt-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--divider);
  padding-top: 10px;
  font-size: 11.5px;
  color: var(--dim);
  flex-wrap: wrap;
}

/* ---------- Table (users / warranties) ---------- */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
  padding: 13px 16px;
  border-bottom: 1px solid var(--divider);
  white-space: nowrap;
  background: var(--card2);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--divider); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(20, 28, 40, 0.5); }
.cell-main { font-weight: 700; }
.cell-sub { font-size: 11.5px; color: var(--dim); margin-top: 2px; overflow-wrap: anywhere; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }

.status-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid;
}
.status-neon { color: var(--neon); border-color: rgba(229,255,0,.45); background: rgba(229,255,0,.1); }
.status-amber { color: var(--amber); border-color: rgba(245,181,68,.45); background: rgba(245,181,68,.1); }

/* ---------- v5.41 Anti-Theft Mode: parked-pack markers (amber = intentional,
   never a fault) ---------- */
.chip-parked {
  color: var(--amber);
  border-color: rgba(245,181,68,.45);
  background: rgba(245,181,68,.1);
}
.pill-parked {
  color: var(--amber);
  border: 1px solid rgba(245,181,68,.5);
  background: rgba(245,181,68,.12);
}
.log-type.log-antitheft {
  color: var(--amber);
  border-color: rgba(245,181,68,.45);
  background: rgba(245,181,68,.1);
}
.status-red { color: var(--red); border-color: rgba(240,82,82,.45); background: rgba(240,82,82,.1); }
.status-cyan { color: var(--cyan); border-color: rgba(6,182,212,.45); background: rgba(6,182,212,.1); }
.status-muted { color: var(--muted); border-color: var(--border); background: var(--card2); }

.text-muted { color: var(--dim); }
.text-neon { color: var(--neon); }

/* ---------- Footer / responsive ---------- */
.view-footer {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--divider);
  color: var(--dim);
  font-size: 11.5px;
  text-align: center;
}

/* ---------- Brand footer (v5.40): INFILITH wordmark chip + tagline + site link.
   The wordmark artwork is dark-on-transparent (green #39E600 strokes), so it
   rides on a white chip in both themes; tagline/link use var(--neon), which
   the light theme already re-inks to a dark olive. */
.footer-logo {
  display: inline-block;
  height: 30px;
  width: auto;
  box-sizing: content-box;   /* global border-box would squash the bitmap */
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
}
.footer-tag {
  margin-top: 10px;
  color: var(--neon);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 3.2px;
}
.footer-line {
  margin: 6px 0 0;
  color: var(--dim);
  font-size: 11.5px;
}
.footer-line a { color: var(--neon); text-decoration: underline; }
.signin-footer { width: min(400px, 100%); text-align: center; }
.view-footer .footer-logo { margin-bottom: 4px; }
.view-footer .footer-copy { margin-top: 8px; }

@media (max-width: 900px) {
  .topbar { gap: 10px; padding: 10px 14px; }
  /* flex:none so width:100% is honored (base flex:1 / basis:0 would ignore it
     and squeeze the tabs into row 1). v5.39 fix. */
  .tabs { order: 3; flex: none; width: 100%; justify-content: flex-start; }
  .u-email { max-width: 150px; }
  .view { padding: 14px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Remote Telemetry: Online/Offline tabs ---------- */
.view-tabs { display: flex; gap: 8px; margin: 2px 0 14px; }
.view-tab {
  flex: 1;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.view-tab:hover { color: var(--text); background: var(--card2); }
.view-tab.active {
  color: var(--neon);
  border-color: rgba(229,255,0,.45);
  background: rgba(229,255,0,.1);
}
.view-tab[data-fleet-filter="offline"].active {
  color: var(--dim);
  border-color: var(--border);
  background: var(--card2);
}

/* ---------- Per-cell voltages (mirrors the app's cell grid) ---------- */
.cell-block { display: flex; flex-direction: column; gap: 8px; }
.cell-head {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--muted);
}
.cell-head span:first-child { color: var(--text); font-weight: 800; }
.cell-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 5px; }
.cell {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 2px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.cell-idx { font-size: 8px; color: var(--dim); font-weight: 700; line-height: 1; }
.cell-v { font-family: Consolas, "Courier New", monospace; font-size: 10.5px; font-weight: 800; color: var(--muted); line-height: 1; }
.cell-min { border-color: rgba(245,181,68,.55); }
.cell-min .cell-v { color: var(--amber); }
.cell-max { border-color: rgba(91,156,248,.55); }
.cell-max .cell-v { color: var(--blue); }

/* ---------- Search box (Users tab) ---------- */
.search-box {
  width: 100%;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-box::placeholder { color: var(--dim); }
.search-box:focus {
  border-color: var(--neon);
  box-shadow: 0 0 0 3px rgba(229, 255, 0, 0.12);
}
#userSearch { margin: 0 0 14px; }

/* ---------- Announcement banners (customer / dealer panels) ---------- */
.ann-banners { display: flex; flex-direction: column; gap: 10px; margin: 0 0 16px; }
.ann-banner {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.ann-banner-head { display: flex; align-items: center; gap: 8px; }
.ann-icon { font-size: 15px; line-height: 1; }
.ann-title { font-size: 14px; font-weight: 800; margin: 0; flex: 1; overflow-wrap: anywhere; }
.ann-body { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ann-link { display: inline-block; margin-top: 8px; color: var(--cyan); font-size: 12.5px; text-decoration: none; overflow-wrap: anywhere; }
.ann-link:hover { text-decoration: underline; }

/* ---------- Announcement manager (admin tab) ---------- */
.ann-grid {
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 920px) { .ann-grid { grid-template-columns: 1fr; } }
.ann-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ann-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ann-card-head h3 { font-size: 14.5px; font-weight: 800; margin: 0; }
.ann-seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.ann-seg-btn {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--dim);
  padding: 9px 8px;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.ann-seg-btn:hover { color: var(--text); background: var(--card2); }
.ann-seg-btn.active.cyan { color: var(--cyan); background: rgba(6, 182, 212, 0.13); }
.ann-seg-btn.active.amber { color: var(--amber); background: rgba(245, 181, 68, 0.13); }
.ann-label {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--dim);
}
.ann-textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.ann-schedule { display: flex; align-items: center; gap: 8px; }
.ann-schedule .search-box { flex: 1; min-width: 0; }
.ann-schedule input[type="datetime-local"] { color-scheme: dark; }
.ann-switch { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); cursor: pointer; }
.ann-switch input { width: 16px; height: 16px; accent-color: var(--neon); cursor: pointer; }
.ann-error { color: var(--red); font-size: 12.5px; font-weight: 600; }
.ann-actions { display: flex; gap: 10px; margin-top: 2px; }
.btn-sm { padding: 6px 11px !important; font-size: 12px !important; }
.ann-danger { color: var(--red) !important; border-color: rgba(240, 82, 82, 0.4) !important; }
.ann-danger:hover { background: rgba(240, 82, 82, 0.12) !important; }
.ann-list { display: flex; flex-direction: column; gap: 8px; }
.ann-item {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: flex-start;
  border: 1px solid var(--border);
  background: var(--card2);
  border-radius: 12px;
  padding: 11px 13px;
}
.ann-item.editing { border-color: rgba(229, 255, 0, 0.5); }
.ann-item-main { min-width: 0; flex: 1; }
.ann-item-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ann-item-title { font-size: 13.5px; overflow-wrap: anywhere; }
.ann-aud { font-size: 9.5px; font-weight: 900; letter-spacing: 0.7px; }
.ann-aud.cyan { color: var(--cyan); }
.ann-aud.amber { color: var(--amber); }
.ann-item-body { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.ann-item-meta { font-size: 10.5px; color: var(--dim); margin-top: 5px; }
.ann-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* --- v5.12: collapsible pack sub-groups, cell calibration, lockdown
   scheduling, repair history, warranty void fields --- */
.ctrl-group { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.ctrl-group:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.ctrl-group-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; background: none; border: 0; color: inherit; cursor: pointer;
  font-size: 11.5px; font-weight: 900; letter-spacing: 1.1px; text-transform: uppercase;
  padding: 4px 0; text-align: left; font-family: inherit;
}
.ctrl-group-head:hover { color: var(--neon); }
.ctrl-group-head .ctrl-chev { color: var(--neon); font-size: 13px; }
.ctrl-group-body { margin-top: 6px; display: flex; flex-direction: column; gap: 10px; }
.ctrl-cells { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px 10px; }
.ctrl-sched { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 10px;
  padding: 11px; border: 1px dashed rgba(240, 82, 82, 0.45); border-radius: 10px; }
.ctrl-sched .ctrl-field { flex: 1 1 170px; }
.ctrl-sched input[type="datetime-local"] { color-scheme: dark; }
.ctrl-sched-notify { display: flex; align-items: center; gap: 7px; font-size: 12.5px;
  color: var(--muted); cursor: pointer; padding-bottom: 9px; }
.ctrl-sched-notify input { width: 15px; height: 15px; accent-color: var(--neon); cursor: pointer; }
.repair-row { border: 1px solid var(--border); background: var(--card2); border-radius: 10px;
  padding: 9px 11px; display: flex; flex-direction: column; gap: 5px; }
.repair-row.closed { opacity: 0.72; }
.repair-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.repair-date { color: var(--dim); font-size: 11px; }
.repair-notes { font-size: 12px; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.repair-sub { font-size: 10.5px; color: var(--dim); }
.repair-add { display: flex; flex-direction: column; gap: 8px; border-top: 1px dashed var(--border); padding-top: 9px; }
.void-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.repair-actions { display: flex; gap: 8px; flex-wrap: wrap; }
/* v5.18 pack logs */
.log-row { border: 1px solid var(--border); background: var(--card2); border-radius: 10px;
  padding: 8px 11px; display: flex; flex-direction: column; gap: 3px; }
.log-head { display: flex; align-items: center; gap: 8px; }
.log-type { font-size: 12px; font-weight: 700; }
.log-live { color: var(--red); }
.log-stored { color: var(--warn, #f5a524); }
.log-count { font-family: Consolas, "Courier New", monospace; font-size: 12px; font-weight: 700; }
.log-time { font-family: Consolas, "Courier New", monospace; font-size: 10.5px; color: var(--dim); }
.log-detail { font-size: 11.5px; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.log-error { font-size: 12px; color: var(--red); }
/* v5.19: live fault flash + scheduled-lockdown row + log actions */
.log-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fault-banner {
  padding: 7px 11px;
  border: 1px solid rgba(255, 77, 77, 0.55);
  border-radius: 10px;
  background: rgba(255, 77, 77, 0.12);
  color: #ff6b6b;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  overflow-wrap: anywhere;
}
.batt-card.fault-flash {
  border-color: rgba(255, 77, 77, 0.8);
  animation: fault-pulse 1.4s ease-in-out infinite;
}
@keyframes fault-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 60, 60, 0.5); }
  50% { box-shadow: 0 0 14px 4px rgba(255, 60, 60, 0.35); }
}
@media (prefers-reduced-motion: reduce) {
  .batt-card.fault-flash { animation: none; }
}
.ctrl-sched-row-live {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px dashed rgba(245, 165, 36, 0.45);
  border-radius: 10px;
}

/* ==========================================================================
   v5.30 light theme — set on <html> by the pre-paint script in index.html
   (AUTO follows the device's prefers-color-scheme; DARK/LIGHT pin it).
   Declared after :root so the equal-specificity variable overrides win.
   ========================================================================== */
html[data-theme="light"] {
  --bg: #F1F4F9;
  --card: #FFFFFF;
  --card2: #E8EDF5;
  --border: #D9DFE9;
  --divider: #DCE2EC;
  --text: #131826;
  --muted: #4C5A70;
  --dim: #71809A;
  --neon: #767C00;
  --neon-light: #A9B100;
  --neon-glow: rgba(118, 124, 0, 0.22);
  --blue: #2563EB;
  --cyan: #0E7490;
  --amber: #B45309;
  --red: #DC2626;
  --purple: #7C3AED;
}

/* Dark-only literals lifted out of the cascade for paper mode. */
html[data-theme="light"] .topbar { background: var(--bg); }
html[data-theme="light"] tbody tr:hover td { background: rgba(226, 232, 240, 0.7); }
html[data-theme="light"] .ann-schedule input[type="datetime-local"],
html[data-theme="light"] .ctrl-sched input[type="datetime-local"] { color-scheme: light; }

/* Banner / fault / role text tuned for dark cards — re-ink for light ones. */
html[data-theme="light"] .banner { color: var(--red); }
html[data-theme="light"] .banner.info { color: var(--cyan); }
html[data-theme="light"] .fault-banner { color: var(--red); }
html[data-theme="light"] .role-TECHNICIAN {
  color: var(--purple);
  border-color: rgba(124, 58, 237, 0.5);
  background: rgba(124, 58, 237, 0.08);
}

/* The neon-yellow logo washes out on paper — swap to the darkened accent
   (SVG presentation attributes are overridable from CSS). */
html[data-theme="light"] .logo path[stroke="#E5FF00"] { stroke: var(--neon); }
html[data-theme="light"] .logo path[fill="#E5FF00"] { fill: var(--neon); }

/* Theme switch button in the topbar. */
.theme-btn { white-space: nowrap; }

/* ==========================================================================
   v5.39 responsive pass — mobile / tablet / desktop (user request 2026-10-15).
   Desktop (>=1025px) keeps the layout above untouched. Tiers below compress
   the chrome and reflow content to one column on phones. Theme-safe: every
   color comes from the var() tokens, so light mode inherits automatically.
   ========================================================================== */

/* ---- Tablet / small laptop (<=1024px): tighter frame ----------------- */
@media (max-width: 1024px) {
  .view { padding: 18px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .u-email { max-width: 170px; }
}

/* ---- Phone landscape / small tablet (<=640px): one scrollable tab row,
       single-column content, comfortable touch targets ------------------ */
@media (max-width: 640px) {
  /* Header: brand row stays together, tabs drop to a scrollable second row
     (nowrap + overflow-x — the 5 tabs never wrap into ugly stacked lines). */
  .topbar { gap: 8px; padding: 8px 12px 0; flex-wrap: wrap; }
  .brand { border-right: 0; padding: 10px 2px; flex: 1 1 auto; }
  .brand-title { font-size: 11px; letter-spacing: 1.4px; }
  .theme-btn { padding: 7px 10px; font-size: 10.5px; }
  .userchip { border-left: 0; padding: 8px 0; gap: 8px; flex: 0 0 auto; margin-left: auto; }
  .u-email { display: none; } /* role badge + Sign out carry identity on phones */
  .tabs {
    order: 3;
    flex: none; /* wins over base flex:1 so width:100% forces its own row */
    width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-top: 1px solid var(--divider);
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { padding: 13px 12px 12px; font-size: 10.5px; white-space: nowrap; }

  .view { padding: 12px; }
  .grid { grid-template-columns: 1fr; } /* the 340px minmax overflows phones */
  .wiz-grid { grid-template-columns: 1fr; }
  .ctrl-fields { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .ctrl-mos-row { gap: 10px; }
  .soc-ring-row { flex-wrap: wrap; justify-content: center; }
  .view-tabs { flex-wrap: wrap; }
  .view-tab { flex: 1 1 140px; }
  .ctrl-assign { flex-wrap: wrap; }
  .ann-schedule { flex-wrap: wrap; }
  .ann-item { flex-wrap: wrap; }
  .ann-item-actions { width: 100%; justify-content: flex-end; }
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Forms: 16px font stops iOS Safari zoom-on-focus; taller controls tap well. */
  .ctrl-input, .ctrl-select, .search-box, .meta-input {
    padding: 10px 11px;
    font-size: 16px;
  }
  .btn-neon, .btn-ghost { min-height: 42px; }
  .ann-seg-btn { padding: 12px 10px; }

  .signin-card { padding: 30px 18px; }
  .banner { margin: 12px 12px 0; }
  .greeting-line { padding: 8px 12px; font-size: 12.5px; }
}

/* ---- Small phones (<=480px): further compaction ---------------------- */
@media (max-width: 480px) {
  .view { padding: 10px; }
  .view-title { font-size: 16px; }
  .signin-card { padding: 26px 16px; border-radius: 14px; }
  .signin-title { font-size: 26px; }
  .qr-frame svg { width: 132px; height: 132px; }
  .soc-value { font-size: 34px; }
  .soc-ring { width: 112px; height: 112px; }
  .soc-ring .soc-ring-val { font-size: 26px; }
  .metric { padding: 8px; }
  .cell-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
  .ctrl-cells { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  table { font-size: 12.5px; }
  thead th, tbody td { padding: 10px 12px; }
  .empty { padding: 34px 16px; }
}

/* ================= UI/UX round � Phase 1 (PLAN.md 2026-10-25) ================= */

/* P1-2: DANGER tier � destructive actions read as destructive at a glance
   (outlined red surface, not just red text on a ghost button). */
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: rgba(240, 82, 82, 0.10);
  color: var(--red);
  border: 1px solid rgba(240, 82, 82, 0.55);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 8px 13px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn-danger:hover { background: rgba(240, 82, 82, 0.20); border-color: var(--red); }
.btn-danger:disabled { background: var(--card2); border-color: var(--border); color: var(--dim); cursor: default; }

/* P1-1: themed modal � replaces window.confirm / the confirmation half of
   the alert flow. Flat card, hairline border, dim backdrop, no blur. */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(460px, 100%);
  padding: 20px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}
.modal-danger { border-color: rgba(240, 82, 82, 0.55); }
.modal-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--neon);
  margin-bottom: 10px;
}
.modal-danger .modal-title { color: var(--red); }
.modal-body { font-size: 13px; line-height: 1.55; color: var(--text); }
.modal-body p { margin: 0 0 9px; white-space: pre-wrap; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-require {
  display: block;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
}
.modal-require b { color: var(--text); font-family: var(--mono, monospace); }
.modal-input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 13px;
}
.modal-input:focus { outline: none; border-color: var(--neon); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 18px;
}

/* P1-4: hints collapse to two lines with a "more" toggle; expanded state is
   per-hint and survives re-renders only until the next paint (by design �
   the render pass re-wraps fresh nodes). */
.ctrl-hint.clapsible { position: relative; padding-right: 52px; }
.ctrl-hint.clapsible .hint-body {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ctrl-hint.clapsible.open { padding-right: 0; }
.ctrl-hint.clapsible.open .hint-body { display: block; }
.hint-toggle {
  position: absolute;
  right: 0;
  top: -2px;
  background: none;
  border: none;
  color: var(--neon);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 4px;
}
.ctrl-hint.clapsible.open .hint-toggle { top: auto; bottom: -2px; right: 0; }

/* P1-3: SOC preset row inside the voltage-table group. */
.soc-presets {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 2px 0 8px;
}
.soc-presets .preset-label { font-size: 11.5px; color: var(--muted); }
.soc-presets .ctrl-input { max-width: 260px; }

/* ================= UI/UX round � Phase 2 (PLAN.md 2026-10-25) ============== */

/* P2-2: the compact Controls card always shows its quick actions � the head
   no longer collapses (heavy content moved into the Configure panel). */
.ctrl-card .batt-details { display: flex; flex-direction: column; gap: 14px; }
.ctrl-config-cta { margin-top: 12px; }
.ctrl-config-cta .btn-neon { width: 100%; }

/* P2-2: full-screen Configure panel � flat instrument sheet over the page. */
.config-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(4, 6, 10, 0.78);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 24px 16px;
}
.config-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(980px, 100%);
  display: flex;
  flex-direction: column;
  max-height: 100%;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
}
.config-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.config-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--neon);
}
.config-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.config-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 18px 0;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.config-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 8px 10px;
  cursor: pointer;
}
.config-tab:hover { color: var(--text); }
.config-tab.active { color: var(--neon); border-bottom-color: var(--neon); }
.config-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* P2-3: session command history strip under the status line. */
.cmd-history {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card2);
  padding: 10px 12px;
  margin-top: 4px;
}
.cmd-history-title {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 7px;
}
.cmd-hist-row {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  padding: 4px 0;
  font-size: 12px;
}
.cmd-hist-type { color: var(--text); font-weight: 700; }
.cmd-hist-age { color: var(--dim); font-size: 11.5px; }
.cmd-hist-detail { color: var(--muted); font-size: 11.5px; }

/* ============ UI/UX round � Phase 3 / P3-2 responsive pass ================ */

/* Buttons: the plan's floor � nothing tappable goes under 36px tall. */
.btn-neon, .btn-ghost, .btn-danger, .theme-btn, .ann-seg-btn { min-height: 36px; }

/* P3-2: the small-screen nav select (mirrors #tabs) � hidden on desktop. */
.nav-select { display: none; }

@media (max-width: 1024px) {
  /* Tablets: keep the two-up field grid (already set at 1024) � nothing to
     change here beyond the 1024 rules above; this block exists so the three
     planned breakpoints are all present and readable together. */
}

@media (max-width: 768px) {
  /* Nav: the tab row gives way to one select (same sections, same gates). */
  .tabs { display: none; }
  .nav-select {
    display: block;
    order: 3;
    flex: 1 1 100%;
    background: var(--card2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
    padding: 10px 11px;
    min-height: 42px;
  }

  /* Field grids: single column from here down (cell grid keeps its own
     multi-column rule � .ctrl-cells is more specific and stays). */
  .ctrl-fields:not(.ctrl-cells) { grid-template-columns: 1fr; }

  /* Tables (Users, Warranties) become stacked cards � one row per record,
     each cell labelled from its data-label attribute. */
  .table-wrap { overflow: visible; }
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  .table-wrap td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    border: 0;
    padding: 5px 0;
    text-align: right;
  }
  .table-wrap td + td { border-top: 1px dashed var(--divider); }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--dim);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-align: left;
  }
  .table-wrap td:not([data-label])::before { content: none; }
  .table-wrap td[data-label] { text-align: left; }
  .table-wrap .cell-main, .table-wrap .cell-sub { text-align: right; }

  /* Touch comfort: 44px targets from tablet down. */
  .btn-neon, .btn-ghost, .btn-danger { min-height: 44px; }
  .btn-sm { min-height: 40px !important; }
}

/* P3-4: prompt textarea (restore-backup paste box). */
.modal-textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.45;
}

/* ================= Wave 2 (portal ?v=5.72) ============================== */
/* Fleet summary strip — the before-scrolling readout (online/offline, avg
   SOC, open faults, staff-only freshness). Reuses .metric* so it matches
   the expanded cards; auto-fit keeps 4-5 tiles on one row on desktop. */
.fleet-summary {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 10px 0 2px;
}
.fs-staff {
  display: inline-block;
  margin-left: 5px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--dim);
  font-size: 8.5px;
  letter-spacing: 0.5px;
  vertical-align: 1px;
}

/* Map tab — Leaflet (bundled locally), OSM tiles, circleMarker SVG dots. */
.fleet-map {
  height: min(72vh, 620px);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin: 10px 0 14px;
  background: var(--card);
}
.map-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.map-pane { height: 100%; }
.map-pop {
  min-width: 165px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
}
.map-pop strong {
  display: block;
  margin-bottom: 2px;
  color: var(--neon);
  font-size: 13px;
  overflow-wrap: anywhere;
}
/* v5.67: the pack id under the popup's name line — present, readable,
   clearly secondary to the name it identifies. */
.map-pop-id {
  color: var(--muted, #8A93A3);
  font-size: 11px;
  overflow-wrap: anywhere;
  margin-bottom: 4px;
}
/* leaflet.css is appended to <head><meta charset="utf-8"> AFTER this file, so every equal-
   specificity rule here used to lose the cascade — that is what rendered
   the popup solid white while the text kept the dark theme's light colors
   (unreadable). These selectors outrank leaflet.css, so the active theme
   always wins in both light and dark. */
html .leaflet-container {
  background: var(--bg);
  font-family: inherit;
}
.leaflet-container .leaflet-popup-content-wrapper,
.leaflet-container .leaflet-popup-tip {
  background: var(--card2);
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}
.leaflet-container .leaflet-popup-content { margin: 10px 14px; }
.leaflet-popup-close-button { color: var(--muted) !important; }
.leaflet-bar {
  border: 1px solid var(--border) !important;
  box-shadow: none !important;
}
.leaflet-container .leaflet-bar a,
.leaflet-container .leaflet-bar a:hover,
.leaflet-container .leaflet-bar a:focus {
  background: var(--card2);
  color: var(--text);
  border-bottom-color: var(--border);
}
.leaflet-container .leaflet-bar a:hover,
.leaflet-container .leaflet-bar a:focus {
  background: var(--card);
}
.leaflet-container .leaflet-bar a.leaflet-disabled,
.leaflet-container .leaflet-bar a.leaflet-disabled:hover {
  background: var(--card);
  color: var(--dim);
}
html .leaflet-container .leaflet-control-attribution {
  background: rgba(16, 23, 32, 0.82);
  color: var(--muted);
  font-size: 10px;
}
html .leaflet-container .leaflet-control-attribution a { color: var(--muted); }
/* The dark chip above suits paperless mode; on paper the chip flips light
   so the muted link colour keeps its contrast. */
html[data-theme="light"] .leaflet-container .leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
}
html[data-theme="light"] .leaflet-container .leaflet-control-attribution a { color: var(--muted); }

/* ================= Wave 3 (portal ?v=5.72) ============================== */
/* Open-alert banner above the fleet summary strip. Amber by default; red
   when a protection trip or site-leave is among the open rows. */
.alert-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 0;
  padding: 9px 12px;
  border: 1px solid rgba(245, 181, 68, 0.55);
  border-radius: 10px;
  background: rgba(245, 181, 68, 0.10);
  color: var(--text);
  font-size: 12.5px;
}
.alert-banner strong { color: var(--amber); font-size: 14px; }
.alert-banner-icon { color: var(--amber); font-size: 15px; }
.alert-banner > span:nth-child(2) { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alert-banner-red {
  border-color: rgba(255, 90, 90, 0.55);
  background: rgba(255, 90, 90, 0.10);
}
.alert-banner-red .alert-banner-icon,
.alert-banner-red strong { color: var(--red); }

/* Alerts tab — open rows first, then resolved history. */
.alert-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.alert-section-label {
  margin: 6px 0 0;
  color: var(--dim);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.alert-row {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}
.alert-row-open { border-color: rgba(245, 181, 68, 0.5); }
.alert-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.alert-type { font-size: 12.5px; font-weight: 700; color: var(--amber); }
.alert-type-PROTECTION, .alert-type-SITE_LEAVE { color: var(--red); }
.alert-type-OFFLINE { color: var(--muted); }
.alert-row-main { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 5px; }
.alert-pack {
  padding: 0;
  border: 0;
  background: none;
  color: var(--neon);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
.alert-detail { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.alert-row-time { margin-top: 4px; color: var(--dim); font-size: 11.5px; }

/* Geofence site cell-block (expanded battery card). */
.site-line { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.site-state { color: var(--neon); }
.site-state-off { color: var(--dim); }
.site-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.site-hint { color: var(--dim); font-size: 11.5px; }

/* ================= Wave 4 (portal ?v=5.72) ============================== */
/* Per-pack history chart group: range chips (24h / 7d / 30d), metric chips
   (SOC / V / A / W / Ah / °C), fixed-height chart box + export actions. */
.hist-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 8px;
}
.hist-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.hist-chip {
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.hist-chip:hover { border-color: var(--muted); color: var(--text); }
.hist-chip.active {
  border-color: var(--neon);
  color: var(--neon);
  background: rgba(229, 255, 0, 0.10);
}
.hist-chart-box {
  position: relative;
  height: 210px;          /* fixed: Chart.js responsive sizing needs it */
  margin: 2px 0 6px;
}
.hist-canvas { width: 100% !important; height: 100% !important; }
.hist-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  margin-bottom: 8px;
  color: var(--dim);
  font-size: 11px;
}
.hist-hint { color: var(--dim); opacity: 0.8; }

/* ================= Portal ?v=5.72 — live session chart ================= */
/* App SessionChartCard parity: the head dot pulses green while the newest
   point is <= 45 s old (gray = loaded but not updating); the foot legend
   dots carry the dual-axis series colours (SOC neon, current portal purple). */
.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--dim);
  vertical-align: middle;
}
.live-dot.on {
  background: #57E389;
  box-shadow: 0 0 6px rgba(87, 227, 137, 0.8);
  animation: livePulse 1.6s ease-in-out infinite;
}
@keyframes livePulse { 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) {
  .live-dot.on { animation: none; }
}
.live-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.live-key { display: inline-flex; align-items: center; gap: 5px; color: var(--text); }
.live-key-dot { width: 7px; height: 7px; border-radius: 50%; }
.live-key-soc { background: #E5FF00; }
.live-key-cur { background: #9B8CFF; }

/* ================= Wave 7 (portal ?v=5.72) ============================== */
/* Devices panel: badge cluster on the right of a device row, centered
   action row for retry, and the honest-limitation footnote under the list. */
.device-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.devices-actions { display: flex; justify-content: center; margin-top: 8px; }
.devices-note { margin: 10px 0 0; color: var(--dim); font-size: 11.5px; line-height: 1.5; }
