/* ============ PerioSight design prototype ============ */
:root {
  --bg: #070b14;
  --bg2: #0b1220;
  --panel: #0e1626;
  --panel2: #121c30;
  --line: #1d2a44;
  --line2: #27395e;
  --txt: #e6edf7;
  --mut: #8ea3c2;
  --dim: #5c7195;
  --accent: #2dd4bf;
  --accent2: #38bdf8;
  --warn: #fbbf24;
  --bad: #f87171;
  --implant: #38bdf8;
  --graft: #a78bfa;
  --perio: #fbbf24;
  --nonsurg: #34d399;
  --extract: #f87171;
  --maintain: #94a3b8;
  --cosmetic: #22d3ee;
  --laser: #e879f9;
  --fullarch: #fb923c;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(45, 212, 191, .07), transparent 60%),
    radial-gradient(900px 420px at 10% 110%, rgba(56, 189, 248, .06), transparent 60%),
    var(--bg);
  color: var(--txt);
  font-size: 14.5px;
  line-height: 1.5;
}
::selection { background: rgba(45,212,191,.3); }
h1,h2,h3,h4 { font-weight: 650; letter-spacing: .01em; }
button { font: inherit; cursor: pointer; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 14px 22px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18,28,48,.9), rgba(11,18,32,.75));
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  font-size: 20px; color: #04211c;
  background: linear-gradient(135deg, #2dd4bf, #38bdf8);
  box-shadow: 0 0 22px rgba(45,212,191,.45);
}
.brand h1 { font-size: 19px; }
.brand p { font-size: 11.5px; color: var(--mut); }
.proto-tag { color: var(--accent); font-weight: 600; }
.case-switch { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.case-switch label { font-size: 12px; color: var(--mut); }
select {
  background: var(--panel2); color: var(--txt); border: 1px solid var(--line2);
  border-radius: 9px; padding: 7px 10px; font-size: 13px; outline: none;
}
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  background: transparent; color: var(--mut); border: 1px solid transparent;
  padding: 7px 13px; border-radius: 999px; font-size: 13px; transition: all .15s;
}
.tab:hover { color: var(--txt); background: rgba(255,255,255,.04); }
.tab.active {
  color: #06251f; background: linear-gradient(135deg, #2dd4bf, #5eead4);
  font-weight: 650; box-shadow: 0 2px 14px rgba(45,212,191,.35);
}

/* ---------- layout ---------- */
main { padding: 22px; max-width: 1460px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.cols-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-3-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.cols-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 980px) { .cols-2, .cols-3, .cols-3-2, .cols-2-1 { grid-template-columns: 1fr; } }

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card h3 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card h3 .sub { font-size: 12px; color: var(--dim); font-weight: 400; }
.muted { color: var(--mut); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }

/* ---------- badges & pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line2); color: var(--mut); background: rgba(255,255,255,.03);
}
.badge.ok { color: #34d399; border-color: rgba(52,211,153,.35); background: rgba(52,211,153,.08); }
.badge.warn { color: #fbbf24; border-color: rgba(251,191,36,.35); background: rgba(251,191,36,.08); }
.badge.bad { color: #f87171; border-color: rgba(248,113,113,.35); background: rgba(248,113,113,.08); }
.badge.info { color: #38bdf8; border-color: rgba(56,189,248,.35); background: rgba(56,189,248,.08); }
.badge.real { color: #2dd4bf; border-color: rgba(45,212,191,.4); background: rgba(45,212,191,.08); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

.btn {
  border: 1px solid var(--line2); background: var(--panel2); color: var(--txt);
  padding: 9px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  transition: all .15s; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(135deg, #2dd4bf, #38bdf8); color: #04211c; border: none;
  box-shadow: 0 4px 18px rgba(45,212,191,.35);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost.primary { opacity: 1; }
.viewer-toolbar .btn.ghost { color: var(--mut); }
.viewer-toolbar .btn.ghost.primary { color: #04211c; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- patient banner ---------- */
.patient-banner {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
  background: linear-gradient(120deg, rgba(56,189,248,.08), rgba(45,212,191,.05));
  border: 1px solid var(--line2); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 18px;
}
.patient-banner .avatar {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 16px; color: #04211c;
  background: linear-gradient(135deg, #38bdf8, #2dd4bf);
}
.patient-banner .who h2 { font-size: 17px; }
.patient-banner .who p { font-size: 12px; color: var(--mut); }
.patient-banner .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* ---------- intake ---------- */
.doc-groups { display: grid; gap: 14px; }
.doc-row {
  display: flex; align-items: center; gap: 14px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.015);
  transition: border-color .15s;
}
.doc-row:hover { border-color: var(--line2); }
.doc-icon {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 16px; background: rgba(56,189,248,.1); border: 1px solid rgba(56,189,248,.25);
  flex-shrink: 0;
}
.doc-icon.doc { background: rgba(45,212,191,.08); border-color: rgba(45,212,191,.25); }
.doc-icon.photo { background: rgba(232,121,249,.08); border-color: rgba(232,121,249,.25); }
.doc-info { flex: 1; min-width: 0; }
.doc-info .name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-info .meta { font-size: 11.5px; color: var(--dim); }
.dropzone {
  border: 1.5px dashed var(--line2); border-radius: var(--radius);
  padding: 34px; text-align: center; color: var(--mut);
  transition: all .2s; cursor: pointer; margin-bottom: 16px;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(45,212,191,.05); color: var(--txt); }
.source-note { font-size: 12px; color: var(--dim); margin-top: 10px; }
.source-note a { color: var(--accent2); text-decoration: none; }
.source-note a:hover { text-decoration: underline; }

/* ---------- pipeline ---------- */
.model-row {
  display: grid; grid-template-columns: 44px 1fr 220px 110px; gap: 14px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 11px; margin-bottom: 10px;
  background: rgba(255,255,255,.015);
}
.model-row .mid { font-weight: 700; color: var(--accent2); font-size: 15px; }
.model-row .mname { font-weight: 600; font-size: 13.5px; }
.model-row .mio { font-size: 11.5px; color: var(--dim); }
.model-row.running { border-color: rgba(45,212,191,.5); box-shadow: 0 0 0 1px rgba(45,212,191,.25), 0 0 24px rgba(45,212,191,.12) inset; }
.model-row.done { border-color: rgba(52,211,153,.3); }
.mbar { height: 7px; background: #0a1120; border-radius: 99px; overflow: hidden; }
.mbar > div { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, #2dd4bf, #38bdf8); transition: width .2s; }
.status-pill { font-size: 11px; font-weight: 700; text-align: center; padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,.05); color: var(--dim); }
.status-pill.running { color: #2dd4bf; background: rgba(45,212,191,.1); }
.status-pill.done { color: #34d399; background: rgba(52,211,153,.1); }
.console {
  background: #050910; border: 1px solid var(--line); border-radius: 11px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 12px;
  padding: 14px; height: 240px; overflow-y: auto; color: #9fb6d8;
}
.console .ln { margin-bottom: 3px; }
.console .ok { color: #34d399; }
.console .info { color: #38bdf8; }
.console .hot { color: #fbbf24; }

/* ---------- odontogram ---------- */
.odonto-wrap { overflow-x: auto; }
svg text { user-select: none; }
.tooth { cursor: pointer; }
.tooth:hover .crown { filter: brightness(1.35); }
.tooth.selected .crown { stroke: #fff; stroke-width: 2.2; }

/* ---------- recommendations ---------- */
.site-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; background: linear-gradient(180deg, var(--panel), var(--panel2)); transition: border-color .15s; }
.site-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(45,212,191,.4), 0 0 30px rgba(45,212,191,.08); }
.site-card .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.tooth-badge {
  font-weight: 800; font-size: 14px; color: #04211c; padding: 4px 11px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
}
.findings { list-style: none; margin: 8px 0 12px; }
.findings li { font-size: 12.5px; color: var(--mut); padding-left: 18px; position: relative; margin-bottom: 4px; }
.findings li::before { content: "▸"; position: absolute; left: 2px; color: var(--accent2); }
.dist-row { display: grid; grid-template-columns: 1fr 52px; gap: 12px; align-items: center; margin-bottom: 8px; }
.dist-name { font-size: 13px; }
.dist-name .reco { color: var(--accent); font-weight: 700; font-size: 10.5px; letter-spacing: .06em; margin-right: 6px; }
.dist-track { height: 9px; background: #0a1120; border-radius: 99px; overflow: hidden; }
.dist-fill { height: 100%; border-radius: 99px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.dist-pct { text-align: right; font-weight: 700; font-size: 13px; }
.evi-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.evi-chip {
  font-size: 11.5px; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line2); background: rgba(56,189,248,.06); color: var(--accent2);
  transition: all .15s; font-weight: 600;
}
.evi-chip:hover { border-color: var(--accent2); background: rgba(56,189,248,.14); }
.conf { font-size: 11px; color: var(--dim); }
.conf b { color: var(--accent); }

/* phases */
.phase { position: relative; padding: 0 0 22px 30px; border-left: 2px solid var(--line2); margin-left: 8px; }
.phase:last-child { border-left-color: transparent; padding-bottom: 4px; }
.phase::before {
  content: ""; position: absolute; left: -8px; top: 0; width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(135deg, #2dd4bf, #38bdf8); box-shadow: 0 0 12px rgba(45,212,191,.6);
}
.phase .ptime { font-size: 11px; color: var(--accent2); font-weight: 700; letter-spacing: .05em; }
.phase h4 { font-size: 13.5px; margin: 2px 0 6px; }
.phase ul { list-style: none; }
.phase ul li { font-size: 12.5px; color: var(--mut); margin-bottom: 3px; padding-left: 14px; position: relative; }
.phase ul li::before { content: "–"; position: absolute; left: 0; color: var(--dim); }
.phase .dep { font-size: 11px; color: var(--warn); margin-top: 6px; }

/* case distribution */
.casedist-row { display: grid; grid-template-columns: 120px 1fr 46px; gap: 10px; align-items: center; margin-bottom: 9px; font-size: 12.5px; }
.casedist-track { height: 12px; background: #0a1120; border-radius: 8px; overflow: hidden; }
.casedist-fill { height: 100%; border-radius: 8px; }
.stacked-bar { display: flex; height: 26px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line2); }
.stacked-bar > div { display: grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #04211c; }

/* ---------- imaging ---------- */
.viewer-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.canvas-frame {
  position: relative; background: #000; border: 1px solid var(--line2); border-radius: 12px; overflow: hidden;
}
.canvas-frame img, .canvas-frame canvas { display: block; width: 100%; }
.overlay-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ov-box { fill: none; stroke-width: 2.5; }
.ov-label { font-size: 11px; font-weight: 800; paint-order: stroke; stroke: #000; stroke-width: 3px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--mut); }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }
.dcm-strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; }
.dcm-thumb { width: 74px; flex-shrink: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer; }
.dcm-thumb.active { border-color: var(--accent); }
.dcm-thumb canvas { width: 100%; display: block; }
.wl { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--mut); }
.wl input[type=range] { width: 130px; accent-color: #2dd4bf; }

/* ---------- 3d ---------- */
.three-frame { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line2); background: radial-gradient(900px 500px at 50% 30%, #101b30, #05080f 80%); }
.three-frame canvas { display: block; width: 100%; height: 100%; }
.three-hud { position: absolute; left: 14px; bottom: 12px; right: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; pointer-events: none; }
.three-hud > * { pointer-events: auto; }
.three-tip {
  position: absolute; top: 14px; left: 14px; right: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
#threeContainer { height: 620px; }

/* ---------- education ---------- */
.edu-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: linear-gradient(180deg, var(--panel), var(--panel2)); }
.edu-card h4 { margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.edu-card p { font-size: 13px; color: var(--mut); }
.edu-num { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-weight: 800; color: #04211c; background: linear-gradient(135deg, #2dd4bf, #38bdf8); flex-shrink: 0; font-size: 13px; }
.path-row { display: flex; gap: 10px; align-items: stretch; margin-bottom: 10px; }
.path-box { flex: 1; border: 1px solid var(--line2); border-radius: 11px; padding: 12px; font-size: 12px; background: rgba(255,255,255,.02); }
.path-box .t { font-weight: 700; margin-bottom: 4px; color: var(--txt); }
.path-box .d { color: var(--mut); }
.arrow { align-self: center; color: var(--accent); font-size: 18px; }

/* ---------- design view ---------- */
pre.ascii {
  font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 11.5px; line-height: 1.45;
  background: #050910; border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  overflow-x: auto; color: #9fb6d8;
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th, table.tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tbl th { color: var(--dim); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; }
table.tbl tr:hover td { background: rgba(255,255,255,.02); }

/* ---------- modal & toast ---------- */
#modalRoot .modal-back {
  position: fixed; inset: 0; background: rgba(3,6,12,.7); backdrop-filter: blur(6px);
  display: grid; place-items: center; z-index: 90; animation: fade .18s ease;
}
.modal {
  width: min(720px, 92vw); max-height: 86vh; overflow-y: auto;
  background: linear-gradient(180deg, #101a2e, #0b1220);
  border: 1px solid var(--line2); border-radius: 16px; padding: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal h3 { margin-bottom: 4px; }
.modal .msub { font-size: 12px; color: var(--dim); margin-bottom: 14px; }
.evi-section { margin-top: 14px; }
.evi-section .lbl { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
blockquote.note {
  border-left: 3px solid var(--accent2); padding: 10px 14px; background: rgba(56,189,248,.06);
  border-radius: 0 10px 10px 0; font-size: 13px; color: var(--txt); font-style: italic;
}
.chart-row-tbl { width: 100%; font-size: 12.5px; border-collapse: collapse; }
.chart-row-tbl td { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.chart-row-tbl td:first-child { color: var(--dim); }
.photo-frame { background: #000; border-radius: 10px; overflow: hidden; border: 1px solid var(--line2); }
#toastRoot { position: fixed; bottom: 22px; right: 22px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #101a2e; border: 1px solid var(--accent); color: var(--txt);
  border-radius: 11px; padding: 11px 16px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: slidein .2s ease; max-width: 340px;
}
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.footer {
  display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  padding: 16px 24px 26px; color: var(--dim); font-size: 11.5px;
  border-top: 1px solid var(--line); margin-top: 30px;
}
.footer b { color: var(--mut); }

/* cap DICOM canvas display height */
#dcmCanvas { width: 100%; max-height: 470px; object-fit: contain; }

/* ============ mobile & small screens ============ */
@media (max-width: 980px) {
  .tabs {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    width: 100%; padding-bottom: 4px; scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: 0 0 auto; }
}
@media (max-width: 700px) {
  body { font-size: 13.5px; }
  main { padding: 14px 12px; }
  .topbar { padding: 10px 12px 8px; gap: 10px; }
  .brand-mark { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }
  .brand h1 { font-size: 16px; }
  .brand p { font-size: 10px; }
  .case-switch { margin-left: 0; width: 100%; }
  .case-switch select { flex: 1; min-width: 0; }
  .patient-banner { padding: 12px 14px; gap: 10px; }
  .patient-banner .meta { margin-left: 0; }
  .card { padding: 14px; border-radius: 12px; }
  .card h3 { font-size: 13.5px; flex-wrap: wrap; }
  /* pipeline rows: stack under the name */
  .model-row { grid-template-columns: 34px 1fr; row-gap: 7px; }
  .model-row .mbar { grid-column: 2; }
  .model-row .status-pill { grid-column: 2; justify-self: start; }
  /* odontogram: keep readable, scroll horizontally */
  .odonto-wrap { -webkit-overflow-scrolling: touch; }
  .odonto-wrap svg { min-width: 640px; }
  /* 3D: shorter scene, controls become a scrollable strip */
  #threeContainer { height: 470px; }
  .three-tip { left: 10px; right: 10px; top: 10px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .three-tip::-webkit-scrollbar { display: none; }
  .three-tip .btn { flex: 0 0 auto; padding: 8px 11px; font-size: 11.5px; }
  .three-hud .card { max-width: calc(100vw - 60px) !important; }
  .console { height: 190px; font-size: 11px; }
  .btn { padding: 11px 15px; }
  .btn-row .btn { flex: 1 1 auto; justify-content: center; }
  .phase { padding-left: 22px; }
  .viewer-toolbar .wl { width: 100%; }
  .casedist-row { grid-template-columns: 92px 1fr 42px; font-size: 11.5px; }
  .footer { padding: 14px 16px 20px; flex-direction: column; gap: 6px; }
  #dcmCanvas { max-height: 300px; }
}
