/* DE IoT Dashboard — design system.
   Aesthetic: electric-cyan SCADA / control-room instrumentation. Dark, cool,
   data-dense. Archivo display + IBM Plex Sans body + IBM Plex Mono for all
   telemetry values (device IDs, timestamps, seq, metrics). */

@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
  /* Surfaces — cool slate-black, layered by elevation */
  --bg:        #0b0f14;
  --bg-grid:   rgba(34, 211, 238, 0.035);
  --panel:     #111821;
  --panel-2:   #0d1319;
  --input-bg:  #0a0f15;
  --border:    #1e2a36;
  --border-bright: #2c3f50;

  /* Text */
  --text:  #d6e0ea;
  --muted: #6d8092;
  --faint: #47566380;

  /* Signal accent — electric cyan */
  --accent:      #22d3ee;
  --accent-2:    #38bdf8;
  --accent-dim:  rgba(34, 211, 238, 0.13);
  --accent-line: rgba(34, 211, 238, 0.30);
  --accent-glow: rgba(34, 211, 238, 0.45);
  --accent-ink:  #04141a;         /* dark text on cyan fills */

  /* Status */
  --green: #34d399;
  --red:   #f87171;
  --amber: #fbbf24;
  --green-dim: rgba(52, 211, 153, 0.15);
  --red-dim:   rgba(248, 113, 113, 0.15);

  /* Per-pin signal colors — kept distinct */
  --pin1: #38bdf8;
  --pin2: #fbbf24;
  --pin3: #34d399;
  --pin4: #fb7185;

  /* TAP Controller accent — violet, distinct from the four pin colours */
  --tap:      #c084fc;
  --tap-dim:  rgba(192, 132, 252, 0.16);
  --tap-line: rgba(192, 132, 252, 0.40);

  /* Type */
  --font-display: 'Archivo', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Ambient control-room backdrop: faint engineering grid + a cyan glow bloom.
   Fixed, non-interactive, sits behind everything. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 600px at 12% -8%, rgba(34, 211, 238, 0.07), transparent 60%),
    radial-gradient(700px 500px at 100% 0%, rgba(56, 189, 248, 0.05), transparent 55%),
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 46px 46px, 46px 46px;
}

a { color: inherit; text-decoration: none; }

/* Themed scrollbars — thin, dark, subtle (app-wide) */
* { scrollbar-width: thin; scrollbar-color: var(--border-bright) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #3a5164; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

h1, h2, h3, h4 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
}
h1 { font-size: 22px; }
h2 { font-size: 15px; }

/* ---------- Layout ---------- */

.layout { display: flex; min-height: 100vh; }

.nav {
  width: 214px;
  flex: 0 0 214px;
  background: linear-gradient(180deg, #0e141b, #0b1016);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav-logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  padding: 0 18px 16px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 9px;
}
/* pulsing status LED next to the wordmark */
.nav-logo::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-glow);
  animation: pulse 2.4s ease-out infinite;
}

.nav-links { display: flex; flex-direction: column; gap: 1px; flex: 1; padding: 0 10px; }

.nav-link {
  display: block;
  padding: 9px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: color .14s, background .14s, border-color .14s;
}
.nav-link:hover { color: var(--text); background: rgba(255, 255, 255, 0.035); }
.nav-link.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

.nav-footer { padding: 14px 14px 0; margin-top: 10px; border-top: 1px solid var(--border); }
/* User card: avatar + email + role badge in a bordered chip */
.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}
.nav-avatar {
  width: 34px; height: 34px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent-line);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}
.nav-user-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.nav-user-email {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  line-height: 1.3;
  word-break: break-word;
}
.nav-footer .btn { width: 100%; justify-content: center; }

.content {
  flex: 1;
  padding: 26px 28px;
  min-width: 0;
  animation: rise .4s ease-out both;
}

/* Responsive: sidebar → top bar under 800px */
@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .nav {
    width: 100%; flex: 0 0 auto; height: auto; position: static;
    flex-direction: row; align-items: center; padding: 8px 12px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .nav-logo { padding: 0 12px 0 0; border-bottom: none; margin-bottom: 0; }
  .nav-links { flex-direction: row; flex-wrap: wrap; flex: 1; padding: 0 8px; }
  .nav-link { border-left: none; border-bottom: 2px solid transparent; padding: 6px 10px; }
  .nav-link.active { border-left-color: transparent; border-bottom-color: var(--accent); }
  .nav-footer { border-top: none; margin-top: 0; padding: 0 0 0 12px; display: flex; align-items: center; gap: 10px; }
  .nav-user { margin-bottom: 0; }
  .content { padding: 16px; }
}

/* ---------- Toolbar (page header row) ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.toolbar h1 { margin: 0; }

/* ---------- Panels / cards ---------- */

.panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 40%),
    var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel > h2:first-child, .panel > h1:first-child { margin-top: 0; }

/* subtle section label */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Live device cards (full-width, self-contained) ---------- */
.card-stack { display: flex; flex-direction: column; gap: 16px; }
.device-card { margin: 0; padding: 0; overflow: hidden; }
/* Offline unit: muted so live cards stand out; badge stays full-strength. */
.device-card.card-offline { opacity: .62; }
.device-card.card-offline .card-badge { opacity: 1; }

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.04), transparent);
}
.card-uid { font-family: var(--font-mono); font-weight: 600; font-size: 15px; color: var(--text); letter-spacing: -0.01em; }
.card-name { color: var(--muted); font-size: 13px; }
.card-badge { margin-left: auto; }
.chip {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  letter-spacing: 0.04em;
}

.pin-bank { padding: 16px 18px; }
.pin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 11px; }
.pin-tile {
  position: relative;
  padding: 12px 13px 13px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--pin-color, var(--accent));
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.pin-tile[data-pin="1"] { --pin-color: var(--pin1); }
.pin-tile[data-pin="2"] { --pin-color: var(--pin2); }
.pin-tile[data-pin="3"] { --pin-color: var(--pin3); }
.pin-tile[data-pin="4"] { --pin-color: var(--pin4); }
/* faint pin-tinted glow bloom in the corner */
.pin-tile::after {
  content: '';
  position: absolute; top: -30px; right: -30px;
  width: 70px; height: 70px; border-radius: 50%;
  background: radial-gradient(circle, var(--pin-color), transparent 70%);
  opacity: 0.10; pointer-events: none;
}
.pin-label { font-family: var(--font-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.09em; }
.pin-state {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0.01em;
  color: var(--muted);
}
.pin-state.hi { color: var(--green); text-shadow: 0 0 14px rgba(52, 211, 153, 0.35); }
.pin-state.lo { color: var(--muted); }
/* Global active-level labelling: ACTIVE = strong attention, IDLE = muted. */
.pin-state.active { color: var(--amber); text-shadow: 0 0 16px rgba(251, 191, 36, 0.4); }
.pin-state.idle { color: var(--muted); }
.pin-dur { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }

/* Per-device metrics strip */
.card-metrics {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 14px;
}
.metric {
  display: flex; flex-direction: column; gap: 1px;
  padding: 7px 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 74px;
}
.metric-k { font-family: var(--font-mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.metric-v { font-family: var(--font-mono); font-size: 13px; color: var(--text); }

/* Per-device live event log — full-width, collapsible (replaces old ticker) */
.card-log {
  border-top: 1px solid var(--border);
  background: var(--panel-2);
}
.card-log-head {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  background: transparent; border: none; cursor: pointer;
  font-family: var(--font-mono);
  color: var(--muted);
  text-align: left;
}
.card-log-head:hover { color: var(--text); background: rgba(34, 211, 238, 0.04); }
.card-log-title {
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
}
.card-log-count {
  font-size: 10.5px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  padding: 1px 8px;
}
.card-log-chev {
  margin-left: auto;
  font-size: 12px;
  transition: transform .22s ease;
}
.card-log:not(.collapsed) .card-log-chev { transform: rotate(90deg); }
.card-log-rows {
  overflow: hidden;
  max-height: 0;
  transition: max-height .28s ease;
  padding: 0 18px;
  font-family: var(--font-mono); font-size: 12px;
}
.card-log:not(.collapsed) .card-log-rows {
  max-height: 340px;
  overflow-y: auto;
  padding-bottom: 12px;
}
.log-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px; align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid rgba(30, 42, 54, 0.5);
}
.log-row:last-child { border-bottom: none; }
.log-time { color: var(--muted); }
.log-pin { color: var(--pin-color, var(--text)); }
.log-pin[data-pin="1"] { --pin-color: var(--pin1); }
.log-pin[data-pin="2"] { --pin-color: var(--pin2); }
.log-pin[data-pin="3"] { --pin-color: var(--pin3); }
.log-pin[data-pin="4"] { --pin-color: var(--pin4); }
.log-edge { text-align: right; }
.log-edge.hi { color: var(--green); }
.log-edge.lo { color: var(--muted); }
.log-edge.active { color: var(--amber); font-weight: 600; }
.log-edge.idle { color: var(--muted); }
.log-empty { color: var(--faint); font-size: 12px; }
@keyframes logflash { from { background: var(--accent-dim); } to { background: transparent; } }
.log-row.new { animation: logflash 1s ease-out; }

/* ---------- TAP Controller card (Live + device detail) ---------- */
.tap-bank { padding: 16px 18px; }
/* Live cards nest .tap-bank inside the already-padded .pin-bank. */
.pin-bank > .tap-bank { padding: 0; }
.tap-main { display: flex; align-items: center; gap: 20px; margin-bottom: 14px; }
.tap-pos {
  font-family: var(--font-display); font-weight: 800; font-size: 56px; line-height: 1;
  min-width: 84px; text-align: center; color: var(--tap);
  text-shadow: 0 0 22px var(--tap-line);
}
.tap-pos.unknown { color: var(--red); text-shadow: 0 0 18px rgba(248, 113, 113, 0.4); }
.tap-pos.nodata { color: var(--muted); text-shadow: none; }
.tap-pos.flash { animation: tapflash .8s ease-out; }
@keyframes tapflash { from { transform: scale(1.12); } to { transform: scale(1); } }
.tap-meta { display: flex; flex-direction: column; gap: 6px; }
.tap-label { font-family: var(--font-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.09em; }
.tap-since { font-size: 11.5px; color: var(--muted); }
.tap-strip { display: grid; grid-template-columns: repeat(17, 1fr); gap: 4px; }
.tap-cell {
  font-family: var(--font-mono); font-size: 11px; text-align: center; padding: 6px 0;
  border: 1px solid var(--border); border-radius: 4px; color: var(--muted); background: var(--panel-2);
}
.tap-cell.on { background: var(--tap); color: #0b1118; font-weight: 700; border-color: var(--tap); box-shadow: 0 0 12px var(--tap-line); }
.tap-log-move { color: var(--tap); font-weight: 600; }
.tap-move strong { color: var(--tap); }
@media (max-width: 640px) { .tap-strip { grid-template-columns: repeat(9, 1fr); } }

/* ---------- TAP Controller stats ---------- */
.tap-stats-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tap-stats-panel { margin-bottom: 12px; }
.tap-bar-row { display: grid; grid-template-columns: 28px 1fr 170px; gap: 10px; align-items: center; padding: 3px 0; }
.tap-bar-label { color: var(--muted); font-size: 11px; text-align: right; }
.tap-bar-track { height: 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.tap-bar { height: 100%; background: var(--tap); border-radius: 999px; }
.tap-bar-val { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tap-cols { display: flex; gap: 6px; align-items: stretch; height: 150px; overflow-x: auto; padding-bottom: 4px; }
.tap-col { flex: 1 0 30px; display: flex; flex-direction: column; align-items: center; min-width: 30px; }
.tap-col-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.tap-col-bar { width: 100%; background: var(--tap); border-radius: 3px 3px 0 0; }
.tap-col-n { font-size: 10px; color: var(--text); height: 14px; margin-top: 2px; }
.tap-col-label { font-size: 9.5px; color: var(--muted); }
@media (max-width: 640px) { .tap-bar-row { grid-template-columns: 24px 1fr 110px; } }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  color: var(--muted);
  text-transform: uppercase;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  font-weight: 500;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

/* Sortable column headers (Events → Activations: Started/Ended) */
.th-sort {
  cursor: pointer;
  user-select: none;
}
.th-sort:hover { color: var(--text); }
.sort-arr {
  font-size: 9px;
  color: var(--muted);
  opacity: 0.55;
}
.sort-arr-active {
  color: var(--accent);
  opacity: 1;
  font-size: 10px;
}

td {
  font-size: 13px;
  padding: 9px 12px;
  border-bottom: 1px solid rgba(30, 42, 54, 0.6);
  vertical-align: middle;
}
/* numeric/id data reads as mono */
td.mono, .mono { font-family: var(--font-mono); }

tbody tr { transition: background .1s; }
tbody tr:hover { background: rgba(34, 211, 238, 0.05); }

/* ---------- Badges ---------- */
.badge-on, .badge-off, .badge-neutral, .badge-active {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
}
.badge-on::before, .badge-off::before, .badge-neutral::before, .badge-active::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
/* ACTIVE edge (global active-level labelling) — amber, attention-grabbing */
.badge-active { background: rgba(251, 191, 36, 0.16); color: var(--amber); border-color: rgba(251, 191, 36, 0.38); }
.badge-active::before { box-shadow: 0 0 6px currentColor; }
.badge-on {
  background: var(--green-dim); color: var(--green); border-color: rgba(52, 211, 153, 0.3);
}
.badge-on::before { box-shadow: 0 0 6px currentColor; }
.badge-off { background: var(--red-dim); color: var(--red); border-color: rgba(248, 113, 113, 0.28); }
.badge-neutral { background: rgba(109, 128, 146, 0.14); color: var(--muted); border-color: var(--border); }
.badge-type { margin-left: 6px; font-size: 10px; letter-spacing: 0.08em; vertical-align: 1px; }

/* Role badges — superadmin amber, admin cyan, viewer grey (nav footer + Users) */
.role-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  vertical-align: middle;
}
.role-superadmin { background: rgba(251, 191, 36, 0.15); color: var(--amber); border-color: rgba(251, 191, 36, 0.4); }
.role-admin { background: var(--accent-dim); color: var(--accent); border-color: var(--accent-line); }
.role-viewer { background: rgba(109, 128, 146, 0.14); color: var(--muted); border-color: var(--border); }

/* Role badges: superadmin = amber, admin = cyan, viewer = grey */
.role-badge { display:inline-block; font-family:var(--font-mono); font-size:10px; font-weight:500; text-transform:uppercase; letter-spacing:.05em; padding:2px 8px; border-radius:999px; border:1px solid transparent; }
.role-superadmin { background:rgba(251,191,36,.15); color:var(--amber); border-color:rgba(251,191,36,.4); }
.role-admin { background:var(--accent-dim); color:var(--accent); border-color:var(--accent-line); }
.role-viewer { background:rgba(109,128,146,.14); color:var(--muted); border-color:var(--border); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #16202b;
  color: var(--text);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .13s, border-color .13s, box-shadow .13s, transform .05s;
}
.btn:hover { background: #1c2836; border-color: var(--accent-line); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: #16202b; border-color: var(--border-bright); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover {
  background: #4ee0f5;
  border-color: #4ee0f5;
  box-shadow: 0 0 0 1px var(--accent-line), 0 4px 16px var(--accent-dim);
}

.btn-danger { background: transparent; border-color: rgba(248, 113, 113, 0.5); color: var(--red); }
.btn-danger:hover { background: var(--red-dim); border-color: var(--red); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---------- Inputs ---------- */
input, select, textarea {
  background: var(--input-bg);
  border: 1px solid var(--border-bright);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-family: var(--font-body);
  font-size: 13px;
  transition: border-color .13s, box-shadow .13s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder { color: var(--faint); }

/* Date/time inputs: render the native control (text, spinners, picker popup) in
   dark so it matches the field instead of the browser's default light chrome. */
input[type="date"], input[type="datetime-local"], input[type="time"], input[type="month"] {
  color-scheme: dark;
}
/* Dim + clickable calendar icon so it reads on the dark field. */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
  opacity: 0.7;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }

/* Native <select> → themed: strip OS chrome, custom cyan-muted chevron */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 30px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236d8092' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}
select:hover { border-color: var(--accent-line); }
select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2322d3ee' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
/* Themed option list where the browser honours it (Chrome/Firefox) */
select option { background: var(--panel); color: var(--text); }

/* Strip the ugly OS spinner arrows on number inputs */
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Themed checkbox + radio */
input[type="checkbox"], input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 18px !important; height: 18px !important;
  min-width: 18px;
  padding: 0; margin: 0;
  flex: none;
  vertical-align: middle;
  background: var(--input-bg);
  border: 1px solid var(--border-bright);
  cursor: pointer;
  position: relative;
  transition: background .13s, border-color .13s, box-shadow .13s;
}
input[type="checkbox"] { border-radius: 5px; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--accent-line); }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--accent-dim);
}
input[type="checkbox"]:checked, input[type="radio"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute; left: 5px; top: 1.5px;
  width: 5px; height: 9px;
  border: solid var(--accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="radio"]:checked::after {
  content: '';
  position: absolute; inset: 4px;
  border-radius: 50%;
  background: var(--accent-ink);
}

/* ---------- Pin chip (inline color key) ---------- */
.pin-chip {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: middle;
  box-shadow: 0 0 5px currentColor;
}
.pin-chip.pin-1 { background: var(--pin1); color: var(--pin1); }
.pin-chip.pin-2 { background: var(--pin2); color: var(--pin2); }
.pin-chip.pin-3 { background: var(--pin3); color: var(--pin3); }
.pin-chip.pin-4 { background: var(--pin4); color: var(--pin4); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(4, 8, 12, 0.72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fade .15s ease-out;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 22px;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  animation: rise .2s ease-out;
}

/* ---------- Row flash (live edge) ---------- */
@keyframes flash {
  0% { background: var(--accent-dim); box-shadow: inset 3px 0 0 var(--accent); }
  100% { background: transparent; box-shadow: inset 3px 0 0 transparent; }
}
.flash { animation: flash 0.9s ease-out; }

/* ---------- Keyframes ---------- */
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent-glow); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.login-card { width: 100%; max-width: 360px; position: relative; overflow: hidden; }
/* cyan scanline across the card top */
.login-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.login-logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.01em;
  margin-bottom: 4px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
}
.login-logo::before {
  content: '';
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-glow);
  animation: pulse 2.4s ease-out infinite;
}
.login-sub {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 22px;
}
.login-field { margin-bottom: 14px; }
.login-field input { width: 100%; }
.login-error { color: var(--red); font-size: 12px; min-height: 16px; margin-bottom: 10px; font-family: var(--font-mono); }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
.shake { animation: shake 0.4s ease-in-out; }

/* ---------- Toasts ---------- */
#toast-area {
  position: fixed;
  bottom: 22px; right: 22px;
  display: flex; flex-direction: column; gap: 9px;
  z-index: 1000; max-width: 380px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
  word-break: break-word;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ---------- Kebab / row menu ---------- */
.btn-menu {
  padding: 2px 10px; font-size: 18px; line-height: 1;
  background: transparent; border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm); color: var(--muted); cursor: pointer;
}
.btn-menu:hover { background: rgba(34, 211, 238, 0.06); color: var(--text); border-color: var(--accent-line); }
.row-menu {
  position: absolute; right: 8px; top: 100%; z-index: 500;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  text-align: left;
}
.row-menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; font-size: 12.5px;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text); cursor: pointer; font-family: var(--font-body);
}
.row-menu button:hover { background: rgba(34, 211, 238, 0.07); }
.row-menu button.danger { color: var(--red); }
.row-menu button.danger:hover { background: var(--red-dim); }

/* ---------- Connection-lost banner (floating pill, top-center) ---------- */
.conn-banner {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 3000;
  display: flex; align-items: center; gap: 9px;
  padding: 8px 16px;
  background: rgba(17, 24, 33, 0.96);
  border: 1px solid var(--amber);
  border-radius: 999px;
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 12px; letter-spacing: 0.03em;
  box-shadow: var(--shadow-lg);
  animation: rise .2s ease-out;
}
.conn-banner::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--amber);
  animation: blink 1.1s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- Reusable modal (ui.js confirmDialog / promptDialog) ---------- */
.ui-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(4, 8, 12, 0.66);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade .14s ease-out;
}
.ui-modal {
  width: 100%; max-width: 420px;
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 40%), var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 22px;
  animation: rise .18s ease-out;
}
.ui-modal::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.ui-modal-title { font-family: var(--font-display); font-weight: 700; font-size: 16px; margin-bottom: 10px; }
.ui-modal-body { color: var(--muted); font-size: 13.5px; line-height: 1.55; margin-bottom: 18px; }
.ui-modal-input { width: 100%; margin-bottom: 18px; }
.ui-modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Reusable anchored menu (ui.js openMenu) ---------- */
.ui-menu {
  position: fixed; z-index: 2100;
  min-width: 210px;
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  animation: rise .12s ease-out;
}
.ui-menu-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 11px;
  font-size: 12.5px; font-family: var(--font-body);
  background: transparent; border: none; border-radius: 6px;
  color: var(--text); cursor: pointer;
}
.ui-menu-item:hover { background: rgba(34, 211, 238, 0.08); }
.ui-menu-item.danger { color: var(--red); }
.ui-menu-item.danger:hover { background: var(--red-dim); }
.ui-menu-item:disabled { color: var(--faint); cursor: default; background: transparent; }

/* device-detail link (device UID cell in the Devices table) */
.dev-link { color: var(--accent); transition: color .12s; }
.dev-link:hover { color: #4ee0f5; text-decoration: underline; }

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.u-muted { color: var(--muted); }
.u-mono { font-family: var(--font-mono); }
.u-right { text-align: right; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
