:root {
  color-scheme: dark;
  --bg: #12161f; --panel: #181d28; --panel2: #202634; --line: #2c3444; --text: #e6e9ef; --muted: #8b95a8;
  --text2: #c3cad7; --brand: #cfd6e4; --input: #0f131b; --hover: #262d3e; --hover-line: #3d4860;
  --drop-line: #3a4459; --drop-hover: #1a2233; --float: rgba(24, 29, 40, .88); --shadow: rgba(0, 0, 0, .4);
  --toast: #26324a; --toast-line: #3a4b6d; --err: #4a2630; --err-line: #7a3a47; --overlay: rgba(8, 10, 15, .6);
  --spinner-track: #334; --chart-active: #fff; --gum-chip: #f2b4bb;
  --accent: #4fa3ff; --accent2: #2f7fd8; --danger: #e5646e; --ok: #4fc78a; --warn: #f0b64f;
  /* 3D view and staging chart (read from JS) */
  --view-bg: #1b2130; --gantt-bg: #141925; --gantt-label: #9aa4b8; --gantt-idle: #262e40; --gantt-empty: #1a1f2b; --gantt-axis: #6f7a8f;
  --gantt-upper: #4fa3ff; --gantt-lower: #4fc78a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
/* Light theme follows the computer's appearance setting */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eef1f6; --panel: #ffffff; --panel2: #f1f4f9; --line: #d6dce6; --text: #1d2433; --muted: #69748a;
    --text2: #3a4458; --brand: #2a3345; --input: #ffffff; --hover: #e6ebf3; --hover-line: #b9c3d3;
    --drop-line: #b6c0d0; --drop-hover: #eaf2fd; --float: rgba(255, 255, 255, .92); --shadow: rgba(30, 40, 60, .18);
    --toast: #ffffff; --toast-line: #cdd6e4; --err: #fdecee; --err-line: #e7a3ab; --overlay: rgba(235, 239, 245, .7);
    --spinner-track: #d3dae6; --chart-active: #1d2433; --gum-chip: #b44b5a;
    --accent: #2479d6; --accent2: #2f7fd8; --danger: #c93c49; --ok: #1f9a5e; --warn: #b7791f;
    --view-bg: #e3e8f0; --gantt-bg: #f4f6fa; --gantt-label: #4c566b; --gantt-idle: #dde3ec; --gantt-empty: #eceff4; --gantt-axis: #7a8599;
    --gantt-upper: #2f7fd8; --gantt-lower: #1f9a5e;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* the hidden attribute always wins over component display rules */
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 13px; }
header { height: 48px; display: flex; align-items: center; gap: 16px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-size: 17px; letter-spacing: .3px; color: var(--brand); }
.brand b { color: var(--accent); }
.patient { display: flex; gap: 6px; flex: 1; }
.header-actions { display: flex; gap: 6px; }
#app { display: flex; height: calc(100% - 48px); }
#sidebar { width: 380px; min-width: 380px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
#steps { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); }
#steps button { background: none; border: none; border-radius: 0; color: var(--muted); padding: 8px 0 6px; font-weight: 600; font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 2px; border-bottom: 2px solid transparent; }
#steps button span { font-size: 10px; font-weight: 500; }
#steps button.active { color: var(--text); border-bottom-color: var(--accent); background: var(--panel2); }
#steps button.done { color: var(--ok); }
#arch-switch { margin: 10px 14px 0; }
#panels { overflow-y: auto; flex: 1; padding: 4px 14px 30px; }
#step-foot { display: flex; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--panel); }
#step-foot button { min-width: 120px; }
/* model builder: the trim controls sit under the Base heading */
#base-slot #trim-block > h3 { display: none; }
.panel { display: none; }
.panel.active { display: block; }
h2 { font-size: 15px; margin: 12px 0 6px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 18px 0 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; line-height: 1.45; }
button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: 12.5px; cursor: pointer; }
button:hover { border-color: var(--hover-line); background: var(--hover); }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
button.primary:hover { background: var(--accent); }
button.danger { color: var(--danger); }
button.ghost { background: none; }
button.small { padding: 3px 8px; font-size: 11.5px; }
button.on { background: var(--accent2); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .45; cursor: default; }
input, select { background: var(--input); color: var(--text); border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; font-size: 12.5px; }
input[type=number] { width: 70px; }
input.short { width: 120px; } input.tiny { width: 56px; }
input[type=range] { padding: 0; flex: 1; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; align-items: center; }
.field { display: flex; align-items: center; gap: 6px; margin: 7px 0; flex-wrap: wrap; }
.field > span:first-child { min-width: 120px; color: var(--text2); }
.field output { min-width: 60px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 6px; margin: 8px 0; cursor: pointer; }
.check.inline { display: inline-flex; margin: 0 6px 0 0; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin: 8px 0; }
.seg button { flex: 1; border: none; border-radius: 0; background: none; }
.seg button.on { background: var(--accent2); color: #fff; }
.drop { display: flex; flex-direction: column; gap: 4px; border: 1.5px dashed var(--drop-line); border-radius: 9px; padding: 14px; margin: 10px 0; cursor: pointer; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--drop-hover); }
.drop.loaded { border-style: solid; border-color: var(--ok); }
.file-info { color: var(--muted); font-size: 12px; }
.stats { margin-top: 10px; font-size: 12px; color: var(--text2); line-height: 1.55; }
.stats table, #stage-table table, #ipr-table table, #limits-table table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
td, th { padding: 3px 4px; border-bottom: 1px solid var(--line); text-align: right; }
th { color: var(--muted); font-weight: 500; }
td:first-child, th:first-child { text-align: left; }
#limits-table input { width: 100%; padding: 3px; }
#stage-table input { width: 42px; padding: 2px 4px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--danger); }
.rot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 8px 0; }
.step-pick { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text2); margin-left: auto; }
/* descriptions tucked into a pop-up on a small (i) beside the heading: only the (i) opens it */
h2:has(.tip), h3:has(.tip) { position: relative; }
.tip { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; margin-left: 7px; border: 1px solid var(--muted);
  border-radius: 50%; color: var(--muted); font-size: 10px; font-weight: 700; font-style: normal; text-transform: none; letter-spacing: 0; cursor: help; vertical-align: 1px; }
.tip::before { content: 'i'; font-family: Georgia, 'Times New Roman', serif; line-height: 1; }
.tip:hover, .tip:focus { color: var(--accent); border-color: var(--accent); outline: none; }
.tip .tipbox { display: none; position: absolute; left: 0; top: calc(100% + 4px); z-index: 30; width: min(270px, 90vw); padding: 8px 10px; border-radius: 8px;
  background: var(--toast); border: 1px solid var(--toast-line); box-shadow: 0 8px 22px var(--shadow); color: var(--text); font-size: 12px; font-weight: 400;
  font-family: inherit; line-height: 1.45; text-transform: none; letter-spacing: 0; cursor: default; }
.tip:hover .tipbox, .tip:focus .tipbox { display: block; }
/* 2 x 2 views */
.quad-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.quad-overlay .quad-label { position: absolute; font-size: 11.5px; padding: 2px 8px; border-radius: 5px; background: var(--float); color: var(--text2); }
.quad-overlay .q0 { left: 8px; bottom: calc(50% + 8px); } .quad-overlay .q1 { left: calc(50% + 8px); bottom: calc(50% + 8px); }
.quad-overlay .q2 { left: 8px; bottom: 8px; } .quad-overlay .q3 { left: calc(50% + 8px); bottom: 8px; }
.quad-overlay .quad-v { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line); }
.quad-overlay .quad-h { position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--line); }
.tooth-chart { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; margin: 10px 0; }
.tooth-chart button { padding: 5px 0; font-size: 10.5px; border-radius: 4px; position: relative; }
.tooth-chart button.midline { margin-left: 4px; }
.tooth-chart button .sw { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 3px; border-radius: 2px; }
.tooth-chart button.active { outline: 2px solid var(--chart-active); outline-offset: -1px; }
.tooth-chart button.absent { opacity: .35; }
.tooth-chart button.moved { color: var(--warn); font-weight: 700; }
.chip.gum { border-color: #e79aa3; color: var(--gum-chip); }
.chip.gum.active { background: #b86470; color: #fff; }
#move-editor .mv { display: grid; grid-template-columns: 1fr 28px 70px 28px 20px; gap: 4px; align-items: center; margin: 4px 0; }
#move-editor .mv input { width: 100%; text-align: right; }
#move-editor .mv label { font-size: 12px; color: var(--text2); }
#move-editor .mv small { grid-column: 1 / -1; color: var(--muted); margin-top: -2px; font-size: 10.5px; }
#move-editor .title { font-size: 14px; font-weight: 600; margin: 8px 0; }
.summary { background: var(--panel2); border-radius: 8px; padding: 10px; margin: 10px 0; line-height: 1.6; }
.summary b { font-size: 15px; }
#gantt { width: 100%; margin-top: 10px; border-radius: 6px; }
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--text2); margin-bottom: 6px; }
#viewport { flex: 1; position: relative; overflow: hidden; }
#viewport canvas { display: block; }
#view-toolbar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; pointer-events: none; }
#view-toolbar > * { pointer-events: auto; }
#view-toolbar button { background: var(--float); padding: 5px 9px; }
#view-toolbar .sep { width: 10px; }
#view-toolbar label { background: var(--float); padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); }
#stagebar { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); width: min(640px, 90%); display: flex; gap: 10px; align-items: center; background: var(--float); border: 1px solid var(--line); padding: 8px 12px; border-radius: 10px; }
#stage-label { min-width: 130px; font-variant-numeric: tabular-nums; }
#hint { position: absolute; top: 50px; left: 10px; max-width: 420px; color: var(--text2); background: var(--float); padding: 6px 10px; border-radius: 6px; font-size: 12px; }
#hint:empty { display: none; }
#busy { position: fixed; inset: 0; background: var(--overlay); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 50; }
#busy[hidden] { display: none; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--spinner-track); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; bottom: 18px; right: 18px; max-width: 420px; display: flex; flex-direction: column; gap: 6px; z-index: 60; }
#toast div { background: var(--toast); border: 1px solid var(--toast-line); padding: 9px 12px; border-radius: 8px; box-shadow: 0 6px 20px var(--shadow); }
#toast div.err { background: var(--err); border-color: var(--err-line); }

a.brand { text-decoration: none; }
.module-name { color: var(--muted); font-size: 13px; padding-left: 10px; border-left: 1px solid var(--line); }
body.mode-models .mtm-only { display: none !important; }
body:not(.mode-models) .models-only { display: none !important; }
body.mode-models #steps { grid-template-columns: repeat(4, 1fr); }

/* patient name in the header: links back to their chart */
a.pt-name { font-weight: 600; font-size: 14px; white-space: nowrap; color: inherit; text-decoration: none; border-radius: 6px; padding: 3px 6px; margin: 0 -6px; }
a.pt-name:hover { background: var(--panel2); color: var(--accent); }
.brand .brand-sub { margin-left: 6px; font-size: 11px; font-weight: 500; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
