/* HeadMap — calm medical green theme */

:root {
  --bg: #040714;
  --bg-stage: #070b16;
  --surface-1: rgba(255, 255, 255, 0.03);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.09);
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text-primary: #f9f9f9;
  --text-secondary: #cacaca;
  --text-muted: rgba(255, 255, 255, 0.55);
  --accent: #059669;
  --accent-bright: #10b981;
  --accent-soft: rgba(5, 150, 105, 0.15);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.12);
  --warning: #f59e0b;
  --font: 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 15px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --dur: 0.2s;
  --header-h: 68px;
  --strip-h: 34px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  z-index: 100;
  border-radius: 0 0 var(--radius-sm) 0;
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus { top: 0; }

/* ── Frame ──────────────────────────────────────────────────────────────── */
.app-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.disclaimer-strip {
  min-height: var(--strip-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px var(--space-5);
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: rgba(244, 63, 94, 0.07);
  border-bottom: 1px solid var(--border-subtle);
}
.disclaimer-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(380px, 1fr);
}

/* ── Stage (3D) ─────────────────────────────────────────────────────────── */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--bg-stage);
  overflow: hidden;
}
.head-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.stage-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}
.loader {
  width: 34px;
  height: 34px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent-bright);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  text-align: center;
  padding: var(--space-5);
}

.stage-toolbar {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  display: flex;
  gap: var(--space-2);
  z-index: 6;
}
.chip-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(7, 11, 22, 0.72);
  backdrop-filter: blur(8px);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--dur);
}
.chip-btn:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-bright);
}

.stage-hint {
  position: absolute;
  left: 50%;
  bottom: var(--space-4);
  transform: translateX(-50%);
  background: rgba(7, 11, 22, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.4s;
}
.stage-hint.dim { opacity: 0.35; }

.zone-tooltip {
  position: absolute;
  z-index: 7;
  pointer-events: none;
  background: rgba(7, 11, 22, 0.9);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transform: translate(12px, -28px);
}

/* ── Panel ──────────────────────────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border-subtle);
  background: var(--surface-1);
}
.tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}
.tab {
  flex: 1;
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 8px;
  cursor: pointer;
  transition: color var(--dur), border-color var(--dur);
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent-bright); border-bottom-color: var(--accent-bright); }

.tabpanel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
}
.tabpanel.active { display: block; }
.tabpanel > * + * { margin-top: var(--space-4); }

.panel-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.panel-block h2, .panel-block-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}
.pill {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  background: var(--surface-3);
  color: var(--text-secondary);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  vertical-align: middle;
}
.fine-print {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}
.muted { color: var(--text-muted); }
.empty-note {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 9px 16px;
  cursor: pointer;
  transition: all var(--dur);
  text-align: center;
}
.btn--sm { padding: 5px 10px; font-size: 0.8rem; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-bright); }
.btn--secondary { background: var(--surface-3); color: var(--text-primary); border-color: var(--border); }
.btn--secondary:hover { border-color: var(--border-strong); }
.btn--ghost { background: none; color: var(--text-muted); border-color: var(--border-subtle); }
.btn--ghost:hover { color: var(--text-primary); border-color: var(--border-strong); }
.btn--danger { background: none; color: var(--danger); border-color: rgba(244, 63, 94, 0.4); }
.btn--danger:hover { background: var(--danger-soft); }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 120px; }

/* ── Editor ─────────────────────────────────────────────────────────────── */
.editor-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.editor-zone {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 1rem;
  min-width: 0;
}
.editor-zone .dot { flex-shrink: 0; }
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px currentColor;
}
.editor-desc { margin: -6px 0 var(--space-3); font-size: 0.8rem; color: var(--text-muted); }

.field { margin-top: var(--space-3); }
.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.field-value { color: var(--text-primary); font-weight: 700; }
.field-desc { font-size: 0.76rem; color: var(--text-muted); margin-top: 4px; }

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffcccc, #ff6666 30%, #cc0000 60%, #5a0000);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border-strong), 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border-strong);
  cursor: pointer;
}

.guidance-card {
  margin-top: 8px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.guidance-card--severe {
  border-color: rgba(244, 63, 94, 0.4);
  background: var(--danger-soft);
}
.guidance-title { font-size: 0.78rem; font-weight: 700; color: var(--warning); }
.guidance-card--severe .guidance-title { color: #fda4af; }
.guidance-card ul {
  margin: 6px 0 0;
  padding-left: 16px;
  font-size: 0.76rem;
  color: var(--text-secondary);
}
.guidance-card li { margin: 3px 0; }
.guidance-root {
  margin: 8px 0 0;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  color: var(--text-muted);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur);
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-bright);
}

textarea.note-input {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
textarea.note-input:focus { outline: none; border-color: var(--accent); }
.note-counter { font-size: 0.72rem; color: var(--text-muted); text-align: right; }

.editor-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.editor-actions .btn { flex: 1; }

/* ── Groups ─────────────────────────────────────────────────────────────── */
.group-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-1);
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color var(--dur), background var(--dur);
}
.group-row:hover { border-color: var(--border-strong); }
.group-row.active { border-color: var(--accent); background: var(--accent-soft); }
.group-swatch {
  appearance: none;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 6px currentColor;
  cursor: pointer;
  padding: 0;
  transition: transform var(--dur);
}
.group-swatch:hover { transform: scale(1.2); }
.group-rename {
  width: 100%;
  font: inherit;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}
.group-rename:focus { outline: none; }
.dot--sm { width: 8px; height: 8px; box-shadow: none; }
.chip--group { display: inline-flex; align-items: center; gap: 6px; }

/* ── Points list ────────────────────────────────────────────────────────── */
.point-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-1);
  margin-bottom: 6px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: border-color var(--dur), background var(--dur);
}
.point-row:hover { border-color: var(--border-strong); }
.point-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.point-main { flex: 1; min-width: 0; }
.point-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.point-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.point-del {
  appearance: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.point-del:hover { color: var(--danger); background: var(--danger-soft); }

/* ── Zone browser ───────────────────────────────────────────────────────── */
.zone-browser {
  margin-top: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-1);
}
.zone-browser summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  list-style-position: inside;
}
.zone-browser[open] summary { border-bottom: 1px solid var(--border-subtle); }
.zone-group { padding: 8px 12px; }
.zone-group-name {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 6px 0;
}
.zone-grid { display: flex; flex-wrap: wrap; gap: 5px; }
.zone-btn {
  appearance: none;
  font: inherit;
  font-size: 0.75rem;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur);
}
.zone-btn:hover { border-color: var(--accent); color: var(--accent-bright); }

/* ── Conditions ─────────────────────────────────────────────────────────── */
.match-card, .library-card, .redflag-card, .episode-card, .privacy-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-1);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
}
.match-card { border-left: 3px solid var(--accent); }
.match-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}
.match-name { font-weight: 700; font-size: 0.92rem; }
.match-score { font-weight: 800; font-size: 0.9rem; color: var(--accent-bright); white-space: nowrap; }
.score-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
  margin: 7px 0;
  overflow: hidden;
}
.score-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
}
.match-why { font-size: 0.78rem; color: var(--text-secondary); margin: 0 0 6px; }

.cond-detail { margin-top: var(--space-2); font-size: 0.82rem; }
.cond-detail p { margin: 6px 0; }
.cond-detail .k { color: var(--text-muted); font-weight: 700; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; }
.cond-redflags {
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: #fda4af;
}
.cond-actions { margin-top: var(--space-2); }
.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--accent-bright);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.tier-pill {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-muted);
}
.tier-pill.common { color: var(--accent-bright); background: var(--accent-soft); }

.redflag-card { border-color: rgba(244, 63, 94, 0.35); background: var(--danger-soft); }
.redflag-card h3 { margin: 0 0 6px; font-size: 0.9rem; color: #fda4af; }
.redflag-card ul { margin: 0; padding-left: 18px; font-size: 0.82rem; color: var(--text-secondary); }
.redflag-card li { margin: 3px 0; }

.rootcause-card {
  border: 1px solid rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.07);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
}
.rootcause-card h3 { margin: 0 0 6px; font-size: 0.9rem; color: var(--warning); }
.rootcause-card p { margin: 0; font-size: 0.82rem; color: var(--text-secondary); }

.scope-note strong { color: var(--accent-bright); }

.demo-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.demo-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 2px 9px;
}

.section-title { font-size: 0.95rem; font-weight: 700; margin: 0 0 var(--space-2); }

/* ── Episodes ───────────────────────────────────────────────────────────── */
.privacy-card { font-size: 0.8rem; color: var(--text-secondary); }
.episode-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-1);
  margin-bottom: 6px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: border-color var(--dur);
}
.episode-row:hover { border-color: var(--border-strong); }
.episode-row.active { border-color: var(--accent); background: var(--accent-soft); }
.episode-main { flex: 1; min-width: 0; }
.episode-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.episode-meta { font-size: 0.74rem; color: var(--text-muted); }
.episode-rename {
  width: 100%;
  font: inherit;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}
.episode-rename:focus { outline: none; border-color: var(--accent); }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(7, 11, 22, 0.95);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 999px;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.info-footer {
  flex-shrink: 0;
  padding: 8px var(--space-5);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  justify-content: space-between;
}
.footer-link { color: var(--text-secondary); }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  body { overflow: auto; height: auto; }
  .app-layout { display: block; }
  .stage {
    height: 44dvh;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border-subtle);
  }
  .panel { border-left: none; }
  .tabs { position: sticky; top: 44dvh; background: var(--bg); z-index: 9; }
  .tabpanel { overflow: visible; }
  .info-footer { flex-direction: column; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .loader { animation: none; }
  * { transition: none !important; }
}
