/* Palette moved to /shared/tokens.css in Phase 5 so every module shares it.
   Link that file before this one. */
/* [SocketStudio v1.7] frontend/css/app.css | Apple-style glass UI: light (default) + dark theme via
   [data-theme], translucent blurred surfaces, soft curves, RTL-first logical properties, bilingual-safe.
   All v1-v1.6 selectors preserved; new in v1.7: icon-btn, modal-card, modal-head, viewer-card, grp,
   danger, wallet-balance. | STATUS: COMPLETE */

/* ===================== v2.8.0 brand palettes =====================
   Default palette "brand" comes from the SocketStudio identity kit:
   Deep Navy #16223A / Muted Sage #7B9D8E / Soft Slate #EDF2F6 / Clean White #FFFFFF /
   Action Blue #3B82F6 -- processed separately for the light and dark themes.
   The original v1.7 Apple-glass palette is kept as "classic"; both palette and default
   theme are owner-selectable from the hidden admin panel (html[data-palette] attribute). */

/* "classic" = the original v1.7 Apple-glass palette (kept per user request, admin-selectable) */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui), -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 85% -10%, var(--body-a), transparent 60%),
    radial-gradient(900px 520px at -10% 110%, var(--body-b), transparent 60%),
    var(--bg2);
  font-size: 14px;
  transition: background 0.25s ease, color 0.25s ease;
}
html[lang="en"] body { font-family: var(--font-en), Inter, "Segoe UI", sans-serif; }

/* v2.12 polished neomorphism, keeping brand colors and both light/dark modes */

/* theme + font menu */
.theme-wrap { position:relative; }
.theme-menu { position:absolute; top:43px; inset-inline-end:0; width:310px; padding:14px; z-index:500; border:1px solid var(--border); border-radius:17px; background:var(--glass2); box-shadow:var(--shadow); backdrop-filter:blur(24px) saturate(160%); }
.theme-menu-title { font-weight:700; font-size:13px; margin-bottom:9px; }
.theme-grid { display:grid; grid-template-columns:1fr 1fr; gap:7px; margin-bottom:12px; }
.theme-grid button { display:flex; align-items:center; gap:8px; border:1px solid var(--border); border-radius:11px; padding:8px; color:var(--text); background:var(--bg2); cursor:pointer; font:inherit; font-size:var(--text-sm); text-align:start; }
.theme-grid button.active { border-color:var(--blue); color:var(--blue-strong); box-shadow:0 0 0 2px var(--blue-bg); }
.theme-swatch { width:24px; height:24px; border-radius:8px; flex:none; box-shadow:inset 0 0 0 1px rgba(0,0,0,.08); }.brand-light{background:linear-gradient(135deg,#fff 50%,#7b9d8e 50%)}.brand-dark{background:linear-gradient(135deg,#16223a 50%,#8fb8a5 50%)}.classic-light{background:linear-gradient(135deg,#fff 50%,#0a84ff 50%)}.classic-dark{background:linear-gradient(135deg,#1c1c1e 50%,#409cff 50%)}.neo-light{background:linear-gradient(135deg,#f7fafd,#d7e0eb)}.neo-dark{background:linear-gradient(135deg,#243246,#111925)}

.hidden { display: none !important; }
.sm { font-size: 12px; }
.muted { color: var(--text2); }

::selection { background: var(--blue-bg); }

/* ---------- layout ---------- */
#topbar {
  height: 54px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-block-end: 1px solid var(--border);
  position: relative;
  z-index: 30;
}
#topbar .brand { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
#topbar .brand b { font-weight: 700; color: var(--sage); }
/* v2.8.1: real cropped brand mark (img/logo.png, transparent) in topbar + login card */
.brand-logo { width: 25px; height: 25px; vertical-align: -7px; margin-inline-end: 7px; }
.auth-logo { width: 34px; height: 34px; vertical-align: -10px; margin-inline-end: 9px; }
.crumb { flex: 1; color: var(--text2); font-size: 13px; text-align: center; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.user-box { display: inline-flex; align-items: center; gap: 8px; }

/* round glass icon buttons (theme / language / close) */
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--glass2);
  color: var(--text);
  border-radius: 50%;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, background 0.15s ease;
}
.icon-btn:hover { background: var(--bg3); transform: scale(1.06); }
.icon-btn:active { transform: scale(0.96); }

.badge {
  font-size: var(--text-sm);
  background: var(--blue-bg);
  color: var(--blue-strong);
  border-radius: 999px;
  padding: 3px 11px;
  vertical-align: middle;
}
.badge.ok { background: var(--green-bg); color: var(--green); }

#viewOnlyBar {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
}

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 12px; }
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
}

#layout {
  display: flex;
  /* The shell sits above every module, so its height is part of the sum.
     Hard-coding one header's height pushed the app below the fold the
     moment a second one appeared. */
  height: calc(100vh - 54px - var(--shell-h));
}

/* ---------- sidebar ---------- */
#sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-inline-end: 1px solid var(--border);
  padding: 12px 10px;
  overflow-y: auto;
}
.nav-label {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text2);
  margin: 14px 8px 6px;
}
#sidebar .step {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  text-align: start;
  transition: background 0.15s ease;
}
#sidebar .step:hover:not(:disabled) { background: var(--bg3); }
#sidebar .step.active { background: var(--blue-bg); color: var(--blue-strong); font-weight: 600; }
#sidebar .step:disabled { color: var(--text2); opacity: 0.5; cursor: default; }
#sidebar .num {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg3);
  font-size: var(--text-sm);
  font-weight: 600;
}
#sidebar .step.active .num { background: var(--blue); color: var(--accent-on); }
#sidebar .chip {
  margin-inline-start: auto;
  font-size: 10px;
  background: var(--orange-bg);
  color: var(--orange);
  padding: 1px 8px;
  border-radius: 999px;
}

/* ---------- centre column: viewer, the assistant's row, the SaaS pages ---------- */
#centre { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- viewer ---------- */
/* min-height:0 is what lets the assistant's row keep its height: without it a
   flex item refuses to shrink below its content and the row is squeezed out. */
#viewerWrap { position: relative; flex: 1; min-width: 0; min-height: 0; background: var(--bg2); }
#canvas3d { width: 100%; height: 100%; display: block; touch-action: none; }

#emptyState {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  padding: 0 40px;
}
#emptyState .icon { font-size: 56px; }
#emptyState h2 { margin: 12px 0 4px; font-weight: 600; }
#emptyState p { max-width: 420px; color: var(--text2); margin: 0; }

#viewerHud {
  position: absolute;
  top: 14px;
  inset-inline-start: 14px;
  display: flex;
  gap: 8px;
}
.hud-btn {
  border: 1px solid var(--border);
  background: var(--glass2);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.12s ease;
}
.hud-btn:hover { background: var(--bg3); transform: translateY(-1px); }
.hud-btn.on { background: var(--blue-bg); color: var(--blue-strong); border-color: var(--blue); }

#heatLegend {
  position: absolute;
  bottom: 14px;
  inset-inline-start: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--glass2);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  box-shadow: var(--shadow-sm);
}
#heatLegend .c { width: 14px; height: 14px; border-radius: 5px; display: inline-block; }
#heatLegend .c.blue { background: #4b8fe0; }
#heatLegend .c.red { background: #e05a4b; }

#busy {
  position: absolute;
  inset: 0;
  background: var(--busy-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 20;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--blue-bg);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- SaaS pages ---------- */
#pageWrap { flex: 1; min-width: 0; overflow-y: auto; padding: 24px; }
.page-card {
  background: var(--glass2);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px 26px;
  margin-block-end: 20px;
  max-width: 980px;
}
.page-card h2 { margin: 0 0 2px; font-size: 19px; letter-spacing: -0.01em; }
.page-card h3 { margin: 24px 0 10px; font-size: 15px; }
.page-card .sub { color: var(--text2); font-size: 13px; margin-block-end: 14px; }
.trend-svg { width: 100%; height: 170px; }

/* ---------- side panel ---------- */
#panel {
  width: 322px;
  flex: 0 0 322px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-inline-start: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
}
#panel h3 { margin: 2px 0 14px; font-size: 15px; }
#panel h4 {
  margin: 18px 0 8px;
  font-size: 12px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 11px;
  padding: 8px 15px;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.btn:hover:not(:disabled) { background: var(--bg3); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.sm { padding: 6px 11px; font-size: var(--text-sm); border-radius: 9px;
          min-height: var(--control-h); }
.btn.block { display: block; width: 100%; margin-block-start: 18px; }
.btn.primary {
  background: var(--blue);
  border-color: transparent;
  color: var(--accent-on);
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(10, 132, 255, 0.35);
}
.btn.primary:hover:not(:disabled) { background: var(--blue-strong); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text2); box-shadow: none; }
.btn.ghost:hover { background: var(--bg3); color: var(--text); }

/* `search` was missing from this list, so the patients filter was the one
   unstyled control in the application -- 21px tall and borderless. And without
   an explicit min-height, padding alone left every field under the 32px the
   rest of the interface is built on. */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="search"],
input[type="date"], input:not([type]), select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 11px;
  min-height: var(--control-h);
  width: 100%;
  min-width: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { min-height: calc(var(--control-h) * 2); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}
textarea { resize: vertical; line-height: 1.6; }
/* The native file button sizes itself; give the row it sits in the same height
   as everything beside it so the control is a real target. */
input[type="file"] { border: none; background: transparent; padding: 4px 0;
                     min-height: var(--control-h); }

/* Rows wrap. A row that fits still sits on one line; one that does not used to
   crush its fields to 24px wide on a phone rather than taking a second line. */
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
       margin-block-end: 8px; }
.row > input, .row > select { flex: 1 1 12ch; }
.row .btn { flex: 0 0 auto; }
.unit { color: var(--text2); }

.fld { display: block; margin-block-end: 10px; }
.fld span { display: block; font-size: 12px; color: var(--text2); margin-block-end: 4px; }
.fld.num { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.fld.num span { flex: 1; margin: 0; }
.fld.num input { flex: 0 0 90px; text-align: center; }

/* v1.7: form field group (modals + case/clinic pages) */
.grp {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 12px 14px 6px;
  margin-block-end: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 16px;
}
.grp .nav-label { grid-column: 1 / -1; margin: 0 0 8px; }
@media (max-width: 700px) {
  .grp { grid-template-columns: 1fr; }
}

.check { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px;
         min-height: var(--control-h); cursor: pointer; }
/* The native box is the visible control here, so it is enlarged rather than
   covered. The whole label is the hit area either way. */
.check input { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
.check:focus-within { outline: 2px solid var(--focus); outline-offset: 2px;
                      border-radius: var(--radius-sm); }

input[type="range"] { width: 100%; accent-color: var(--blue); padding: 0; border: none; box-shadow: none; }
.slider-row { display: block; margin-block-end: 10px; }
.slider-row > span:first-child { display: block; font-size: 12px; color: var(--text2); margin-block-end: 2px; }
.slider-row .val { font-size: 12px; color: var(--text); }

.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
  margin-block-end: 12px;
  background: var(--bg3);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 7px 4px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s ease;
}
.seg button:first-child { border-inline-start: none; }
.seg button.active { background: var(--bg); color: var(--blue-strong); font-weight: 600; box-shadow: var(--shadow-sm); }

/* ---------- dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 30px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--blue); background: var(--blue-bg); }
.dz-icon { font-size: 30px; color: var(--blue); margin-block-end: 6px; }

.ok-line {
  background: var(--green-bg);
  color: var(--green);
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 600;
  margin-block-start: 14px;
}
.warn-chip {
  display: inline-block;
  background: var(--orange-bg);
  color: var(--orange);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: var(--text-sm);
  margin: 6px 4px 0 0;
  direction: ltr;
}

/* ---------- measurements ---------- */
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.kv .k { color: var(--text2); font-size: 12px; }
.kv .v { font-weight: 600; font-size: 13px; text-align: end; }

.table-scroll { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th {
  text-align: start;
  font-size: var(--text-sm);
  color: var(--text2);
  background: var(--bg2);
  position: sticky;
  top: 0;
}
table.data td, table.data th { padding: 8px 10px; border-block-end: 1px solid var(--border); }
table.data tr:last-child td { border-block-end: none; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--blue-bg); }
table.data a { color: var(--blue-strong); text-decoration: none; }
table.data a:hover { text-decoration: underline; }

/* ---------- landmarks ---------- */
.lm-list { list-style: none; margin: 8px 0 0; padding: 0; }
.lm-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  margin-block-end: 4px;
  font-size: 13px;
}
.lm-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); flex: 0 0 10px; }
.lm-del {
  margin-inline-start: auto;
  border: none;
  background: none;
  color: var(--text2);
  font-size: 15px;
  cursor: pointer;
  padding: 0 4px;
}
.lm-del:hover { color: var(--red); }

/* ---------- exports ---------- */
.export-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow-sm);
  padding: 13px 15px;
  margin-block-end: 10px;
}
.export-card .uid { font-weight: 700; font-family: "SF Mono", Consolas, monospace; direction: ltr; text-align: start; }
.export-links { display: flex; gap: 10px; margin-block-start: 10px; flex-wrap: wrap; align-items: center; }
.export-links a { color: var(--blue-strong); text-decoration: none; font-size: 13px; font-weight: 600; }
.export-links a:hover { text-decoration: underline; }
.export-links a.btn { text-decoration: none; font-weight: 500; }

.callout {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 12px;
  margin-block-start: 16px;
}
.callout.warn { background: var(--orange-bg); color: var(--warn-text); border: 1px solid var(--warn-border); }

/* v2.12 visual adapter bolt orientation */
.adapter-orient-box { margin:12px 0; padding:12px; border:1px solid var(--border); border-radius:var(--radius); background:var(--bg2); text-align:center; }
.adapter-orient-box p { margin:4px 0 8px; }
.adapter-dial { width:150px; height:150px; margin:8px auto; border-radius:50%; position:relative; cursor:crosshair; touch-action:none; background:radial-gradient(circle at 42% 35%,var(--glass2),var(--bg3)); border:1px solid var(--border); box-shadow:inset 4px 4px 10px rgba(22,34,58,.10),inset -4px -4px 10px rgba(255,255,255,.55),var(--shadow-sm); }
.adapter-dial:focus-visible { outline:2px solid var(--blue); outline-offset:3px; }
.adapter-dial::before,.adapter-dial::after { content:""; position:absolute; background:var(--border); pointer-events:none; }.adapter-dial::before{height:1px;left:10px;right:10px;top:50%}.adapter-dial::after{width:1px;top:10px;bottom:10px;left:50%}
.dial-axis { position:absolute; font:600 10px ui-monospace,monospace; color:var(--text2); }.axis-x{right:5px;top:calc(50% - 7px)}.axis-y{top:3px;left:calc(50% + 5px)}
.adapter-rotor { position:absolute; inset:18px; border:1px dashed var(--sage); border-radius:50%; transition:transform .08s linear; pointer-events:none; }
.adapter-rotor i { position:absolute; width:14px; height:14px; margin:-7px; border-radius:50%; background:var(--blue); border:2px solid var(--bg); box-shadow:0 2px 5px rgba(0,0,0,.25); }.adapter-rotor i:nth-child(1){left:100%;top:50%}.adapter-rotor i:nth-child(2){left:50%;top:0}.adapter-rotor i:nth-child(3){left:0;top:50%}.adapter-rotor i:nth-child(4){left:50%;top:100%}
.dial-arrow { position:absolute; left:50%; top:50%; width:43%; height:3px; background:var(--sage-strong); transform-origin:left center; border-radius:3px; }.dial-arrow::after{content:"";position:absolute;right:-1px;top:-4px;border-left:8px solid var(--sage-strong);border-top:5px solid transparent;border-bottom:5px solid transparent}
.dial-center { position:absolute; width:12px; height:12px; border-radius:50%; left:50%; top:50%; transform:translate(-50%,-50%); background:var(--text); box-shadow:0 0 0 4px var(--bg); }
.adapter-orient-actions { display:flex; justify-content:center; align-items:center; gap:7px; flex-wrap:wrap; }.adapter-orient-actions strong{min-width:48px;color:var(--blue-strong)}
.global-reduction-card{padding:12px;border:1px solid var(--border);border-radius:var(--radius);background:var(--bg2);margin-bottom:12px}.fixed-mark-panel{margin-top:9px;padding-top:9px;border-top:1px solid var(--border)}

/* ---------- analysis ---------- */
.an-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-block-end: 10px;
  background: var(--bg);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s;
}
.an-card.an-state-ok { border-color: var(--green); }
.an-card.an-state-err { border-color: var(--red); }
.an-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-block-end: 4px;
}
.an-title { font-weight: 600; font-size: 13px; }
.an-desc { color: var(--text2); font-size: 12px; margin-block-end: 8px; }
.an-result {
  font-size: 12px;
  line-height: 1.6;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  margin-block-start: 8px;
}
.an-ok { color: var(--green); font-weight: 600; }
.an-warn { color: var(--orange); font-weight: 600; }
.an-err { color: var(--red); font-weight: 600; }
.an-note { color: var(--text2); font-size: var(--text-sm); }
.an-running { color: var(--text2); }
/* fix suggestion / undo area below print_check result */
.an-fix-area {
  margin-block-start: 10px;
  padding: 10px;
  background: var(--orange-bg);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
}
.an-fix-info {
  font-size: 12px;
  color: var(--warn-text);
  margin-block-end: 8px;
}

/* v2.11 pressure/clearance analysis popup */
#pressureModal { z-index: 140; padding: 18px; }
.pressure-card { width: min(1380px, 96vw); height: min(860px, 94vh); background: var(--glass2); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 14px; }
.pressure-head { height: 42px; display:flex; align-items:center; justify-content:space-between; }
.pressure-layout { height: calc(100% - 42px); display:grid; grid-template-columns: minmax(0,1fr) 330px; gap:14px; }
.pressure-stage { min-width:0; min-height:0; border:1px solid var(--border); border-radius:13px; overflow:hidden; background:#101827; }
#pressureCanvas { width:100%; height:100%; display:block; }
.pressure-tools { overflow:auto; padding-inline:4px; }
.pressure-two,.pressure-six { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.pressure-six { grid-template-columns:repeat(3,1fr); margin:8px 0; }
.pressure-six input { width:100%; min-width:0; }
.pressure-legend { margin:10px 0 14px; }
.pressure-gradient { height:18px; border-radius:9px; border:1px solid var(--border); background:linear-gradient(90deg,#ff2d2d,#ffdf32,#fff 50%,#30c878,#1647c8); }
.pressure-legend>div:last-child { display:flex; justify-content:space-between; font-size:var(--text-sm); color:var(--text2); margin-top:4px; }
.pressure-transform { border-top:1px solid var(--border); padding-top:12px; margin-top:12px; }
@media(max-width:850px){.pressure-layout{grid-template-columns:1fr;grid-template-rows:minmax(330px,1fr) 310px}.pressure-card{height:96vh}.pressure-tools{padding-bottom:10px}}

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  bottom: 18px;
  inset-inline-end: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--glass2);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  backdrop-filter: blur(18px) saturate(170%);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 11px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: rise 0.2s ease-out;
  max-width: 340px;
}
.toast.ok { border-color: var(--green); box-shadow: 0 8px 26px rgba(48, 209, 88, 0.2); }
.toast.err { border-color: var(--red); box-shadow: 0 8px 26px rgba(255, 69, 58, 0.24); }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- overlays: auth + modals (v1.7) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.auth-card {
  background: var(--glass2);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 360px;
  max-width: calc(100vw - 40px);
  padding: 24px 26px 26px;
}
.auth-head { display: flex; justify-content: space-between; align-items: center; margin-block-end: 8px; }
.auth-head .brand { font-size: 19px; font-weight: 700; }
.auth-head .brand b { color: var(--sage); }
.auth-card h2 { font-size: 15px; margin: 6px 0 16px; }
.auth-error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  margin-block-end: 10px;
}

/* v1.7 generic form modal */
.modal-card {
  background: var(--glass2);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 480px;
  max-width: calc(100vw - 36px);
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 22px;
  animation: pop 0.18s ease-out;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-block-end: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
@keyframes pop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* v1.7 mini 3D viewer modal */
.viewer-card {
  background: var(--glass2);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: min(92vw, 780px);
  height: min(78vh, 600px);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}
.viewer-card .row {
  /* in flow, not over the canvas: laid over it, the bar hid the top of a tall socket */
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  border-block-end: 1px solid var(--border);
}
/* the viewer sizes itself to its canvas's parent, so the canvas gets one of its own */
.mini-canvas { flex: 1 1 auto; min-height: 0; }
#miniCanvas { width: 100%; height: 100%; display: block; touch-action: none; }

/* v1.7 clinic wallet */
.wallet-balance {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  font-size: 14px;
  margin-block-end: 10px;
}
.wallet-balance b { font-size: 20px; color: var(--green); letter-spacing: 0.01em; }
.wallet-balance.neg b { color: var(--red); }

/* v1.7 danger zone (delete case) */
.danger {
  margin-block-start: 28px;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  background: var(--red-bg);
  padding: 12px 14px;
}
.danger .nav-label { color: var(--red); margin: 0 0 8px; }
.danger .btn { border-color: var(--red); color: var(--red); background: transparent; }
.danger .btn:hover:not(:disabled) { background: var(--red); color: var(--accent-on); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #sidebar { width: 64px; flex-basis: 64px; }
  #sidebar .step span:not(.num), #sidebar .nav-label, #sidebar .chip { display: none; }
  #panel { width: 260px; flex-basis: 260px; }
}

/* ================= v1.8 hidden admin panel ================= */
/* v1.9: the admin panel is a POPUP over the running app -- the page stays visible behind a
   light dim, and clicking outside the card closes it (see admin.js). */
.admin-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(20, 22, 28, 0.34);
  backdrop-filter: blur(5px) saturate(1.1);
  -webkit-backdrop-filter: blur(5px) saturate(1.1);
  display: flex; align-items: center; justify-content: center; overflow: auto; padding: 24px;
}
.admin-card {
  background: var(--glass2); border: 1px solid var(--border); border-radius: 20px;
  padding: 26px; width: 340px; box-shadow: 0 24px 70px rgba(0,0,0,.35);
  display: flex; flex-direction: column; gap: 12px;
}
.admin-card h2 { margin: 0 0 4px; font-size: 18px; }
.admin-card input, .admin-sec input {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 11px; font: inherit; width: 100%; box-sizing: border-box;
}
.admin-row { display: flex; gap: 8px; margin-top: 4px; }
.admin-panel {
  background: var(--glass2); backdrop-filter: blur(30px) saturate(1.4);
  -webkit-backdrop-filter: blur(30px) saturate(1.4);
  border: 1px solid var(--border); border-radius: 24px;
  width: min(780px, 94vw); max-height: 84vh; overflow: auto;
  padding: 20px 24px; box-shadow: 0 28px 80px rgba(0,0,0,.35); margin: auto;
}
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.admin-head h2 { margin: 0; font-size: 20px; }
.admin-body { display: flex; flex-direction: column; gap: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; text-align: center;
}
.stat-v { font-size: 19px; font-weight: 700; }
.stat-l { font-size: 11.5px; color: var(--text2); margin-top: 3px; }
.admin-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 800px) { .admin-cols { grid-template-columns: 1fr; } }
.admin-sec {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.admin-sec h3 { margin: 0; font-size: 14.5px; }
.admin-sec table { width: 100%; font-size: 12px; }
.admin-sets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 800px) { .admin-sets { grid-template-columns: 1fr; } }
.admin-set { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text2); }
.chart-svg { width: 100%; height: 120px; display: block; background: var(--bg); border-radius: 10px; }
.chart-range { text-align: center; }
.order-files a { margin-inline-end: 8px; white-space: nowrap; }
.mono { font-family: ui-monospace, monospace; direction: ltr; }

/* ================= v2.7.1 UI/UX polish ================= */
/* keyboard focus ring -- :focus-visible only, so mouse clicks stay clean */
.btn:focus-visible, .icon-btn:focus-visible, .hud-btn:focus-visible,
#sidebar .step:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
/* full UI lock while the busy overlay is up: side panels cannot fire actions mid-generate */
body.busy-lock #sidebar, body.busy-lock #panel, body.busy-lock #pageWrap {
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.2s ease;
}
body.busy-lock #viewerHud { pointer-events: none; }
/* order rows -> case page links */
.o-case { color: var(--blue-strong); text-decoration: none; font-weight: 600; }
.o-case:hover { text-decoration: underline; }


/* ---------------------------------------------------- Phase: UI pass ---
 * A range input's own box is the track, which is thinner than any pointer
 * target ought to be. The control keeps its thin track and gains a 32px
 * gesture area around it.
 */
input[type="range"] { height: var(--control-h); }
.btn, .icon-btn, .hud-btn, #sidebar .step, .seg button { min-height: var(--control-h); }
#modeBadge { font-size: var(--text-sm); }

/* Icons are inline SVG now, not glyphs; a glyph renders differently on every
   platform and is read aloud as prose. currentColor keeps them on-theme. */
.icon-btn svg, .btn svg, .hud-btn svg { width: 16px; height: 16px; flex: none; }


/* --------------------------------------------------- admin: print profiles ---
 * Whether a socket profile is installed decides whether sockets export with a
 * recipe or as bare geometry, so it is stated in colour and in words.
 */
.prof-ok { color: var(--ok); }
.prof-warn { color: var(--warn); }
tr.prof-note td { padding-block-start: 0; }


/* ------------------------------------------------------- owner panel type ---
 * The panel had never been audited -- it opens only with a token -- and three
 * of its styles sat below the 12px floor. A stat label and a table header are
 * read, not glanced at.
 */
.admin-panel .stat-l { font-size: var(--text-sm); }


/* ------------------------------------------------------- first sign-in ---
 * The auth card's second face: the account exists, but on a password somebody
 * else chose.
 */
.auth-note{margin:0 0 16px;font-size:14px;line-height:1.55;color:var(--text2);
  background:var(--bg3);border-radius:10px;padding:12px 14px}

/* ===================================================== print orders (v4) ===
 * An order is a priced document. The quote is shown as a bill rather than a
 * total, because a clinic that can see the lines does not ring up to ask what
 * the number is made of.
 */
.order-card { border: 1px solid var(--border); border-radius: 12px;
              padding: 16px 18px; margin-block-end: 12px; background: var(--bg2); }
.order-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
              margin-block-end: 10px; }
.order-head a { color: var(--text); text-decoration: none;
                display: inline-flex; align-items: center; min-height: 32px; }
.order-head a:hover { text-decoration: underline; }

.quote { max-width: 46ch; margin-block: 10px; font-size: 13px; }
.q-line { display: flex; justify-content: space-between; gap: 16px;
          padding-block: 3px; color: var(--text2); }
.q-line b { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 500; }
.q-line.rule { border-block-start: 1px solid var(--border); margin-block-start: 6px;
               padding-block-start: 7px; }
.q-line.total b { font-size: 15px; font-weight: 600; }
.q-line.credit b { color: var(--ok); }
.q-note { margin-block-start: 8px; padding-block-start: 8px;
          border-block-start: 1px dashed var(--border); color: var(--text2);
          font-size: 12.5px; }
.q-note b { color: var(--ok); font-variant-numeric: tabular-nums; }

.o-actions { margin-block-start: 12px; }
.o-actions input { max-width: 280px; }


/* ---------------------------------------------------------- scan check --- */
/* Findings about the file, as sentences with a place on the mesh. A code in a
   chip told nobody anything; a sentence with a Show button does. */
.scan-findings{list-style:none;margin:8px 0 0;padding:0;display:flex;flex-direction:column;gap:6px}
.scan-findings li{display:flex;gap:8px;align-items:flex-start;font-size:13px;line-height:1.45}
.scan-findings li .lvl{flex:none;font-size:11px;font-weight:600;letter-spacing:.04em;
  text-transform:uppercase;padding:2px 6px;border-radius:8px;margin-top:2px}
.scan-findings li.info .lvl{background:var(--sunken,#eef2f6);color:var(--ink-3,#5a6b80)}
.scan-findings li.warn .lvl{background:var(--warn-soft,#fbf0dc);color:var(--warn,#8a5300)}
.scan-findings li.bad .lvl{background:var(--danger-soft,#fbe9e7);color:var(--danger,#b4231c)}
.scan-findings li{flex-wrap:wrap}
.scan-findings li>span:nth-child(2){flex:1 1 12ch;min-width:0}
.scan-findings li .acts{display:flex;gap:6px;flex:1 0 100%;justify-content:flex-end;padding-left:26px}
.scan-refused{color:var(--danger,#b4231c);font-weight:600}
.scan-refused-list{margin:4px 0 0 18px;padding:0;font-size:13px}

/* ---------- v2.30 the stage assistant, v2.32 as a row under the viewer ---------- */
/* A third of the screen, and collapsible to its own header. It is a sibling of
   the viewer, so the rule below hides it on the SaaS pages -- which hide the
   viewer -- without anything having to remember to. */
.stage-box { flex: 0 0 33vh; min-height: 0; overflow-y: auto; padding: 0;
  border-block-start: 1px solid var(--border); background: var(--bg2); }
.stage-box.collapsed { flex: 0 0 auto; overflow: hidden; }
.stage-box.collapsed .stage-body { display: none; }
#viewerWrap.hidden ~ .stage-box { display: none; }
.stage-box .stage-head { position: sticky; top: 0; z-index: 1; background: var(--bg2);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 9px 14px 7px;
  border-block-end: 1px solid var(--border); }
.stage-box .stage-head b { font-size: 13px; }
.stage-box .stage-toggle { margin-inline-start: auto; flex: none; }
.stage-box .stage-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.stage-box .stage-list li { display: flex; align-items: center; gap: 6px; font-size: 12px;
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; }
.stage-box .stage-list li.current { border-color: var(--blue); }
.stage-box .stage-list li.approved { color: var(--green); border-color: var(--green); }
.stage-box .stage-pill { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; background: var(--bg3); color: var(--text2); }
.stage-box .stage-pill.done { background: var(--blue-bg); color: var(--blue); }
.stage-box .stage-pill.approved { background: var(--green-bg); color: var(--green); }
/* The row is wide, so the report reads as columns rather than one long scroll:
   what it did, what it asks and what to review sit side by side. */
.stage-box .stage-body { display: grid; gap: 10px; align-items: start; padding: 10px 14px 14px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.stage-box .stage-body > p, .stage-box .stage-actions { grid-column: 1 / -1; }
.stage-box .stage-msg { border-radius: 10px; padding: 8px 10px; margin: 0; font-size: 12.5px; background: var(--bg); border: 1px solid var(--border); }
.stage-box .stage-msg h5 { margin: 0 0 6px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--text2); }
.stage-box .stage-msg ul { margin: 0; padding-inline-start: 18px; }
.stage-box .stage-msg li { margin: 3px 0; }
.stage-box .stage-msg.ask { border-color: var(--blue); }
.stage-box .stage-msg.review { border-color: var(--orange); }
.stage-box .stage-msg.review label { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0; cursor: pointer; }
.stage-box .stage-msg.review input { margin-top: 2px; flex: none; accent-color: var(--accent); }
.stage-box .stage-q { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 5px 0; }
.stage-box .stage-q span { flex: 1 1 100%; }
.stage-box .stage-q input, .stage-box .stage-q select { flex: 1 1 10ch; }
.stage-box .stage-q .stage-tag { flex: none; font-style: normal; font-size: 10px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--orange); }
.stage-box .stage-src { flex: 1 1 100%; margin: 0; font-size: 11px; color: var(--text2); }
.stage-box .stage-ref { margin: 0; padding-inline-start: 0; list-style: none; }
.stage-box .stage-ref li { margin: 6px 0; padding-inline-start: 8px; border-inline-start: 2px solid var(--border); }
.stage-box .stage-ref .stage-src { display: block; }
.stage-box .stage-head .stage-warn { flex: 1 1 100%; margin: 2px 0 0; font-weight: 400; }
.stage-box .stage-prop { width: 100%; font-size: 12px; border-collapse: collapse; }
.stage-box .stage-prop td { padding: 3px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.stage-box .stage-prop td:last-child { color: var(--text2); }
.stage-box .stage-prop input { width: 9ch; }
.stage-box .stage-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-block-start: 2px; }
/* v2.35: one signature per step -- the step's stages side by side in one body, each
   its own section of columns, and one button under them all. */
.stage-box .stage-sec { grid-column: 1 / -1; display: grid; gap: 8px; align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  padding-block-start: 8px; border-block-start: 1px solid var(--border); }
.stage-box .stage-sec:first-child { border-block-start: 0; padding-block-start: 0; }
.stage-box .stage-sec-head { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin: 0; font-size: 12.5px; }
.stage-box .stage-sec-head .stage-rerun { margin-inline-start: auto; }
.stage-box .stage-sec > p { grid-column: 1 / -1; margin: 0; }
.stage-box .stage-msg h6 { margin: 0 0 6px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--text2); }
.stage-box details.stage-msg summary { cursor: pointer; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--text2); }
.stage-box .stage-warn { color: var(--orange); font-size: 12px; }

/* ---------- v2.35 the socket step: a recipe named, Advanced, the dot back to it ---------- */
.recipe-row { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg2); margin-bottom: 12px; }
/* the simple view hides only what has not moved (a moved field shows with its dot) */
.adv-hidden { display: none !important; }
/* a 12 px dot in a 24 px target: the transparent border is the part a finger hits */
.revert-dot { flex: none; box-sizing: content-box; width: 12px; height: 12px; min-height: 0; padding: 0;
  margin-inline-start: 2px; border: 6px solid transparent; background-clip: padding-box;
  border-radius: 50%; background-color: var(--accent); cursor: pointer; vertical-align: middle; }
.turn-box { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg2); }
.turn-box.low { border-color: var(--warn-border); }
.turn-row { flex-wrap: wrap; gap: 6px; align-items: center; }
