/* EchoTwin POC v2 — "porcelain room, black instruments"
   Spa-clinical light UI (Neko/Prenuvo register); imaging lives in near-black
   device bezels. paper #F7F5F1 · ink #17211E · clinical green #0F6B5C ·
   data teal #0F8A76 (validated, light mode) · amber #B77918 */

:root {
  --paper: #F7F5F1;
  --card: #FFFFFF;
  --border: #E5E1D8;
  --mist: #EDEAE3;
  --ink: #17211E;
  --sub: #5A6963;
  --faint: #97A19A;
  --green: #0F6B5C;
  --green-soft: #DCEAE5;
  --data: #0F8A76;
  --amber: #B77918;
  --bezel-bg: #0C1210;
  --dop-lo: #2C6ED5;
  --dop-hi: #C33B2E;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Instrument Sans", -apple-system, "Segoe UI", sans-serif;
  --shadow: 0 30px 60px -30px rgba(23, 33, 30, 0.35);
}

* { box-sizing: border-box; margin: 0; }
html { height: 100%; }
body {
  height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--green); outline-offset: 2px;
}

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 24px;
  padding: 14px 40px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--green); }
.brand-mark { width: 26px; height: 26px; }
.brand-name { font-family: var(--serif); font-size: 20px; color: var(--ink); }
.stepper { display: flex; gap: 4px; margin-inline: auto; }
.step-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  color: var(--sub); font-size: 13.5px;
}
.step-btn i {
  width: 8px; height: 8px; border-radius: 50%;
  background: none; border: 1.5px solid var(--faint);
}
.step-btn:hover { color: var(--ink); background: var(--mist); }
.step-btn.active { color: var(--ink); background: var(--card); box-shadow: 0 1px 4px rgba(23,33,30,.08); }
.step-btn.active i { background: var(--green); border-color: var(--green); }
.step-btn.aside { margin-left: 20px; position: relative; }
.step-btn.aside::before {
  content: ""; position: absolute; left: -11px; top: 8px; bottom: 8px;
  width: 1px; background: var(--border);
}
.top-tag { font-size: 12px; color: var(--faint); }

/* ---------- shared ---------- */
main { flex: 1; min-height: 0; width: 100%; max-width: 1280px; margin: 0 auto; overflow-y: auto; }
.screen { display: none; padding: 22px 40px 22px; }
.screen.active { display: block; }
/* fit screens fill the viewport exactly; inner stage flexes to the remainder */
.screen.fit.active { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.screen-head { margin-bottom: 16px; }
.screen-head h2 { font-family: var(--serif); font-weight: 400; font-size: 27px; margin-bottom: 6px; }
.head-note { color: var(--sub); max-width: 64ch; }
.readouts { display: flex; gap: 28px; flex-wrap: wrap; color: var(--faint); font-size: 13px; }
.readouts b { color: var(--ink); font-weight: 600; margin-left: 6px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.card-title { font-size: 13px; color: var(--sub); margin-bottom: 14px; }

.bezel {
  background: var(--bezel-bg);
  border-radius: 18px;
  padding: 10px;
  box-shadow: var(--shadow);
}
.bezel > canvas { display: block; border-radius: 10px; }

/* ---------- journey ---------- */
.hero {
  display: grid; grid-template-columns: 1.1fr 0.9fr; align-items: center;
  flex: 1; min-height: 0; gap: 24px;
}
.hero-copy h1 {
  font-family: var(--serif); font-weight: 300;
  font-size: clamp(40px, 4.6vw, 62px); line-height: 1.06;
  letter-spacing: -0.01em;
}
.hero-copy em { font-style: italic; color: var(--green); }
.lede { color: var(--sub); max-width: 50ch; margin: 24px 0 32px; font-size: 17px; }
.hero-actions { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.cta {
  background: var(--green); color: #FDFCFA;
  font-weight: 600; padding: 14px 28px; border-radius: 999px;
  box-shadow: 0 10px 24px -12px rgba(15, 107, 92, 0.7);
  transition: transform .15s, box-shadow .15s;
}
.cta:hover { transform: translateY(-1px); box-shadow: 0 14px 28px -12px rgba(15, 107, 92, 0.8); }
.cta.small { padding: 11px 20px; font-size: 13.5px; }
.cta.ghost { background: transparent; color: var(--green); border: 1.5px solid var(--green); box-shadow: none; }
.cta.ghost:hover { background: var(--green-soft); transform: none; }
.hero-note { color: var(--faint); font-size: 12.5px; max-width: 26ch; }
.hero-art { position: relative; overflow: hidden; align-self: stretch; }
.hero-art svg { width: 100%; height: 100%; }
.wave { transform-origin: 400px 260px; animation: ripple 4.5s ease-out 2; }
.w2 { animation-delay: .35s; } .w3 { animation-delay: .7s; }
.w4 { animation-delay: 1.05s; } .w5 { animation-delay: 1.4s; }
@keyframes ripple {
  0% { transform: scale(0.92); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.flow {
  list-style: none; padding: 28px 0 0; counter-reset: step;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 36px;
  border-top: 1px solid var(--border);
}
.flow li { counter-increment: step; }
.flow h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.flow h3::before {
  content: counter(step);
  display: inline-grid; place-items: center; flex: none;
  width: 24px; height: 24px;
  background: var(--green-soft); border-radius: 50%;
  font-size: 12px; color: var(--green); font-weight: 600;
}
.flow p { color: var(--sub); font-size: 13.5px; }

/* ---------- scan ---------- */
.scan-grid { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: stretch; flex: 1; min-height: 0; }
.body-panel { display: flex; flex-direction: column; min-height: 0; }
#body-svg { flex: 1; width: 100%; min-height: 0; }
.sweep-caption { text-align: center; color: var(--sub); font-size: 13px; margin-top: 8px; min-height: 20px; }
.us-stage { display: flex; flex-direction: column; min-height: 0; }
.us-frame { position: relative; display: flex; justify-content: center; flex: 1; min-height: 0; }
#us-canvas { height: 100%; width: auto; max-width: 100%; object-fit: contain; }
.live-tag {
  position: absolute; top: 22px; left: 22px; z-index: 2;
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: #EDEAE3; background: rgba(12,18,16,.72);
  padding: 4px 10px; border-radius: 999px;
}
.live-tag .dot { width: 7px; height: 7px; border-radius: 50%; background: #E5484D; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.us-scale {
  position: absolute; top: 20px; right: 22px; bottom: 20px;
  display: flex; flex-direction: column; justify-content: space-between;
  color: #66736D; font-size: 10px; text-align: right;
}
.scan-progress { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.scan-progress-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--mist); overflow: hidden; }
.scan-progress-bar.wide { width: 100%; margin-top: 18px; }
#sweep-fill, #recon-fill { height: 100%; width: 0%; background: var(--data); border-radius: 3px; transition: width .2s linear; }
#sweep-pct { font-size: 13px; color: var(--sub); width: 40px; text-align: right; }

.recon-overlay[hidden] { display: none; }
.recon-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(247, 245, 241, 0.85); backdrop-filter: blur(8px);
  display: grid; place-items: center;
}
.recon-card {
  width: 430px; background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 26px; text-align: center;
  box-shadow: var(--shadow);
}
.recon-card h3 { font-family: var(--serif); font-weight: 400; font-size: 23px; margin-top: 20px; }
.recon-card p { color: var(--sub); font-size: 13.5px; margin-top: 6px; }
#recon-canvas { width: 100%; }

/* ---------- twin ---------- */
.twin-layout { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: stretch; flex: 1; min-height: 0; }
.twin-side { display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow-y: auto; }
.twin-stage { position: relative; overflow: hidden; min-height: 0; }
.twin-stage canvas { display: block; border-radius: 10px; }
.twin-hint {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: #7C8A83; font-size: 12.5px; pointer-events: none; z-index: 2;
  text-align: center; white-space: nowrap;
}
.hint-attr { display: block; font-size: 10px; color: #55635C; margin-top: 3px; }
.layer-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 14px; cursor: pointer; }
.layer-row input { accent-color: var(--green); width: 15px; height: 15px; }
.ramp { height: 8px; border-radius: 4px; margin-top: 10px;
  background: linear-gradient(90deg, var(--dop-lo), #9a9cb0 50%, var(--dop-hi)); }
.ramp-labels { display: flex; justify-content: space-between; color: var(--faint); font-size: 11.5px; margin-top: 5px; }
.attribution { margin-top: 12px; color: var(--faint); font-size: 11.5px; }

/* anatomy labels with leader lines (inside the twin bezel) */
.anat-overlay { position: absolute; inset: 10px; pointer-events: none; z-index: 2; overflow: hidden; }
.anat-overlay svg { position: absolute; inset: 0; }
.anat-label {
  position: absolute; transform: translateY(-50%);
  font-size: 11.5px; color: #E4EAE6; white-space: nowrap;
  background: rgba(12, 18, 16, 0.62); border: 1px solid rgba(228, 234, 230, 0.18);
  padding: 2px 9px; border-radius: 999px;
}
.anat-label.left { left: 12px; }
.anat-label.right { right: 12px; }

/* AI assistant — floating button + slide-in side panel */
.ai-fab {
  position: absolute; right: 24px; bottom: 24px;
  z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 5px;
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--green); color: #FDFCFA;
  box-shadow: 0 10px 26px -8px rgba(15, 107, 92, 0.75), 0 0 0 5px rgba(29, 194, 117, 0.16);
  justify-content: center;
  transition: transform .18s, box-shadow .18s;
}
.ai-fab svg { width: 22px; height: 22px; }
.ai-fab span { font-size: 9.5px; font-weight: 600; letter-spacing: .02em; margin-top: -3px; }
.ai-fab:hover {
  transform: scale(1.07);
  box-shadow: 0 14px 30px -8px rgba(15, 107, 92, 0.85), 0 0 0 8px rgba(29, 194, 117, 0.14);
}

.ai-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
  width: 380px; max-width: 92vw;
  display: flex; flex-direction: column;
  background: var(--card); border-left: 1px solid var(--border);
  box-shadow: -24px 0 60px -30px rgba(23, 33, 30, 0.45);
  transform: translateX(105%);
  transition: transform .28s cubic-bezier(.32, .72, .28, 1);
}
.ai-drawer.open { transform: translateX(0); }
.ai-head {
  display: flex; align-items: center; gap: 11px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.ai-head .adot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); flex: none; }
.ai-head .adot.off { background: var(--amber); }
.ai-head-titles { display: flex; flex-direction: column; line-height: 1.25; }
.ai-head-titles b { font-size: 14.5px; }
.assistant-model { font-size: 11px; color: var(--faint); }
.ai-close {
  margin-left: auto; width: 32px; height: 32px; border-radius: 50%;
  font-size: 21px; line-height: 1; color: var(--sub);
  display: grid; place-items: center;
}
.ai-close:hover { background: var(--mist); color: var(--ink); }
.assistant-msgs {
  flex: 1; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; scroll-behavior: smooth; background: var(--paper);
}
.msg { font-size: 13px; line-height: 1.55; padding: 9px 13px; border-radius: 14px; max-width: 88%; }
.msg p { margin: 0; }
.msg p + p, .msg ul + p, .msg p + ul { margin-top: 7px; }
.msg ul { margin: 0; padding-left: 17px; }
.msg li { margin: 3px 0; }
.msg b { font-weight: 600; }
.msg.bot { background: var(--mist); color: var(--ink); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.user { background: var(--green); color: #FDFCFA; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.err { background: #F7E7E4; color: #8C2F22; align-self: flex-start; }
.msg.typing::after { content: "…"; animation: pulse 1s infinite; }
.assistant-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 12px 18px 4px; }
.chip-btn {
  font-size: 11.5px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--green); color: var(--green); background: var(--card);
}
.chip-btn:hover { background: var(--green-soft); }
.assistant-input { display: flex; gap: 9px; padding: 12px 18px 16px; }
.assistant-input input {
  flex: 1; border: 1px solid var(--border); border-radius: 999px;
  padding: 11px 16px; font: inherit; font-size: 13px; background: var(--card); color: var(--ink);
}
.assistant-input input:focus { outline: 2px solid var(--green); outline-offset: 0; border-color: transparent; }
.assistant-input button {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  background: var(--green); color: #FDFCFA;
  display: grid; place-items: center;
}
.assistant-input button svg { width: 17px; height: 17px; }
.assistant-input button:hover { background: #12836F; }
.assistant-input button:disabled { opacity: 0.5; cursor: default; }
.assistant-note { padding: 0 18px 14px; font-size: 11.5px; color: var(--amber); }

.report-next {
  display: flex; align-items: center; gap: 18px;
  margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border);
  color: var(--faint); font-size: 13px;
}
.metrics div { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.metrics dt { color: var(--sub); font-size: 13px; }
.metrics dd { font-weight: 600; }
.chip {
  display: inline-block; margin-top: 14px; padding: 4px 12px;
  border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--green-soft); color: var(--green);
}
.chip.warn { background: #F5E8D0; color: var(--amber); }
.chip.warn::before { content: "▲ "; }

/* ---------- volume lab ---------- */
.vol-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.seg { display: flex; background: var(--mist); border-radius: 999px; padding: 3px; }
.seg-btn { padding: 7px 16px; color: var(--sub); font-size: 13.5px; border-radius: 999px; }
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(23,33,30,.1); }
.file-btn {
  border: 1.5px solid var(--green); color: var(--green); font-weight: 600;
  padding: 7px 16px; border-radius: 999px; font-size: 13.5px; cursor: pointer;
}
.file-btn:hover { background: var(--green-soft); }
.drop-hint { color: var(--faint); font-size: 12.5px; }
.vol-stage { flex: 1; min-height: 0; position: relative; }
.zoom-ctl {
  position: absolute; right: 22px; bottom: 22px; z-index: 2;
  display: flex; flex-direction: column; gap: 7px;
}
.zoom-ctl button {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(241, 247, 243, 0.10); color: #E4EAE6;
  border: 1px solid rgba(228, 234, 230, 0.22);
  font-size: 19px; line-height: 1; display: grid; place-items: center;
  backdrop-filter: blur(4px);
}
.zoom-ctl button:hover { background: rgba(241, 247, 243, 0.22); }
#nv-canvas { width: 100%; height: 100%; }

/* ---------- report ---------- */
.report-grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
.trend-panel, .plan-panel { grid-column: 1 / -1; }
.score-panel { text-align: center; }
#score-dial { width: 100%; max-width: 230px; margin: 4px auto 0; display: block; }
.score-delta { color: var(--sub); font-size: 12.5px; margin-top: 6px; }

.bar-row { display: grid; grid-template-columns: 150px 1fr 46px; align-items: center; gap: 12px; padding: 4px 0; font-size: 13.5px; }
.bar-row .bar-label { color: var(--sub); }
.bar-track { height: 14px; background: var(--mist); border-radius: 4px; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--data); }
.bar-fill.warn { background: var(--amber); }
.bar-val { font-weight: 600; text-align: right; }
.bar-state { color: var(--amber); font-size: 12px; }

#trend-chart { position: relative; }
#trend-chart svg { display: block; width: 100%; height: auto; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--ink); color: #F7F5F1; border-radius: 8px;
  padding: 8px 12px; font-size: 12.5px; white-space: nowrap;
  transform: translate(-50%, -120%);
  display: none;
}
.tooltip b { display: block; font-size: 14px; }

.table-view { margin-top: 14px; }
.table-view summary { color: var(--faint); font-size: 12.5px; cursor: pointer; }
.table-view table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 13px; }
.table-view th, .table-view td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.table-view th { color: var(--sub); font-weight: 500; }

.plan { list-style: none; padding: 0; font-size: 13px; }
.plan li { padding: 8px 0; border-bottom: 1px solid var(--border); color: var(--sub); }
.plan li:last-child { border: none; }
.plan b { color: var(--ink); font-weight: 600; }

/* ---------- responsive & motion ---------- */
@media (max-width: 960px) {
  .top { padding: 10px 16px; flex-wrap: wrap; }
  .stepper { order: 3; width: 100%; overflow-x: auto; }
  .top-tag { display: none; }
  .screen { padding: 28px 20px 48px; }
  .hero { grid-template-columns: 1fr; min-height: 0; }
  .hero-art { display: none; }
  .flow { grid-template-columns: 1fr 1fr; gap: 24px; }
  .scan-grid, .report-grid, .twin-layout { grid-template-columns: 1fr; }
  .twin-stage { height: 60vh; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
