/* PurpleSensor -- stylesheet */

:root {
  --purple:        #7b2fbe;
  --purple-light:  #9d54d4;
  --purple-pale:   #f3eafd;
  --purple-dark:   #4a1a7a;
  --text:          #1a1a2e;
  --text-muted:    #666;
  --border:        #ddd;
  --bg:            #fafafa;
  --card-bg:       #ffffff;
  --success:       #1a7a3a;
  --error:         #b91c1c;
  --error-bg:      #fef2f2;
  --radius:        10px;
  --shadow:        0 2px 12px rgba(0,0,0,0.07);

  /* -- Sensor tier colors -- single source of truth -- */
  --tier-green:        #2e7d32;
  --tier-green-bg:     #e8f5e9;
  --tier-yellow:       #f9a825;
  --tier-yellow-bg:    #fff8e1;
  --tier-red:          #c62828;
  --tier-red-bg:       #ffebee;
  --tier-purple:       #6a1b9a;
  --tier-purple-bg:    #f3e5f5;
  /* Clean/elevated/critical for time-in-cluster charts */
  --tier-clean:        #2e7d32;
  --tier-elevated:     #f9a825;
  --tier-critical:     #6a1b9a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -- Header -------------------------------------------------------- */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
}

.header-inner {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: bold;
  letter-spacing: -0.02em;
  color: var(--purple-dark);
}

.logo-dot {
  width: 14px;
  height: 14px;
  background: var(--purple);
  border-radius: 50%;
  display: inline-block;
}

.header-links {
  display: flex;
  gap: 1.5rem;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
}

/* -- Main layout --------------------------------------------------- */
main {
  flex: 1;
  padding: 2rem 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.stage { width: 100%; }
.stage.hidden { display: none; }
.stage.active { display: block; }

/* -- Stage 1: Upload ----------------------------------------------- */
.stage-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2.5rem;
  align-items: start;
}

.about-col h2 {
  font-size: 1.15rem;
  margin-bottom: 0.75rem;
  color: var(--purple-dark);
}

.about-col p {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.supported-formats {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--purple-pale);
  border-radius: var(--radius);
}

.supported-formats h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--purple-dark);
  margin-bottom: 0.6rem;
  font-family: system-ui, sans-serif;
}

.supported-formats ul {
  list-style: none;
  font-size: 0.9rem;
  font-family: system-ui, sans-serif;
}

.supported-formats li {
  padding: 0.2rem 0;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ext {
  font-family: monospace;
  font-size: 0.8rem;
  background: white;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--purple);
  border: 1px solid var(--purple-light);
}

/* Drop zone */
.drop-zone {
  border: 2.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--card-bg);
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--purple);
  background: var(--purple-pale);
}

.drop-zone.drag-over .drop-icon { color: var(--purple); }

.drop-icon {
  color: var(--border);
  margin-bottom: 1rem;
  transition: color 0.15s;
}

.drop-primary {
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.drop-secondary {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.btn-browse {
  display: inline-block;
  background: var(--purple);
  color: white;
  padding: 0.55rem 1.4rem;
  border-radius: 6px;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-browse:hover { background: var(--purple-dark); }

.drop-hint {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: system-ui, sans-serif;
}

/* Upload status / error */
.upload-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.85rem 1.1rem;
  background: var(--purple-pale);
  border-radius: var(--radius);
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--purple-dark);
}

.status-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--purple-light);
  border-top-color: var(--purple-dark);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.upload-error {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.85rem 1.1rem;
  background: var(--error-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--error);
}

.hidden { display: none !important; }

/* -- Stage 2 ------------------------------------------------------- */
.stage-inner {
  width: 870px;
  max-width: 870px;
  min-width: 870px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* File summary card */
.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.1rem;
}

.summary-badge {
  display: inline-block;
  background: var(--purple-pale);
  color: var(--purple-dark);
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-label {
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.summary-value {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}

/* Config card */
.config-title {
  font-size: 1.05rem;
  margin-bottom: 1.25rem;
  color: var(--purple-dark);
}

.config-section {
  margin-bottom: 1.4rem;
}

.config-label {
  display: block;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.toggle-btn {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
}

.toggle-btn.active {
  border-color: var(--purple);
  background: var(--purple-pale);
  color: var(--purple-dark);
}

.toggle-btn.active .toggle-hint { color: var(--purple); }

.toggle-btn:hover:not(.active) {
  border-color: var(--purple-light);
  color: var(--text);
}

.select-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.select-btn {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 0.35rem 0.9rem;
  font-family: system-ui, sans-serif;
  font-size: 0.87rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.select-btn.active {
  border-color: var(--purple);
  background: var(--purple-pale);
  color: var(--purple-dark);
  font-weight: 600;
}

.select-btn:hover:not(.active) {
  border-color: var(--purple-light);
  color: var(--text);
}

.date-input {
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: white;
  width: 200px;
}

.date-input:focus {
  outline: none;
  border-color: var(--purple);
}

.config-hint {
  margin-top: 0.4rem;
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.checkbox-group {
  display: flex;
  gap: 1.5rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: system-ui, sans-serif;
  font-size: 0.92rem;
  cursor: pointer;
}

.checkbox-item input[type=checkbox] {
  accent-color: var(--purple);
  width: 16px;
  height: 16px;
}

.btn-generate {
  width: 100%;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 0.85rem;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-generate:hover:not(:disabled) { background: var(--purple-dark); }
.btn-generate:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* -- Results ------------------------------------------------------- */
.result-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.result-meta {
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--purple-dark);
}

.result-actions {
  display: flex;
  gap: 0.75rem;
}

.btn-download, .btn-view {
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1.5px solid;
  transition: background 0.15s;
}

.btn-download {
  background: var(--purple);
  color: white;
  border-color: var(--purple);
}

.btn-download:hover { background: var(--purple-dark); border-color: var(--purple-dark); }

.btn-view {
  background: white;
  color: var(--purple);
  border-color: var(--purple-light);
}

.btn-view:hover { background: var(--purple-pale); }

.result-image-wrap {
  padding: 1.25rem;
  text-align: center;
}

.result-image-wrap img {
  max-width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
  margin: 0 auto;
}

.render-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2.5rem;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--purple-dark);
}

.render-error {
  padding: 1.25rem;
  background: var(--error-bg);
  color: var(--error);
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  border-top: 1px solid #fca5a5;
}

/* Misc */
.btn-link {
  background: none;
  border: none;
  color: var(--purple);
  font-family: system-ui, sans-serif;
  font-size: 0.87rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.btn-link:hover { color: var(--purple-dark); }

.upload-new-btn { font-size: 0.85rem; }

/* -- Footer -------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
}

/* -- Generation overlay -------------------------------------------- */
.gen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.92);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
}

.gen-overlay.hidden { display: none !important; }

.gen-overlay-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  min-width: 320px;
  width: 320px;
}

.gen-spinner {
  width: 72px;
  height: 72px;
  border: 6px solid var(--purple-pale);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.gen-title {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--purple-dark);
  font-family: system-ui, sans-serif;
}

.gen-subtitle {
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* -- Stage 2 two-column layout ------------------------------------- */
.stage-two-col {
  /* Sidebar removed — this is now just a passthrough wrapper */
  display: block;
}

.stage-main-col {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* -- Empty upload zone (Stage 2 main column) ---------------------- */
.empty-upload-zone {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.empty-upload-zone .drop-zone {
  max-width: 520px;
}

/* -- File tab bar (replaces sidebar) --------------------------------------- */
.file-tab-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-bottom: 3px solid var(--purple);
  border-radius: var(--radius) var(--radius) 0 0;
  margin-bottom: 0;
  overflow: visible;
  background: var(--card-bg);
  padding: 0.5rem 0.5rem 0;
}

.file-tab-list {
  display: flex;
  gap: 0.25rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding-bottom: 0;
  align-items: flex-end;
}

.file-tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.45rem 0.9rem 0.6rem;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--card-bg);
  cursor: pointer;
  font-family: system-ui, sans-serif;
  transition: background 0.12s;
  flex-shrink: 0;
}

.file-tab:hover { background: var(--purple-pale); }

.file-tab-active {
  background: var(--card-bg);
  border-color: var(--purple);
  border-bottom: 3px solid var(--card-bg);
  margin-bottom: -3px;
  font-weight: 600;
}

.file-tab-upload {
  margin-left: auto;
  border-color: var(--purple-light);
  color: var(--purple);
  font-weight: 700;
  flex-shrink: 0;
}

.file-tab-label {
  font-size: 0.82rem;
  color: var(--purple-dark);
  font-weight: 600;
  white-space: nowrap;
}

.file-tab-date {
  font-size: 0.7rem;
  color: #777;
  white-space: nowrap;
}

.file-tab-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.25rem;
  flex-shrink: 0;
}

/* -- Dataset sidebar (keep hidden, referenced by old IDs) ------------------ */
.dataset-sidebar { display: none !important; }

.sidebar-title {
  font-family: system-ui, sans-serif;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  margin-top: 0;
}

.sidebar-header-row .sidebar-title { margin-bottom: 0; }

.dataset-group {
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 0.25rem;
  margin-bottom: 0.25rem;
}

.dataset-group:last-of-type { border-bottom: none; }

.dataset-group-active > .dataset-group-header {
  color: var(--purple-dark);
}

.dataset-group-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.5rem 0.35rem;
  cursor: pointer;
  border-radius: 5px;
  transition: background 0.12s;
}

.dataset-group-header:hover { background: var(--purple-pale); }

.dataset-group-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-family: system-ui, sans-serif;
  font-size: 0.83rem;
  color: var(--text);
  min-width: 0;
}

.dataset-group-sub {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 400;
}

.dataset-toggle-icon {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 4px;
  flex-shrink: 0;
}

.dataset-renders {
  padding-left: 0.5rem;
  margin-bottom: 0.25rem;
}

.render-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.4rem;
  border-radius: 5px;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--text);
  transition: background 0.1s;
  flex-wrap: wrap;
}

.render-item:hover { background: var(--purple-pale); color: var(--purple-dark); }
.render-item-active { color: var(--purple-dark); font-weight: 600; }
.render-item-empty { color: var(--text-muted); font-style: italic; cursor: default; }
.render-item-empty:hover { background: none; }

.render-item-icon { font-size: 0.65rem; color: var(--purple-light); flex-shrink: 0; }

/* Samples section */
.samples-section {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 2px solid var(--purple-pale);
}

.sidebar-title-samples {
  color: var(--purple);
  margin-bottom: 0.5rem;
}

.sample-item { flex-direction: column; align-items: flex-start; }
.sample-sub  { font-size: 0.72rem; color: var(--text-muted); margin-left: 1rem; }
.sample-badge {
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  background: var(--purple-pale);
  color: var(--purple-dark);
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.result-header-sample { background: var(--purple-pale); }
.sample-result { border-color: var(--purple-light); }

.btn-zip {
  width: 100%;
  margin-top: 0.85rem;
  background: none;
  border: 1.5px solid var(--purple-light);
  border-radius: 6px;
  padding: 0.45rem 0.5rem;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--purple);
  cursor: pointer;
  transition: background 0.12s;
}

.btn-zip:hover { background: var(--purple-pale); }

/* In the title row, Download All should be auto-width, not full-width */
.ssp-dl-btn {
  width: auto;
  margin-top: 0;
  flex-shrink: 0;
  white-space: nowrap;
}
/* -- Responsive: collapse sidebar on mobile ------------------------ */
@media (max-width: 700px) {
  .stage-two-col { flex-direction: column; }
  .dataset-sidebar {
    width: 100%;
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }
  .sidebar-title { width: 100%; margin-bottom: 0.25rem; }
  .dataset-item {
    border: 1.5px solid var(--border);
    border-radius: 20px;
    padding: 0.3rem 0.75rem;
    border-bottom: 1.5px solid var(--border);
  }
  .dataset-item.active { border-color: var(--purple); border-left-width: 1.5px; padding-left: 0.75rem; }
  .btn-zip { width: auto; margin-top: 0; }
}
@media (max-width: 700px) {
  .stage-layout {
    grid-template-columns: 1fr;
  }

  .about-col { order: 2; }
  .upload-col { order: 1; }

  .toggle-group {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .footer-inner {
    flex-direction: column;
    gap: 0.4rem;
  }
}

/* -- Touch device adjustments -------------------------------------- */
@media (hover: none) and (pointer: coarse) {
  .no-touch { display: none; }
  .drop-zone { padding: 2rem 1.5rem; }
  .btn-browse { font-size: 1.05rem; padding: 0.85rem 2rem; margin-top: 0.5rem; }
  .drop-icon { margin-bottom: 0.5rem; }
}

/* -- Nav active state ---------------------------------------------- */
.nav-link { color: var(--text-muted); transition: color 0.12s; }
.nav-link:hover { color: var(--purple-dark); text-decoration: none; }
.nav-active { color: var(--purple-dark) !important; font-weight: 600; }

.sidebar-faq-link {
  display: block;
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--purple);
  padding: 0.5rem 0.35rem;
  border-radius: 5px;
  transition: background 0.12s;
}
.sidebar-faq-link:hover {
  background: var(--purple-pale);
  text-decoration: none;
}

/* Sidebar header row with Upload New button */
.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.btn-upload-new {
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 5px;
  padding: 0.25rem 0.65rem;
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-upload-new:hover { background: var(--purple-dark); }

/* Remove old gen-spinner since we use SVG animation now */
.gen-spinner { display: none; }

/* --- Session modals ---------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.hidden { display: none !important; }

.modal-box {
  background: white;
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 520px;
  width: 94%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-title {
  font-size: 1.15rem;
  color: var(--purple-dark);
}

.modal-body {
  font-family: system-ui, sans-serif;
  font-size: 0.93rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.modal-body strong {
  color: var(--purple-dark);
  font-size: 1.1rem;
}

/* Session warning modal report list */
.modal-header { margin-bottom: 0.25rem; }

.session-report-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  margin: 0.5rem 0;
}

.session-report-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.6rem;
  background: var(--purple-pale);
  border-radius: 6px;
  gap: 0.75rem;
}

.session-report-label {
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--purple-dark);
  font-weight: 500;
}

.session-dl-btn {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.modal-dl-all {
  display: block;
  padding: 0.7rem;
  font-size: 0.95rem;
}

.btn-outline-purple {
  width: 100%;
  background: none;
  border: 1.5px solid var(--purple-light);
  color: var(--purple);
  border-radius: var(--radius);
  padding: 0.7rem;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-outline-purple:hover { background: var(--purple-pale); }

.gen-note {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Active dataset outlined */
.dataset-group-active {
  border-radius: var(--radius);
  padding: 0.35rem;
  margin: -0.35rem -0.5rem 0.75rem -0.5rem;
  box-shadow: 0 0 0 2px var(--purple);
}

/* Dashboard entry bold */
.render-item-dashboard { font-weight: 600; }

/* Select a Date button */
.btn-select-date {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 5px;
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.btn-select-date:hover { background: var(--purple-dark); }

/* -- Session stats panel --------------------------------------------------- */
.session-stats-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: 3px solid var(--purple);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.5rem;
  font-family: system-ui, sans-serif;
  min-width: 0;
  overflow-x: auto;
}

.ssp-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.ssp-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--purple-dark);
}

.ssp-scope {
  font-size: 0.74rem;
  color: #999;
}

.ssp-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ssp-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--purple-pale);
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.35rem 0.75rem;
  min-width: 72px;
}

.ssp-chip-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--purple-dark);
  line-height: 1.2;
}

.ssp-chip-label {
  font-size: 0.67rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.1rem;
  white-space: nowrap;
}

/* TIR 3-zone compact chip */
.ssp-chip.ssp-tir3 {
  align-items: flex-start;
  min-width: unset;
}

.ssp-tir3-zones {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.ssp-tir3-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  min-width: 52px;
}

.ssp-tir3-lo  { background: #ffebee; }
.ssp-tir3-mid { background: #e8f5e9; }
.ssp-tir3-hi  { background: #fff3e0; }

.ssp-tir3-pct {
  font-size: 1.0rem;
  font-weight: 700;
  line-height: 1.2;
}

.ssp-tir3-lo  .ssp-tir3-pct { color: var(--tier-red); }
.ssp-tir3-mid .ssp-tir3-pct { color: var(--tier-green); }
.ssp-tir3-hi  .ssp-tir3-pct { color: var(--tier-yellow); }

.ssp-tir3-lbl {
  font-size: 0.65rem;
  color: #666;
  white-space: nowrap;
}

/* Sensor health chip -- 4 tier boxes */
.ssp-chip.ssp-sensor-health {
  align-items: flex-start;
  min-width: unset;
}

.ssp-sh-tiers {
  display: flex;
  gap: 10px;
  margin-top: 0.25rem;
  align-items: flex-start;
}

.ssp-sh-tier-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.ssp-sh-tier {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 42px;
  border-radius: 7px;
  overflow: hidden;
  border: none;
  background: var(--tc);
  /* Drop shadow only for critical/warning tiers — set via --tier-shadow on the element */
  box-shadow: var(--tier-shadow, none);
}

.ssp-sh-tier-bar {
  display: none;
}

.ssp-sh-tier-count {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
}

.ssp-sh-tier-pct {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--tc);
  opacity: 0.8;
}

.ssp-sh-tier-lbl {
  font-size: 9px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}

/* Chip label always on top, value below */
.ssp-chip-label {
  order: -1;
}

/* Descriptive line (used in post-cluster hypos chip) */
.ssp-chip-desc {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--purple-dark);
  white-space: nowrap;
  margin-top: 0.15rem;
}

.ssp-chip.ssp-alert .ssp-chip-value { color: var(--tier-red); }

/* -- Session stats panel rows and per-device sensor health ------------------- */
.ssp-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ssp-section {
  padding: 0.6rem 1.25rem 0.6rem 0.75rem;
  background: var(--purple-pale);
  border-radius: 8px;
  margin-top: 0.25rem;
}

.ssp-sh-by-device {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.4rem 0 0.5rem;
}

.ssp-sh-device-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.ssp-sh-device-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--purple-dark);
}

.ssp-sh-tier-legend {
  display: flex;
  gap: 0.9rem;
  font-size: 0.68rem;
  color: #666;
  margin-top: 0.15rem;
}

/* Median score table */
.score-table {
  width: 100%;
  border-collapse: collapse;
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
  margin-top: 0.5rem;
}
.score-table thead th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
  font-weight: 600;
  padding: 0 0.75rem 0.5rem 0;
  border-bottom: 1px solid #eee;
}
.score-table tbody tr:hover { background: #fafafa; }
.score-table td {
  padding: 0.55rem 0.75rem 0.55rem 0;
  border-bottom: 1px solid #f5f5f5;
  vertical-align: middle;
}
.st-device { font-weight: 700; color: #222; width: 100px; }
.st-n      { color: #333; font-size: 0.8rem; width: 80px; }
.st-score  { font-weight: 800; font-size: 1.05rem; width: 100px; }
.st-tier   { font-size: 0.82rem; font-weight: 500; }

/* Stats page two-column card rows */
.stats-row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 700px) {
  .stats-row-2col { grid-template-columns: 1fr; }
}

.stats-row-2col .stat-card {
  margin-bottom: 0;
}

/* Sensor duration histogram */
.dur-chart     { display: flex; flex-direction: column; gap: 1.5rem; margin-top: 0.5rem; }
.dur-group     { display: flex; flex-direction: column; gap: 0.4rem; }
.dur-device    { font-size: 0.92rem; font-weight: 700; color: #222; display: flex; align-items: center; gap: 0.75rem; }
.dur-total     { font-weight: 400; color: #555; font-size: 0.85rem; }
.dur-fail-note { font-size: 0.85rem; color: var(--tier-red); font-weight: 600; }
.dur-bars      { display: flex; align-items: flex-end; gap: 3px; height: 100px; }
.dur-bar-wrap  { display: flex; flex-direction: column; align-items: center; width: 28px; }
.dur-bar       { width: 100%; border-radius: 3px 3px 0 0; min-height: 2px;
                 position: relative; transition: opacity 0.15s; }
.dur-bar:hover { opacity: 0.8; }
.dur-bar-lbl   { position: absolute; top: -1.1rem; left: 50%;
                 transform: translateX(-50%);
                 font-size: 0.7rem; font-weight: 700; color: #333; white-space: nowrap; }
.dur-bar-day   { font-size: 0.7rem; color: #555; margin-top: 0.15rem; }
.dur-bar-day-mark { color: var(--purple-dark); font-weight: 700; }
.dur-legend    { font-size: 0.82rem; color: #555; margin-top: 0.75rem;
                 display: flex; flex-direction: column; gap: 0.2rem; }

/* -- Report tab strip ------------------------------------------------------- */
.report-tab-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--purple);
  padding: 0 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--purple) transparent;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}

.report-tab {
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--purple-dark);
  background: #f0edf8;
  border: 1.5px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  margin-right: 3px;
  margin-bottom: -2px;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.report-tab:hover:not(.report-tab-active) {
  border-color: var(--purple);
  color: var(--purple);
  background: var(--purple-pale);
}
.report-tab-active:hover {
  background: var(--purple);  /* stay purple, don't invert */
  color: #fff;
}

.report-tab-active {
  background: var(--purple);
  color: #fff;
  border-color: var(--purple);
  position: relative;
  z-index: 1;
}

/* Icons inside report tabs (download) and file tabs (share) */
.tab-icon-btn {
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
  opacity: 0.4;
  vertical-align: middle;
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 2px;
  flex-shrink: 0;
}
.tab-icon-btn:hover {
  opacity: 1;
  background: rgba(0,0,0,0.1);
}
.report-tab .tab-dl-icon,
.report-tab .tab-rerender-icon {
  color: var(--purple-dark);
  opacity: 0.5;
  margin-left: 4px;
}
.report-tab-active .tab-dl-icon,
.report-tab-active .tab-rerender-icon {
  color: #fff;
  opacity: 0.75;
}
.report-tab .tab-dl-icon:hover {
  opacity: 1 !important;
  color: var(--purple) !important;
  background: rgba(123,47,190,0.12) !important;
  border-radius: 3px;
}
.report-tab-active .tab-dl-icon:hover,
.report-tab-active .tab-rerender-icon:hover {
  opacity: 1 !important;
  color: #fff !important;
  background: rgba(255,255,255,0.25) !important;
  border-radius: 3px;
}
.file-tab-icons {
  position: absolute;
  top: 0.3rem;
  right: 0.35rem;
  display: flex;
  gap: 2px;
}
.file-tab-icons .tab-icon-btn {
  padding: 2px 3px;
  margin-left: 0;
  color: #222;
  opacity: 0.7;
}
.file-tab-icons .tab-icon-btn:hover {
  opacity: 1;
  color: var(--purple);
  background: rgba(123,47,190,0.08);
}
.file-tab-icons .tab-trash-icon:hover {
  color: #c62828;
  background: rgba(198,40,40,0.08);
}

.report-tab-select-date {
  margin-left: auto;
  background: transparent;
  border-color: transparent;
  color: var(--purple);
  font-weight: 600;
  opacity: 0.75;
  flex-shrink: 0;
}

.report-tab-select-date:hover {
  background: var(--purple-pale);
  color: var(--purple);
  opacity: 1;
}

.report-tab-content {
  /* content sits directly below the tab strip */
}

/* -- Page sub-tabs (multi-page dashboards) --------------------------------- */
.page-tab-strip {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.page-tab {
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  border: 1.5px solid var(--purple);
  background: transparent;
  color: var(--purple);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.page-tab-active {
  background: var(--purple);
  color: #fff;
}

.page-tab:hover:not(.page-tab-active) {
  background: var(--purple-pale);
}

.page-dl-bar {
  display: flex;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

/* -- Select-a-date bar inside Dashboard tab -------------------------------- */
.tab-date-picker-bar {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.tab-date-picker-bar .btn-select-date {
  font-size: 0.88rem;
}

/* -- Session health panel two-column layout --------------------------------- */
.ssp-two-col {
  display: flex;
  gap: 0;
  align-items: flex-start;
}

.ssp-left-col {
  flex: 0 0 345px;
  min-width: 0;
  overflow: hidden;
}

.ssp-divider {
  width: 2px;
  background: #c5aee0;
  align-self: stretch;
  margin: 0 1.25rem;
  flex-shrink: 0;
  border-radius: 1px;
}

.ssp-right-col {
  flex: 1 1 auto;
  min-width: 380px;
  overflow: hidden;
  padding-right: 0.75rem;
}

.ssp-col-title {
  margin-bottom: 0.6rem;
}

.ssp-col-title strong {
  display: block;
  font-size: 0.88rem;
  color: #222;
  font-weight: 700;
}

.ssp-col-title span {
  font-size: 0.72rem;
  color: #666;
}

/* -- Hypo stat tiles -------------------------------------------------------- */
.ssp-hypo-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.ssp-hypo-row-baseline {
  border-top: 1px dashed var(--border);
  padding-top: 0.5rem;
}

.ssp-hypo-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.2rem 0.35rem;
  min-width: 38px;
}

.ssp-hypo-ratio {
  background: var(--purple-pale);
  border-color: var(--purple-light);
}

.ssp-hypo-val {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1a237e;
  line-height: 1;
}

.ssp-hypo-lbl {
  font-size: 0.62rem;
  color: #555;
  margin-top: 0.2rem;
  text-align: center;
  line-height: 1.2;
}

@media (max-width: 500px) {
  .ssp-two-col { flex-direction: column; }
  .ssp-divider { width: 100%; height: 1px; margin: 0.75rem 0; }
}

/* -- Session panel outer title ---------------------------------------------- */
.ssp-outer-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 1rem;
}

.ssp-outer-title {
  font-size: 1.0rem;
  font-weight: 700;
  color: #1a237e;
  letter-spacing: 0.01em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.ssp-dl-btn {
  flex-shrink: 0;
}

.ssp-collapse-btn {
  background: transparent;
  border: 1.5px solid var(--purple-light);
  color: var(--purple);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  line-height: 1.2;
  opacity: 0.7;
  flex-shrink: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.ssp-collapse-btn:hover { opacity: 1; background: var(--purple-pale); border-color: var(--purple); }

/* -- Hypo footnote ---------------------------------------------------------- */
.ssp-hypo-footnote {
  font-size: 0.72rem;
  color: #555;
  margin-top: 0.5rem;
  line-height: 1.45;
  max-width: 340px;
}

/* -- Admin device chart legend --------------------------------------------- */
.device-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: #333;
}

.device-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.device-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* -- Voluntary retain consent checkbox in upload modal --------------------- */
.modal-retain-row {
  margin: 0.75rem 0 1rem;
  padding: 0.65rem 0.75rem;
  background: #f3f0fa;
  border-radius: 8px;
  border: 1px solid var(--purple-light);
}

.retain-label {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  cursor: pointer;
  font-size: 0.83rem;
  color: #333;
  line-height: 1.45;
}

.retain-label input[type="checkbox"] {
  margin-top: 0.15rem;
  accent-color: var(--purple);
  flex-shrink: 0;
  width: 15px;
  height: 15px;
}

/* -- Share button left of tab strip ---------------------------------------- */
.tab-strip-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-bottom: 2px solid var(--purple);
  background: var(--bg);
}

.btn-share-report {
  flex-shrink: 0;
  padding: 0.45rem 0.9rem;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--purple);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.15s;
}

.btn-share-report:hover {
  background: var(--purple-pale);
}

/* Adjust tab strip to live inside the row without double border */
.tab-strip-row .report-tab-strip {
  border-bottom: none;
  flex: 1;
}


/* ═══════════════════════════════════════════════════════════════════════════
   HTML Report Layout  (v118)
   ═══════════════════════════════════════════════════════════════════════════ */

.report-html-wrap {
  display: flex;
  flex-direction: column;
  background: #fafafa;
  border-radius: 6px;
  overflow: hidden;
}

/* ── Header: 2-col layout ──────────────────────────────────────────────────── */
/* .report-html-header removed — date/days moved to Upload Summary title */
.rh-actions-standalone {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}
.rh-actions-standalone .btn-view,
.rh-actions-standalone .btn-outline-sm,
.rh-actions-standalone .btn-download {
  font-size: 0.78rem;
  padding: 0.22rem 0.65rem;
}

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.report-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid #e0e0e0;
}
@media (max-width: 640px) {
  .report-cards { grid-template-columns: repeat(2, 1fr); }
}
.stat-card {
  padding: 0.65rem 0.9rem 0.6rem;
  border-right: 1px solid #e0e0e0;
  background: #fff;
}
.stat-card:last-child { border-right: none; }
.sc-title {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #1a237e;
  margin-bottom: 0.4rem;
  padding-bottom: 0.28rem;
  border-bottom: 2px solid #e8eaf6;
}
.sc-rows { display: flex; flex-direction: column; gap: 0.15rem; }
.sc-row  { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.82rem; line-height: 1.35; gap: 0.3rem; }
.sc-lbl  { color: #666; white-space: nowrap; }
.sc-val  {
  font-weight: 600;
  color: #111;
  font-variant-numeric: tabular-nums;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.83rem;
}

/* TIR card value accents */
.sc-tir .sc-row:nth-child(3) .sc-val { color: #2e7d32; }
.sc-tir .sc-row:nth-child(4) .sc-val,
.sc-tir .sc-row:nth-child(5) .sc-val { color: #b71c1c; }

/* ── Chart image ──────────────────────────────────────────────────────────── */
.report-chart-wrap {
  background: #fafafa;
  padding: 1.1rem 0.8rem 0.9rem;
  border-top: 1px solid #e8e8e8;
}
.report-chart-wrap img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* ── HTML chart header (Phase A) ─────────────────────────────────────────────
 * Sits above the PNG inside .report-chart-wrap. Single-line layout with the
 * title-and-tiers on the left, other legend groups on the right; subtitle
 * on its own centered row.
 *
 * The sensor-health tier legend (4 colored swatches: Clean/Marginal/
 * Compromised/Severe) sits inline immediately after the title, introduced
 * by the title's trailing colon. Other legend groups (Insulin / Clusters
 * / BGM) render in chip-style frames.
 *
 * Phase A: matplotlib still draws its own header inside the PNG -- this
 * is additive. Phase B will strip the matplotlib version.
 */
.chart-header {
  font-family: "DejaVu Serif", serif;
  margin: 0 auto 0.4rem;
  max-width: 100%;
  padding: 0 0.4rem;
}
/* Top info row: "Pump: X    Sensor: Y" centered, larger than legend.
 * Sits above the title/legend row. Either side may be omitted -- the
 * server emits info_row.pump and info_row.sensor independently. */
.chart-header .ch-info-row {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 400;
  color: #222;
  margin: 0 0 0.5rem;
  padding: 0.2rem 0;
  letter-spacing: 0.01em;
}
.chart-header .ch-info-item {
  display: inline-block;
}
.chart-header .ch-info-sep {
  display: inline-block;
  width: 2.5rem;     /* generous gap between pump and sensor */
}
.chart-header .ch-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
/* Daily reports: no title/tier legend on the left, so center the legend
 * group horizontally rather than letting it default to right-alignment. */
.chart-header .ch-row1.ch-row1-legend-only {
  justify-content: center;
}
.chart-header .ch-title-and-tiers {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.chart-header .ch-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1a237e;
  white-space: nowrap;
}
.chart-header .ch-title-colon {
  color: #1a237e;
}
.chart-header .ch-tiers-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  font-size: 1.05rem;        /* matches title size per Dan's spec */
  font-weight: 600;
  color: #222;
}
.chart-header .ch-tiers-inline .ch-item-tier {
  display: inline-flex;
  align-items: center;
}

.chart-header .ch-legend {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  font-size: 1.05rem;        /* matches title size per Dan's spec */
}
.chart-header .ch-group {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.18rem 0.55rem;
  border: 1px solid #cfcfd5;
  border-radius: 4px;
  background: rgba(255,255,255,0.85);
  white-space: nowrap;
}
.chart-header .ch-group-title {
  font-weight: 700;
  color: #333;
}
.chart-header .ch-group-extra {
  color: #555;
  font-weight: 600;
}
.chart-header .ch-item {
  display: inline-flex;
  align-items: center;
  color: #222;
}

.chart-header .ch-subtitle {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #333;
  margin-top: 0.3rem;
}

/* ── Hypo table ───────────────────────────────────────────────────────────── */
.hypo-section {
  padding: 0.75rem 0.85rem 1rem;
  background: #fff;
  border-top: 2px solid #e0e0e0;
}
.hypo-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #c62828;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.hypo-count {
  font-size: 0.72rem;
  font-weight: 400;
  color: #777;
  background: #f3f3f3;
  border-radius: 10px;
  padding: 0.1rem 0.5rem;
}
.hypo-row-current-date {
  background: #ede7f6 !important;
  border-left:   3px solid var(--purple) !important;
  border-right:  3px solid var(--purple) !important;
  border-top:    3px solid var(--purple) !important;
  border-bottom: 3px solid var(--purple) !important;
}
/* For consecutive current-day rows, suppress the top border so adjacent rows
   share a single line rather than showing a doubled 6px gap. */
.hypo-row-current-date + .hypo-row-current-date {
  border-top: none !important;
}
.hypo-row-current-date td:first-child {
  padding-left: 0.4rem;
}

.hypo-table-wrap {
  overflow-y: auto;
  max-height: 260px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.hypo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.79rem;
}
.hypo-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}
.hypo-table thead tr { background: #e8eaf6; }
.hypo-table th {
  padding: 0.3rem 0.55rem;
  text-align: left;
  font-weight: 700;
  color: #1a237e;
  border-bottom: 2px solid #c5cae9;
  white-space: nowrap;
}
.hypo-table td {
  padding: 0.27rem 0.55rem;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
  white-space: nowrap;
}
.hypo-row { cursor: pointer; transition: background 0.1s; }
.hypo-even { background: #fff; }
.hypo-odd  { background: #f5f9ff; }
.hypo-row:hover    { background: #e8f0fe !important; }
.hypo-selected     { background: #c5cae9 !important; }
.hypo-bg           { color: #b71c1c; font-weight: 700; font-variant-numeric: tabular-nums; }
.hypo-type-crit    { color: #b71c1c; font-weight: 600; }
.hypo-type-elev    { color: #e65100; font-weight: 600; }

/* During-cluster hypo: sensor was noisy while glucose was actually low */
.hypo-during-cluster { background: #FFF8E1; }
.hypo-during-cluster:hover { background: #FFF0C8 !important; }
.hypo-during-flag {
  color: #5D4037;
  font-weight: 600;
  font-style: italic;
  cursor: help;
  border-bottom: 1px dashed #8D6E63;
}

.hypo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.67rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}
.hypo-day { background: #FFD600; color: #111; border: 1.5px solid #333; }
.hypo-noc { background: #111;    color: #fff; border: 1.5px solid #111; }

.hypo-span { font-variant-numeric: tabular-nums; font-family: 'Courier New', Courier, monospace; font-size: 0.77rem; }
.hypo-time { font-variant-numeric: tabular-nums; }

.btn-show-detail {
  margin-left: auto;
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1.5px solid #1a237e;
  border-radius: 4px;
  background: #fff;
  color: #1a237e;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-show-detail:hover:not(:disabled) { background: #1a237e; color: #fff; }
.btn-show-detail:disabled { opacity: 0.35; cursor: default; }
