:root {
  --bg: #070b14;
  --surface: rgba(18, 25, 45, 0.65);
  --surface-raised: rgba(30, 40, 65, 0.7);
  --surface-hover: rgba(45, 60, 90, 0.5);
  --border: rgba(255, 255, 255, 0.06);
  --border-visible: rgba(255, 255, 255, 0.08);
  --text: #ecedee;
  --text-secondary: #a1aab4;
  --text-muted: #5d6570;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.12);
  --accent-hover: #2dd4bf;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.03);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --transition: 0.2s ease;

  /* Category colors */
  --cat-heart: #f472b6;
  --cat-heart-dim: rgba(244, 114, 182, 0.12);
  --cat-sleep: #a78bfa;
  --cat-sleep-dim: rgba(167, 139, 250, 0.12);
  --cat-activity: #fbbf24;
  --cat-activity-dim: rgba(251, 191, 36, 0.12);
  --cat-body: #60a5fa;
  --cat-body-dim: rgba(96, 165, 250, 0.12);
  --cat-labs: #fb7185;
  --cat-labs-dim: rgba(251, 113, 133, 0.12);
  --cat-other: #5eead4;
  --cat-other-dim: rgba(94, 234, 212, 0.10);
}

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

html, body, #root { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Global Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.14);
}
::-webkit-scrollbar-corner { background: transparent; }

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

/* Subtle radial vignette — soft glow from top-center */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse at 50% 0%, rgba(94, 234, 212, 0.04) 0%, transparent 55%);
  pointer-events: none;
}

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

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  background: var(--accent);
  color: #071012;
  font-weight: 600;
  transition: all var(--transition);
}
button:hover { background: var(--accent-hover); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

input, select, textarea {
  user-select: text;
  width: 100%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-visible);
  background: rgba(18, 25, 45, 0.5);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
select { color-scheme: dark; }
select option {
  background-color: #0f1729;
  color: var(--text);
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

label {
  display: block;
  margin-bottom: 1rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

/* ── Layout ─────────────────────────────────────────── */
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 1.5rem;
  background: rgba(18, 25, 45, 0.7);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 2rem;
}
.topbar-brand {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
  white-space: nowrap;
}
.topbar-brand:hover { text-decoration: none; opacity: 0.85; }
.brand-tag {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.35rem;
  vertical-align: middle;
}
.topbar-nav {
  display: flex;
  gap: 0.25rem;
}
.topbar-nav-link {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.topbar-nav-link:hover {
  background: var(--surface-raised);
  color: var(--text);
}
.topbar-right {
  position: relative;
  display: flex;
  align-items: center;
}
.topbar-scratchpad-btn {
  position: relative;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  margin-right: 0.5rem;
  transition: color var(--transition), border-color var(--transition);
}
.topbar-scratchpad-btn:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}
.sp-topbar-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  background: var(--accent);
  color: #070b14;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0 4px;
  border-radius: 6px;
  line-height: 1.4;
}

.topbar-user-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.topbar-user-btn:hover { background: var(--surface-raised); color: var(--text); }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  overflow: hidden;
}
.user-avatar-img { width: 100%; height: 100%; object-fit: cover; }
.user-email {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
}
.user-chevron { font-size: 0.6rem; color: var(--text-muted); }
.topbar-login-btn {
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
}
.user-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 220px;
  background: rgba(18, 25, 45, 0.85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-visible);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.user-dropdown-header {
  padding: 0.6rem 0.85rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}
.user-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.85rem;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 0;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.user-dropdown-item:hover { background: var(--surface-raised); color: var(--text); }
.user-dropdown-item.danger { color: var(--danger); }
.user-dropdown-item.danger:hover { background: rgba(239, 68, 68, 0.08); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-weight: 500;
}
.btn-ghost:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.main-content {
  flex: 1;
  padding: 2rem;
}

/* ── Page basics ────────────────────────────────────── */
.page {
  max-width: 1400px;
  margin: 0 auto;
}
.page-header {
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h2 {
  font-size: 1.75rem;
  font-weight: 700;
}
.page-header .subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}


.loading {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}
.empty-state {
  background: rgba(18, 25, 45, 0.2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.empty-state p { margin-bottom: 0.5rem; }
.empty-state p:last-child { margin-bottom: 0; }

/* ── Alerts ─────────────────────────────────────────── */
.alert {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.15);
  color: #fca5a5;
}
.alert-warning {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.15);
  color: #fcd34d;
}
.alert-info {
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.15);
  color: #93c5fd;
}

/* ── Login ──────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: radial-gradient(ellipse at 50% 0%, rgba(94, 234, 212, 0.06) 0%, transparent 60%);
}
.login-card {
  background: rgba(18, 25, 45, 0.6);
  backdrop-filter: blur(24px);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.login-card h1 .brand-tag {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.4rem;
  vertical-align: middle;
  -webkit-text-fill-color: var(--accent);
}
.login-card .subtitle {
  color: var(--text-secondary);
  margin-bottom: 1.75rem;
}
.login-card form > * + * { margin-top: 0.75rem; }

/* Field wrapper */
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0;
}

/* Real-time validation states */
.field input.valid { border-color: var(--success); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.08); }
.field input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.08); }

.field-hint {
  font-size: 0.75rem;
  transition: color 0.2s;
}
.field-hint.ok { color: var(--success); }
.field-hint.warn { color: var(--danger); }

/* Password strength bar */
.strength-bar {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.15rem;
}
.strength-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease, background 0.4s ease;
}
.strength-fill.weak { background: var(--danger); }
.strength-fill.okay { background: var(--warning); }
.strength-fill.good { background: var(--accent); }
.strength-fill.strong { background: var(--success); }

.login-error {
  color: #fca5a5;
  font-size: 0.85rem;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.15);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
}
.login-card .toggle {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.login-card .link {
  background: none;
  color: var(--accent);
  padding: 0;
  font-weight: 500;
}
/* ── Health Nuggets ────────────────────────────────── */
.tile.nugget-tile { cursor: default; }
.tile.nugget-tile:hover { transform: none; border-color: var(--border); box-shadow: var(--shadow); }
.nugget-rows { padding: 0.25rem 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; }
.nugget-row { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--text-secondary); }
.nugget-icon { font-size: 0.85rem; flex-shrink: 0; }
.nugget-text { line-height: 1.35; }

/* ── Dashboard dropzone ────────────────────────────── */
.dashboard-dropzone {
  border: 2px dashed var(--border-visible);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  text-align: center;
  transition: all var(--transition);
  cursor: pointer;
  background: rgba(18, 25, 45, 0.35);
  backdrop-filter: blur(8px);
}
.dashboard-dropzone:hover,
.dashboard-dropzone.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 40px rgba(94, 234, 212, 0.06);
}
.dashboard-dropzone.uploading {
  cursor: default;
  border-color: var(--border-visible);
  opacity: 0.7;
}
.dropzone-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.dropzone-icon { font-size: 1.25rem; }
.dropzone-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-left: 0.5rem;
}

.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px dashed var(--accent);
  margin: 2rem;
  border-radius: var(--radius-lg);
}
.drag-overlay-content {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Accordion Sections ─────────────────────────────── */
.accordion-section {
  margin-bottom: 0.75rem;
  background: rgba(18, 25, 45, 0.5);
  backdrop-filter: blur(12px);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.accordion-section:hover {
  border-color: var(--border-visible);
  box-shadow: var(--shadow);
}
.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.accordion-header:hover { background: rgba(255, 255, 255, 0.02); }
.accordion-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.accordion-chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.accordion-chevron.open { transform: rotate(180deg); }
.accordion-body {
  padding: 0 1.25rem 1.25rem 1.25rem;
  animation: slideDown 0.2s ease;
}
.accordion-body.collapsed { display: none; }

/* ── Metric tiles ───────────────────────────────────── */
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

/* Metric tile internals — scoped under .metric-tile to avoid collision with .tile */
.metric-tile .tile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1rem 0 1rem;
  user-select: none;
}
.metric-tile .tile-header h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.metric-tile .tile-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Category sparkline + trend colors */
.metric-tile.cat-heart .tile-sparkline svg .recharts-line-curve { stroke: var(--cat-heart) !important; }
.metric-tile.cat-heart .trend-badge.up { color: var(--cat-heart); background: var(--cat-heart-dim); }
.metric-tile.cat-sleep .tile-sparkline svg .recharts-line-curve { stroke: var(--cat-sleep) !important; }
.metric-tile.cat-sleep .trend-badge.up { color: var(--cat-sleep); background: var(--cat-sleep-dim); }
.metric-tile.cat-activity .tile-sparkline svg .recharts-line-curve { stroke: var(--cat-activity) !important; }
.metric-tile.cat-activity .trend-badge.up { color: var(--cat-activity); background: var(--cat-activity-dim); }
.metric-tile.cat-body .tile-sparkline svg .recharts-line-curve { stroke: var(--cat-body) !important; }
.metric-tile.cat-body .trend-badge.up { color: var(--cat-body); background: var(--cat-body-dim); }
.metric-tile.cat-labs .tile-sparkline svg .recharts-line-curve { stroke: var(--cat-labs) !important; }
.metric-tile.cat-labs .trend-badge.up { color: var(--cat-labs); background: var(--cat-labs-dim); }

.lab-panel .lab-marker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}
.lab-panel .lab-marker {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.02);
  font-size: 0.85rem;
}
.lab-panel.expanded .lab-marker {
  grid-template-columns: 1.4fr auto auto auto;
}
.lab-panel .lab-marker.flag-high,
.lab-panel .lab-marker.flag-low,
.lab-panel .lab-marker.flag-critical {
  background: rgba(251, 113, 133, 0.08);
  border-left: 2px solid var(--cat-labs);
  padding-left: 6px;
}
.lab-panel .lab-marker-name {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lab-panel .lab-marker-val {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.lab-panel .lab-marker-unit {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}
.lab-panel .lab-marker-ref {
  color: var(--text-muted);
  font-size: 0.7rem;
  white-space: nowrap;
}
.lab-panel .lab-marker-flag {
  font-size: 0.65rem;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.lab-panel .lab-marker-flag.flag-high,
.lab-panel .lab-marker-flag.flag-low { color: var(--cat-labs); background: var(--cat-labs-dim); }
.lab-panel .lab-marker-flag.flag-critical { color: #fca5a5; background: rgba(239, 68, 68, 0.18); }
.lab-panel .more-row {
  background: transparent;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  font-size: 0.78rem;
  border-left: none;
  padding-left: 8px;
}
.lab-panel .trend-badge.stable {
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
}

/* HealthOMeter */
.hometer-tile { cursor: pointer; }
.hometer-row {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 12px;
  padding: 8px 0;
}
.health-gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}
.health-gauge .gauge-svg {
  width: 100%;
  max-width: 130px;
  height: auto;
}
.health-gauge.gauge-large .gauge-svg { max-width: 180px; }
.health-gauge .gauge-pct-text {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.health-gauge.gauge-large .gauge-pct-text { font-size: 28px; }
.health-gauge .gauge-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
}
.health-gauge .gauge-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}
.health-gauge .gauge-pct.muted {
  font-size: 1.5rem;
  color: var(--text-muted);
  font-weight: 700;
}
.hometer-detail {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-visible);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.hometer-detail-section h5 {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 1px;
  font-weight: 600;
}
.hometer-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.hometer-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  font-size: 0.78rem;
  color: var(--text);
  border: 1px solid var(--border-visible);
  white-space: nowrap;
}
.hometer-pill.has-flagged { border-color: var(--cat-labs); }
.hometer-pill.rating-strong { border-color: var(--success); }
.hometer-pill.rating-moderate { border-color: var(--accent); }
.hometer-pill.rating-limited { border-color: var(--warning); }
.hometer-pill em { color: var(--cat-labs); font-style: normal; }

.stack-gauge-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
}
.stack-gauge-wrap .supp-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.metric-tile.cat-other .tile-sparkline svg .recharts-line-curve { stroke: var(--cat-other) !important; }
.metric-tile.cat-other .trend-badge.up { color: var(--cat-other); background: var(--cat-other-dim); }

.metric-tile .tile-body {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem 0.75rem 1rem;
}
.metric-tile .tile-value {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.metric-tile .tile-number {
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.2;
}
.metric-tile .tile-unit {
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.metric-tile .tile-detail {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-left: 0.25rem;
}
.metric-tile .tile-sparkline {
  width: 100px;
  flex-shrink: 0;
  opacity: 0.7;
}

.metric-tile .tile-detail-row {
  padding: 0 1rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
}

.metric-tile .tile-detail-chip {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.metric-tile .tile-detail-chip strong {
  color: var(--text-secondary);
  font-weight: 600;
}

.metric-tile .tile-chart {
  padding: 0 0.75rem 0.75rem 0.75rem;
  animation: slideDown 0.25s ease;
}
.metric-tile .tile-legend {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
  padding: 0 0.25rem;
}
.metric-tile .legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.metric-tile .legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.metric-tile .tile-smoothing {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.smooth-chip {
  padding: 0.25rem 0.6rem;
  font-size: 0.73rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  font-weight: 500;
}
.smooth-chip:hover { border-color: var(--border-visible); color: var(--text); }
.smooth-chip.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(94, 234, 212, 0.2);
  font-weight: 600;
}

.trend-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  white-space: nowrap;
}
.trend-badge.up { color: var(--success); background: rgba(52, 211, 153, 0.10); }
.trend-badge.down { color: var(--danger); background: rgba(248, 113, 113, 0.10); }
.trend-badge.stable { color: var(--text-muted); background: rgba(255, 255, 255, 0.04); }

/* Tile tooltip */
.tile-tooltip {
  position: fixed;
  z-index: 100;
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: fadeIn 0.15s ease;
}
.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  padding: 0.15rem 0;
}
.tooltip-label {
  color: var(--text-muted);
  text-transform: capitalize;
}
.tooltip-val {
  color: var(--text);
  font-weight: 600;
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 400px; }
}

/* ── Document groups (expandable list → card grid) ─────────────────── */
.doc-groups {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.doc-group {
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.doc-group.open {
  border-color: rgba(255,255,255,0.1);
}
.doc-group-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.85rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}
.doc-group-header:hover {
  background: rgba(255,255,255,0.025);
}
.doc-group-icon { font-size: 1.4rem; flex-shrink: 0; }
.doc-group-name {
  font-size: 0.85rem;
  color: #e2e8f0;
  font-weight: 500;
  flex: 1;
}
.doc-group-count {
  font-size: 0.68rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.doc-group-chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
}
.doc-group .tile-grid {
  border-top: 1px solid rgba(255,255,255,0.05);
  padding: 0.75rem;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.doc-type {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}
.doc-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.doc-summary {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}
/* ── Upload ─────────────────────────────────────────── */
.upload-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
@media (max-width: 600px) {
  .upload-form { grid-template-columns: 1fr; }
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-secondary);
  transition: all 0.2s;
  cursor: pointer;
  background: var(--surface);
}
.upload-zone:hover, .upload-zone.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.upload-zone.uploading {
  cursor: default;
  border-color: var(--border);
}
.upload-prompt .upload-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}
.upload-prompt p {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}
.upload-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Extracted results ──────────────────────────────── */
.extracted-results {
  margin-top: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.results-header h3 { font-size: 1.2rem; }
.model-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}
.summary {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.extracted-section {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.extracted-section h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.flag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}
.flag.normal { color: var(--success); background: rgba(34,197,94,0.1); }
.flag.high, .flag.critical { color: var(--danger); background: rgba(239,68,68,0.1); }
.flag.low { color: var(--warning); background: rgba(245,158,11,0.1); }

/* Pills */
.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.pill {
  background: rgba(30, 40, 65, 0.5);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.pill strong { color: var(--text); }
.pill span { color: var(--text-muted); font-size: 0.8rem; }

/* Diagnosis list */
.diagnosis-list {
  list-style: none;
}
.diagnosis-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
  font-size: 0.9rem;
}
.diagnosis-list .status {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
}
.diagnosis-list .status.active { color: var(--accent); background: var(--accent-dim); }
.diagnosis-list .status.chronic { color: var(--warning); background: rgba(245,158,11,0.1); }
.diagnosis-list .status.resolved { color: var(--success); background: rgba(34,197,94,0.1); }
.diagnosis-list .date { color: var(--text-muted); font-size: 0.8rem; margin-left: auto; }

.patient-info {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ── Buttons ────────────────────────────────────────── */
.btn-secondary {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
}
.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-primary {
  background: var(--accent);
  color: #071012;
  border: none;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); }

/* ── Insights ───────────────────────────────────────── */
.insight-card h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.insight-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.insight-card li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding-left: 0.85rem;
  position: relative;
  line-height: 1.45;
}
.insight-card li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--accent);
}
.insight-card.recommendation li::before { color: var(--success); }
.insight-card.trend li::before { color: var(--warning); }

.disclaimer-banner {
  background: rgba(251, 191, 36, 0.05);
  border: 1px solid rgba(251, 191, 36, 0.12);
  color: #fcd34d;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* ── Stack Evidence Gauge ──────────────────────────── */
.stack-gauge-value {
  font-size: 1.6rem;
  font-weight: 700;
  transition: color 0.8s ease;
  flex-shrink: 0;
}
.stack-gauge-svg {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
}

/* ── Stack (redesigned) ─────────────────────────────── */
.supp-add-card {
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.supp-add-card h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.supp-add-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.supp-add-form input { flex: 1; min-width: 140px; }
.supp-add-form select { width: 140px; flex-shrink: 0; }
.supp-add-form button { flex-shrink: 0; }
.supp-add-form .btn-small { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

.meta-chip {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text-secondary);
}
.meta-chip.warning {
  background: rgba(var(--warning-rgb, 255 193 7), 0.15);
  color: var(--warning);
}
.meta-chip.muted { opacity: 0.6; }
.stack-review-empty {
  border: 1px dashed var(--border);
}
.stack-review-empty:hover {
  border-color: var(--accent);
}

.supp-card {
  padding: 0.85rem 1rem;
}
.supp-card.stopped { opacity: 0.55; }
.supp-card-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}
.supp-card-info { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 0; }
.supp-name { font-size: 0.95rem; color: var(--text); }
.supp-dose { font-size: 0.78rem; color: var(--text-muted); }
.supp-notes { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }
.supp-summary { font-size: 0.78rem; color: var(--text-secondary); margin-top: 0.4rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.supp-card-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  flex-shrink: 0;
}

.research-badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.research-badge.researching { background: var(--surface-raised); color: var(--accent); animation: pulse 1.5s ease infinite; }

.supp-research-popup {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  animation: slideDown 0.2s ease;
  max-height: 420px;
  overflow-y: auto;
}
.supp-research-inline {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  animation: slideDown 0.2s ease;
}
.research-rating {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}
.research-quick {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 0.6rem;
}
.research-section {
  margin-bottom: 0.55rem;
}
.research-section h5 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.research-section p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.55;
}
.research-benefits {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.research-benefits li {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}
.research-benefits li strong {
  display: block;
  font-size: 0.82rem;
  color: var(--text);
}
.evidence-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.4rem;
  background: var(--text-muted);
}
.evidence-dot.strong { background: var(--success); }
.evidence-dot.moderate { background: var(--accent); }
.evidence-dot.limited { background: var(--warning); }
.evidence-level {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 0.35rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
}
.benefit-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  line-height: 1.45;
}
.research-date {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.stopped-badge {
  color: var(--danger);
  font-weight: 600;
}

/* ── Integration cards ──────────────────────────────── */
.integration-card {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.integration-card.connected { border-left: 3px solid var(--success); }
.int-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  color: #fff;
}
.int-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}
.int-card-body strong { font-size: 0.95rem; color: var(--text); }
.int-card-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.int-card-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}
.int-card-status.ok { color: var(--success); }
.int-card-extra {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.int-card-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* Integrations page */
.integrations-page {
  max-width: 800px;
}
.integrations-page h1,
.integrations-embedded h1 {
  margin-bottom: 1.5rem;
}
.integrations-page .card,
.integrations-embedded .card {
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.integrations-page .card h2,
.integrations-embedded .card h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.section-header h2 {
  margin-bottom: 0 !important;
}
.profile-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.25rem 0;
  padding: 1rem;
  background: rgba(30, 40, 65, 0.3);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
}
.form-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.form-row input,
.form-row select {
  flex: 1;
  min-width: 200px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font-size: 0.9rem;
}
.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--accent);
}
.profile-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}
.profile-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(30, 40, 65, 0.4);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}
.profile-item .badge {
  margin-left: 0.5rem;
}
.btn-small {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}


/* Email list (additional Integrations page styles) */
.email-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}
.email-item {
  background: rgba(30, 40, 65, 0.4);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}
.email-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}
.email-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.badge.processed {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}
.query-tag {
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  margin-left: 0.5rem;
}
/* Upload results - category badge */
.category-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.category-badge .cat {
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  text-transform: capitalize;
}
.category-badge .sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.category-badge .conf {
  font-size: 0.75rem;
  background: var(--surface-raised);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.category-badge .conf.low {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}
.category-badge .conf.high {
  color: var(--success);
  background: rgba(34, 197, 94, 0.15);
}
.provider {
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.order-block {
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}
.order-item {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}
.order-total {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 0.5rem;
  color: var(--accent);
}


/* Job toast cards — bottom of screen, one per file/job */
.job-toast-container {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 420px;
  max-width: calc(100vw - 2rem);
  pointer-events: none;
}
.job-toast {
  background: rgba(18, 25, 45, 0.8);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-visible);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
  pointer-events: auto;
}
.job-toast.done {
  border-left: 3px solid var(--success);
  opacity: 0.85;
}
.job-toast.failed {
  border-left: 3px solid var(--danger);
}
.job-toast.active {
  border-left: 3px solid var(--accent);
}
.job-toast-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}
.job-toast-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 65%;
}
.job-toast-stage {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 500;
}
.job-toast.done .job-toast-stage { color: var(--success); }
.job-toast.failed .job-toast-stage { color: var(--danger); }
.job-toast-bar {
  height: 3px;
  background: var(--surface-raised);
  border-radius: 999px;
  overflow: hidden;
}
.job-toast-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.5s ease;
}
.job-toast-fill.done { background: var(--success); }
.job-toast-fill.failed { background: var(--danger); }

/* Toast colour variants */
.job-toast.toast-success { border-left-color: var(--success); }
.job-toast.toast-success .job-toast-stage { color: var(--success); }
.job-toast.toast-success .job-toast-fill { background: var(--success); }
.job-toast.toast-error { border-left-color: var(--danger); }
.job-toast.toast-error .job-toast-stage { color: var(--danger); }
.job-toast.toast-error .job-toast-fill { background: var(--danger); }
.job-toast.toast-warning { border-left-color: var(--warning); }
.job-toast.toast-warning .job-toast-stage { color: var(--warning); }
.job-toast.toast-warning .job-toast-fill { background: var(--warning); }
.job-toast.toast-info { border-left-color: var(--accent); }
.job-toast.toast-info .job-toast-stage { color: var(--accent); }
.job-toast.toast-info .job-toast-fill { background: var(--accent); }

.job-toast.toast-flash {
  animation: slideUp 0.25s ease, fadeAway 0.5s ease 5.5s forwards;
}
@keyframes fadeAway {
  to { opacity: 0; transform: translateY(-8px); }
}

/* Insights run selector */
.run-selector {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: rgba(30, 40, 65, 0.3);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
}
.run-chip {
  background: rgba(18, 25, 45, 0.4);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.run-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}
.run-chip.active {
  background: var(--accent-dim);
  border-color: rgba(94, 234, 212, 0.25);
  color: var(--accent);
  font-weight: 600;
}
/* Multi-file upload progress */
.upload-progress-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 480px;
}
.upload-progress-list p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.file-progress {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.file-progress li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.75rem;
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.file-progress li .fp-name {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 85%;
}
.file-progress li .fp-status {
  font-size: 0.9rem;
}
.file-progress li.done {
  border-left: 3px solid var(--success);
}
.file-progress li.error {
  border-left: 3px solid var(--danger);
}

/* Result cards */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1rem;
}
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  background: var(--surface);
}
.result-card .results-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.result-card .file-tag {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-raised);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.document-card {
  cursor: pointer;
}
/* ── Standard delete icon button — hidden until parent hover ── */
.btn-delete-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 0.9rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.btn-delete-icon:hover { color: var(--danger); }
/* parent hover reveals */
.conv-item:hover .btn-delete-icon,
.run-meta:hover .btn-delete-icon { opacity: 1; }

/* Conversation delete — positioned absolute right, vertically centered */
.conv-item { position: relative; }
.conv-delete {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
}

/* Run meta delete — pushed to the right via flex */
.run-meta .btn-delete-icon { margin-left: auto; }

/* ── Tile System ───────────────────────────────────── */

/* Base tile — universal card chrome. Replaces .metric-tile, .supp-card, .card-glass over time. */
.tile {
  background: rgba(18, 25, 45, 0.45);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  animation: cardEnter 0.35s ease both;
}

/* Category accent strip */
.tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  opacity: 0;
  transition: opacity var(--transition);
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 1;
}
.tile:hover::before { opacity: 1; }
.tile.cat-heart::before { background: var(--cat-heart); }
.tile.cat-sleep::before { background: var(--cat-sleep); }
.tile.cat-activity::before { background: var(--cat-activity); }
.tile.cat-body::before { background: var(--cat-body); }
.tile.cat-other::before { background: var(--cat-other); }

/* Hover — lift + shadow */
.tile:hover {
  border-color: var(--border-visible);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* Size modifiers */
.tile.w-quarter { }                           /* default — 1 grid cell */
.tile.w-half    { grid-column: span 2; }
.tile.w-full    { grid-column: 1 / -1; }
.tile.h-tall    { grid-row: span 2; }

/* Drag handle — hidden until tile hover */
.tile-drag-handle {
  position: absolute;
  top: 0.35rem; left: 0.35rem;
  z-index: 2;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: grab;
  font-size: 1rem;
  padding: 0.15rem 0.3rem;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity var(--transition);
  line-height: 1;
}
.tile:hover .tile-drag-handle { opacity: 1; }
.tile-drag-handle:active { cursor: grabbing; }

/* Remove button — hidden until tile hover */
.tile-remove-btn {
  position: absolute;
  top: 0.35rem; right: 0.35rem;
  z-index: 2;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
  line-height: 1;
}
.tile:hover .tile-remove-btn { opacity: 1; }
.tile-remove-btn:hover { color: var(--danger); }

/* Tile grid — single responsive grid replacing all legacy grids */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min, 280px), 1fr));
  gap: var(--tile-gap, 0.875rem);
  grid-auto-flow: dense;
}

/* ── Shared Primitives ────────────────────────────────── */

/* Glass-morphism card — deprecated, prefer <Tile>. Kept for section containers (forms, panels). */
.card-glass {
  background: rgba(18, 25, 45, 0.45);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Accent badge — SSOT for pills, chips, and status indicators */
.badge {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.75rem;
}

/* Mono tool chip — SSOT for code-style tool name indicators */
.tool-chip-mono {
  display: inline-block;
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.45rem;
  color: var(--text-secondary);
  font-family: var(--font-mono, monospace);
  font-size: 0.7rem;
}

/* Memory notes */
.memory-content {
  user-select: text;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
  max-height: 400px;
  overflow-y: auto;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: rgba(18, 25, 45, 0.85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-visible);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(18, 25, 45, 0.9);
  backdrop-filter: blur(20px);
  z-index: 1;
}
.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  text-transform: capitalize;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.modal-body {
  padding: 1.5rem;
}
.raw-json-section {
  margin-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 0.75rem;
}
.raw-json-section summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8rem;
  user-select: none;
}
.raw-json {
  user-select: text;
  margin-top: 0.5rem;
  max-height: 400px;
  overflow: auto;
  font-size: 0.7rem;
  background: rgba(0,0,0,0.3);
  padding: 0.75rem;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}
.btn-small {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
/* ── Confirm Dialog ──────────────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(4, 8, 18, 0.6);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.15s ease;
}
.confirm-dialog {
  background: rgba(18, 25, 45, 0.9);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-visible);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.confirm-dialog h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}
.confirm-dialog p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 1.25rem;
}
.confirm-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}
.confirm-actions .btn-ghost {
  width: auto;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}
.confirm-danger-btn {
  background: var(--danger);
  color: #fff;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: all var(--transition);
}
.confirm-danger-btn:hover {
  background: #ef4444;
  transform: translateY(-1px);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes cardEnter {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Animated entries for dashboard cards */
.accordion-section { animation: cardEnter 0.3s ease both; }

/* Stagger children within tile grids for cascade effect */
.tile-grid .tile:nth-child(1) { animation-delay: 0s; }
.tile-grid .tile:nth-child(2) { animation-delay: 0.06s; }
.tile-grid .tile:nth-child(3) { animation-delay: 0.12s; }
.tile-grid .tile:nth-child(4) { animation-delay: 0.18s; }
.tile-grid .tile:nth-child(n+5) { animation-delay: 0.24s; }

/* ── Settings ────────────────────────────────────────── */
.settings-modal { max-width: 520px; }
.settings-section {
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border);
}
.settings-section:first-child { padding-top: 0; }
.settings-section:last-child { border-bottom: none; padding-bottom: 0; }
.settings-section h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-weight: 600;
}
.settings-picture {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform var(--transition);
}
.settings-picture:hover { transform: scale(1.04); }
.profile-img { width: 100%; height: 100%; object-fit: cover; }
.profile-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--accent-dim), rgba(167, 139, 250, 0.2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}
.profile-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  opacity: 0;
  transition: opacity var(--transition);
}
.settings-picture:hover .profile-overlay { opacity: 1; }
.settings-row {
  display: flex;
  gap: 0.75rem;
}
.settings-row input { flex: 1; }
.settings-row .btn-small { flex-shrink: 0; }
.readonly-input {
  opacity: 0.6;
  cursor: not-allowed;
}
.storage-info { padding-top: 0.25rem; }
.storage-bar-bg {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.storage-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent-dim);
  transition: width 0.5s ease;
  min-width: 2px;
}
.storage-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.plan-premium { padding: 0.5rem 0; }
.plan-premium-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.plan-badge {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #071012;
}
.plan-status { font-size: 0.8rem; color: var(--success); font-weight: 600; }
.plan-detail { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 0.6rem; }
.plan-tiers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}
.plan-tier {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.plan-tier strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}
.plan-tier ul {
  list-style: none;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 0;
}
.plan-tier ul li::before { content: '✓ '; color: var(--success); }
.plan-price {
  display: block;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}
.plan-price span { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); }
.plan-tier-current {
  border-color: rgba(255, 255, 255, 0.1);
}
.plan-tier-current strong::after {
  content: ' (current)';
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
}
.plan-tier-premium {
  border-color: rgba(94, 234, 212, 0.25);
  background: linear-gradient(135deg, rgba(94, 234, 212, 0.05) 0%, rgba(167, 139, 250, 0.04) 100%);
  box-shadow: 0 0 20px rgba(94, 234, 212, 0.06);
}
.plan-tier-premium ul li::before { content: '∞ '; color: var(--accent); }
.danger-zone {
  background: rgba(248, 113, 113, 0.05);
  border: 1px solid rgba(248, 113, 113, 0.15);
  border-radius: var(--radius);
  padding: 1.25rem !important;
  margin-top: 0.5rem;
}
.danger-zone h4 { color: var(--danger) !important; }
.danger-zone p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  font-weight: 600;
}
.btn-danger:hover { background: #ef4444; }

/* Data sources summary on Insights page */
.data-sources h4 {
  margin: 0 0 0.25rem 0;
  font-size: 0.95rem;
  color: var(--text);
}
.data-sources-hint {
  margin: 0 0 0.75rem 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.source-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(18, 25, 45, 0.5);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: help;
}
.source-chip .source-icon {
  font-size: 1rem;
}
.source-chip .source-label {
  font-weight: 500;
}

/* Insights section headers */
.insights-section {
  margin-bottom: 1.25rem;
}
.insights-section h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

/* Category-grouped insight cards */
.insight-card.category-group {
  border-left: 3px solid var(--accent);
}
.insight-card.category-group h4 {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

/* ── Insight Type Selector ────────────────────────────── */
.insight-type-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}
.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(18, 25, 45, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.type-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}
.type-chip.active {
  background: rgba(94, 234, 212, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}
.type-chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.type-chip.generating {
  border-color: var(--accent);
  opacity: 1;
}
.type-chip .type-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 0.3rem;
}
.type-chip .type-icon {
  font-size: 0.9rem;
}
.type-chip .type-label {
  font-weight: 500;
  white-space: nowrap;
}
/* ── Generating indicator ─────────────────────────────── */
.generating-indicator {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.generating-spinner {
  width: 2rem;
  height: 2rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.generating-title {
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0;
}
.generating-stage {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0.15rem 0 0 0;
}
.generating-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

/* ── Run meta type badge ───────────────────────────────── */
.run-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.run-chip-type {
  font-size: 0.7rem;
  margin-left: 0.2rem;
}

/* ── Tool call history chips ─────────────────────────── */
.tool-call-history {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  font-size: 0.75rem;
}
.tool-call-label {
  color: var(--text-muted);
  margin-right: 0.25rem;
}

/* ── Chat ────────────────────────────────────────────── */
.chat-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.chat-sidebar {
  width: 260px;
  background: rgba(18, 25, 45, 0.5);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 0.75rem;
}
.btn-new-chat {
  width: 100%;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(94, 234, 212, 0.2);
  padding: 0.6rem;
  font-size: 0.9rem;
  border-radius: var(--radius);
  transition: all var(--transition);
}
.btn-new-chat:hover {
  background: var(--accent);
  color: #071012;
}
.chat-conversations {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  flex: 1;
}
.conv-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  border: none;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: background 0.15s;
}
.conv-item:hover { background: rgba(255, 255, 255, 0.03); }
.conv-item.active {
  background: rgba(94, 234, 212, 0.06);
  border-left: 3px solid var(--accent);
}
.conv-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.conv-date { font-size: 0.75rem; color: var(--text-muted); }
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.chat-empty {
  margin: auto;
  text-align: center;
  max-width: 480px;
  color: var(--text-secondary);
}
.chat-empty h2 { color: var(--text); margin-bottom: 0.5rem; }
.chat-examples {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-examples button {
  background: var(--surface-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 400;
  text-align: left;
}
.chat-examples button:hover { border-color: var(--accent); color: var(--accent); }
.chat-message { display: flex; }
.chat-message.user { justify-content: flex-end; }
.chat-message.assistant { justify-content: flex-start; }
.message-bubble {
  max-width: 720px;
  padding: 0.875rem 1.125rem;
  border-radius: var(--radius-lg);
  background: rgba(30, 40, 65, 0.5);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
}
.chat-message.user .message-bubble {
  background: rgba(94, 234, 212, 0.10);
  border-color: rgba(94, 234, 212, 0.2);
}
.chat-message.error .message-bubble { border-color: var(--danger); }

/* ── System message banner ────────────────────── */
.chat-system-msg {
  display: flex;
  justify-content: center;
  padding: 0.5rem 1rem;
  margin: 0.25rem 0;
  animation: fadeIn 0.3s ease;
}
.chat-system-msg span {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 600px;
  line-height: 1.45;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(94, 234, 212, 0.06);
  border: 1px solid rgba(94, 234, 212, 0.12);
}

.message-role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.message-content {
  user-select: text;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}
.tool-calls {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.tool-calls summary { cursor: pointer; color: var(--accent); margin-bottom: 0; }
.tool-calls pre {
  background: var(--bg);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.75rem;
  margin-top: 0.25rem;
}
.tool-calls code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
}
.chat-input-bar {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  background: rgba(18, 25, 45, 0.4);
}
.chat-input-bar input { flex: 1; }

.chat-mic-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.chat-mic-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-mic-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.chat-mic-btn.recording { background: rgba(239, 68, 68, 0.15); border-color: var(--danger); color: var(--danger); animation: pulse 1.5s ease infinite; }
.chat-mic-btn.playing { border-color: var(--accent); color: var(--accent); }
.chat-mic-btn.connecting { border-color: var(--warning); color: var(--warning); animation: pulse 1s ease infinite; }
.chat-mic-btn.enabled { background: var(--accent-dim); }
.chat-mic-btn.error { border-color: var(--danger); color: var(--danger); }
.chat-voice-error {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 12px; margin: 4px 8px; border-radius: 6px;
  background: rgba(239, 68, 68, 0.12); border: 1px solid var(--danger);
  color: var(--danger); font-size: 0.85em;
}
.chat-voice-error-action {
  background: transparent; border: 1px solid var(--danger); color: var(--danger);
  padding: 2px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85em;
}
.chat-voice-error-action:hover { background: rgba(239, 68, 68, 0.18); }
.breath-row { margin: 2px 0; }
.breath-row .message-bubble.breath-bubble {
  background: none; border: none; padding: 1px 14px; box-shadow: none;
}
.breath-indicator { font-size: 0.85rem; opacity: 0.55; animation: breathFade 1.5s ease forwards; pointer-events: none; display: inline-block; }
@keyframes breathFade { 0% { opacity: 0.6; } 50% { opacity: 0.35; } 100% { opacity: 0; } }
.typing-indicator {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  height: 1.5rem;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
.muted { color: var(--text-muted); font-size: 0.875rem; }

/* Chat enhancements */

.thinking-block {
  margin-bottom: 0.5rem;
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
}
.thinking-block summary {
  cursor: pointer;
  color: #a855f7;
  font-size: 0.8rem;
  font-weight: 600;
}
.thinking-content {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: #c4b5fd;
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}

.tool-indicator {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.tool-chip {
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  animation: chipIn 0.2s ease;
}
.tool-chip.running {
  background: rgba(94, 234, 212, 0.1);
  color: var(--accent);
}
.tool-chip.done {
  background: rgba(94, 234, 212, 0.05);
  color: var(--success);
}
.tool-chip.failed {
  background: rgba(248, 113, 113, 0.08);
  color: #f87171;
}
.tool-error {
  font-size: 0.78rem;
  color: #f87171;
  background: rgba(248, 113, 113, 0.06);
  border: 1px solid rgba(248, 113, 113, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  margin-bottom: 0.5rem;
}
.tool-error-msg {
  display: block;
  font-size: 0.68rem;
  opacity: 0.8;
  margin-top: 0.15rem;
}
@keyframes chipIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-bubble.streaming {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.1);
}

/* ── Floating Chat Widget ───────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 500;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #2dd4bf);
  color: #071012;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(94, 234, 212, 0.3), 0 0 0 0 rgba(94, 234, 212, 0.4);
  border: none;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  animation: fabGlow 3s ease-in-out infinite;
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(94, 234, 212, 0.5), 0 0 0 8px rgba(94, 234, 212, 0);
}

@keyframes fabGlow {
  0%, 100% { box-shadow: 0 4px 24px rgba(94, 234, 212, 0.3), 0 0 0 0 rgba(94, 234, 212, 0.4); }
  50% { box-shadow: 0 4px 28px rgba(94, 234, 212, 0.4), 0 0 0 6px rgba(94, 234, 212, 0); }
}

.chat-panel {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 500;
  width: 420px;
  height: 560px;
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 6rem);
  background: rgba(18, 25, 45, 0.8);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-visible);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease;
}
.chat-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}
.chat-panel-actions {
  display: flex;
  gap: 0.35rem;
}
.chat-panel-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 1.1rem;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1;
}
.chat-panel-btn:hover { background: var(--surface-raised); color: var(--text); }

.chat-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-panel-body .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.chat-panel-body .chat-input-bar {
  padding: 0.75rem;
}
.chat-panel-body .message-bubble { max-width: 100%; }
.chat-panel-body .message-content { font-size: 0.9rem; }
.chat-panel-body .chat-empty h2 { font-size: 1.1rem; }
.chat-panel-body .chat-empty p { font-size: 0.85rem; }
.chat-panel-body .chat-examples button { font-size: 0.8rem; padding: 0.5rem 0.75rem; }

.chat-minimize-btn {
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

/* Fullscreen chat overlay */
.chat-fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  animation: fadeIn 0.2s ease;
}
.chat-layout.fullscreen {
  display: flex;
  width: 100%;
  height: 100%;
}
.chat-layout.fullscreen .chat-sidebar { height: 100%; }
.chat-layout.fullscreen .chat-main { height: 100%; }

/* Embedded components (inside accordions) */
.insights-embedded .page-header,
.stack-embedded .page-header { display: none; }
.insights-embedded { padding-top: 0.25rem; }
.stack-embedded { padding-top: 0.25rem; }
.integrations-embedded { padding-top: 0.25rem; }
.integrations-embedded h1 { display: none; }

/* Metric category within accordion */
.metric-category { margin-bottom: 1.5rem; }
.metric-category:last-child { margin-bottom: 0; }

/* ── Health Correlation ─────────────────────────────────────────────── */
.correlation-embedded { padding-top: 0.25rem; }

.correlation-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.correlation-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.75rem;
  justify-content: center;
  margin-top: 0.75rem;
}

.correlation-legend label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.05);
  background: rgba(255,255,255,0.02);
  transition: var(--transition);
}
.correlation-legend label:has(input:checked) {
  color: var(--text-primary);
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
}
.correlation-legend label input { display: none; }

.toggle-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--dot-color, var(--accent));
  flex-shrink: 0;
}

.correlation-chart-container {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 1rem 1rem 0.5rem;
}

/* ── Legend trays ──────────────────────────────────────────────────── */
.legend-tray {
  margin-top: 0.35rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}
.legend-tray .correlation-legend {
  margin: 0;
}

/* ── Rug tooltip (floating over chart) ─────────────────────────────── */
.rug-tooltip {
  position: absolute;
  z-index: 20;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  min-width: 200px;
  max-width: 340px;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
.rug-tooltip-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding-bottom: 0.3rem;
}
.rug-tooltip-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.15rem 0;
}
.rug-tooltip-icon { flex-shrink: 0; font-size: 0.75rem; line-height: 1.3; }
.rug-tooltip-body { min-width: 0; }
.rug-tooltip-cat {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.rug-tooltip-detail {
  font-size: 0.78rem;
  color: #e2e8f0;
  line-height: 1.4;
  margin-top: 0.05rem;
}

/* ── Scratch Pad — floating AI visual panel ──────────────────────────── */

.scratchpad-panel {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 460px;
  max-width: 92vw;
  background: rgba(7, 11, 20, 0.92); /* --bg at 92% opacity */
  backdrop-filter: blur(24px);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 10001;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s var(--transition);
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.5);
}
.scratchpad-panel.open {
  transform: translateX(0);
}

.sp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
.sp-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
.sp-icon { font-size: 1.1rem; }
.sp-badge {
  background: var(--accent);
  color: #070b14;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  line-height: 1.5;
}
.sp-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.sp-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sp-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 3rem 1rem;
}

/* Chart cards */
.sp-chart-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 1rem;
}
.sp-chart-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
}
.sp-chart-wrap {
  margin: 0 -0.5rem;
}
.sp-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.sp-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.sp-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.sp-legend-range {
  color: var(--text-muted);
  font-size: 0.68rem;
  opacity: 0.7;
}
.sp-annotations {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--accent);
}
.sp-anno {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.sp-anno-marker {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

/* Note cards */
.sp-note-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 1rem;
}
.sp-note-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
}
.sp-note-content {
  font-size: 0.8rem;
  color: #cbd5e1;
  line-height: 1.5;
}
.sp-note-content h1, .sp-note-content h2, .sp-note-content h3 {
  font-size: 0.9rem;
  margin: 0.5rem 0 0.25rem;
  color: var(--text-primary);
}
.sp-note-content ul, .sp-note-content ol {
  padding-left: 1.25rem;
  margin: 0.25rem 0;
}
.sp-note-content p { margin: 0.25rem 0; }

/* Floating toggle FAB */
.sp-fab {
  position: fixed;
  left: 1rem;
  bottom: 50%;
  transform: translateY(50%);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px);
  transition: background var(--transition);
  z-index: 1199;
}
.sp-fab:hover {
  background: rgba(30, 40, 65, 0.85);
}
.sp-fab-count {
  background: var(--accent);
  color: #070b14;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0 5px;
  border-radius: 8px;
  margin-left: 0.3rem;
}

/* ── Reports ────────────────────────────────────────── */
.report-modal { max-width: 800px; }
.report-body {
  user-select: text;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}
.report-body h2 { font-size: 1.2rem; margin: 1rem 0 0.5rem; color: var(--text); }
.report-body h3 { font-size: 1.05rem; margin: 0.85rem 0 0.4rem; color: var(--text); }
.report-body h4 { font-size: 0.9rem; margin: 0.6rem 0 0.3rem; color: var(--text-secondary); }
.report-body p { margin: 0.35rem 0; color: var(--text-secondary); }
.report-body ul { padding-left: 1.5rem; margin: 0.35rem 0; }
.report-body li { color: var(--text-secondary); margin: 0.15rem 0; }
.report-body strong { color: var(--text); }
.report-body table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; font-size: 0.85rem; }
.report-body td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.report-body tr:first-child td { color: var(--text); font-weight: 600; }

.source-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  font-weight: 600;
}

@media print {
  body::before { display: none; }
  .accordion-section,
  .chat-fab,
  .sp-fab,
  .job-toast-container,
  .page-header,
  .run-selector,
  .alert,
  .generating-indicator,
  .empty-state { display: none !important; }
  .modal-overlay {
    position: static;
    background: none;
    backdrop-filter: none;
    padding: 0;
  }
  .modal-content {
    box-shadow: none;
    border: none;
    max-width: 100%;
    background: none;
    backdrop-filter: none;
  }
  .modal-header { position: static; }
  .modal-header button { display: none; }
  .report-body { color: #000; }
  .report-body p, .report-body li, .report-body td { color: #222; }
  .report-body h2, .report-body h3, .report-body h4 { color: #000; }
  .memory-content {
    background: none;
    border: none;
    padding: 0;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 11pt;
    line-height: 1.5;
    color: #000;
    max-height: none;
    overflow: visible;
  }
}

/* ---- Audio & Devices settings ---- */
.settings-expand-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.05);
  border: none;
  border-radius: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.settings-expand-btn:hover { background: rgba(255,255,255,0.1); }
.settings-audio-body {
  margin-top: 0.75rem;
  padding-left: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.settings-field label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}
.settings-field select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  font-size: 0.8125rem;
}
.settings-field select:focus { outline: none; border-color: var(--accent); }

/* ---- Device Tester ---- */
.device-tester {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.375rem;
}
.device-tester-bar {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}
.device-tester-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 75ms ease-out;
  background: linear-gradient(to right, #a855f7, #3b82f6, #22d3ee);
}
.btn-tiny {
  font-size: 0.6875rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
}
.tester-active { color: #c4b5fd; background: rgba(168,85,247,0.15); }
