:root {
  --bg: #080c10;
  --bg-2: #0d1219;
  --bg-3: #131b24;
  --bg-4: #1a2332;
  --border: #1e2d3d;
  --border-2: #253545;
  --text: #d4e0ec;
  --text-2: #7a97b3;
  --text-3: #4a637a;
  --accent: #00d4ff;
  --accent-dim: rgba(0,212,255,.12);
  --accent-2: #0099cc;
  --green: #00e676;
  --green-dim: rgba(0,230,118,.12);
  --amber: #ffb300;
  --amber-dim: rgba(255,179,0,.12);
  --red: #ff3d57;
  --red-dim: rgba(255,61,87,.12);
  --purple: #a259ff;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  --transition: 0.18s ease;
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.mono { font-family: 'Space Mono', monospace; }
.text-2 { color: var(--text-2); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.full-width { width: 100%; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Login ── */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 1000;
}
.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  margin-bottom: 36px;
}
.login-logo h1 {
  font-family: 'Space Mono', monospace;
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 2px;
  margin: 12px 0 4px;
}
.login-logo p { color: var(--text-2); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
.logo-mark {
  font-size: 48px;
  color: var(--accent);
  line-height: 1;
  animation: pulse-glow 3s ease-in-out infinite;
}
.logo-mark.small { font-size: 22px; color: var(--accent); }
@keyframes pulse-glow {
  0%,100% { text-shadow: 0 0 10px var(--accent), 0 0 20px var(--accent); opacity: 1; }
  50% { text-shadow: 0 0 20px var(--accent), 0 0 40px var(--accent); opacity: .85; }
}

/* ── Forms ── */
.field-group { margin-bottom: 16px; }
.field-group label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-2); margin-bottom: 6px; }
.field-group input, .field-group select, .field-group textarea {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}
.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,212,255,.08);
}
.field-group textarea { resize: vertical; min-height: 70px; }
.field-group select option { background: var(--bg-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.error-msg { color: var(--red); font-size: 12px; padding: 8px 12px; background: var(--red-dim); border-radius: var(--radius); margin-bottom: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #33ddff; box-shadow: 0 0 12px rgba(0,212,255,.3); }
.btn-secondary { background: var(--bg-4); color: var(--text); border-color: var(--border-2); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--red-dim); color: var(--red); border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { background: none; border: none; color: var(--text-2); cursor: pointer; padding: 6px; border-radius: var(--radius); font-size: 16px; transition: color var(--transition); display: flex; align-items: center; }
.btn-icon:hover { color: var(--text); }

/* ── App Shell ── */
.app-shell { display: flex; height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}
.logo-text { font-family: 'Space Mono', monospace; font-size: 13px; color: var(--accent); letter-spacing: 1px; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.live-indicator { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-3); }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3);
  transition: background var(--transition);
}
.live-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); animation: blink 2s ease-in-out infinite; }
.live-dot.error { background: var(--red); }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ── Main ── */
#app { display: flex; width: 100%; }
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.topbar h2 { font-size: 15px; font-weight: 600; }
#user-badge { font-size: 12px; color: var(--text-2); }
.page { display: none; flex: 1; overflow-y: auto; padding: 24px; }
.page.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-2); font-weight: 600; }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.stat-card.blue::before { background: var(--accent); }
.stat-card.green::before { background: var(--green); }
.stat-card.amber::before { background: var(--amber); }
.stat-card.red::before { background: var(--red); }
.stat-card.purple::before { background: var(--purple); }
.stat-value { font-family: 'Space Mono', monospace; font-size: 32px; font-weight: 700; line-height: 1; margin: 8px 0 4px; }
.stat-card.blue .stat-value { color: var(--accent); }
.stat-card.green .stat-value { color: var(--green); }
.stat-card.amber .stat-value { color: var(--amber); }
.stat-card.red .stat-value { color: var(--red); }
.stat-card.purple .stat-value { color: var(--purple); }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-2); }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border-2); }
thead th { padding: 10px 12px; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-3); font-weight: 600; }
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:hover { background: var(--bg-3); }
tbody td { padding: 12px 12px; font-size: 13px; vertical-align: middle; }
tbody td:last-child { white-space: nowrap; }

/* ── Status Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-online { background: var(--green-dim); color: var(--green); }
.badge-offline { background: var(--bg-4); color: var(--text-3); }
.badge-unknown { background: var(--bg-4); color: var(--text-3); }
.badge-alert { background: var(--amber-dim); color: var(--amber); }
.badge-admin { background: rgba(162,89,255,.12); color: var(--purple); }
.badge-manager { background: var(--accent-dim); color: var(--accent); }
.badge-type { background: var(--bg-4); color: var(--text-2); font-size: 10px; }

/* ── Page toolbar ── */
.page-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.toolbar-filters { display: flex; gap: 8px; align-items: center; }
.filter-select {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-2);
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--accent); color: var(--text); }

/* ── Map ── */
.map-container { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.location-map { height: 480px; }
#page-map .location-map { height: calc(100vh - 180px); }
.leaflet-container { background: #0a1520 !important; }
.leaflet-tile { filter: brightness(.7) saturate(.6) hue-rotate(200deg); }
.map-toolbar { padding: 12px 16px; background: var(--bg-3); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.map-toolbar select { background: var(--bg-4); border: 1px solid var(--border-2); color: var(--text); padding: 6px 10px; border-radius: var(--radius); font-family: inherit; font-size: 13px; outline: none; cursor: pointer; min-width: 200px; }

/* ── Map markers ── */
.map-marker-gw, .map-marker-dev {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 16px;
  border: 2px solid;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  transition: transform .2s;
  cursor: pointer;
}
.map-marker-gw { width: 36px; height: 36px; background: var(--accent-dim); border-color: var(--accent); }
.map-marker-dev { width: 30px; height: 30px; background: var(--bg-3); border-color: var(--border-2); }
.map-marker-dev.online { border-color: var(--green); background: var(--green-dim); }
.map-marker-dev.alert { border-color: var(--amber); background: var(--amber-dim); animation: pulse-amber 1.5s ease-in-out infinite; }
.map-marker-dev.offline { border-color: var(--text-3); opacity: .6; }
@keyframes pulse-amber { 0%,100% { box-shadow: 0 0 0 0 rgba(255,179,0,.4); } 50% { box-shadow: 0 0 0 8px rgba(255,179,0,0); } }

/* ── Popup / Info box ── */
.leaflet-popup-content-wrapper {
  background: var(--bg-3) !important;
  border: 1px solid var(--border-2) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow) !important;
  color: var(--text) !important;
  padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; padding: 0 !important; }
.leaflet-popup-tip { background: var(--border-2) !important; }
.leaflet-popup-close-button { color: var(--text-2) !important; top: 8px !important; right: 8px !important; }
.info-popup { padding: 16px; min-width: 220px; }
.info-popup h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.info-popup .eui { font-family: 'Space Mono', monospace; font-size: 10px; color: var(--text-3); margin-bottom: 12px; }
.info-reading { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.info-reading:last-child { border-bottom: none; }
.info-reading .val { font-family: 'Space Mono', monospace; color: var(--accent); }

/* ── Dashboard ── */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dash-grid .full { grid-column: 1 / -1; }
.recent-readings { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.reading-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--bg-3);
  border-radius: var(--radius);
  border-left: 2px solid var(--border-2);
  transition: border-color var(--transition);
}
.reading-row.new { border-left-color: var(--accent); animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.reading-icon { font-size: 18px; width: 28px; text-align: center; }
.reading-info { flex: 1; }
.reading-device { font-size: 13px; font-weight: 500; }
.reading-values { font-size: 11px; color: var(--text-2); font-family: 'Space Mono', monospace; }
.reading-time { font-size: 11px; color: var(--text-3); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 16px; padding: 4px; border-radius: var(--radius); }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px; }

/* ── QR Modal ── */
.qr-container { text-align: center; padding: 16px 0; }
.qr-container img { max-width: 200px; border-radius: var(--radius); background: #fff; padding: 8px; }
.qr-url { font-family: 'Space Mono', monospace; font-size: 11px; color: var(--text-2); word-break: break-all; margin-top: 12px; padding: 8px; background: var(--bg-3); border-radius: var(--radius); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn .2s ease;
  max-width: 320px;
  display: flex; align-items: center; gap: 8px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Map coord picker ── */
.coord-row { display: flex; gap: 8px; align-items: flex-end; }
.coord-row .field-group { flex: 1; margin-bottom: 0; }
.coord-row .btn { flex-shrink: 0; margin-bottom: 0; }
.coord-picker-map { height: 220px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-2); margin-top: 8px; }

/* ── Device type icons ── */
.device-icon-air_quality::before { content: '💨'; }
.device-icon-temperature::before { content: '🌡️'; }
.device-icon-door_sensor::before { content: '🚪'; }
.device-icon-mousetrap::before { content: '🪤'; }
.device-icon-humidity::before { content: '💧'; }
.device-icon-motion::before { content: '🔵'; }
.device-icon-other::before { content: '📡'; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .dash-grid .full { grid-column: 1; }
}
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .page { padding: 16px; }
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px; color: var(--text-3); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ── Alert device pulse in table ── */
tr.device-alert td:first-child { position: relative; }
.alert-pulse {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--amber); margin-right: 6px;
  animation: pulse-amber 1.5s ease-in-out infinite;
}

/* ══════════════════════════════════════════════════════════
   DEVICE READING CARDS — graphics, battery, signal
   ══════════════════════════════════════════════════════════ */

/* ── Device card grid ── */
.device-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
  position: relative;
}
.device-card:hover { border-color: var(--border-2); box-shadow: 0 4px 20px rgba(0,0,0,.3); }
.device-card.alert { border-color: var(--amber); }
.device-card.alert::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--amber);
  animation: blink 1.5s ease-in-out infinite;
}

.device-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.device-card-title {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
}
.device-card-icon { font-size: 20px; flex-shrink: 0; }
.device-card-name { font-size: 13px; font-weight: 600; truncate: true; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-card-sub  { font-size: 10px; color: var(--text-3); }
.device-card-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Battery indicator ── */
.battery-indicator {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px;
  font-family: 'Space Mono', monospace;
}
.battery-icon {
  position: relative;
  width: 22px; height: 11px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}
.battery-icon::after {
  content: '';
  position: absolute;
  right: -5px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 5px;
  background: currentColor;
  border-radius: 0 1px 1px 0;
}
.battery-fill {
  position: absolute;
  left: 1px; top: 1px; bottom: 1px;
  border-radius: 1px;
  transition: width .5s ease, background .5s ease;
}
.battery-indicator.high  { color: var(--green); }
.battery-indicator.high  .battery-fill { background: var(--green); }
.battery-indicator.mid   { color: var(--amber); }
.battery-indicator.mid   .battery-fill { background: var(--amber); }
.battery-indicator.low   { color: var(--red); animation: blink 1.5s ease-in-out infinite; }
.battery-indicator.low   .battery-fill { background: var(--red); }
.battery-indicator.none  { color: var(--text-3); }

/* ── Signal / RSSI indicator ── */
.signal-indicator {
  display: flex; align-items: flex-end; gap: 2px;
  height: 14px;
}
.signal-bar {
  width: 4px;
  border-radius: 1px 1px 0 0;
  background: var(--border-2);
  transition: background .4s;
}
.signal-bar.b1 { height: 30%; }
.signal-bar.b2 { height: 55%; }
.signal-bar.b3 { height: 75%; }
.signal-bar.b4 { height: 100%; }
.signal-bar.active.strong { background: var(--green); }
.signal-bar.active.good   { background: var(--accent); }
.signal-bar.active.fair   { background: var(--amber); }
.signal-bar.active.weak   { background: var(--red); }

/* ── Reading values area ── */
.device-card-body { padding: 14px 16px; }

.reading-primary {
  display: flex; align-items: baseline; gap: 6px;
  margin-bottom: 10px;
}
.reading-primary-val {
  font-family: 'Space Mono', monospace;
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}
.reading-primary-unit {
  font-size: 14px;
  color: var(--text-2);
}
.reading-primary-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin-top: 2px;
}

.reading-secondary {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.reading-secondary-item {
  display: flex; flex-direction: column;
}
.reading-secondary-val  { font-family: 'Space Mono', monospace; font-size: 15px; color: var(--text); }
.reading-secondary-label{ font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-3); }

/* ── Sparkline chart ── */
.sparkline-wrap {
  margin-top: 8px;
  height: 44px;
  position: relative;
}
.sparkline-wrap canvas { width: 100% !important; }

/* ── Boolean / state readings ── */
.state-display {
  display: flex; align-items: center; justify-content: center;
  padding: 20px 0 10px;
  flex-direction: column; gap: 6px;
}
.state-icon-large { font-size: 40px; line-height: 1; }
.state-label-large {
  font-size: 16px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px;
}
.state-open     { color: var(--amber); }
.state-closed   { color: var(--green); }
.state-triggered{ color: var(--red); }
.state-clear    { color: var(--green); }

/* ── Card footer ── */
.device-card-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-3);
}
.card-footer-time { font-size: 10px; color: var(--text-3); }
.card-footer-gw   { font-size: 10px; color: var(--text-3); font-family: 'Space Mono', monospace; }

/* ── Dashboard live feed updated ── */
.reading-row { gap: 10px; }
.reading-row-signals { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Gauge SVG styling ── */
.gauge-wrap { display: flex; justify-content: center; margin: 4px 0 8px; }
.gauge-wrap svg text { font-family: 'Space Mono', monospace; }

/* ── History chart in popup ── */
.history-chart-wrap {
  height: 160px;
  margin-top: 12px;
  background: var(--bg-3);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 8px;
}

/* ── Nav badge ── */
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  animation: blink 2s ease-in-out infinite;
}

/* ── Alert severity ── */
.severity-critical { color: var(--red);    }
.severity-warning  { color: var(--amber);  }
.severity-info     { color: var(--accent); }

.alert-row-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  gap: 0 14px;
  align-items: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.alert-row-card:hover { border-color: var(--border-2); background: var(--bg-3); }
.alert-row-card.critical { border-left: 3px solid var(--red); }
.alert-row-card.warning  { border-left: 3px solid var(--amber); }
.alert-row-card.info     { border-left: 3px solid var(--accent); }

.alert-icon-cell  { font-size: 20px; text-align: center; }
.alert-body       { min-width: 0; }
.alert-title      { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-subtitle   { font-size: 11px; color: var(--text-2); }
.alert-value-cell { text-align: right; }
.alert-value      { font-family: 'Space Mono', monospace; font-size: 14px; font-weight: 700; }
.alert-time-cell  { text-align: right; white-space: nowrap; }
.alert-time       { font-size: 11px; color: var(--text-3); }
.alert-loc        { font-size: 10px; color: var(--text-3); }

.alerts-list { display: flex; flex-direction: column; gap: 6px; }

/* ── Readings search page ── */
.search-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}
.search-bar .field-group { margin-bottom: 0; flex: 1; min-width: 140px; }
.search-bar .btn { flex-shrink: 0; align-self: flex-end; }

.pagination {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 16px 0 4px;
  font-size: 13px; color: var(--text-2);
}
.pagination .btn { min-width: 36px; }

/* ── Device detail page ── */
.detail-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; gap: 16px;
}
.detail-title-row { display: flex; align-items: center; gap: 12px; }
.detail-icon { font-size: 32px; }
.detail-name { font-size: 20px; font-weight: 700; }
.detail-meta { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.detail-stats { display: flex; gap: 12px; flex-wrap: wrap; }
.detail-stat {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  text-align: center; min-width: 80px;
}
.detail-stat-val   { font-family: 'Space Mono', monospace; font-size: 18px; font-weight: 700; }
.detail-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-3); }

.detail-chart-wrap {
  height: 220px; margin-bottom: 4px;
}
.detail-chart-tabs {
  display: flex; gap: 4px; margin-bottom: 12px;
}
.chart-tab {
  padding: 5px 12px; border-radius: var(--radius);
  font-size: 12px; cursor: pointer; border: 1px solid var(--border-2);
  background: var(--bg-3); color: var(--text-2); transition: all var(--transition);
}
.chart-tab.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* ── Reading detail modal ── */
.reading-detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;
}
.reading-detail-item {
  background: var(--bg-3); border-radius: var(--radius);
  padding: 10px 14px;
}
.reading-detail-label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-3); }
.reading-detail-val   { font-family: 'Space Mono', monospace; font-size: 16px; font-weight: 700; color: var(--text); margin-top: 2px; }

.raw-payload-box {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  font-family: 'Space Mono', monospace; font-size: 11px;
  color: var(--text-2); word-break: break-all; margin-top: 8px;
  max-height: 100px; overflow-y: auto;
}
