/* =========================================================
   CardioPulse Pro — Medical Monitor Station Theme
   Reference: Dark cockpit ECG monitor aesthetic
   ========================================================= */

:root {
  --bg-deep: #0D1117;
  --bg-surface: #161B22;
  --bg-elevated: #1C2333;
  --bg-hover: #252D3A;
  --bg-inset: #0A0E14;

  /* Accent colours */
  --accent-cyan: #00BCD4;
  --accent-cyan-dim: rgba(0, 188, 212, 0.12);
  --accent-cyan-glow: rgba(0, 188, 212, 0.25);
  --accent-green: #00C853;      /* ECG trace / normal — calm clinical green */
  --accent-green-dim: rgba(0, 200, 83, 0.10);
  --accent-red: #EF5350;        /* Clinical alert red */
  --accent-red-dim: rgba(239, 83, 80, 0.15);
  --accent-amber: #FFB300;      /* Warning amber */
  --accent-purple: #7E57C2;     /* AFIB */

  /* Text */
  --text-primary: #E6EDF3;
  --text-secondary: #C9D1D9;
  --text-muted: #8B949E;

  /* Chrome borders — neutral, no ECG tint */
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-panel:  rgba(255, 255, 255, 0.10);
  --border-tab:    rgba(255, 255, 255, 0.14);
  --border-glow:   rgba(255, 255, 255, 0.08);
  --border-color:  rgba(255, 255, 255, 0.10); /* compatibility alias */

  /* ECG-specific borders — reserved for data containers only */
  --border-ecg:     rgba(0, 200, 83, 0.35);
  --border-ecg-dim: rgba(0, 200, 83, 0.12);

  /* Shadows */
  --shadow-float:  0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-window: 0 20px 60px rgba(0, 0, 0, 0.65), 0 2px 8px rgba(0, 0, 0, 0.40);
  --shadow-inset:  inset 0 1px 3px rgba(0, 0, 0, 0.3);

  /* ECG Grid */
  --grid-major: rgba(0, 200, 83, 0.06);
  --grid-minor: rgba(0, 200, 83, 0.025);

  /* Type scale */
  --text-2xs:  9px;
  --text-xs:   10px;
  --text-sm:   11px;
  --text-base: 13px;
  --text-md:   14px;
  --text-lg:   16px;
  --text-xl:   20px;

  /* Spacing (8dp grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius:    6px; /* legacy alias */

  /* Zone colours — perceptually distinct */
  --zone-1-color: #26A69A;
  --zone-2-color: #66BB6A;
  --zone-3-color: #FFA726;
  --zone-4-color: #EF5350;
  --zone-5-color: #AB47BC;

  --header-height: 48px;    /* 8dp-aligned */
  --sidebar-width: 60px;
  --sidebar-expanded: 360px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: #060A10;  /* Even darker behind the window */
  height: 100%;
}

body {
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  font-size: 12px;
  margin: 12px;
  height: calc(100vh - 24px);
  position: relative;
  display: grid;
  grid-template-areas:
    "sidebar header header"
    "sidebar panel main";
  grid-template-columns: var(--sidebar-width) 0px 1fr;
  grid-template-rows: var(--header-height) 1fr;
  column-gap: 4px;
  overflow: hidden;
  transition: grid-template-columns 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  -webkit-font-smoothing: antialiased;
  
  /* Glass window frame */
  border-radius: 12px;
  border: 1px solid var(--border-panel);
  box-shadow: var(--shadow-window);
}

body.panel-open {
  grid-template-columns: var(--sidebar-width) var(--sidebar-expanded) 1fr;
}

body.panel-open #panel-help.open {
  min-width: 420px;
}

body.panel-open:has(#panel-help.open) {
  grid-template-columns: var(--sidebar-width) 420px 1fr;
}

/* ================================================
   WINDOW CHROME — macOS Title Bar
   ================================================ */
.app-header {
  grid-area: header;
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
  border-bottom: 1px solid var(--border-tab);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  z-index: 100;
  -webkit-app-region: drag;
  user-select: none;
  border-radius: 12px 12px 0 0;  /* Match window rounding */
}

/* Traffic Light Dots */
.window-controls {
  display: flex;
  gap: 6px;
  -webkit-app-region: no-drag;
}
.window-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
}
.dot-close { background: #FF5F57; }
.dot-minimize { background: #FFBD2E; }
.dot-maximize { background: var(--accent-green); }

.brand-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.03em;
}
#breadcrumbSession {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0;
}

.theme-toggle-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  -webkit-app-region: no-drag;
}
.theme-toggle-btn:hover {
  background: var(--bg-hover);
}
.theme-icon {
  font-size: 14px;
}

/* ================================================
   SIDEBAR — Icon + Label Strip (Reference Match)
   ================================================ */
.app-sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-surface) 50%, var(--bg-deep) 100%);
  border-right: none;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  gap: 4px;
  overflow: hidden;
  z-index: 110;
  align-items: center;
  border-radius: 12px 0 0 12px;
}

/* Sidebar Nav Item — Icon + Label stacked */
.sidebar-item {
  width: 48px;
  min-height: 52px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  color: var(--text-primary);
  font-size: 16px;
  flex-shrink: 0;
  border: none;
  background: none;
  padding: 6px 0;
}

.sidebar-item:hover {
  color: #FFFFFF;
}

.sidebar-item .item-label {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: inherit;
  line-height: 1;
}

/* Active state — glowing cyan strip + highlighted icon */
.sidebar-item.active {
  color: var(--accent-cyan);
}

.sidebar-item.active .sidebar-icon-wrap {
  background: rgba(0, 188, 212, 0.12);
  box-shadow: 0 0 12px rgba(0, 188, 212, 0.08);
}

/* Full-height cyan glow strip */
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(0, 188, 212, 0.4),
              0 0 24px rgba(0, 188, 212, 0.15);
}

/* Icon wrapper with translucent bg */
.sidebar-icon-wrap {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s;
  background: transparent;
}

.sidebar-item:hover .sidebar-icon-wrap {
  background: var(--bg-elevated);
}

.sidebar-spacer {
  flex: 1;
}

.sidebar-divider {
  width: 28px;
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

/* ================================================
   SIDEBAR PANEL — Flyout when item clicked
   ================================================ */
.sidebar-panel {
  grid-area: panel;
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  background: linear-gradient(180deg, rgba(28,35,51,0.98) 0%, rgba(22,27,34,0.98) 100%);
  border-right: none;
  box-shadow: none;
  z-index: 10;
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-8px);
  border-radius: 0 0 0 12px;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.22s;
  will-change: transform, opacity;
  pointer-events: none;
}
.sidebar-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  pointer-events: auto;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0s;
}

@keyframes pulse {
  from { opacity: 0.3; }
  to   { opacity: 0.6; }
}

.sidebar-panel::before {
  display: none;
}

#panel-data { --panel-accent: var(--accent-cyan); }
#panel-sessions { --panel-accent: var(--accent-green); }
#panel-display { --panel-accent: var(--accent-amber); }
#panel-analysis { --panel-accent: var(--accent-purple); }
#panel-settings { --panel-accent: var(--accent-red); }

/* Main content shrinks when panel is open */
.app-main {
  transition: margin-right 0.2s ease;
}
.app-main.panel-open {
  margin-right: 0;
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

/* ================================================
   FORM CONTROLS
   ================================================ */
.control-row {
  margin-bottom: 8px;
}
.control-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 3px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.styled-select, .styled-input {
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  font-family: inherit;
  font-size: var(--text-sm);
  background: var(--bg-inset);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.styled-select:focus, .styled-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--accent-cyan-dim);
}
.styled-select option {
  background: var(--bg-surface);
}
#sessionSelect {
  background: var(--bg-inset);
  color: var(--text-primary);
  appearance: none;
  -webkit-appearance: none;
}
#sessionSelect option {
  background: var(--bg-inset);
  color: var(--text-primary);
}
#sessionSelect option:checked,
#sessionSelect option:selected {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 9999px var(--bg-hover);
}
#sessionSelect:focus option:checked,
#sessionSelect:focus option:selected {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 9999px var(--bg-hover);
}
.action-btn {
  width: 100%;
  padding: 8px 14px;
  background: var(--accent-cyan);
  color: var(--bg-deep);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  margin-top: var(--space-1);
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.action-btn:hover {
  background: #26C6DA;
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

/* 10-minute segment selector buttons */
.seg-btn {
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-inset);
  color: var(--text-muted);
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
}
.seg-btn:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-color: var(--border-panel);
}
.seg-btn.active {
  background: var(--accent-cyan-dim);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan-dim);
}

/* Segment bar horizontal scrollbar - visible for long sessions */
.seg-bar-left {
  scrollbar-width: thin;
  scrollbar-color: var(--accent-cyan-dim) transparent;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.seg-bar-left:active {
  cursor: grabbing;
}
.seg-bar-left.dragging {
  cursor: grabbing;
}
.seg-bar-left::-webkit-scrollbar {
  height: 8px;
}
.seg-bar-left::-webkit-scrollbar-track {
  background: var(--bg-deep);
  border-radius: 4px;
}
.seg-bar-left::-webkit-scrollbar-thumb {
  background: var(--accent-cyan-dim);
  border-radius: 4px;
}
.seg-bar-left::-webkit-scrollbar-thumb:hover {
  background: var(--accent-cyan);
}

/* Overlay Toggle Controls */
.overlay-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 3px 0;
  transition: all 0.2s;
  user-select: none;
}
.overlay-toggle:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
}
/* When checkbox is checked (using :has if supported, or JS class later if needed) */
.overlay-toggle:has(input:checked) {
  color: var(--text-primary);
  font-weight: 500;
}
.overlay-toggle input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--accent-cyan);
  cursor: pointer;
  margin: 0;
}
.overlay-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  opacity: 0.5;
  transition: all 0.2s;
  background: var(--dot-color, var(--text-secondary));
}
.overlay-toggle:has(input:checked) .overlay-dot {
  opacity: 1;
  box-shadow: 0 0 6px var(--dot-color);
}
/* ================================================
   TAB BAR
   ================================================ */
.main-tabs-header {
  display: flex;
  background: var(--bg-deep);
  padding: 8px 10px 0 10px;
  gap: 6px;
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 2px solid var(--border-tab);
  align-items: flex-end;
  width: 100%;
  min-width: 0;
}

.main-tab {
  padding: 8px 16px;
  background: var(--bg-elevated);
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--text-muted);
  border: 1.5px solid var(--border-subtle);
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  min-width: 90px;
  justify-content: space-between;
  white-space: nowrap;
  position: relative;
  bottom: 0;
  margin-bottom: -2px;
}
.main-tab:hover {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--tab-accent, var(--border-subtle));
}
.main-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  border-color: var(--tab-accent, var(--accent-cyan));
  border-bottom: 2px solid var(--bg-surface);
  padding-bottom: 8px;
  margin-bottom: -2px;
  z-index: 1;
}

.close-tab-btn {
  font-size: 12px;
  line-height: 1;
  color: var(--text-muted);
  border-radius: 50%;
  width: 16px; height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  flex-shrink: 0;
}
.close-tab-btn:hover {
  background: rgba(255,80,80,0.18);
  color: #FF5252;
}

/* ================================================
   MAIN CONTENT
   ================================================ */
.main-tab-content {
  flex: 1;
  background: var(--bg-surface);
  padding: 0;
  overflow: hidden;
  position: relative;
  display: none;
  border-top: none;
  border-left: 1px solid var(--tab-accent, var(--border-tab));
  border-right: 1px solid var(--tab-accent, var(--border-tab));
  border-bottom: 1px solid var(--tab-accent, var(--border-tab));
  width: 100%;
  min-width: 0;
}
.main-tab-content.active {
  display: flex;
  flex-direction: column;
}

.app-main {
  grid-area: main;
  background: var(--bg-deep);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  min-width: 0;
}

/* ================================================
   RESTORE BANNER
   ================================================ */
.restore-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border-bottom: 2px solid var(--accent-cyan);
  border-left: 3px solid var(--accent-cyan);
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
  animation: bannerSlideIn 0.25s ease;
}
@keyframes bannerSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.restore-banner-icon {
  font-size: 16px;
  flex-shrink: 0;
}
.restore-banner-msg {
  flex: 1;
  color: var(--text-secondary);
}
.restore-banner-msg strong {
  color: var(--text-primary);
}
.restore-banner-btn {
  background: var(--accent-cyan);
  color: #000;
  border: none;
  border-radius: 5px;
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.restore-banner-btn:hover { opacity: 0.85; }
.restore-banner-btn:disabled { opacity: 0.5; cursor: default; }
.restore-banner-dismiss {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.1s;
}
.restore-banner-dismiss:hover { color: var(--accent-red); }

/* ================================================
   WELCOME / EMPTY STATE
   ================================================ */
#welcomeMessage {
  color: var(--text-muted) !important;
}

/* ================================================
   VISIBILITY CONTROL BAR
   ================================================ */
.viz-bar {
  display: flex;
  justify-content: space-between;
  padding: 0 var(--space-4);
  height: 48px;
  background: var(--bg-deep);
  border-top: 1px solid var(--border-subtle);
  border-bottom: none;
  overflow-x: auto;
  align-items: center;
  flex-shrink: 0;
}

.viz-bar-left,
.viz-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viz-bar-left {
  flex-wrap: wrap;
}

.viz-bar-right {
  margin-left: auto;
  padding-left: 12px;
}

.viz-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  user-select: none;
  white-space: nowrap;
  opacity: 1;
}

[data-theme="light"] .viz-toggle {
  border-color: var(--border-subtle);
  color: var(--text-muted);
}

.viz-toggle:hover {
  background: rgba(255,255,255,0.04);
  border-color: var(--border-panel);
  color: var(--text-secondary);
}

.viz-toggle.active {
  background: rgba(0, 188, 212, 0.10);
  color: var(--text-primary);
  border: 1px solid var(--active-color, var(--accent-cyan));
  font-weight: 600;
  opacity: 1;
}

.export-btn:active {
  transform: scale(0.96);
  opacity: 0.8;
}

.viz-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--border-panel);
  background: transparent;
  transition: all 0.15s;
  flex-shrink: 0;
}
[data-theme="light"] .viz-dot {
  border-color: var(--border-panel);
}
.viz-toggle.active .viz-dot {
  background: var(--active-color, currentColor);
  border-color: var(--active-color, currentColor);
  box-shadow: 0 0 6px var(--active-color, currentColor);
}

/* Light theme: dot follows text color automatically via currentColor */

.viz-toggle-right {
  flex-shrink: 0;
}

.viz-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  user-select: none;
  white-space: nowrap;
}

.viz-btn:hover {
  background: rgba(255,255,255,0.04);
  border-color: var(--border-panel);
  color: var(--text-secondary);
}

.viz-btn.active {
  background: rgba(0, 188, 212, 0.10);
  color: var(--text-primary);
  border: 1px solid var(--accent-cyan);
  font-weight: 600;
}

/* Zone colors */
.zone-z0 { color: #E8F5E8; }
.zone-z1 { color: #C8E6C9; }
.zone-z2 { color: #A5D6A7; }
.zone-z3 { color: #81C784; }
.zone-z4 { color: #66BB6A; }
.zone-z5 { color: #4CAF50; }

/* ================================================
   BOTTOM CONTROLS BAR
   ================================================ */
.bottom-controls-bar {
  flex-shrink: 0;
  height: 48px;
  background: var(--bg-deep);
  border-top: 1px solid var(--border-subtle);
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  z-index: 100;
}

.bottom-controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ================================================
   THEMES
   ================================================ */
[data-theme="light"] {
  --bg-deep: #F0F4F8;
  --bg-surface: #FFFFFF;
  --bg-elevated: #F8FAFC;
  --bg-hover: #E2E8F0;
  --bg-inset: #E2E8F0;
  
  --accent-cyan: #0EA5A7;
  --accent-cyan-dim: rgba(14, 165, 167, 0.12);
  --accent-cyan-glow: rgba(14, 165, 167, 0.25);
  --accent-green: #16A34A;      /* Clinical green */
  --accent-green-dim: rgba(22, 163, 74, 0.10);
  --accent-red: #D32F2F;        /* Darker red */
  --accent-red-dim: rgba(211, 47, 47, 0.15);
  --accent-amber: #FBC02D;
  --accent-purple: #7E57C2;
  
  --text-primary: #1E293B;
  --text-secondary: #475569;
  --text-muted: #64748B;
  
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-panel: rgba(0, 0, 0, 0.12);
  --border-tab:   #CBD5E1;                  /* Tab chrome borders */
  --border-glow: rgba(0, 0, 0, 0.15);
  
  --shadow-window: 0 4px 12px rgba(0, 0, 0, 0.05), 0 20px 40px rgba(0, 0, 0, 0.15);
  
  --grid-major: rgba(0, 0, 0, 0.08);
  --grid-minor: rgba(0, 0, 0, 0.03);

  --border-ecg:     rgba(22, 163, 74, 0.40);
  --border-ecg-dim: rgba(22, 163, 74, 0.16);
  --border-color:   rgba(0, 0, 0, 0.12);
}

html[data-theme="light"] {
  background: #CBD5E1; 
}

[data-theme="light"] .sidebar-panel {
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
  border-right-color: var(--border-panel);
}

/* Light theme: soften active sidebar glow */
[data-theme="light"] .sidebar-item.active::before {
  box-shadow: 0 0 8px rgba(14, 165, 167, 0.25), 0 0 14px rgba(14, 165, 167, 0.1);
}

/* Light theme: add subtle active tab underline for clarity */
[data-theme="light"] .main-tab.active {
  box-shadow: inset 0 -2px 0 var(--tab-accent, var(--accent-cyan));
}

/* Accessibility: visible focus ring on key interactive elements */
[data-theme="light"] .sidebar-item:focus-visible,
[data-theme="light"] .main-tab:focus-visible,
[data-theme="light"] .action-btn:focus-visible,
[data-theme="light"] .seg-btn:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* ─── Session Card Styles ───────────────────────────────────────── */
.session-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--session-accent, var(--border-subtle));
  border-radius: var(--radius-lg);
  padding: 12px 12px 12px 9px; /* compensate left border */
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.15s;
}

.session-card-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-card-date {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.session-card-badges {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.session-card-badge {
  font-size: 10px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.session-card-badge-icon {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.session-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 600;
}

.session-badge-events {
  background: var(--accent-red);
  color: white;
}

.session-badge-sleep {
  background: var(--accent-purple);
  color: #fff;
}

.session-badge-reviewed {
  background: var(--accent-green);
  color: #000;
}

.session-card-active {
  margin-left: auto;
  font-size: 9px;
  color: var(--accent-cyan);
  font-weight: 700;
}

/* ─── Monitor Playback HUD ───────────────────────────────────────── */
.ecg-hud {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 10px 12px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 12px;
    color: var(--accent-green);
    z-index: 1000;
    min-width: 280px;
    min-height: 200px;
    max-width: 600px;
    max-height: 500px;
    width: 320px;
    height: 240px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ecg-hud-close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: rgba(0, 200, 83, 0.65);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.ecg-hud-close:hover {
    background: rgba(0, 200, 83, 0.16);
    color: var(--accent-green);
}
.ecg-hud-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 4px;
}
.ecg-hud-play-btn {
    background: var(--accent-green-dim);
    border: 1px solid var(--border-ecg-dim);
    color: var(--accent-green);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.ecg-hud-play-btn:hover {
    background: rgba(0, 200, 83, 0.18);
    border-color: var(--border-ecg);
}
.ecg-hud-speed-group {
    display: flex;
    gap: 2px;
}
.ecg-hud-speed-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    flex: 1;
}
.ecg-hud-speed-btn:hover {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text-secondary);
}
.ecg-hud-speed-btn.active {
    background: rgba(0, 200, 83, 0.22);
    border-color: var(--border-ecg-dim);
    color: var(--accent-green);
}
.ecg-hud-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ecg-hud-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: ecg-pulse 1s infinite;
    flex-shrink: 0;
}
.ecg-hud-bpm {
    font-size: 18px;
    font-weight: 600;
    line-height: 1;
    flex-shrink: 0;
}
.ecg-hud-bpm-label {
    font-size: 11px;
    opacity: 0.7;
    flex-shrink: 0;
}
.ecg-hud-spark {
    margin: 2px 0;
    border-radius: 3px;
    background: rgba(0,0,0,0.2);
    width: 100%;
    height: 28px;
    flex-shrink: 0;
}
.ecg-hud-meta {
    font-size: 10px;
    opacity: 0.7;
    gap: 12px;
    justify-content: space-between;
}
.ecg-hud-tag {
    font-size: 11px;
    color: var(--accent-green);
    opacity: 0.85;
    text-align: center;
    padding: 2px 0;
    flex-shrink: 0;
}
.ecg-hud-grip {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
    opacity: 0.5;
    background-image: linear-gradient(45deg, transparent 30%, currentColor 30%, currentColor 45%, transparent 45%, transparent 60%, currentColor 60%, currentColor 75%, transparent 75%);
    background-size: 6px 6px;
    background-repeat: no-repeat;
    background-position: bottom left;
    z-index: 10;
    user-select: none;
}
.ecg-hud-grip:hover {
    opacity: 0.7;
}
.ecg-hud-plot {
    flex: 1;
    min-height: 60px;
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-ecg-dim);
    overflow: hidden;
}
@keyframes ecg-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.9); }
}

.ecg-hover-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 10px 12px;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    color: var(--text-secondary);
    z-index: 1000;
    min-width: 200px;
    min-height: 150px;
    max-width: 400px;
    max-height: 300px;
    width: 240px;
    height: 180px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ecg-hover-close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.ecg-hover-close:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}
.ecg-hover-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}
.ecg-hover-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.ecg-hover-label {
    font-size: 11px;
    opacity: 0.8;
    flex-shrink: 0;
}
.ecg-hover-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-cyan);
    text-align: right;
}
.ecg-hover-grip {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
    opacity: 0.5;
    background-image: linear-gradient(45deg, transparent 30%, currentColor 30%, currentColor 45%, transparent 45%, transparent 60%, currentColor 60%, currentColor 75%, transparent 75%);
    background-size: 6px 6px;
    background-repeat: no-repeat;
    background-position: bottom left;
    z-index: 10;
    user-select: none;
}
.ecg-hover-grip:hover {
    opacity: 0.7;
}

/* Play button "playing" state — red pulse */
.seg-btn.play-btn.playing {
  background: linear-gradient(180deg, #FF5252 0%, #D32F2F 100%);
  color: #fff;
  border-color: #FF5252;
  box-shadow: 0 0 0 2px rgba(255, 82, 82, 0.25);
  animation: play-pulse 1.5s infinite;
}
@keyframes play-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(255, 82, 82, 0.25); }
  50%      { box-shadow: 0 0 0 5px rgba(255, 82, 82, 0.0); }
}
.seg-btn.speed-btn.active {
  background: var(--accent-cyan, #00BCD4);
  color: #fff;
  border-color: var(--accent-cyan, #00BCD4);
}

/* Keep cursor as pointer over Plotly charts (override pan cursor) */
.plotly, .js-plotly-plot, .plot-container, .svg-container {
  cursor: default !important;
}
.plotly .cursor-crosshair, .plotly .cursor-ew-resize, .plotly .cursor-ns-resize {
  cursor: default !important;
}

/* ================================================
   SHARED OVERLAY BASE — HUD + Hover Panel
   ================================================ */
/* Shared styling — HUD + Hover panel share bg, border, shadow, font */
.ecg-overlay {
    background: rgba(10, 14, 20, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-ecg);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.04);
}
/* Entrance animation — add class 'entering' when making visible */
@keyframes ecgOverlayEnter {
    from { opacity: 0; transform: translateY(-6px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.ecg-overlay.entering {
    animation: ecgOverlayEnter 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ================================================
   DATA CARD SYSTEM — Analytics + Summary cards
   ================================================ */
.data-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.data-card-header {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--ls-widest, 0.08em);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}
.data-card-value {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}
.data-card-unit {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

/* ================================================
   SESSION CARD — hover elevation
   ================================================ */
.session-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* ================================================
   TAB ENTRY ANIMATION
   ================================================ */
@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.main-tab-content.active {
  animation: tabFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ================================================
   MICRO-INTERACTIONS
   ================================================ */

/* Sidebar item — nudge right on hover */
.sidebar-item:hover .sidebar-icon-wrap {
  transform: translateX(2px);
}
.sidebar-icon-wrap {
  transition: transform 0.15s, background 0.15s;
}

/* viz-toggle — tactile press */
.viz-toggle:active {
  transform: scale(0.96);
  transition: transform 0.06s;
}

/* action-btn — press */
.action-btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

/* seg-btn — press */
.seg-btn:active {
  transform: scale(0.96);
}

/* ================================================
   WELCOME / EMPTY STATE — Structured card
   ================================================ */
.welcome-card {
  max-width: 460px;
  margin: 0 auto;
  padding-top: var(--space-8);
  text-align: center;
}
.welcome-card-icon {
  margin-bottom: var(--space-6);
  opacity: 0.10;
  display: flex;
  justify-content: center;
}
.welcome-card-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
  letter-spacing: var(--ls-tight, -0.01em);
}
.welcome-card-desc {
  font-size: var(--text-base);
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: var(--space-6);
}
.welcome-card-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
}
.welcome-card-actions .action-btn {
  width: auto;
  padding: 10px 20px;
  font-size: var(--text-sm);
}

/* ================================================
   STATUS DOT — colour-coded status text prefix
   ================================================ */
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}
.status-dot.ok     { background: var(--accent-green); }
.status-dot.warn   { background: var(--accent-amber); }
.status-dot.error  { background: var(--accent-red); }
.status-dot.idle   { background: var(--text-muted); }
.status-dot.active { background: var(--accent-cyan); box-shadow: 0 0 6px var(--accent-cyan-glow); }

/* ================================================
   PWA STANDALONE MODE — Hide window controls
   ================================================ */
@media (display-mode: standalone) {
  .window-controls {
    display: none;
  }

  .app-header {
    -webkit-app-region: none;
  }

  body {
    margin: 0;
    height: 100vh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}

/* ================================================
   RESPONSIVE BREAKPOINTS — Tablet Support
   ================================================ */

/* Tablet portrait (768px - 1024px) */
@media (max-width: 1024px) {
  body {
    margin: 0;
    height: 100vh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  /* Sidebar becomes icon-only strip */
  .app-sidebar {
    width: 48px;
  }

  .sidebar-item {
    width: 40px;
    min-height: 48px;
  }

  .sidebar-item .item-label {
    display: none;
  }

  .sidebar-icon-wrap {
    width: 24px;
    height: 24px;
    font-size: 16px;
  }

  /* Panel becomes full-screen overlay */
  .sidebar-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    border-radius: 0;
    background: var(--bg-deep);
  }

  body.panel-open {
    grid-template-columns: 48px 0px 1fr;
  }

  /* Hide panel area in grid when overlay is used */
  .sidebar-panel {
    grid-area: main;
  }

  /* Tab header scrolls horizontally */
  .main-tabs-header {
    flex-wrap: nowrap;
  }

  .main-tab {
    min-width: 80px;
    padding: 8px 12px;
  }

  /* Increase touch hit areas */
  .action-btn {
    padding: 12px 16px;
    min-height: 44px;
  }

  .seg-btn {
    padding: 8px 12px;
    min-height: 36px;
  }

  .viz-toggle {
    padding: 8px 12px;
    min-height: 36px;
  }

  .viz-btn {
    padding: 8px 12px;
    min-height: 36px;
  }

  .overlay-toggle {
    padding: 6px 10px;
    min-height: 36px;
  }
}

/* Tablet landscape (1024px - 1280px) */
@media (min-width: 1025px) and (max-width: 1280px) {
  .sidebar-panel {
    max-width: 320px;
  }

  body.panel-open {
    grid-template-columns: var(--sidebar-width) 320px 1fr;
  }
}

/* Mobile portrait (< 768px) */
@media (max-width: 767px) {
  body {
    grid-template-areas:
      "header header"
      "main main";
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) 1fr;
  }

  .app-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    padding: 0 8px;
    gap: 0;
    border-radius: 0;
    border-top: 1px solid var(--border-panel);
    background: var(--bg-surface);
    z-index: 500;
  }

  .sidebar-item {
    flex: 1;
    width: auto;
    min-height: 100%;
    border-radius: 0;
  }

  .sidebar-item .item-label {
    display: block;
    font-size: 8px;
  }

  .sidebar-icon-wrap {
    width: 20px;
    height: 20px;
    font-size: 18px;
  }

  .sidebar-spacer {
    display: none;
  }

  .sidebar-divider {
    display: none;
  }

  /* Panel becomes full-screen overlay with close button */
  .sidebar-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 60px;
    width: 100vw;
    height: calc(100vh - 60px);
    z-index: 1000;
    border-radius: 0;
  }

  /* Main content area needs bottom padding for nav bar */
  .app-main {
    padding-bottom: 60px;
  }

  /* Tab buttons smaller on mobile */
  .main-tab {
    min-width: 70px;
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Hide window controls on mobile */
  .window-controls {
    display: none;
  }
}
