@font-face {
  font-family: "Cairo";
  src: url("fonts/Cairo-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --page: #141026;
  --panel: #241b40;
  --line: #574779;
  --ink: #fbf6ff;
  --muted: #c7bcde;
  --gold: #ffdf97;
  --purple: #c7a7ff;
  --teal: #88e5d7;
  --ok: #6ee7b7;
  --warn: #f472b6;
  --amber: #fbbf24;
  --ink-dark: #1e1338;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 16px/1.6 "Cairo",Tahoma,Arial,sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 75% -15%,#3a2b62 0,transparent 58%),var(--page);
  min-height: 100vh;
}

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

a:focus-visible,button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 3px;
}

[hidden] {
  display: none!important;
}

.shell {
  width: min(1140px,calc(100% - 36px));
  margin-inline: auto;
}

.top {
  border-bottom: 1px solid #69568e;
  background: #1f1536ee;
  box-shadow: 0 5px 18px #120d2560;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.nav {
  min-height: 62px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand,nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-weight: 800;
  white-space: nowrap;
}

.moon {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #9074cf;
  border-radius: 11px;
  background: linear-gradient(145deg,#6949a5,#39266b);
  color: var(--gold);
  font: 700 28px/1 Arial;
  box-shadow: 0 3px 0 #100d22;
}

.moon.large {
  width: 55px;
  height: 55px;
  font-size: 41px;
  margin-bottom: 7px;
}

.nav-link {
  font: inherit;
  background: none;
  color: var(--muted);
  border: 0;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 8px;
  transition: color .18s ease, background .18s ease;
}

.nav-link.selected,.nav-link:hover {
  color: var(--gold);
  background: #ffffff0d;
}

main {
  padding-block: 24px 48px;
}

h1,h2,h3,p {
  margin: 0 0 10px;
}

h1 {
  font-size: clamp(24px,3.8vw,35px);
  line-height: 1.35;
  margin-block: 0 12px;
}

h2 {
  font-size: 19px;
  line-height: 1.45;
}

h3 {
  font-size: 16px;
}

p,small,.subtle {
  color: var(--muted);
}

small {
  font-size: 13px;
}

button,input,select,textarea {
  font: inherit;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.title-with-pill {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.page-title-row {
  margin-bottom: 14px;
}

.page-title-row h1 {
  margin: 0;
}

.block-sub {
  display: block;
}

.unit-inline {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.button,.light {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 17px;
  border-radius: 10px;
  border: 1px solid #f3d5ff;
  background: linear-gradient(#d9bdff,#bd96f7);
  color: var(--ink-dark);
  font-weight: 800;
  box-shadow: 0 3px 0 #7147a6;
  cursor: pointer;
  text-align: center;
  transition: filter .15s ease, transform .12s ease;
}

.light {
  background: #463269;
  color: var(--ink);
  border-color: #9d80c5;
  box-shadow: 0 2px 0 #160f2b;
  padding: 6px 11px;
  font-size: 14px;
  font-weight: 600;
}

.button:hover,.light:hover {
  filter: brightness(1.1);
}

.button:active,.light:active {
  transform: translateY(1px);
  box-shadow: 0 2px 0 #7147a6;
}

.button:disabled {
  opacity: .65;
  cursor: wait;
}

.button.small {
  padding: 6px 13px;
  font-size: 14px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 13px;
  margin-bottom: 17px;
}

.kpi-grid {
  grid-template-columns: repeat(4,minmax(0,1fr));
  margin-top: 14px;
  margin-bottom: 8px;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.metric,.panel {
  border-radius: 15px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 0 #140e27,0 8px 24px #0e091f55;
  animation: riseIn .26s ease both;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 14px 16px;
  background: linear-gradient(135deg,#422c68,#2b2049);
}

.metric.teal {
  background: linear-gradient(135deg,#214a50,#242645);
}

.metric.gold {
  background: linear-gradient(135deg,#553f28,#362646);
}

.metric.indigo {
  background: linear-gradient(135deg,#33346e,#231f44);
}

.metric strong {
  font-size: clamp(23px,3.2vw,34px);
  line-height: 1.2;
  color: var(--purple);
  font-variant-numeric: tabular-nums;
  margin-block: 5px;
}

.metric.teal strong {
  color: var(--teal);
}

.metric.gold strong {
  color: var(--gold);
}

.metric.indigo strong {
  color: #b7d2ff;
}

.panel {
  padding: 17px 19px;
  margin-bottom: 17px;
  background: linear-gradient(145deg,#2b2148,#221a3c);
}

.section-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
}

.section-top h2,.section-top p {
  margin: 0;
}

.filter {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--muted);
}

input,select,textarea {
  border: 1px solid #806aa7;
  border-radius: 8px;
  background: #170f2d;
  color: var(--ink);
  padding: 8px 10px;
  min-width: 0;
}

textarea {
  width: 100%;
  resize: vertical;
}

.seg-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
  background: #17102c;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid #4c3d70;
}

.seg-btn {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.seg-btn:hover {
  color: var(--ink);
  background: #ffffff10;
}

.seg-btn.active {
  background: #5b4391;
  color: #fff;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}

.status-pill.ok {
  background: #1b4d44;
  color: #b7ffec;
  border-color: #3a8c7b;
}

.status-pill.warn {
  background: #582548;
  color: #ffd0eb;
  border-color: #b34d89;
}

.status-pill.amber {
  background: #543e1b;
  color: #ffe8a3;
  border-color: #a67f2e;
}

.status-pill.purple {
  background: #3e2e6b;
  color: #e4d4ff;
  border-color: #7c61bd;
}

.status-pill.muted {
  background: #352b50;
  color: #cfc4e6;
  border-color: #5b4c80;
}

.note-badge {
  display: inline-block;
  margin-inline-start: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: #402e69;
  color: var(--gold);
  font-size: 11.5px;
}

.period-footnote {
  margin: 8px 0 0;
  font-size: 13.5px;
}

/* Trend Explorer */
.trend-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.trend-readout {
  background: #191230;
  border: 1px solid #4e3e72;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 14px;
  color: var(--gold);
  margin-bottom: 10px;
  min-height: 36px;
}

.trend-svg-wrap,.raster-wrap,.report-chart-wrap {
  overflow-x: auto;
}

.trend-svg {
  display: block;
  width: 100%;
  min-width: 640px;
  height: auto;
}

.trend-hit {
  fill: transparent;
}

.trend-node:hover .tbar,.trend-node:focus .tbar {
  filter: brightness(1.22);
}

.tbar.ok { fill: var(--teal); }
.tbar.steady { fill: var(--teal); }
.tbar.events,.tbar.amber { fill: var(--amber); }
.tbar.leak,.tbar.warn { fill: var(--warn); }
.tbar.short,.tbar.purple { fill: var(--purple); }
.tbar.summary,.tbar.muted { fill: #7f729f; }
.tbar.teal { fill: var(--teal); }
.tbar.gold-soft { fill: #ffdf9799; }

.ref-line {
  stroke-width: 1.2;
  stroke-dasharray: 5 4;
}

.ref-line.ref-warn { stroke: #f472b6b0; }
.ref-line.ref-teal { stroke: #88e5d799; }
.ref-line.ref-muted { stroke: #c7bcde77; }

.ref-label {
  font: 11px "Cairo", sans-serif;
  fill: var(--gold);
}

.trend-axis {
  font: 11px "Cairo", sans-serif;
  fill: #cfc4e6;
}

.trend-legend,.legend-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.leg-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.leg-dot::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  background: var(--purple);
}

.leg-dot.ok::before,.leg-dot.teal::before { background: var(--teal); }
.leg-dot.amber::before { background: var(--amber); }
.leg-dot.warn::before { background: var(--warn); }
.leg-dot.muted::before { background: #7f729f; }
.leg-dot.gold::before { background: var(--gold); }

/* Sleep Raster */
.raster-svg {
  display: block;
  width: 100%;
  min-width: 600px;
  height: auto;
}

.raster-grid {
  stroke: #493a6b;
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.raster-axis {
  font: 11.5px "Cairo", sans-serif;
  fill: var(--muted);
}

.raster-day-lbl {
  font: 12px "Cairo", sans-serif;
  fill: var(--purple);
  font-weight: 600;
}

.raster-track {
  fill: #18112d;
  stroke: #3c2e5b;
  stroke-width: 1;
}

.raster-seg.ok { fill: #5ddbc8; }
.raster-seg.amber { fill: #fbbf24; }
.raster-seg.warn { fill: #f472b6; }
.raster-row:hover .raster-seg { filter: brightness(1.15); }

/* Tables */
.history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.table-wrap {
  overflow: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  white-space: nowrap;
}

th,td {
  padding: 9px 8px;
  text-align: start;
  border-bottom: 1px solid #4e406d;
  font-variant-numeric: tabular-nums;
}

thead th {
  font-weight: 600;
  color: var(--muted);
  font-size: 13.5px;
}

tbody tr:hover {
  background: #372954;
}

tr.row-warn {
  background: #4e22403d;
}

tr.row-amber {
  background: #4d39173d;
}

tbody th a,.text-link {
  color: var(--purple);
  text-decoration: underline;
  text-underline-offset: 4px;
}

tbody small {
  font-size: 12px;
  margin-inline-start: 6px;
}

.pill {
  background: #47385c;
  color: #f0dffb;
  border-radius: 20px;
  padding: 3px 9px;
  font-size: 13px;
}

.pill.full {
  background: #285051;
  color: #c4fff2;
}

.auth-card {
  width: min(100%,430px);
  margin: clamp(10px,6vh,70px) auto;
  text-align: center;
  padding: 27px;
}

.stack {
  display: grid;
  gap: 13px;
  text-align: start;
  margin-block: 14px 6px;
}

.stack label {
  display: grid;
  gap: 5px;
}

.stack input {
  width: 100%;
}

.notice {
  color: #ddfff6;
  background: #244e49;
  border: 1px solid #659884;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.notice.error {
  background: #532840;
  border-color: #bd6b8a;
  color: #ffe0ec;
}

.import-layout {
  max-width: 650px;
}

.file-label {
  padding: 10px;
  border: 1px dashed #806aa7;
  border-radius: 10px;
}

.file-label code {
  direction: ltr;
  justify-self: start;
  color: var(--gold);
}

/* Night page & Signal Grid */
.night-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.night-pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.signal-grid {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 10px;
  margin-top: 8px;
}

.sig-stat {
  background: #1b1433;
  border: 1px solid #4a3a6d;
  border-radius: 11px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sig-stat.sig-warn {
  border-color: #a9477c;
  background: #3a1d35;
}

.sig-stat strong {
  font-size: 20px;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}

.sig-stat.sig-warn strong {
  color: #ffb8df;
}

.summary dl {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0 0 13px;
}

.summary dl div {
  padding: 6px 8px;
}

.summary dd {
  margin: 0;
  color: var(--gold);
  font-size: 20px;
}

/* Waveform Studio */
.minimap-wrap {
  margin-bottom: 12px;
  border: 1px solid #4d3d70;
  border-radius: 10px;
  background: #17102c;
  padding: 4px 6px;
}

.minimap-svg {
  display: block;
  width: 100%;
  cursor: pointer;
}

.minimap-svg text {
  font: 10.5px "Cairo", sans-serif;
  fill: var(--muted);
}

.minimap-bg {
  fill: #1b1433;
}

.minimap-trace {
  stroke: #88e5d7;
  stroke-width: 1.2;
  fill: none;
}

.minimap-leak {
  stroke: #ffdf9788;
  stroke-width: 1;
  fill: none;
}

.minimap-window {
  fill: #c7a7ff33;
  stroke: #c7a7ff;
  stroke-width: 1.4;
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}

.touch-toggle.active {
  background: #2f5e59;
  border-color: var(--teal);
  color: #d9fff7;
}

.channel-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chan-pill {
  background: #1a1230;
  color: var(--muted);
  border: 1px solid #534275;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 13px;
  cursor: pointer;
}

.chan-pill.active {
  background: #3d2e69;
  color: var(--ink);
  border-color: var(--purple);
}

#recording-status {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 9px;
}

#charts article {
  margin-bottom: 12px;
  border: 1px solid #50406f;
  border-radius: 10px;
  padding: 8px 10px;
  background: #1b1532;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

#charts h3 {
  margin: 0;
}

.chart-readout {
  font-size: 13px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.overlay-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.ov-item::before {
  content: "━━ ";
}

.ov-item.main-p::before { color: var(--teal); }
.ov-item.overlay-ipap::before { color: #f472b6; content: "┄┄ "; }
.ov-item.overlay-epap::before { color: #ffdf97; content: "┄┄ "; }

.waveform {
  display: block;
  width: 100%;
  background: #1b1532;
  user-select: none;
  cursor: crosshair;
}

.waveform.touch-select {
  touch-action: none;
}

.waveform text {
  font: 11px "Cairo", sans-serif;
  fill: #d5c9ea;
}

.grid-line {
  stroke: #564673;
  stroke-width: 1;
  fill: none;
}

.trace {
  stroke: #c6a5ff;
  stroke-width: 1.25;
  fill: none;
}

.Pressure .trace,.IPAPsoll .trace,.EPAPsoll .trace,.EEPAPsoll .trace {
  stroke: #88e5d7;
}

.trace.overlay-ipap {
  stroke: #f472b6;
  stroke-width: 1.2;
  stroke-dasharray: 5 3;
}

.trace.overlay-epap {
  stroke: #ffdf97;
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
}

.LeakFlowBreath .trace,.TotalLeakage .trace {
  stroke: #ffdf97;
}

.BreathVolume .trace,.MV .trace {
  stroke: #93c5fd;
}

.ObstructLevel .trace {
  stroke: #fb7185;
}

.BreathFrequency .trace,.InspExpirRel .trace {
  stroke: #a7f3d0;
}

.crosshair {
  stroke: #ffffffaa;
  stroke-width: 1;
  stroke-dasharray: 3 3;
  pointer-events: none;
}

.event {
  fill: #c39944;
  opacity: .36;
}

.event.ev-OA { fill: #f87171; opacity: .45; }
.event.ev-CA { fill: #fb923c; opacity: .45; }
.event.ev-OH { fill: #fbbf24; opacity: .38; }
.event.ev-CH { fill: #facc15; opacity: .38; }
.event.ev-RERA { fill: #38bdf8; opacity: .35; }
.event.ev-LL,.event.leak-event { fill: #e879f9; opacity: .28; }

.selection {
  fill: #b396ff;
  opacity: .35;
  pointer-events: none;
}

#event-controls {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.event-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ev-badge {
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12.5px;
  background: #352855;
  border: 1px solid #5c488a;
}

.ev-badge.ev-OA { border-color: #f87171; color: #fecaca; }
.ev-badge.ev-CA { border-color: #fb923c; color: #fed7aa; }
.ev-badge.ev-OH { border-color: #fbbf24; color: #fef08a; }
.ev-badge.ev-CH { border-color: #facc15; color: #fef9c3; }
.ev-badge.ev-RERA { border-color: #38bdf8; color: #bae6fd; }
.ev-badge.ev-LL { border-color: #e879f9; color: #f5d0fe; }

.event-nav-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.shortcut-hint {
  margin-top: 8px;
  font-size: 12.5px;
}

/* Night notes form */
.feeling-group {
  border: 1px solid #4e3d70;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
}

.feeling-group legend {
  padding-inline: 6px;
  color: var(--muted);
  font-size: 14px;
}

.feeling-options,.tag-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-radio,.chip-check {
  display: inline-flex!important;
  align-items: center;
  gap: 6px;
  background: #191230;
  border: 1px solid #594680;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 14px;
}

.chip-radio input,.chip-check input {
  width: auto!important;
  margin: 0;
}

.chip-radio:has(input:checked),.chip-check:has(input:checked) {
  background: #483278;
  border-color: var(--purple);
  color: #fff;
}

/* Insights */
.insight {
  border-color: #8f74c4;
  background: linear-gradient(145deg, #362657, #261c44);
}
.insight .section-top {
  margin-bottom: 10px;
}
.insight .insight-lead {
  color: var(--ink);
  font-size: 1.08rem;
}
.insight-alert {
  background: #4e224088;
  border: 1px solid #b34d89;
  border-radius: 9px;
  padding: 8px 12px;
  color: #ffe0f1;
}
.insight p strong {
  color: var(--gold);
}
.insight-next {
  color: var(--teal);
  margin-top: 13px;
}
.insight-settings {
  border-top: 1px solid var(--line);
  padding-block: 5px;
}
.insight-settings summary {
  cursor: pointer;
  color: var(--purple);
}
.insight-settings ul, .insight-steps {
  margin-block: 4px 9px;
  padding-inline-start: 21px;
}
.insight-settings p {
  margin-block: 6px 3px;
}
.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  padding-block: 9px 16px;
}

.peak-comparison {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-block: 10px;
  background: #261c44;
}
.peak-comparison td small,
.peak-comparison th small {
  display: block;
  margin-inline-start: 0;
}
.peak-comparison h3 {
  color: var(--teal);
}

/* Report page */
.report-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.date-range-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.date-range-form label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.report-header {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.report-meta {
  text-align: end;
  font-size: 14px;
}

.report-grid-2 {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.report-block {
  margin-bottom: 18px;
  background: #1b1433;
  border: 1px solid #4a3b6c;
  border-radius: 12px;
  padding: 13px 15px;
}

.report-block h3 {
  color: var(--teal);
  margin-bottom: 10px;
}

.kv-list {
  display: grid;
  gap: 7px;
  margin: 0;
}

.kv-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px dashed #3d305c;
  padding-bottom: 4px;
}

.kv-list dt {
  color: var(--muted);
  font-size: 14px;
}

.kv-list dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.report-svg {
  display: block;
  width: 100%;
  min-width: 520px;
  height: auto;
}

.report-bar-val {
  font: 10px "Cairo", sans-serif;
  fill: var(--gold);
}

@media(max-width:900px){
  .kpi-grid {
    grid-template-columns: repeat(2,minmax(0,1fr));
  }
  .signal-grid {
    grid-template-columns: repeat(2,minmax(0,1fr));
  }
  .report-grid-2 {
    grid-template-columns: 1fr;
  }
}

@media(max-width:600px){
  .shell {
    width: calc(100% - 20px);
  }
  .nav {
    gap: 6px;
  }
  .brand,nav {
    gap: 5px;
  }
  .brand {
    font-size: 14px;
  }
  .nav-link,.button.small {
    font-size: 13px;
    padding-inline: 7px;
  }
  .cards,.kpi-grid,.signal-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .metric {
    padding: 10px 12px;
    font-size: 14px;
  }
  .panel {
    padding: 12px;
  }
  th,td {
    padding: 8px 5px;
  }
  .waveform {
    min-height: 102px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .metric,.panel,.button,.light,.nav-link,.seg-btn {
    animation: none!important;
    transition: none!important;
  }
}

@media print {
  :root {
    color-scheme: light;
  }
  body {
    background: #fff!important;
    color: #111!important;
    font-size: 12px;
  }
  .top,.site-footer,.no-print {
    display: none!important;
  }
  .shell {
    width: 100%;
    max-width: none;
  }
  .panel,.report-sheet,.report-block {
    background: #fff!important;
    color: #111!important;
    border-color: #cbd5e1!important;
    box-shadow: none!important;
    break-inside: avoid;
  }
  .subtle,p,small,.kv-list dt,thead th {
    color: #475569!important;
  }
  .report-block h3 {
    color: #0f172a!important;
  }
  th,td {
    border-bottom-color: #cbd5e1!important;
    padding: 5px 6px;
  }
  .tbar.ok,.tbar.steady { fill: #0d9488!important; }
  .tbar.events,.tbar.amber { fill: #d97706!important; }
  .tbar.leak,.tbar.warn { fill: #be185d!important; }
  .report-bar-val,.trend-axis,.ref-label { fill: #334155!important; }
  .no-print-link {
    text-decoration: none;
    color: #111;
  }
}

/* ===== v1.3.0 — visual summary, sparklines, calendar, hourly chart ===== */
.hero {
  border-color: #8f74c4;
  background: radial-gradient(120% 140% at 100% 0%, #3d2a66 0%, #261c44 55%, #20183a 100%);
}
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr) minmax(0,1.7fr);
  gap: 12px;
}
.hero-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 13px 14px;
  border-radius: 13px;
  background: #1a1332b8;
  border: 1px solid #4e3e72;
  min-width: 0;
}
.hero-wide {
  align-items: stretch;
}
.hero-label {
  align-self: stretch;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--muted);
}
.hero-label-gap {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid #4e3e72;
}
.hero-inline {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.hero-inline.ok { color: var(--ok); }
.hero-inline.amber { color: var(--amber); }
.hero-inline.warn { color: var(--warn); }
.hero-foot {
  font-size: 12px;
  text-align: center;
}
.hero-steps {
  margin-top: 14px;
  padding-top: 4px;
  border-top: 1px solid #4e3e72;
}
.hero-steps .insight-next {
  color: var(--teal);
}

.gauge {
  width: min(100%, 230px);
  height: auto;
}
.gauge-track,.gauge-fill {
  fill: none;
  stroke-width: 12;
  stroke-linecap: round;
}
.gauge-track,.ring-track { stroke: #3a2d5c; }
.gauge-fill.ok { stroke: var(--ok); }
.gauge-fill.amber { stroke: var(--amber); }
.gauge-fill.warn { stroke: var(--warn); }
.gauge-tick {
  stroke: #fbf6ffb8;
  stroke-width: 1.6;
  stroke-linecap: round;
}
.gauge-num {
  font: 700 27px "Cairo", sans-serif;
  fill: var(--ink);
}
.gauge-num.ok { fill: var(--ok); }
.gauge-num.amber { fill: var(--amber); }
.gauge-num.warn { fill: var(--warn); }
.gauge-num.muted { fill: var(--muted); }
.gauge-scale {
  direction: ltr;
  unicode-bidi: isolate;
  font: 8px "Cairo", sans-serif;
  fill: #cfc4e6;
}

.rings {
  width: min(100%, 150px);
  height: auto;
}
.ring-track,.ring-fill {
  fill: none;
  stroke-width: 8;
}
.ring-fill { stroke-linecap: round; }
.ring-fill.purple { stroke: var(--purple); }
.ring-fill.teal { stroke: var(--teal); }
.ring-num {
  font: 700 17px "Cairo", sans-serif;
  fill: var(--ink);
}

.meter,.mix {
  display: block;
  width: 100%;
  border-radius: 7px;
}
.meter { height: 16px; }
.mix { height: 14px; }
.zone.ok { fill: #6ee7b72e; }
.zone.amber { fill: #fbbf2433; }
.zone.warn { fill: #f472b638; }
.meter-fill.ok { fill: var(--ok); }
.meter-fill.amber { fill: var(--amber); }
.meter-fill.warn { fill: var(--warn); }
.meter-mark { fill: #fbf6ff; }
.meter-scale {
  position: relative;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}
.meter-scale .at24,.meter-scale .at35 {
  position: absolute;
  transform: translateX(-50%);
}
.meter-scale .at24 { left: 48%; }
.meter-scale .at35 { left: 70%; }

.evf-oh { fill: var(--amber); }
.evf-ch { fill: var(--gold); }
.evf-oa { fill: var(--warn); }
.evf-ca { fill: var(--purple); }
.evf-rera { fill: #7f729f; }
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--purple);
}
.dot.teal { background: var(--teal); }
.dot.evb-oh,.leg-dot.evb-oh::before { background: var(--amber); }
.dot.evb-ch,.leg-dot.evb-ch::before { background: var(--gold); }
.dot.evb-oa,.leg-dot.evb-oa::before { background: var(--warn); }
.dot.evb-ca,.leg-dot.evb-ca::before { background: var(--purple); }
.dot.evb-rera { background: #7f729f; }
.leg-dot.purple::before { background: var(--purple); }
.mix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 13px;
  font-size: 13px;
  color: var(--muted);
}
.mix-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.mix-legend .is-zero { opacity: .55; }
.mix-legend bdi {
  color: var(--ink);
  font-weight: 700;
}

.hero-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.hero-wide .hero-chips { justify-content: flex-start; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid #574779;
  background: #2a2049;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}
.chip bdi {
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chip.delta.ok { border-color: #2f8f72; background: #17372f; color: var(--ok); }
.chip.delta.warn { border-color: #a6477d; background: #43203a; color: #ffb3d9; }
.chip.delta.muted { color: var(--muted); }
.chip.delta.ok bdi,.chip.delta.warn bdi { color: inherit; }

/* Folded text briefing / tables */
.brief-fold {
  margin-bottom: 17px;
}
.brief-fold > summary {
  cursor: pointer;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #1f1739;
  color: var(--purple);
  font-weight: 600;
}
.brief-fold[open] > summary {
  margin-bottom: 10px;
}
.brief-fold > summary:hover { background: #2a2049; }
.table-fold { margin: 10px 0 0; }

/* KPI tiles: sparkline + delta */
.metric .spark {
  width: 100%;
  height: 34px;
  margin-top: 8px;
  display: block;
}
.spark-line {
  fill: none;
  stroke: var(--purple);
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.spark-area { fill: #c7a7ff24; }
.spark-dot { fill: var(--purple); }
.metric.teal .spark-line { stroke: var(--teal); }
.metric.teal .spark-area { fill: #88e5d724; }
.metric.teal .spark-dot { fill: var(--teal); }
.metric.gold .spark-line { stroke: var(--gold); }
.metric.gold .spark-area { fill: #ffdf9724; }
.metric.gold .spark-dot { fill: var(--gold); }
.metric .chip.delta { margin-top: 2px; }
.period-footnote {
  font-size: 12.5px;
  margin-top: 4px;
}

/* Trend explorer: moving average + tooltip */
#trend-explorer { position: relative; }
.trend-avg {
  fill: none;
  stroke: #fbf6ff;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  opacity: .9;
  pointer-events: none;
}
.trend-node:hover .trend-hit,.trend-node:focus .trend-hit { fill: #c7a7ff1c; }
.trend-node { outline: none; }
.leg-dot.avg::before {
  height: 2px;
  width: 16px;
  border-radius: 1px;
  background: #fbf6ff;
}
.trend-tip {
  position: absolute;
  z-index: 5;
  min-width: 170px;
  max-width: 240px;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid #8f74c4;
  background: #140e27f2;
  box-shadow: 0 8px 22px #0009;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink);
  pointer-events: none;
  direction: rtl;
}
.trend-tip strong {
  display: block;
  color: var(--gold);
}
.trend-tip .tip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}
.trend-tip .tip-row b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Calendar heatmap */
.heat-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}
.heat {
  display: flex;
  gap: 4px;
  width: max-content;
  margin-inline: auto;
}
.heat-week {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.heat-month {
  height: 17px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: visible;
  width: 30px;
  direction: rtl;
}
.heat-day {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
}
.heat-days .heat-day { width: 20px; }
.heat-days .heat-month { width: 20px; }
.heat-cell {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  color: var(--ink-dark);
  transition: transform .12s ease, box-shadow .12s ease;
}
a.heat-cell:hover,a.heat-cell:focus-visible {
  transform: scale(1.14);
  box-shadow: 0 0 0 2px #fbf6ff;
  outline: none;
}
.heat-cell.steady { background: var(--teal); }
.heat-cell.events { background: var(--amber); }
.heat-cell.leak { background: var(--warn); }
.heat-cell.short { background: var(--purple); }
.heat-cell.summary { background: #7f729f; color: #fff; }
.heat-cell.none {
  background: #1f1739;
  border: 1px dashed #4e3e72;
  color: #8377a3;
  font-weight: 400;
}
.heat-cell.pad { background: transparent; }

/* History table mini bars */
.mini-bar {
  display: block;
  width: 100%;
  max-width: 120px;
  min-width: 60px;
  height: 6px;
  border-radius: 3px;
  margin-block: 4px 2px;
}
.mini-track { fill: #3a2d5c; }
.mini-fill.purple { fill: var(--purple); }
.mini-fill.teal { fill: var(--teal); }
.mini-fill.ok { fill: var(--ok); }
.mini-fill.amber { fill: var(--amber); }
.mini-fill.warn { fill: var(--warn); }
.mini-fill.muted { fill: #7f729f; }
.mini-mark { fill: #fbf6ffb0; }

/* Hourly chart (night page) */
.hourly-svg {
  display: block;
  height: 236px;
  width: auto;
  max-width: none;
  margin-inline: auto;
}
.hourly-legend { margin-bottom: 8px; }
.session-sep {
  stroke: #c7a7ff88;
  stroke-width: 1;
  stroke-dasharray: 2 4;
}
.hourly-svg .trend-node:hover rect:not(.trend-hit),
.hourly-svg .trend-node:focus rect:not(.trend-hit) { filter: brightness(1.2); }
.report-chart-title {
  margin: 12px 0 4px;
  font-size: 14px;
  color: var(--muted);
}

@media(max-width:900px){
  .hero-grid {
    grid-template-columns: repeat(2,minmax(0,1fr));
  }
  .hero-wide { grid-column: 1 / -1; }
}

@media(max-width:600px){
  .hero-grid { gap: 8px; }
  .hero-tile { padding: 10px 9px; }
  .hero-label { font-size: 12.5px; justify-content: center; text-align: center; }
  .hero-wide .hero-label { justify-content: space-between; text-align: start; }
  .gauge-num { font-size: 25px; }
  .chip { font-size: 12px; padding: 2px 7px; }
  .heat-cell,.heat-day,.heat-month { width: 26px; }
  .heat-cell,.heat-day { height: 26px; }
  .heat { margin-inline: 0; }
  .trend-tip { font-size: 12px; min-width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .heat-cell { transition: none!important; }
}

@media print {
  .hero,.hero-tile,.brief-fold > summary { background: #fff!important; border-color: #cbd5e1!important; }
  .gauge-track,.ring-track { stroke: #e2e8f0!important; }
  .gauge-num,.ring-num { fill: #0f172a!important; }
  .gauge-scale { fill: #334155!important; }
  .chip { background: #fff!important; color: #334155!important; border-color: #cbd5e1!important; }
  .chip bdi,.hero-inline,.mix-legend bdi { color: #0f172a!important; }
  .trend-tip { display: none!important; }
  .report-chart-title { color: #0f172a!important; }
  .tbar.short,.tbar.purple { fill: #7c3aed!important; }
  .tbar.summary,.tbar.muted { fill: #94a3b8!important; }
  .tbar.teal { fill: #0d9488!important; }
}

/* Date navigation and shortcuts belong above the charts. */
.dashboard-heading {
  margin-block-end: 12px;
}

.night-header,
.night-date-nav,
.day-arrows,
.day-picker,
.dashboard-jumps {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.night-header {
  justify-content: space-between;
}

.night-header .dashboard-heading {
  margin: 0;
}

.night-date-nav {
  justify-content: flex-start;
  margin-block: 10px 14px;
}

.night-date-nav .light {
  min-height: 36px;
}

.night-date-nav .disabled {
  opacity: .45;
  cursor: default;
}

.day-picker {
  gap: 7px;
}

.day-picker input {
  max-width: 150px;
  min-height: 36px;
  padding-block: 3px;
}

.day-picker label {
  color: var(--muted);
  font-size: 14px;
}

.dashboard-jumps {
  margin-block: 10px 14px;
}

.dashboard-jumps a {
  color: var(--purple);
  font-size: 14px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #261b43;
}

.dashboard-jumps a:hover,
.review-card:hover {
  border-color: var(--purple);
}

main [id] {
  scroll-margin-top: 78px;
}

.hero-steps {
  margin: 10px 0 14px;
  padding: 6px 12px;
  border: 1px solid #73578e;
  border-radius: 10px;
  background: #1d153594;
}

.hero-steps h3 {
  margin: 0;
}

.hero-steps li:last-child {
  margin-bottom: 0;
}

.meter .meter-track {
  fill: #3a2d5c;
  stroke: none;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.review-card {
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(150deg, #382851, #211836);
  box-shadow: 0 3px 0 #151026;
}

.review-flags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tbar.gap { fill: var(--gold); }
.heat-cell.gap { background: var(--gold); }
.leg-dot.gap::before { background: var(--gold); }

#history-empty {
  padding-top: 10px;
}

@media (max-width: 600px) {
  .night-date-nav, .day-arrows {
    gap: 6px;
  }
  .night-date-nav .light {
    padding-inline: 8px;
  }
  .night-date-nav {
    margin-block: 7px 12px;
  }
  .night-header h1 {
    font-size: 23px;
  }
  .night-header .light {
    font-size: 12px;
  }
  .review-grid {
    grid-template-columns: 1fr;
  }
}

.device-settings summary {
  cursor: pointer;
  font-weight: 750;
  color: var(--purple);
}
.device-settings[open] summary {
  margin-block-end: 12px;
}
.device-settings h3 {
  margin-block: 12px 4px;
}
.device-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(146px, 100%), 1fr));
  gap: 8px;
  margin-block: 8px 12px;
}
.device-fields div {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #221937;
}
.device-fields span,
.device-fields strong {
  display: block;
}
.device-fields span {
  color: var(--muted);
  font-size: 13px;
}
.device-fields strong {
  color: var(--teal);
}

.pressure-review {
  margin-block: 10px 14px;
  padding: 10px 13px;
  border: 1px solid #816ba6;
  border-radius: 10px;
  background: #2d214a;
}
.pressure-review h3 {
  margin-block-end: 4px;
  color: var(--gold);
}
.pressure-review p:last-child {
  margin-block-end: 0;
}
.pressure-review summary {
  color: var(--purple);
  cursor: pointer;
}
.pressure-review-items {
  display: grid;
  gap: 10px;
  margin-block: 10px;
}
.pressure-review-items dt {
  font-weight: 750;
  color: var(--teal);
}
.pressure-review-items dd {
  margin-inline-start: 0;
}

.primary-nav {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dashboard-modes {
  flex-wrap: wrap;
  margin-block: 12px 16px;
}

.feature-form {
  display: grid;
  gap: 8px;
  justify-items: start;
  margin-block: 12px;
}

.feature-form input:not([type="checkbox"]), .feature-form select, .feature-form textarea {
  min-block-size: 48px;
  font-size: max(1rem, 1em);
  max-inline-size: 100%;
}

.feature-form textarea {
  inline-size: min(100%, 30rem);
}

.compare-picker {
  grid-template-columns: repeat(2, minmax(0, 1fr)) max-content;
  align-items: end;
  gap: 14px;
}

.compare-picker > div {
  display: grid;
  inline-size: 100%;
  gap: 4px;
}

.compare-table {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: 34rem;
}

.compare-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
}

.compare-table thead th, .compare-table tbody th {
  background: var(--panel, #261b40);
}

.compare-table td {
  white-space: nowrap;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.compare-chart-card {
  margin: 0;
}

.compare-chart {
  display: block;
  inline-size: 100%;
}

.compare-chart text {
  fill: var(--muted);
  font-size: 12px;
}

.compare-chart a line {
  stroke-width: 5;
  stroke-linecap: butt;
}

.compare-chart a:hover line, .compare-chart a:focus-visible line {
  stroke-width: 9;
}

.series-ipap { stroke: var(--gold); }
.series-epap { stroke: #bd9fff; }
.series-leak { stroke: #78e3ce; }

.saved-windows {
  display: grid;
  gap: 10px;
  padding: 0;
  list-style: none;
}

.saved-windows li {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding-block: 8px;
  border-block-end: 1px solid #ffffff30;
  overflow-wrap: anywhere;
}

.saved-windows small, .summary dd small {
  display: block;
}

.saved-windows p {
  margin: 0;
  white-space: pre-wrap;
}

.import-example {
  overflow: auto;
  background: #160f28;
  border-radius: 8px;
  padding: 12px;
}

@media (max-width: 600px) {
  .nav {
    flex-wrap: wrap;
    padding-block: 7px;
  }

  .primary-nav {
    justify-content: flex-start;
  }

  .compare-picker, .comparison-grid {
    grid-template-columns: 1fr;
  }
}
