/* ===========================================================
   Device Dashboard — end-user live status view
   Pairs with portal/device-dashboard.html + assets/device-dashboard.js
   Inherits tokens from marketing.css + structure from device-builder.css.
   =========================================================== */

.dash-page {
  background: var(--color-bg-alt);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ---------- Slim toolbar (device picker + connection) ---------- */
.dash-toolbar {
  background: white;
  border-bottom: 1px solid var(--color-border);
  padding: 10px 24px;
}
.dash-toolbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.dash-toolbar .spacer { flex: 1; }
.dash-toolbar .device-picker {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 6px 4px 12px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 999px;
}
.dash-toolbar .device-picker label {
  font-size: 12px; color: var(--color-text-light); font-weight: 500;
}
.dash-toolbar .device-picker select {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-dark);
  padding: 4px 6px;
  cursor: pointer;
  outline: none;
  max-width: 240px;
}
.dash-toolbar .pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--color-bg-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.dash-toolbar .pill::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: #94a3b8;
}
.dash-toolbar .pill.ok    { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.dash-toolbar .pill.ok::before    { background: #10b981; }
.dash-toolbar .pill.warn  { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.dash-toolbar .pill.warn::before  { background: #f59e0b; }
.dash-toolbar .pill.err   { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.dash-toolbar .pill.err::before   { background: #ef4444; }
.dash-toolbar .pill.pill-viewers {
  background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe;
  font-variant-numeric: tabular-nums;
}
.dash-toolbar .pill.pill-viewers::before {
  /* Use a small "eye" glyph instead of the colored dot — overrides the
     default ::before { content:''; background: ... } pattern. */
  background: transparent;
  content: '👁';
  width: auto; height: auto; border-radius: 0;
  font-size: 11px; line-height: 1;
}
.dash-toolbar .btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: white;
  font: inherit;
  font-size: 13px; font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  cursor: pointer;
}
.dash-toolbar .btn-ghost:hover { background: var(--color-bg-alt); }

/* ---------- Main shell ---------- */
.dash-main {
  max-width: 1320px;
  margin: 22px auto 0;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Hero status panel ---------- */
.dash-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border-radius: 18px;
  padding: 28px 32px;
  color: white;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  position: relative;
}
.dash-hero::after {
  content: '';
  position: absolute;
  right: -120px; top: -120px;
  width: 320px; height: 320px;
  background: radial-gradient(circle at center, rgba(37, 99, 235, 0.25), transparent 60%);
  pointer-events: none;
}
.hero-armed {
  display: flex; align-items: center; gap: 22px;
  position: relative; z-index: 1;
}
.armed-ring {
  position: relative;
  width: 88px; height: 88px;
  flex-shrink: 0;
}
.armed-ring svg {
  width: 88px; height: 88px;
  transform: rotate(-90deg);
}
.armed-ring svg circle {
  stroke: rgba(255, 255, 255, 0.18);
  stroke-dasharray: 277;
  stroke-dashoffset: 0;
}
.hero-armed.armed .armed-ring svg circle { stroke: #10b981; }
.hero-armed.disarmed .armed-ring svg circle { stroke: rgba(248, 250, 252, 0.45); }
.hero-armed.alarm .armed-ring svg circle {
  stroke: #ef4444;
  animation: hero-ring-pulse 1.2s ease-in-out infinite;
}
@keyframes hero-ring-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.armed-icon {
  position: absolute;
  inset: 0;
  display: grid; place-items: center;
  color: white;
}
.armed-icon svg { width: 36px; height: 36px; }

.armed-text { display: flex; flex-direction: column; gap: 4px; }
.armed-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: rgba(248, 250, 252, 0.55);
}
.armed-state {
  font-size: 36px;
  font-weight: 800;
  margin: 0;
  line-height: 1;
  letter-spacing: -0.02em;
  color: white;
}
.hero-armed.armed .armed-state   { color: #34d399; }
.hero-armed.alarm .armed-state   { color: #f87171; }
.armed-sub {
  font-size: 14px;
  color: rgba(248, 250, 252, 0.7);
  max-width: 380px;
}

.hero-meta {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(248, 250, 252, 0.08);
  border-radius: 14px;
  padding: 18px 22px;
  display: flex; flex-direction: column; gap: 10px;
  position: relative; z-index: 1;
  font-feature-settings: 'tnum';
}
.meta-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px;
  color: rgba(248, 250, 252, 0.75);
}
.meta-row .meta-key {
  font-weight: 500;
  letter-spacing: 0.02em;
}
.meta-row .meta-val {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 600;
  color: white;
  text-align: right;
  max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

@media (max-width: 880px) {
  .dash-hero { grid-template-columns: 1fr; padding: 22px 22px; }
}

/* ---------- Section header ---------- */
.dash-section { display: flex; flex-direction: column; gap: 14px; }
.dash-section-head {
  display: flex; align-items: baseline; gap: 16px;
  padding: 0 4px;
}
.dash-section-head h3 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-light);
  margin: 0;
}
.dash-section-head .hint {
  font-size: 13px;
  color: var(--color-text-light);
}
.dash-section-head .head-actions { margin-left: auto; }

.filter-chips { display: inline-flex; gap: 4px; background: white; border: 1px solid var(--color-border); border-radius: 999px; padding: 4px; }
.filter-chips .chip {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-light);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.filter-chips .chip:hover { color: var(--color-text-dark); }
.filter-chips .chip.active {
  background: var(--color-primary);
  color: white;
}

/* ---------- Sensor row (circular gauges) ---------- */
.dash-sensor-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.sensor-card {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color 150ms, box-shadow 150ms;
}
.sensor-card.alert { border-color: #fecaca; background: #fff5f5; }
.sensor-card.warn  { border-color: #fde68a; background: #fffaeb; }
.sensor-card.empty { opacity: 0.65; }

.sensor-card .gauge {
  width: 70px; height: 70px;
  flex-shrink: 0;
  position: relative;
}
.sensor-card .gauge svg {
  width: 70px; height: 70px;
  transform: rotate(-90deg);
}
.sensor-card .gauge .track {
  fill: none;
  stroke: var(--color-bg-alt);
  stroke-width: 7;
}
.sensor-card .gauge .progress {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 7;
  stroke-linecap: round;
  transition: stroke-dashoffset 350ms ease, stroke 200ms;
}
.sensor-card.alert .gauge .progress { stroke: #ef4444; }
.sensor-card.warn  .gauge .progress { stroke: #f59e0b; }
.sensor-card .gauge .gauge-value {
  position: absolute;
  inset: 0;
  display: grid; place-items: center;
  color: var(--color-text-dark);
}
.sensor-card .gauge .gauge-value .v {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  font-feature-settings: 'tnum';
  line-height: 1;
}
.sensor-card .gauge .gauge-value .u {
  font-size: 9px;
  letter-spacing: 0.04em;
  color: var(--color-text-light);
  margin-top: 2px;
  text-transform: uppercase;
}

.sensor-card .body { min-width: 0; flex: 1; }
.sensor-card .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-light);
}
.sensor-card .body .value-main {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text-dark);
  font-feature-settings: 'tnum';
  line-height: 1.1;
  margin-top: 2px;
}
.sensor-card .body .value-sub {
  font-size: 11px;
  color: var(--color-text-light);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 4px;
}
.sensor-card.alert .body .value-main { color: #b91c1c; }
.sensor-card.warn  .body .value-main { color: #b45309; }

.sensor-card .state-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-text-light);
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}
.sensor-card .state-dot.ok   { background: #10b981; }
.sensor-card .state-dot.warn { background: #f59e0b; }
.sensor-card .state-dot.alert{ background: #ef4444; }

/* ---------- Power & Sync ---------- */
.power-profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.profile-card {
  background: white;
  border: 1.5px solid var(--color-border);
  border-radius: 14px;
  padding: 16px 16px 14px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--color-text);
  display: flex; flex-direction: column; gap: 10px;
  position: relative;
  transition: border-color 100ms, box-shadow 100ms, transform 80ms;
  box-shadow: var(--shadow-sm);
}
.profile-card:hover {
  border-color: var(--color-primary-light);
  box-shadow: var(--shadow);
}
.profile-card:active { transform: scale(0.995); }
.profile-card.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08), var(--shadow);
  background: linear-gradient(180deg, white, rgba(37, 99, 235, 0.03));
}
.profile-card .head { display: flex; align-items: center; gap: 10px; }
.profile-card .head .icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--color-bg-alt);
  color: var(--color-text-light);
  flex-shrink: 0;
}
.profile-card.active .head .icon {
  background: rgba(37, 99, 235, 0.12);
  color: var(--color-primary);
}
.profile-card .head .icon svg { width: 18px; height: 18px; }
.profile-card .head .title {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text-dark);
  letter-spacing: -0.01em;
}
.profile-card .head .selected-mark {
  margin-left: auto;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  display: grid; place-items: center;
  color: white;
  background: transparent;
  flex-shrink: 0;
}
.profile-card.active .head .selected-mark {
  border-color: var(--color-primary);
  background: var(--color-primary);
}
.profile-card .head .selected-mark svg { width: 10px; height: 10px; }
.profile-card .desc {
  font-size: 13px;
  color: var(--color-text-light);
  line-height: 1.4;
}
.profile-card .timings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text);
}
.profile-card .timings .k { color: var(--color-text-light); font-weight: 500; }
.profile-card .timings .v { font-weight: 600; color: var(--color-text-dark); text-align: right; }
.profile-card .battery-est {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-light);
  font-family: 'JetBrains Mono', monospace;
  padding: 4px 10px;
  background: var(--color-bg-alt);
  border-radius: 999px;
  align-self: flex-start;
}
.profile-card .battery-est svg { width: 12px; height: 12px; }

.power-advanced {
  margin-top: 12px;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.power-advanced summary {
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-dark);
  cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  list-style: none;
}
.power-advanced summary::-webkit-details-marker { display: none; }
.power-advanced summary::before {
  content: '';
  width: 8px; height: 8px;
  border: solid var(--color-text-light);
  border-width: 0 2px 2px 0;
  transform: rotate(-45deg);
  margin-right: 2px;
  transition: transform 120ms;
}
.power-advanced[open] summary::before {
  transform: rotate(45deg);
}
.power-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding: 8px 18px 16px;
  border-top: 1px solid var(--color-border);
}
.power-field {
  display: flex; flex-direction: column; gap: 6px;
}
.power-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
}
.power-field .field-help {
  font-size: 11px;
  color: var(--color-text-light);
  line-height: 1.4;
}
.power-field .field-input {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: white;
  overflow: hidden;
  height: 36px;
}
.power-field .field-input input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  padding: 6px 10px;
  font-weight: 600;
  color: var(--color-text-dark);
  outline: none;
  width: 100%;
  text-align: right;
}
.power-field .field-input .unit {
  padding: 0 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-light);
  border-left: 1px solid var(--color-border);
  background: var(--color-bg-alt);
  height: 100%;
  display: inline-flex; align-items: center;
}
.power-field .field-input:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.power-note {
  margin: 0;
  padding: 0 18px 16px;
  font-size: 11px;
  color: var(--color-text-light);
  font-family: 'JetBrains Mono', monospace;
}

.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary);
  color: white;
  font: inherit;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background 100ms, box-shadow 100ms;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary .dirty-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #facc15;
  display: none;
}
.btn-primary.dirty .dirty-dot { display: inline-block; }

/* Silence Notecard panic button — visually quiet but always actionable.
   Placed in the same head-actions row as the Apply button. */
.dash-section-head .head-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.dash-section-head .head-actions .btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: white;
  font: inherit;
  font-size: 12px; font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}
.dash-section-head .head-actions .btn-ghost:hover {
  border-color: #fda4af;
  color: #b91c1c;
  background: #fff7f7;
}

/* ---------- Zone grid ---------- */
.dash-zone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.empty-zone-card {
  background: white;
  border: 1.5px dashed var(--color-border);
  border-radius: 14px;
  padding: 48px 24px;
  text-align: center;
  grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.empty-zone-card .empty-icon {
  width: 64px; height: 64px;
  border-radius: 14px;
  background: var(--color-bg-alt);
  color: var(--color-text-light);
  display: grid; place-items: center;
}
.empty-zone-card h4 {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-dark);
  margin: 0;
}
.empty-zone-card p {
  font-size: 14px;
  color: var(--color-text-light);
  max-width: 380px;
  margin: 0;
}
.empty-zone-card a { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.empty-zone-card a:hover { text-decoration: underline; }

.zone-card {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 16px 16px 14px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: border-color 150ms, box-shadow 150ms;
}
.zone-card:hover { box-shadow: var(--shadow); }
.zone-card.live  { border-color: rgba(37, 99, 235, 0.4); }
.zone-card.alarm { border-color: #fca5a5; background: #fff5f5; }
.zone-card.alarm::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.zone-card .head {
  display: flex; align-items: center; gap: 10px;
}
.zone-card .head .zone-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--color-bg-alt);
  color: var(--color-text);
  letter-spacing: 0.04em;
}
.zone-card.live .head .zone-chip { background: rgba(37, 99, 235, 0.12); color: var(--color-primary); }
.zone-card.alarm .head .zone-chip { background: rgba(239, 68, 68, 0.14); color: #b91c1c; }
.zone-card .head h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text-dark);
  margin: 0;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zone-card .role-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--color-text-light);
  background: var(--color-bg-alt);
}

.zone-card .state-row {
  display: flex; align-items: center; gap: 14px;
}
.zone-card .indicator {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--color-bg-alt);
  border: 3px solid var(--color-border);
  display: grid; place-items: center;
  color: var(--color-text-light);
  flex-shrink: 0;
  transition: all 180ms;
}
.zone-card .indicator svg { width: 26px; height: 26px; }
.zone-card.live .indicator {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--color-primary);
  color: var(--color-primary);
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.08);
}
.zone-card.alarm .indicator {
  background: rgba(239, 68, 68, 0.12);
  border-color: #ef4444;
  color: #ef4444;
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.1);
  animation: pulse-alarm 1.1s ease-in-out infinite;
}
@keyframes pulse-alarm {
  0%, 100% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.1); }
  50%      { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0.04); }
}

.zone-card .state-text { min-width: 0; flex: 1; }
.zone-card .state-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-dark);
  line-height: 1.2;
}
.zone-card.alarm .state-label { color: #b91c1c; }
.zone-card .state-sub {
  font-size: 11px;
  color: var(--color-text-light);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 4px;
}

.zone-card .fire-btn {
  margin-top: 4px;
  padding: 9px 12px;
  border: 1px solid var(--color-primary);
  background: white;
  color: var(--color-primary);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 100ms;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.zone-card .fire-btn svg { width: 14px; height: 14px; }
.zone-card .fire-btn:hover {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 4px 10px -2px rgba(37, 99, 235, 0.4);
}
.zone-card .fire-btn:active { transform: scale(0.98); }
.zone-card .fire-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Siren / alarm-role: chirp / burst / full trio for fast cycling */
.zone-card .fire-btn-row {
  margin-top: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.zone-card .fire-btn-row .fire-btn {
  margin-top: 0;
  padding: 8px 6px;
  font-size: 12px;
  gap: 4px;
}
.zone-card .fire-btn--chirp {
  border-color: #16a34a;
  color: #16a34a;
}
.zone-card .fire-btn--chirp:hover {
  background: #16a34a;
  color: white;
  box-shadow: 0 4px 10px -2px rgba(22, 163, 74, 0.4);
}
.zone-card .fire-btn--burst {
  border-color: #d97706;
  color: #d97706;
}
.zone-card .fire-btn--burst:hover {
  background: #d97706;
  color: white;
  box-shadow: 0 4px 10px -2px rgba(217, 119, 6, 0.4);
}

/* Analog sparkline */
.zone-card .spark-wrap {
  position: relative;
  background: var(--color-bg-alt);
  border-radius: 8px;
  height: 64px;
  overflow: hidden;
}
.zone-card .spark-wrap svg { display: block; width: 100%; height: 100%; }
.zone-card .spark-bounds {
  display: flex; justify-content: space-between;
  font-size: 10px;
  color: var(--color-text-light);
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
}
.zone-card .spark-current {
  position: absolute;
  top: 6px; right: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-dark);
}

/* ---------- Timeline ---------- */
.dash-timeline {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 6px 0;
  max-height: 520px;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}
.timeline-empty {
  padding: 32px 24px;
  text-align: center;
  font-size: 13px;
  color: var(--color-text-light);
}
.timeline-item {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 14px;
  align-items: flex-start;
  padding: 12px 18px;
  border-bottom: 1px solid var(--color-border);
  position: relative;
}
.timeline-item:last-child { border-bottom: none; }
.timeline-item .t-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--color-bg-alt);
  color: var(--color-text-light);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.timeline-item .t-icon svg { width: 16px; height: 16px; }
.timeline-item.kind-rule_fired .t-icon  { background: rgba(37, 99, 235, 0.12); color: var(--color-primary); }
.timeline-item.kind-alert .t-icon       { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.timeline-item.kind-pin_edge .t-icon    { background: rgba(245, 158, 11, 0.14); color: #b45309; }
.timeline-item.kind-rule_skip .t-icon   { background: rgba(100, 116, 139, 0.14); color: var(--color-text-light); }
.timeline-item.kind-boot .t-icon        { background: rgba(16, 185, 129, 0.12); color: #047857; }

.timeline-item .t-body { min-width: 0; }
.timeline-item .t-kind {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-light);
}
.timeline-item.kind-rule_fired .t-kind  { color: var(--color-primary); }
.timeline-item.kind-alert .t-kind       { color: #b91c1c; }
.timeline-item.kind-pin_edge .t-kind    { color: #b45309; }
.timeline-item .t-summary {
  font-size: 13px;
  color: var(--color-text-dark);
  margin-top: 2px;
  line-height: 1.4;
  word-break: break-word;
}
.timeline-item .t-meta {
  font-size: 11px;
  color: var(--color-text-light);
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
  word-break: break-word;
}
.timeline-item .t-ts {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-light);
  white-space: nowrap;
  margin-top: 6px;
}
.timeline-day {
  padding: 8px 18px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-light);
  background: var(--color-bg-alt);
  border-bottom: 1px solid var(--color-border);
}

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed;
  bottom: 22px; right: 22px;
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast-stack .toast {
  background: var(--color-text-dark);
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  min-width: 220px;
  max-width: 360px;
}
.toast-stack .toast.ok  { background: #047857; }
.toast-stack .toast.err { background: #b91c1c; }

/* ===========================================================
   Customize / edit mode
   =========================================================== */

/* Each section's per-section edit controls (up / down / hide) are
   hidden by default and slide in when the dashboard is in edit mode.
   They sit at the right edge of the section header. */
.dash-section .section-edit-controls {
  display: none;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}
.dash-edit-mode .dash-section .section-edit-controls {
  display: inline-flex;
}
.section-edit-controls button {
  border: 1px solid var(--color-border);
  background: white;
  color: var(--color-text);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
}
.section-edit-controls button:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.section-edit-controls .section-hide:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: #fff5f5;
}
.dash-edit-mode .dash-section {
  outline: 2px dashed transparent;
  outline-offset: 4px;
  transition: outline-color 100ms;
}
.dash-edit-mode .dash-section:hover {
  outline-color: rgba(37, 99, 235, 0.35);
}

/* The customize toggle in the toolbar gets a primary-tinted state when on. */
.dash-toolbar .btn-ghost.is-on {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Hidden-section shelf: visible only when in edit mode AND at least
   one section is hidden. */
.hidden-shelf {
  background: white;
  border: 1.5px dashed var(--color-border);
  border-radius: 12px;
  padding: 14px 18px;
}
.hidden-shelf-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-light);
  margin-bottom: 10px;
}
.hidden-shelf-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.hidden-shelf-items .show-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}
.hidden-shelf-items .show-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: white;
}

/* Per-zone customize pencil — appears in the corner of every zone tile
   only while edit mode is on. */
.zone-card .zone-edit-btn {
  position: absolute;
  top: 8px; right: 8px;
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: white;
  color: var(--color-text-light);
  display: none;
  align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
}
.zone-card .zone-edit-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.zone-card .zone-edit-btn svg { width: 13px; height: 13px; }
.dash-edit-mode .zone-card .zone-edit-btn { display: inline-flex; }

/* Zone-label-editor dialog styling — reuses .builder-dialog shell from
   device-builder.css and adds dashboard-specific form widgets. */
.builder-dialog .form-row {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
}
.builder-dialog .form-row > span { font-weight: 600; color: var(--color-text-dark); }
.builder-dialog .form-row > span .hint { font-weight: 400; color: var(--color-text-light); margin-left: 4px; }
.builder-dialog .form-row input {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  color: var(--color-text-dark);
}
.builder-dialog .form-row input:focus {
  outline: 2px solid var(--color-primary-light);
  outline-offset: -1px;
  border-color: var(--color-primary);
}
.builder-dialog .form-help {
  margin: 4px 0 0;
  padding: 8px 12px;
  background: var(--color-bg-alt);
  border-radius: 6px;
  font-size: 12px;
  color: var(--color-text);
}
.builder-dialog .dialog-foot .ghost {
  background: white;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.builder-dialog .dialog-foot .primary {
  background: var(--color-primary);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* dash-sections wrapper — gives the layout a single flex column that
   re-orders cleanly when JS swaps DOM nodes. */
.dash-sections {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Smaller screens ---------- */
@media (max-width: 720px) {
  .dash-main { padding: 0 16px; gap: 18px; }
  .dash-hero { padding: 22px 18px; }
  .armed-state { font-size: 30px; }
  .dash-zone-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .zone-card { padding: 14px; }
  .zone-card .indicator { width: 50px; height: 50px; }
}

/* ============================================================================
   Custom widget grid — user-built control panel
   ============================================================================ */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  padding: 12px 16px 16px;
}
.widget-empty {
  padding: 28px 24px;
  text-align: center;
  color: #64748b;
  font-size: 14px;
  border: 1px dashed #cbd5e1;
  margin: 12px 16px 16px;
  border-radius: 8px;
}
.widget-empty.hidden { display: none; }

.wcard {
  --accent: #3b82f6;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 14px 12px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 102px;
  transition: transform 80ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.wcard.clickable { cursor: pointer; }
.wcard.clickable:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(15,23,42,0.08); }
.wcard.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.wcard-top {
  display: flex; align-items: center; gap: 8px;
}
.wcard-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.wcard-icon svg { width: 22px; height: 22px; }
.wcard-label {
  flex: 1; font-size: 13px; font-weight: 600; color: #0f172a;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wcard-edit {
  border: 0; background: transparent; padding: 4px; cursor: pointer; color: #94a3b8; border-radius: 4px;
}
.wcard-edit:hover { color: #0f172a; background: #f1f5f9; }

.wcard-sub {
  font-size: 11px; color: #64748b;
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* Button widget — accent-color fill */
.wcard-fire {
  margin-top: auto;
  background: var(--accent);
  color: white;
  border: 0;
  padding: 10px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.wcard-fire:hover { filter: brightness(1.05); }
.wcard-fire:active { transform: translateY(1px); }

/* Status light */
.wcard-light {
  display: flex; align-items: center; gap: 10px;
  margin-top: auto;
}
.wcard-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #cbd5e1;
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: background 120ms, box-shadow 120ms;
}
.wcard.on .wcard-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}
.wcard-state {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px; font-weight: 600; color: #475569;
}
.wcard.on .wcard-state { color: var(--accent); }

/* Numeric reading */
.wcard-value {
  margin-top: auto;
  font-family: "JetBrains Mono", monospace;
  display: flex; align-items: baseline; gap: 4px;
}
.wcard-num { font-size: 30px; font-weight: 700; color: #0f172a; line-height: 1; }
.wcard-unit { font-size: 12px; color: #64748b; }

/* Toggle widget */
.wcard-toggle {
  margin-top: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 6px 0 2px;
}
.wcard-switch {
  width: 56px; height: 30px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  transition: background 120ms;
}
.wcard-switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 120ms;
}
.wcard-switch.on { background: var(--accent); }
.wcard-switch.on::after { transform: translateX(26px); }

/* Editor dialog */
#widget-edit .we-field {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 16px;
}
#widget-edit .we-field label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; font-weight: 600;
}
#widget-edit .we-field input,
#widget-edit .we-field select,
#widget-edit .we-field textarea {
  padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 6px;
  font-size: 14px; font-family: inherit;
}
#widget-edit .we-field input[type="color"] {
  width: 56px; height: 36px; padding: 2px; cursor: pointer;
}
#widget-edit .we-hint { font-size: 12px; color: #64748b; }
.we-icon-row {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.we-icon-btn {
  width: 36px; height: 36px;
  border: 1px solid #cbd5e1;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #475569;
}
.we-icon-btn svg { width: 18px; height: 18px; }
.we-icon-btn:hover { background: #f1f5f9; }
.we-icon-btn.active { border-color: #3b82f6; color: #3b82f6; box-shadow: inset 0 0 0 1px #3b82f6; }
.btn-ghost.danger { color: #b91c1c; }
.btn-ghost.danger:hover { background: #fee2e2; }

#widget-add {
  margin-left: auto;
}

/* ============================================================================
   Telemetry sensor cards v2 — bespoke visuals per metric.
   ============================================================================ */
.dash-sensor-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px; margin: 14px 0 28px; }
@media (max-width: 1240px) { .dash-sensor-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 780px)  { .dash-sensor-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px)  { .dash-sensor-row { grid-template-columns: 1fr; } }

.sensor-card.v2 {
  --sc-accent: #475569;
  --sc-bg: #ffffff;
  --sc-line: #e2e8f0;
  --sc-ink: #0f172a;
  --sc-ink-dim: #64748b;
  position: relative;
  background: var(--sc-bg);
  border: 1px solid var(--sc-line);
  border-radius: 14px;
  padding: 16px 16px 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04), 0 18px 36px -28px rgba(15, 23, 42, 0.14);
  transition: transform 140ms ease, box-shadow 220ms ease, border-color 220ms ease;
  font-family: Inter, system-ui, sans-serif;
  overflow: hidden;
}
.sensor-card.v2::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--sc-accent); opacity: 0.85;
}
.sensor-card.v2.ok    { --sc-accent: #10b981; }
.sensor-card.v2.warn  { --sc-accent: #f59e0b; }
.sensor-card.v2.alert { --sc-accent: #ef4444; box-shadow: 0 1px 0 rgba(239, 68, 68, 0.08), 0 18px 36px -28px rgba(239, 68, 68, 0.40); border-color: rgba(239, 68, 68, 0.30); }
.sensor-card.v2.idle  { --sc-accent: #94a3b8; }

.sensor-card.v2 .sensor-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.sensor-card.v2 .sensor-eyebrow {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--sc-ink-dim); font-weight: 600;
}
.sensor-card.v2 .sensor-pct {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--sc-accent);
  padding: 2px 8px; border: 1px solid currentColor; border-radius: 999px; opacity: 0.9;
}
.sensor-card.v2 .sensor-readout {
  display: flex; align-items: baseline; gap: 6px; margin-top: 2px;
}
.sensor-card.v2 .sensor-readout .big {
  font-family: Inter, system-ui;
  font-size: 28px; font-weight: 700; color: var(--sc-ink);
  letter-spacing: -0.02em; line-height: 1;
}
.sensor-card.v2 .sensor-readout .unit {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px; font-weight: 600; color: var(--sc-ink-dim);
  letter-spacing: 1.2px; text-transform: uppercase;
}
.sensor-card.v2 .sensor-readout.sensor-readout-coords { gap: 10px; flex-wrap: wrap; }
.sensor-card.v2 .sensor-readout .coord {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px; color: var(--sc-ink); font-weight: 500;
}
.sensor-card.v2 .sensor-sub {
  font-size: 12.5px; color: var(--sc-ink-dim); line-height: 1.35; font-weight: 500;
}
.sensor-card.v2 .last-seen {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px; letter-spacing: 0.8px;
  color: var(--sc-ink-dim);
  border-top: 1px dashed var(--sc-line);
  padding-top: 8px; margin-top: 4px;
  display: flex; align-items: center; gap: 6px;
  text-transform: uppercase;
}
.sensor-card.v2 .last-seen::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.45;
}
.sensor-card.v2 .last-seen.fresh::before { background: #10b981; opacity: 1; animation: sc-pulse 1.8s ease-in-out infinite; }
.sensor-card.v2 .last-seen.recent::before { background: #f59e0b; opacity: 0.85; }
.sensor-card.v2 .last-seen.stale::before { background: #94a3b8; opacity: 0.6; }
@keyframes sc-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.55); } 50% { box-shadow: 0 0 0 5px rgba(16,185,129,0.0); } }

.battery-glyph { width: 100%; height: 54px; display: block; }
.battery-glyph .shell  { fill: none; stroke: var(--sc-line); stroke-width: 2; }
.battery-glyph .cap    { fill: var(--sc-line); }
.battery-glyph .fill   { fill: var(--sc-accent); opacity: 0.92; }
.battery-glyph .sep    { stroke: rgba(255,255,255,0.85); stroke-width: 1.5; stroke-dasharray: 3 2; }

.signal-bars { width: 100%; height: 54px; display: block; }
.signal-bars .bar    { fill: var(--sc-line); }
.signal-bars .bar.on { fill: var(--sc-accent); }

.thermo-glyph { width: 100%; height: 54px; display: block; }
.thermo-glyph .track   { fill: #f1f5f9; stroke: var(--sc-line); stroke-width: 1; }
.thermo-glyph .mercury { fill: var(--sc-accent); transition: width 220ms ease; }
.thermo-glyph .tick    { stroke: var(--sc-ink-dim); stroke-width: 1; opacity: 0.6; }

.gps-map {
  position: relative; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--sc-line); height: 120px;
}
.gps-map iframe { width: 100%; height: 100%; border: 0; display: block; filter: saturate(0.85) contrast(0.95); }
.gps-map .gps-open {
  position: absolute; right: 6px; bottom: 6px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px; letter-spacing: 0.6px;
  background: rgba(15, 23, 42, 0.78); color: #fff;
  padding: 3px 7px; border-radius: 4px; text-decoration: none;
}
.gps-map .gps-open:hover { background: rgba(15, 23, 42, 0.92); }

.gps-placeholder {
  height: 120px; display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(45deg, #f8fafc, #f8fafc 6px, #f1f5f9 6px, #f1f5f9 12px);
  border: 1px solid var(--sc-line); border-radius: 8px;
}
.gps-placeholder svg { width: 80%; height: 80%; }
.gps-placeholder .gps-grid  { fill: none; stroke: #cbd5e1; stroke-width: 1; stroke-dasharray: 2 3; }
.gps-placeholder .gps-cross { stroke: #cbd5e1; stroke-width: 1; stroke-dasharray: 2 3; }
.gps-placeholder .gps-pulse { fill: #94a3b8; animation: gps-pulse 2s ease-in-out infinite; }
@keyframes gps-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.motion-wave { width: 100%; height: 54px; display: block; }
.motion-wave .baseline { stroke: var(--sc-line); stroke-width: 1; stroke-dasharray: 3 3; }
.motion-wave .wave { fill: none; stroke: var(--sc-accent); stroke-width: 2.4; stroke-linecap: round; }
.motion-wave.flat .wave { opacity: 0.5; }

/* ============================================================================
   Notify-toggle button states
   ============================================================================ */
#notify-toggle.on {
  border-color: #10b981;
  color: #047857;
  background: rgba(16, 185, 129, 0.08);
}
#notify-toggle.on svg { color: #10b981; }
#notify-toggle.hidden { display: none !important; }

/* ============================================================================
   Mobile (<=720px) — keep the top nav usable on phones.
   - Collapse logo to icon only (drop wrapping brand text).
   - Tighter padding, horizontal scroll for nav links if needed.
   - Stack the toolbar inner into a 2-row flow with wrap.
   - Hero meta gets vertical stacking room.
   ============================================================================ */
@media (max-width: 720px) {
  .builder-nav .nav-container { padding: 10px 12px; gap: 8px; flex-wrap: nowrap; }
  .builder-nav .nav-logo-text { display: none; }
  .builder-nav .nav-links {
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    white-space: nowrap;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
  }
  .builder-nav .nav-links::-webkit-scrollbar { display: none; }
  .builder-nav .nav-links a { flex-shrink: 0; font-size: 13px; }
  .builder-nav .user-pill { font-size: 11px; padding: 4px 10px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; }
  .dash-toolbar-inner { flex-wrap: wrap; gap: 8px; row-gap: 8px; }
  .dash-toolbar-inner .spacer { flex-basis: 100%; height: 0; }
  .dash-toolbar-inner .btn-ghost { font-size: 12px; padding: 6px 10px; }
  .dash-toolbar-inner .device-picker { flex: 1 1 auto; min-width: 0; }
  .dash-toolbar-inner .device-picker select { max-width: 100%; }
  .dash-hero { padding: 16px !important; }
  .dash-section-head h3 { font-size: 14px; }
  .dash-section-head .hint { font-size: 12px; }
}

@media (max-width: 480px) {
  .builder-nav .nav-links a { font-size: 12px; }
  .builder-nav .user-pill { max-width: 100px; }
}
