:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;
  --series-1-100:   #cde2fb;
  --series-2:       #eb6834;
  --series-3:       #1baf7a;
  --series-4:       #eda100;
  --series-5:       #e87ba4;
  --series-6:       #008300;
  --series-7:       #4a3aa7;
  --series-8:       #e34948;
  --overlap:        #898781;
  --status-good:    #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical:#d03b3b;
  --success-text:   #006300;
  --danger-text:    #d03b3b;
  --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Filter-scope badge tiers (see docs/IMPLEMENTATION_NOTES.md D7):
     full = respects every filter chip above; partial = respects some but has
     its own period nav; none = ignores the filter row entirely. */
  --tier-full:      #2a78d6;
  --tier-full-bg:   #eaf2fc;
  --tier-partial:   #a3671a;
  --tier-partial-bg:#fbf0dd;
  --tier-none:      #6b6a65;
  --tier-none-bg:   #ecece8;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.32);
    --series-1:       #3987e5;
    --series-1-100:   #16324f;
    --series-2:       #d95926;
    --series-3:       #199e70;
    --series-4:       #c98500;
    --series-5:       #d55181;
    --series-6:       #008300;
    --series-7:       #9085e9;
    --series-8:       #e66767;
    --overlap:        #898781;
    --success-text:   #0ca30c;
    --danger-text:    #e66767;
    --status-warning: #ffb84d;
    --tier-full:      #6badf5;
    --tier-full-bg:   #142b47;
    --tier-partial:   #e0ac52;
    --tier-partial-bg:#3a2c10;
    --tier-none:      #a5a49e;
    --tier-none-bg:   #232320;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.32);
  --series-1:       #3987e5;
  --series-1-100:   #16324f;
  --series-2:       #d95926;
  --series-3:       #199e70;
  --series-4:       #c98500;
  --series-5:       #d55181;
  --series-6:       #008300;
  --series-7:       #9085e9;
  --series-8:       #e66767;
  --overlap:        #898781;
  --success-text:   #0ca30c;
  --danger-text:    #e66767;
  --status-warning: #ffb84d;
  --tier-full:      #6badf5;
  --tier-full-bg:   #142b47;
  --tier-partial:   #e0ac52;
  --tier-partial-bg:#3a2c10;
  --tier-none:      #a5a49e;
  --tier-none-bg:   #232320;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-sans);
}
body { padding: 24px 32px 64px; }

.page { max-width: 1120px; margin: 0 auto; }

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
header.app-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}
header.app-header .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.app-version {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  vertical-align: middle;
}
.header-actions { display: flex; gap: 8px; align-items: center; }
.device-filter-select {
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
}
.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { background: var(--gridline); }
.icon-btn svg { width: 18px; height: 18px; }

/* Device health banner: warns when a device has gone quiet (or never
   checked in), so a silently-broken tracker (dead server URL, revoked key,
   crashed process) is visible instead of just reading as "no activity". */
.device-health-banner {
  display: none;
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-warning) 45%, var(--border));
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}
.device-health-banner.visible { display: block; }
.device-health-banner-list { display: flex; flex-direction: column; gap: 10px; }
.device-health-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.device-health-row + .device-health-row {
  padding-top: 10px;
  border-top: 1px solid color-mix(in srgb, var(--status-warning) 30%, transparent);
}
.device-health-row .icon {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--status-warning);
}
.device-health-row-text { flex: 1 1 240px; }
.device-health-row-actions { display: flex; gap: 6px; flex: none; }
.device-health-snooze {
  font-size: 12px;
  padding: 4px 10px;
  white-space: nowrap;
}

/* Live timer: progress ring (today vs. 8h goal) + current session */
.live-ring-bar {
  display: flex;
  align-items: center;
  gap: 32px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 32px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.live-ring-wrap {
  position: relative;
  width: 180px;
  height: 180px;
  flex: none;
}
.live-ring {
  width: 180px;
  height: 180px;
  transform: rotate(-90deg);
}
.live-ring-frame {
  fill: none;
  stroke: var(--border);
  stroke-width: 1.5;
}
.live-ring-track {
  fill: none;
  stroke: var(--series-1-100);
  stroke-width: 15;
}
.live-ring-progress {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 15;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease, stroke 0.25s ease;
}
.live-ring-bar[data-active="false"] .live-ring-progress { stroke: var(--baseline); }
.live-ring-center {
  position: absolute;
  inset: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.live-ring-today {
  font-size: 26px;
  font-weight: 650;
  line-height: 1.1;
  /* Ticks every second: tabular figures keep the digits from jittering in width. */
  font-variant-numeric: tabular-nums;
}
.live-ring-goal { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.live-ring-side { flex: 1; min-width: 180px; }
.live-ring-session-label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.live-ring-session-value {
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.live-ring-bar[data-active="false"] .live-ring-session-value { color: var(--text-muted); }
.live-ring-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.live-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-good);
  flex: none;
  transition: background 0.2s ease;
}
.live-ring-bar[data-active="false"] .live-status-dot { background: var(--text-muted); }
@keyframes live-pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-good) 45%, transparent); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--status-good) 0%, transparent); }
}
.live-ring-bar[data-active="true"] .live-status-dot { animation: live-pulse-dot 2s ease-in-out infinite; }

/* Filter row */
.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filter-chip {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-chip:hover { background: var(--gridline); }
.filter-chip[aria-pressed="true"] {
  color: var(--text-primary);
  border-color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 12%, var(--surface-1));
  font-weight: 600;
}
.filter-chip .check { width: 12px; height: 12px; display: none; }
.filter-chip[aria-pressed="true"] .check { display: inline-block; }

/* Stat tiles */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 860px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.stat-tile .label { font-size: 12px; color: var(--text-secondary); }
.stat-tile .value-row {
  display: flex; align-items: baseline; gap: 8px; margin-top: 6px;
}
.stat-tile .value { font-size: 28px; font-weight: 600; line-height: 1; }
.stat-tile .delta { font-size: 12px; font-weight: 600; }
.stat-tile .delta.up.good { color: var(--success-text); }
.stat-tile .delta.down.good { color: var(--success-text); }
.stat-tile .delta.up.bad { color: var(--danger-text); }
.stat-tile .delta.down.bad { color: var(--danger-text); }
.stat-tile .spark { margin-top: 10px; display: block; }

/* Chart cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 16px 8px;
  margin-bottom: 16px;
}
/* Left edge repeats the .scope-badge tier as a fast-scan signal — see D7. */
.card.tier-full { border-left: 3px solid var(--tier-full); }
.card.tier-partial { border-left: 3px solid var(--tier-partial); }
.card.tier-none { border-left: 3px solid var(--tier-none); }

.scope-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  margin-top: 6px;
}
.scope-badge svg { width: 11px; height: 11px; flex: none; }
.scope-badge.tier-full { color: var(--tier-full); background: var(--tier-full-bg); }
.scope-badge.tier-partial { color: var(--tier-partial); background: var(--tier-partial-bg); }
.scope-badge.tier-none { color: var(--tier-none); background: var(--tier-none-bg); }

.stat-grid-header { display: flex; justify-content: flex-end; margin-bottom: 6px; }

.scope-line {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--gridline);
}
.scope-line b { color: var(--text-secondary); font-weight: 600; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.card-header .titles { display: flex; flex-direction: column; }
.card-header h2 { font-size: 14px; font-weight: 600; margin: 0; }
.card-header .caption { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-controls { display: flex; align-items: center; gap: 8px; }

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.segmented-btn {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.segmented-btn:hover { background: var(--gridline); }
.segmented-btn[aria-pressed="true"] {
  background: var(--series-1);
  color: white;
}
.segmented-disabled { opacity: 0.4; }
.segmented-disabled .segmented-btn { cursor: default; }
.segmented-disabled .segmented-btn:hover { background: transparent; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.checkbox-label input[type="checkbox"] { cursor: pointer; }

.nav-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.nav-btn:hover { background: var(--gridline); }
.nav-btn:disabled { opacity: 0.4; cursor: default; }
.week-range { font-size: 13px; color: var(--text-secondary); min-width: 150px; text-align: center; }

.table-toggle {
  font-size: 12px;
  color: var(--text-secondary);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}
.table-toggle:hover { color: var(--text-primary); }

.chart-wrap { position: relative; }
svg.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap[data-view="table"] svg.chart-svg { display: none; }
.chart-wrap[data-view="table"] .data-table-wrap { display: block; }
.data-table-wrap { display: none; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th, table.data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
}
table.data-table th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
}
table.data-table td.num, table.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Tooltip */
.chart-tooltip {
  /* Fixed (not absolute) so viewport coordinates from getBoundingClientRect() /
     pointer events are correct regardless of page scroll position. */
  position: fixed;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.08s ease;
  white-space: nowrap;
  z-index: 5;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-label { color: var(--text-muted); font-size: 11px; margin-bottom: 2px; }
.chart-tooltip .tt-value { font-weight: 600; font-size: 13px; }

/* Bars / lines */
.bar { fill: var(--series-1); cursor: pointer; }
.bar:hover, .bar.active { fill: color-mix(in srgb, var(--series-1) 85%, white 15%); }
.bar-label { font-size: 11px; fill: var(--text-secondary); font-variant-numeric: tabular-nums; text-anchor: middle; }
.axis-label { font-size: 11px; fill: var(--text-muted); }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.baseline { stroke: var(--baseline); stroke-width: 1; }
.trend-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend-area { fill: var(--series-1); opacity: 0.10; }
.trend-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; opacity: 0; }
.hit-col { fill: transparent; }
.hit-col:focus-visible, .timeline-segment:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: -2px;
}
.target-line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.target-label { font-size: 10px; fill: var(--text-muted); }

/* Weekly overview "compare with previous period" ghost bars */
.bar-compare {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.compare-delta { font-size: 11px; font-variant-numeric: tabular-nums; text-anchor: middle; }
.compare-delta.good { fill: var(--success-text); }
.compare-delta.bad { fill: var(--danger-text); }

/* Section grouping (dashboard grouped into "Right now" / "This week's
   shape" / "History" zones) — a quiet label, not a navigation control, so
   everything below stays reachable by plain scroll. */
.section-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 24px 0 10px;
}
.section-label:first-child { margin-top: 0; }
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--gridline);
}

/* Weekly target & balance card */
.target-progress-track { fill: var(--gridline); }
.target-progress-fill { fill: var(--series-1); }
.target-progress-marker { stroke: var(--text-primary); stroke-width: 2; }
.target-progress-marker-label { font-size: 10px; fill: var(--text-secondary); }
.balance-bar.good { fill: var(--series-3); }
.balance-bar.bad { fill: var(--series-2); }
.balance-bar.current { opacity: 0.55; }
.balance-total-line { fill: none; stroke: var(--series-7); stroke-width: 2; stroke-linejoin: round; }
.balance-total-dot { fill: var(--series-7); stroke: var(--surface-1); stroke-width: 2; }

/* Daily rhythm (first-to-last-activity span) chart */
.rhythm-span { fill: var(--series-1); opacity: 0.28; }
.rhythm-span.is-today { fill: var(--series-4); opacity: 0.32; }
.rhythm-dot { fill: var(--series-1); }
.rhythm-dot.is-today { fill: var(--series-4); }
.rhythm-median-line { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 5 4; }

/* Timeline (24h-per-day) view */
.timeline-track { fill: var(--gridline); }
.timeline-core-hours { fill: var(--series-1); opacity: 0.10; }
/* Default/fallback fill — overridden per-segment via an inline style once
   device colors are known (see renderTimelineChart in app.js). Covers the
   brief pre-render state and any path that doesn't set an inline fill. */
.timeline-segment { fill: var(--series-1); cursor: pointer; }
.timeline-segment:hover, .timeline-segment.active { fill: color-mix(in srgb, var(--series-1) 85%, white 15%); }
.timeline-hour-line { stroke: var(--gridline); stroke-width: 1; }
.timeline-core-hours-label { font-size: 10px; fill: var(--text-muted); }

/* Device-color legend, shown above the timeline chart in the aggregated
   (all-devices) view only — one swatch per device that actually appears in
   the current segments, plus an "Overlap" swatch when applicable. */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-item .swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex: none;
}

/* Empty state */
.empty-state {
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* Settings modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center; justify-content: center;
  z-index: 20;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface-1);
  border-radius: 12px;
  border: 1px solid var(--border);
  width: 360px;
  padding: 20px;
}
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal .modal-sub { font-size: 12px; color: var(--text-secondary); margin: 0 0 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--text-secondary); }
.field input[type="number"],
.field input[type="time"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
}
.field .hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.field-row { display: flex; align-items: center; gap: 8px; }
.field-row input[type="time"] { flex: 1; width: auto; }
.field-row-sep { color: var(--text-muted); font-size: 13px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.switch-row .switch-label { font-size: 13px; }
.switch {
  width: 36px; height: 20px; border-radius: 999px;
  background: var(--baseline);
  position: relative;
  cursor: pointer;
  border: none;
}
.switch.on { background: var(--series-1); }

/* Devices modal */
#devicesOverlay .modal { width: 480px; }
.devices-list { display: flex; flex-direction: column; gap: 10px; max-height: 280px; overflow-y: auto; }
.device-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.device-row-name { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.device-row .field-row { flex-wrap: wrap; }
.device-row label { font-size: 11px; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }
.device-row .field-row + .field-row { margin-top: 6px; }
.tracking-mode-group { display: flex; gap: 4px; }
.tracking-mode-btn {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.tracking-mode-btn:hover { background: var(--gridline); }
.tracking-mode-btn[aria-pressed="true"] {
  background: var(--series-1);
  border-color: var(--series-1);
  color: white;
}
.tracking-mode-btn:disabled { opacity: 0.4; cursor: default; }
.tracking-mode-btn:disabled:hover { background: transparent; }
.device-row input[type="number"] {
  width: 64px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
}
#newApiKeyBox {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  word-break: break-all;
}
#newDeviceName {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
}
#newDevicePlatform {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
}
.switch .knob {
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface-1);
  transition: left 0.12s ease;
}
.switch.on .knob { left: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
}
.btn.primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: white;
}
.btn:hover { opacity: 0.9; }
.device-restore { color: var(--series-1); border-color: var(--series-1); }
.device-delete-permanently { color: var(--danger-text); border-color: var(--danger-text); }

.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 30;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger-text); }

footer.notes {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Mobile layout (phones, ≤700px). Everything above already wraps
   reasonably at this width except .card-header: it's a plain
   space-between flex row, so on a narrow viewport its .card-controls
   (segmented groups, checkboxes, period nav, table-toggle) get squeezed
   into one unreadable, overflowing line instead of wrapping. Below that,
   .modal has a fixed pixel width that overflows small screens, and
   .data-table-wrap has no horizontal-scroll fallback for wide tables. */
@media (max-width: 700px) {
  body { padding: 16px 12px 48px; }

  header.app-header { flex-wrap: wrap; row-gap: 12px; }
  .header-actions { flex-wrap: wrap; }

  .live-ring-bar { padding: 16px; gap: 20px; justify-content: center; }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    row-gap: 10px;
  }
  .card-controls {
    width: 100%;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .week-range { min-width: 0; }

  .data-table-wrap { overflow-x: auto; }
  table.data-table { min-width: 480px; }

  .modal-overlay { padding: 16px; }
  .modal,
  #devicesOverlay .modal {
    width: 100%;
    max-width: 360px;
  }
}
