/* ===================================================================
   TeethAtlas — styles
   Design tokens first, layout second, components third, themes last.
   =================================================================== */

:root {
  --bg:             #f7f8fb;
  --surface:        #ffffff;
  --surface-2:      #f0f2f7;
  --surface-3:      #e8ebf3;
  --border:         #e1e4ed;
  --border-strong:  #c5cad8;
  --text-1:         #0c1220;
  --text-2:         #4a5368;
  --text-3:         #8a91a4;
  --accent:         #1a6fc4;
  --accent-dim:     #e6f0fb;
  --accent-hover:   #155ea8;
  --teal:           #00b89c;
  --teal-dim:       #ddf6f2;
  --red:            #e03535;

  --r-xs: 3px;  --r-sm: 5px;  --r: 9px;  --r-lg: 14px;  --r-xl: 20px;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 4px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 16px rgba(0,0,0,.09), 0 1px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.13), 0 2px 8px rgba(0,0,0,.06);

  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'DM Mono', 'Fira Code', ui-monospace, monospace;

  --header-h:  52px;
  --toolbar-h: 48px;
  --infobar-h: 50px;
  --footer-h:  40px;
  --panel-w:   290px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font-body);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

button, select, input { font-family: inherit; }
button { -webkit-tap-highlight-color: transparent; }

/* ---------------------------------------------------------------- header */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.1rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
  position: relative;
  z-index: 50;
}
.logo { display: flex; align-items: baseline; gap: .5rem; text-decoration: none; color: inherit; }
.logo-word { font-family: var(--font-display); font-size: 1.2rem; color: var(--accent); letter-spacing: -.02em; }
.logo-tag  { font-size: .68rem; font-weight: 600; color: var(--text-3); letter-spacing: .1em; text-transform: uppercase; }
.header-right { display: flex; align-items: center; gap: .6rem; }
#hdr-sub { font-size: .72rem; color: var(--text-3); }
.chip {
  font-size: .68rem; font-weight: 600; padding: .2rem .55rem; border-radius: var(--r-xl);
  background: var(--accent-dim); color: var(--accent); letter-spacing: .04em; text-transform: uppercase;
}

/* ------------------------------------------------------------ app layout */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  min-height: 0;              /* critical: lets the viewer shrink instead of overflowing */
  overflow: hidden;
}
.viewer-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

/* ------------------------------------------------------------- info bar */
.info-bar {
  height: var(--infobar-h);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.fdi-badge {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: var(--r-sm);
  padding: .12rem .55rem;
  min-width: 2.6rem;
  text-align: center;
  flex-shrink: 0;
}
.info-text { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.info-text h2 {
  font-family: var(--font-display); font-size: .98rem; font-weight: 400; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.info-text .latin {
  font-size: .7rem; color: var(--text-3); font-style: italic;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.info-sep { width: 1px; height: 28px; background: var(--border); flex-shrink: 0; margin: 0 .1rem; }
#top-wiki-btn { height: 28px; padding: 0 12px; font-size: .72rem; margin-right: 8px; }
#top-wiki-btn[hidden] { display: none; }

.lang-select-wrap { margin-left: auto; flex-shrink: 0; }
.lang-select {
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 500;
  padding: .3rem 1.6rem .3rem .55rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a91a4' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right .45rem center;
  color: var(--text-2);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .12s, background-color .12s;
}
.lang-select:hover { border-color: var(--border-strong); background-color: var(--surface-3); }
.lang-select:focus-visible { border-color: var(--accent); }

/* -------------------------------------------------------------- viewport */
#viewport {
  flex: 1;
  position: relative;
  min-height: 0;
  background: linear-gradient(155deg, #eef2f9 0%, #e4e9f4 100%);
  overflow: hidden;
  cursor: grab;
  touch-action: none;          /* keep mobile drag inside the viewer */
}
#viewport:active { cursor: grabbing; }
#three-canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
  outline: none;
  touch-action: none !important;
}
.view-hint {
  position: absolute; bottom: .85rem; right: .85rem;
  font-size: .65rem; color: var(--text-3);
  background: rgba(255,255,255,.82); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: .28rem .7rem; pointer-events: none; z-index: 4;
}
.compass {
  position: absolute; bottom: .85rem; left: .85rem;
  width: 52px; height: 52px;
  background: rgba(255,255,255,.84); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: 50%;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; z-index: 4;
}
.compass svg { width: 30px; height: 30px; }

#btn-full-mouth-back { position: absolute; top: .6rem; left: .6rem; z-index: 10; display: none; }

/* ------------------------------------------------------------ annotations */
.pin-label {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  background: var(--accent); color: #fff;
  font-family: var(--font-mono); font-size: .68rem; font-weight: 600;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
  transition: transform .15s ease, background .15s ease;
}
.pin-label:hover { transform: scale(1.25); background: var(--red); }
body.dark .pin-label { border-color: var(--border-strong); }

#pin-tooltip {
  position: absolute; left: 0; top: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: .38rem .65rem;
  font-size: .73rem; font-weight: 500; color: var(--text-1);
  box-shadow: var(--shadow);
  pointer-events: none; z-index: 30;
  display: none; white-space: nowrap; line-height: 1.45;
}
#pin-tooltip .tt-id { font-family: var(--font-mono); font-size: .65rem; color: var(--accent); margin-right: .35rem; font-weight: 600; }
#pin-tooltip .tt-name { font-weight: 600; }

/* ---------------------------------------------------------------- loader */
#loader {
  position: absolute; inset: 0;
  background: rgba(238,242,249,.88); backdrop-filter: blur(5px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 40; transition: opacity .3s;
}
#loader.hidden { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .3s, visibility 0s .3s; }
.spin {
  width: 30px; height: 30px;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .65s linear infinite; margin-bottom: .7rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.load-text { font-size: .75rem; color: var(--text-3); font-weight: 500; letter-spacing: .03em; }

/* --------------------------------------------------------------- toolbar */
.toolbar {
  height: var(--toolbar-h);
  display: flex; align-items: center; gap: .4rem;
  padding: 0 .85rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 .1rem; flex-shrink: 0; }
.tb-spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--font-body); font-size: .76rem; font-weight: 500;
  padding: .38rem .8rem; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  cursor: pointer; white-space: nowrap; user-select: none; letter-spacing: .01em;
  transition: background-color .13s, border-color .13s, color .13s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-1); }
.btn.on { background: var(--teal-dim); border-color: var(--teal); color: var(--teal); }
.btn.on:hover { background: #c9f0ea; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn svg { flex-shrink: 0; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ side panel */
.side-panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); overflow: hidden; }
.arch-section { padding: .8rem .9rem .75rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.section-label {
  font-size: .62rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: .6rem;
}
.arch-tabs { display: flex; gap: .3rem; margin-bottom: .55rem; }
.arch-tab {
  flex: 1; padding: .35rem .4rem;
  font-size: .74rem; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--r-xs);
  cursor: pointer; color: var(--text-2); text-align: center;
  transition: background-color .13s, border-color .13s, color .13s;
  user-select: none;
}
.arch-tab:hover { background: var(--surface-2); }
.arch-tab.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
#btn-full-mouth { flex: none; width: 100%; }

.tooth-map { display: flex; flex-direction: column; gap: .3rem; }
.arch-lbl {
  font-size: .6rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3); text-align: center; padding: .05rem 0;
}
.arch-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.arch-div { height: 1px; background: var(--border-strong); margin: .15rem 0; border-radius: 1px; }

.t-cell {
  aspect-ratio: 1;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-xs);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; user-select: none;
  position: relative; z-index: 1;
  transition: background-color .11s, border-color .11s, transform .11s, box-shadow .11s;
}
.t-cell:hover { background: var(--accent-dim); border-color: var(--accent); transform: scale(1.08); z-index: 2; }
.t-cell.sel { background: var(--accent); border-color: var(--accent); transform: scale(1.08); z-index: 2; box-shadow: 0 0 0 2px rgba(26,111,196,.22); }
.t-cell.sel .t-num { color: #fff; }
.t-cell.sel .t-abbr { color: rgba(255,255,255,.7); }
.t-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.t-num { font-family: var(--font-mono); font-size: .68rem; font-weight: 500; color: var(--text-1); line-height: 1; }
.t-abbr { font-size: .52rem; color: var(--text-3); margin-top: 1px; }

.notes-panel {
  flex: 1; overflow-y: auto; padding: .85rem .9rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  overscroll-behavior: contain;
}
.notes-panel::-webkit-scrollbar { width: 4px; }
.notes-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.d-block { margin-bottom: 1rem; }
.d-label {
  font-size: .62rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: .32rem;
}
.d-val { font-size: .79rem; color: var(--text-2); line-height: 1.55; }
.d-val strong { color: var(--text-1); font-weight: 500; }
.d-val em { color: var(--text-3); display: block; margin-bottom: .15rem; }
.d-val.line { line-height: 1.6; }
.tag-row { display: flex; flex-wrap: wrap; gap: .28rem; }
.tag { font-size: .66rem; font-weight: 500; padding: .18rem .5rem; border-radius: var(--r-xl); background: var(--accent-dim); color: var(--accent); }
.pin-list { display: flex; flex-direction: column; gap: .18rem; }
.pin-list b { font-family: var(--font-mono); color: var(--accent); font-weight: 600; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-3); }
.empty-icon { font-size: 2.2rem; margin-bottom: .7rem; opacity: .35; }
.empty p { font-size: .79rem; line-height: 1.55; }

/* ---------------------------------------------------------------- footer */
footer {
  height: var(--footer-h);
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center; gap: 1.5rem;
  font-size: .7rem; color: var(--text-3);
  flex-shrink: 0;
}
footer a { color: inherit; text-decoration: none; }
footer a:hover { color: var(--accent); }

/* ----------------------------------------------------------------- modal */
.wiki-modal {
  display: none;
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0; transition: opacity .3s ease;
}
.wiki-modal.show { display: flex; opacity: 1; }
.wiki-modal-content {
  background-color: rgba(255,255,255,.92);
  border: 1px solid var(--border); border-radius: var(--r-xl);
  width: 100%; max-width: 650px; max-height: 85vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
  padding: 1.8rem;
  transform: translateY(20px); transition: transform .3s ease;
}
.wiki-modal.show .wiki-modal-content { transform: translateY(0); }
.wiki-modal-header {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  border-bottom: 1px solid var(--border); padding-bottom: 1rem; margin-bottom: 1.2rem;
}
.wiki-modal-header h2 { font-family: var(--font-display); font-size: 1.4rem; font-weight: 400; color: var(--accent); }
.wiki-close {
  background: none; border: none; font-size: 2rem; line-height: 1; cursor: pointer;
  color: var(--text-3); transition: color .2s;
}
.wiki-close:hover { color: var(--red); }
.wiki-section { margin-bottom: 1.5rem; }
.wiki-section:last-child { margin-bottom: 0; }
.wiki-modal-body { display: block; }
.wiki-section h3 {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700;
  color: var(--text-3); margin-bottom: .6rem;
  border-left: 3px solid var(--accent); padding-left: .5rem;
}
.wiki-text { font-size: .85rem; line-height: 1.6; color: var(--text-2); white-space: pre-wrap; }
.wiki-text strong { color: var(--text-1); }
.wiki-text a { color: var(--accent); }

/* ------------------------------------------------------- iOS install bar */
#ios-install-banner {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 9999;
  background: #1a6fc4; color: #fff;
  padding: .85rem 1rem; font-size: .78rem; font-family: system-ui, sans-serif;
  align-items: center; justify-content: space-between; gap: .5rem;
  box-shadow: 0 -2px 12px rgba(0,0,0,.3);
}
#ios-install-banner.show { display: flex; }
#ios-install-banner button {
  background: rgba(255,255,255,.2); border: none; color: #fff;
  padding: .3rem .7rem; border-radius: 6px; cursor: pointer;
  font-size: .78rem; flex-shrink: 0;
}

/* ---------------------------------------------------------------- dark mode */
body.dark {
  --bg:            #0e1117;
  --surface:       #161b22;
  --surface-2:     #1c2128;
  --surface-3:     #22272e;
  --border:        #30363d;
  --border-strong: #444c56;
  --text-1:        #e6edf3;
  --text-2:        #8b949e;
  --text-3:        #6e7681;
  --accent:        #58a6ff;
  --accent-dim:    #0d1f38;
  --accent-hover:  #79b8ff;
  --teal:          #3fb950;
  --teal-dim:      #0d2318;
  --red:           #f85149;
}
body.dark #viewport { background: linear-gradient(155deg, #0d1117 0%, #111820 100%); }
body.dark .view-hint,
body.dark .compass { background: rgba(22,27,34,.9); }
body.dark .compass svg { stroke: #8b949e; }
body.dark #loader { background: rgba(14,17,23,.92); }
body.dark #loader.hidden { opacity: 0; }
body.dark .wiki-modal-content { background-color: rgba(22,27,34,.92); }
body.dark .btn.on:hover { background: #123320; }
body.dark .t-cell.sel { box-shadow: 0 0 0 2px rgba(88,166,255,.28); }

/* Smooth theme swap, scoped deliberately.
   NOTE: this must NOT use `*` — a universal rule resets `transition-property`
   on every element and outranks #loader.hidden, which silently killed the
   loader's fade-out (the overlay stayed up and washed out the whole viewer).
   Surfaces only, and the loader is excluded entirely. */
:root, body, header, footer, .app, .viewer-col, .side-panel, .arch-section,
.info-bar, .toolbar, .notes-panel, .btn, .arch-tab, .t-cell, .chip, .tag,
.fdi-badge, .lang-select, .section-label, .d-val, .d-label, .wiki-modal-content,
.pin-tooltip, .empty, footer a {
  transition-property: background-color, border-color, color;
  transition-duration: 200ms;
  transition-timing-function: ease;
}

/* -------------------------------------------------------------- responsive */
@media (max-width: 850px) {
  :root { --panel-w: 100%; }
  body { height: auto; min-height: 100dvh; overflow-y: auto; overflow-x: hidden; }
  .app { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .viewer-col { border-right: none; border-bottom: 1px solid var(--border); }
  .side-panel { overflow: visible; }
  .notes-panel { overflow: visible; flex: none; padding-bottom: 2rem; }
  .header-right #hdr-sub { display: none; }
  #viewport { width: 100%; left: 0; }
  .view-hint { display: none; }
  .compass { width: 40px; height: 40px; bottom: .6rem; left: .6rem; }
  .compass svg { width: 22px; height: 22px; }

  /* smaller pins, but keep a 44px touch target */
  .pin-label { width: 15px; height: 15px; font-size: .45rem; border-width: 1.5px; position: relative; }
  .pin-label::after {
    content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 44px; height: 44px;
  }

  /* force all 8 columns to fit */
  .arch-section { padding: .6rem .5rem; }
  .arch-row { gap: 2px; }
  .t-cell { border-width: 1px; border-radius: 2px; min-width: 0; padding: 0; }
  .t-num { font-size: .6rem; }
  .t-abbr { display: none; }

  .info-bar { flex-wrap: wrap; height: auto; min-height: var(--infobar-h); padding: .45rem .6rem; gap: .35rem; }
  .lang-select-wrap { margin-left: 0; order: 3; }
  .info-sep { display: none; }
  .fdi-badge { font-size: .85rem; padding: .1rem .4rem; }
  #top-wiki-btn { font-size: .68rem; padding: 0 8px; }

  .toolbar { padding: 0 .5rem; }
  .btn { padding: .35rem .5rem; font-size: .7rem; }

  .wiki-modal-content { padding: 1.2rem; }
}

@media (max-width: 360px) {
  .t-num { font-size: .55rem; }
  .arch-row { gap: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ===================================================================
   Voice entry dock
   =================================================================== */
.voice-dock {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "mic mid right"
    "type type type";
  gap: .45rem .55rem;
  align-items: center;
  padding: .5rem .85rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.mic-btn {
  grid-area: mic;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s, transform .1s;
}
.mic-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }
.mic-btn:active { transform: scale(.94); }
.mic-btn.listening {
  background: var(--red); border-color: var(--red); color: #fff;
  animation: micPulse 1.4s ease-out infinite;
}
.mic-btn.unsupported { opacity: .45; cursor: not-allowed; }
@keyframes micPulse {
  0%   { box-shadow: 0 0 0 0 rgba(224,53,53,.45); }
  70%  { box-shadow: 0 0 0 12px rgba(224,53,53,0); }
  100% { box-shadow: 0 0 0 0 rgba(224,53,53,0); }
}

.voice-mid { grid-area: mid; min-width: 0; }
.voice-heard {
  font-size: .78rem;
  color: var(--text-2);
  line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.voice-heard.interim { color: var(--text-3); font-style: italic; }
.voice-heard.ok { color: var(--teal); font-weight: 500; }
.voice-heard.err { color: var(--red); }

.voice-actions {
  font-size: .68rem;
  color: var(--text-3);
  line-height: 1.3;
  margin-top: .1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.voice-right { grid-area: right; }
.voice-lang { padding: .22rem 1.35rem .22rem .4rem; font-size: .68rem; }

.voice-type {
  grid-area: type;
  display: flex; gap: .4rem;
}
.voice-type input {
  flex: 1; min-width: 0;
  font-family: var(--font-body);
  font-size: .78rem;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-1);
  outline: none;
}
.voice-type input:focus { border-color: var(--accent); }
.voice-type .btn { padding: .38rem .8rem; font-size: .76rem; }

/* ===================================================================
   Panel tabs (anatomy reference / examination entry)
   =================================================================== */
.panel-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.panel-tab {
  flex: 1;
  padding: .55rem .4rem;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-3);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .13s, border-color .13s, background-color .13s;
}
.panel-tab:hover { background: var(--surface-2); color: var(--text-1); }
.panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-body[hidden] { display: none; }

/* ===================================================================
   Examination entry panel
   =================================================================== */
.exam-panel {
  flex: 1;
  overflow-y: auto;
  padding: .8rem .9rem 2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.exam-panel::-webkit-scrollbar { width: 4px; }
.exam-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.exam-head {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .7rem;
}
.exam-head .fdi-badge { font-size: .95rem; }
.exam-head-name {
  font-family: var(--font-display);
  font-size: .92rem;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.exam-head-meta { font-size: .66rem; color: var(--text-3); margin-top: .1rem; }

.exam-group { margin-bottom: 1rem; }
.exam-group-label {
  font-size: .62rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: .35rem;
  display: flex; align-items: center; justify-content: space-between;
}

/* the six-site grid */
.site-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 2px;
  font-size: .7rem;
}
.site-grid th {
  font-size: .58rem; font-weight: 600; color: var(--text-3);
  padding: .1rem 0; text-align: center; white-space: nowrap;
}
.site-grid th.rowhead {
  text-align: left; padding-right: .3rem; letter-spacing: .02em;
}
.site-grid td { padding: 0; }
.site-cell {
  width: 100%;
  min-width: 26px;
  padding: .3rem .1rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: .72rem;
  cursor: pointer;
  transition: background-color .1s, border-color .1s;
}
.site-cell:hover { border-color: var(--accent); background: var(--accent-dim); }
.site-cell.filled { background: var(--accent-dim); color: var(--accent); font-weight: 600; border-color: var(--accent); }
.site-cell.danger { background: #fdeaea; color: var(--red); font-weight: 700; border-color: var(--red); }
body.dark .site-cell.danger { background: #3a1a1c; }
.site-cell.bop-on { background: #fdeaea; color: var(--red); font-weight: 700; border-color: var(--red); }
body.dark .site-cell.bop-on { background: #3a1a1c; }
.site-cell.off { color: var(--text-3); }

/* furcation row */
.furc-row { display: flex; gap: .35rem; flex-wrap: wrap; }
.furc-item {
  flex: 1; min-width: 54px;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
}
.furc-item .furc-name { font-size: .58rem; color: var(--text-3); }
.furc-item .site-cell { min-width: 0; }

/* mobility stepper */
.mob-row { display: flex; gap: .3rem; }
.mob-btn {
  flex: 1;
  padding: .35rem 0;
  font-family: var(--font-mono);
  font-size: .75rem;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color .1s, border-color .1s, color .1s;
}
.mob-btn:hover { border-color: var(--accent); }
.mob-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* condition chips */
.cond-grid { display: flex; flex-wrap: wrap; gap: .3rem; }
.cond-chip {
  font-size: .68rem; font-weight: 500;
  padding: .28rem .6rem;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color .11s, border-color .11s, color .11s;
}
.cond-chip:hover { border-color: var(--accent); color: var(--accent); }
.cond-chip.on { background: var(--teal-dim); border-color: var(--teal); color: var(--teal); font-weight: 600; }

/* note */
.note-input {
  width: 100%;
  min-height: 56px;
  resize: vertical;
  font-family: var(--font-body);
  font-size: .78rem;
  line-height: 1.45;
  padding: .45rem .55rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-1);
  outline: none;
}
.note-input:focus { border-color: var(--accent); }

/* per-tooth actions */
.exam-actions {
  display: flex; gap: .35rem; flex-wrap: wrap;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
}
.exam-actions .btn { font-size: .7rem; padding: .3rem .6rem; }

/* chart summary line under the arch map */
.chart-summary {
  margin-top: .55rem;
  padding-top: .5rem;
  border-top: 1px dashed var(--border);
  font-size: .66rem;
  color: var(--text-3);
  text-align: center;
}
.chart-summary span[id] { font-family: var(--font-mono); color: var(--accent); font-weight: 600; }
.cs-sep { margin: 0 .35rem; opacity: .5; }

/* cells that carry charting data get a marker in the tooth map */
.t-cell.has-data::after {
  content: '';
  position: absolute;
  top: 1px; right: 1px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--teal);
}

/* dark-mode tweaks for the new controls */
body.dark .voice-dock { background: var(--surface-2); }
body.dark .site-cell.danger,
body.dark .site-cell.bop-on { background: #3a1a1c; }
body.dark .btn.on { background: var(--teal-dim); }

/* responsive: stack the dock inputs on narrow screens */
@media (max-width: 850px) {
  .voice-dock { padding: .45rem .55rem; }
  .mic-btn { width: 34px; height: 34px; }
  .voice-heard { font-size: .72rem; }
  .panel-tabs { font-size: .72rem; }
  .exam-panel { overflow: visible; }
  .site-cell { min-width: 22px; font-size: .66rem; }
}

/* ===================================================================
   Sweep cursor, draft marks, phase tabs
   =================================================================== */
.voice-right {
  display: flex;
  align-items: center;
  gap: .3rem;
}

.sweep-label {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .68rem;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.sweep-label input { accent-color: var(--accent); cursor: pointer; }

.voice-readout { font-size: .66rem; padding: .2rem 1.25rem .2rem .35rem; }

/* the cell the next spoken number will land in */
.site-cell.cursor {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 3px rgba(26,111,196,.18);
  position: relative;
  z-index: 2;
}

/* values from a whole-mouth baseline: visibly provisional */
.site-cell.draft {
  background: var(--surface-3);
  color: var(--text-3);
  border-style: dashed;
}
.site-cell.draft.filled { background: var(--surface-3); color: var(--text-2); }
.site-cell.draft.danger { background: #f0e6e6; color: #a04848; border-color: #d9b3b3; }
body.dark .site-cell.draft { background: #23262b; }
body.dark .site-cell.draft.danger { background: #2c2224; }

.phase-tabs {
  display: flex;
  gap: .3rem;
  margin-bottom: .55rem;
}
.phase-tab {
  flex: 1;
  padding: .3rem .2rem;
  font-size: .7rem;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color .12s, border-color .12s, color .12s;
}
.phase-tab:hover { background: var(--surface-2); }
.phase-tab.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.cursor-bar {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .68rem;
  color: var(--text-2);
  padding: .3rem .5rem;
  margin-bottom: .6rem;
  background: var(--accent-dim);
  border-radius: var(--r-sm);
}
.cursor-bar strong { color: var(--accent); font-family: var(--font-mono); }
.cursor-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: cursorPulse 1.3s ease-in-out infinite;
}
@keyframes cursorPulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.cs-draft-wrap { display: inline; }
.cs-draft-wrap[hidden] { display: none; }
.cs-draft-badge {
  display: inline-block;
  padding: .05rem .4rem;
  border-radius: var(--r-xl);
  background: #fff3d6;
  color: #8a6d1f;
  font-size: .62rem;
  font-weight: 600;
}
body.dark .cs-draft-badge { background: #3a3018; color: #d8b45a; }

/* ===================================================================
   MCP sync indicator
   =================================================================== */
.mcp-toggle {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .55rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  font-size: .68rem;
  color: var(--text-3);
  white-space: nowrap;
}
.mcp-toggle input { accent-color: var(--accent); cursor: pointer; }
.mcp-state.on { color: var(--teal); font-weight: 600; }
.mcp-state.err { color: var(--red); font-weight: 600; }

/* ===================================================================
   Print sheet — only this is printed
   =================================================================== */
.print-sheet { display: none; }

@media print {
  /* hide the whole application shell */
  body > *:not(#print-sheet) { display: none !important; }
  body {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
    color: #000 !important;
  }

  .print-sheet {
    display: block !important;
    font-family: 'Inter', system-ui, sans-serif;
    color: #000;
    font-size: 9pt;
    padding: 0;
    margin: 0;
  }

  .print-head {
    border-bottom: 2px solid #000;
    padding-bottom: 4pt;
    margin-bottom: 8pt;
  }
  .print-head h1 { font-size: 13pt; margin: 0 0 3pt; font-weight: 600; }
  .print-meta { font-size: 8pt; color: #333; }

  .print-phase {
    margin-bottom: 10pt;
    page-break-inside: avoid;
  }
  .print-phase h2 {
    font-size: 10pt;
    margin: 0 0 3pt;
    padding: 2pt 4pt;
    background: #eee;
    border-left: 3px solid #333;
  }

  table.print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 7.5pt;
    margin-bottom: 6pt;
    table-layout: fixed;
  }
  table.print-table th,
  table.print-table td {
    border: 0.5pt solid #999;
    padding: 1pt 1pt;
    text-align: center;
    line-height: 1.2;
    overflow: hidden;
  }
  /* site columns share space evenly; FDI / mobility / condition are sized */
  table.print-table th.grp { width: 4.2%; }
  table.print-table th.sub { width: auto; font-weight: 500; }
  table.print-table td.toothlabel { width: 4.2%; }
  table.print-table th {
    background: #f2f2f2;
    font-weight: 600;
    font-size: 6.5pt;
  }
  table.print-table th.grp {
    background: #ddd;
    font-weight: 700;
  }
  /* thicken the border that starts each measurement group */
  table.print-table th.grp:not(:first-child) {
    border-left: 1.4pt solid #555;
  }
  table.print-table td:nth-child(7),
  table.print-table td:nth-child(13),
  table.print-table td:nth-child(19) {
    border-left: 1.4pt solid #555;
  }
  table.print-table td.condcell {
    font-size: 6pt;
    text-align: left;
    padding-left: 2pt;
  }
  table.print-table td.rowlabel {
    background: #f7f7f7;
    font-weight: 600;
    text-align: left;
    padding-left: 3pt;
    white-space: nowrap;
  }
  table.print-table td.toothlabel {
    background: #e8e8e8;
    font-weight: 700;
    font-family: 'DM Mono', monospace;
  }
  table.print-table .deep { font-weight: 700; }
  table.print-table .bleed { font-weight: 700; }
  table.print-table .draftv { color: #777; font-style: italic; }

  .print-legend {
    font-size: 7pt;
    color: #444;
    margin-bottom: 6pt;
  }
  .print-legend span { margin-right: 10pt; }

  .print-foot {
    border-top: 1px solid #999;
    margin-top: 8pt;
    padding-top: 3pt;
    font-size: 7pt;
    color: #555;
  }

  @page {
    size: A4 landscape;
    margin: 10mm;
  }
}
