/* Dermatoscan — Design System v3.0 (Apple clinical workstation).
   Light-default, restrained graphite surfaces, SF/Pretendard typography, and
   quiet depth for a polished physician-facing tool. */

@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.css");

/* ─── Legacy token base; final light/dark theme tokens are refined below. ─ */
:root {
  /* Background — deep ink, layered surfaces */
  --color-bg-primary:   #0B0C0F;
  --color-bg-secondary: #16181D;
  --color-bg-tertiary:  #1F2228;

  /* Foreground — warm white (not cold) */
  --color-text-primary:   #F2F1ED;
  --color-text-secondary: #B8B5AE;
  --color-text-tertiary:  #7A7770;
  --color-text-disabled:  #4A4845;

  /* Borders — hairline only */
  --color-border-default:  #2A2D33;
  --color-border-emphasis: #3D414A;
  --color-border-subtle:   #1F2228;

  /* Accent — electric cyan, glows on dark */
  --color-accent-primary:  #22D3EE;
  --color-accent-hover:    #67E8F9;
  --color-accent-active:   #06B6D4;
  --color-accent-subtle:   #0E2F38;
  --color-accent-emphasis: #ECFEFF;

  /* Semantic — saturated for dark-mode legibility */
  --color-critical:        #F87171;
  --color-critical-bg:     #2A1416;
  --color-critical-border: #7F1D1D;
  --color-warning:         #FBBF24;
  --color-warning-bg:      #2A1F0A;
  --color-warning-border:  #92400E;
  --color-success:         #34D399;
  --color-success-bg:      #0A2A1E;
  --color-success-border:  #065F46;
  --color-info:            #60A5FA;
  --color-info-bg:         #0E1F33;
  --color-info-border:     #1E3A8A;

  /* Type families — high-tech: sans + mono. Crimson Pro retired. */
  --font-serif: "Inter Tight", "Pretendard", -apple-system, sans-serif;  /* alias, not actually serif */
  --font-sans:  "Inter", "Pretendard", -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  --font-display: "Inter Tight", "Pretendard", -apple-system, sans-serif;
  --font-mono:  "JetBrains Mono", "Source Code Pro", Menlo, monospace;

  /* Spacing — 8 px base grid */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Motion */
  --transition-fast:    120ms ease-out;
  --transition-default: 180ms ease-out;
  --transition-slow:    280ms ease-out;

  /* Radii — design v1.0 favors small, restrained corners */
  --radius-sm:      3px;
  --radius-default: 4px;
  --radius-md:      6px;
  --radius-lg:      8px;
  --radius-xl:      12px;  /* retained for legacy modal/hero use */
  --radius-2xl:     16px;  /* retained for legacy use */
  --radius-full:    9999px;

  /* Shadows — dark mode uses cyan-tinted glow rather than soft drop. */
  --shadow-sm:       0 1px 0 rgba(34, 211, 238, 0.04);
  --shadow-default:  0 0 0 1px rgba(34, 211, 238, 0.08), 0 2px 12px rgba(0,0,0,0.4);
  --shadow-emphasis: 0 0 0 1px rgba(34, 211, 238, 0.18), 0 8px 32px rgba(0,0,0,0.5);
  --glow-accent:     0 0 0 1px var(--color-accent-primary), 0 0 20px rgba(34, 211, 238, 0.25);
  /* Legacy aliases used in transitional rule bodies */
  --shadow-md:       var(--shadow-default);
  --shadow-lg:       var(--shadow-emphasis);

  /* ─── Legacy alias bridge ───────────────────────────────────────────────
     Old token names map to new tokens so app.js inline var(--…) refs (27
     occurrences) keep working without a sweep. Drop this block in Phase D
     once JS is renamed to new tokens. */
  --bg:          var(--color-bg-primary);
  --bg-card:     var(--color-bg-primary);   /* pure-white #FFF rejected by spec */
  --bg-elev:     var(--color-bg-secondary);

  --ink:         var(--color-text-primary);
  --ink-soft:    var(--color-text-secondary);
  --muted:       var(--color-text-tertiary);
  --muted-soft:  var(--color-text-disabled);

  --rule:        var(--color-border-default);
  --rule-soft:   var(--color-border-subtle);

  --accent:      var(--color-accent-primary);
  --accent-hover:var(--color-accent-hover);
  --accent-soft: var(--color-accent-subtle);

  --gold:        var(--color-warning);       /* gold demoted to amber warning */
  --gold-dark:   var(--color-warning);
  --gold-soft:   var(--color-warning-bg);

  --ok:          var(--color-success);
  --ok-soft:     var(--color-success-bg);
  --warn:        var(--color-warning);
  --warn-soft:   var(--color-warning-bg);
  --danger:      var(--color-critical);
  --danger-soft: var(--color-critical-bg);
}

/* ─── LIGHT THEME (toggled — "clinical instrumentation") ───────────────── */
:root[data-theme="light"] {
  /* High-contrast white surfaces for chairside lighting environments. */
  --color-bg-primary:   #FFFFFF;
  --color-bg-secondary: #F8FAFC;
  --color-bg-tertiary:  #E2E8F0;

  --color-text-primary:   #0F172A;
  --color-text-secondary: #334155;
  --color-text-tertiary:  #64748B;
  --color-text-disabled:  #94A3B8;

  --color-border-default:  #CBD5E1;
  --color-border-emphasis: #94A3B8;
  --color-border-subtle:   #E2E8F0;

  --color-accent-primary:  #0891B2;
  --color-accent-hover:    #0E7490;
  --color-accent-active:   #155E75;
  --color-accent-subtle:   #ECFEFF;
  --color-accent-emphasis: #164E63;

  --color-critical:        #DC2626;
  --color-critical-bg:     #FEF2F2;
  --color-critical-border: #FECACA;
  --color-warning:         #B45309;
  --color-warning-bg:      #FFFBEB;
  --color-warning-border:  #FCD34D;
  --color-success:         #047857;
  --color-success-bg:      #ECFDF5;
  --color-success-border:  #A7F3D0;
  --color-info:            #2563EB;
  --color-info-bg:         #EFF6FF;
  --color-info-border:     #BFDBFE;

  --shadow-sm:       0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-default:  0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-emphasis: 0 4px 16px rgba(15, 23, 42, 0.08);
  --glow-accent:     0 0 0 3px rgba(8, 145, 178, 0.18);
}

html, body {
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.55;
  word-break: keep-all;      /* Korean line-break hygiene */
}
html[lang="ko"] body {
  line-height: 1.75;          /* Korean needs more vertical breathing room than Latin */
}

/* Tailwind utility classes set both font-size AND line-height. For Korean
   the bundled line-heights are too tight — relax them so body prose breathes. */
html[lang="ko"] .text-xs        { line-height: 1.6; }
html[lang="ko"] .text-sm        { line-height: 1.7; }
html[lang="ko"] .text-base      { line-height: 1.75; }
html[lang="ko"] .text-lg        { line-height: 1.65; }
html[lang="ko"] .leading-relaxed { line-height: 1.85; }
html[lang="ko"] .leading-snug    { line-height: 1.6; }

/* Korean optimization: long-form prose reads better in Pretendard sans than
   in any Korean serif at body sizes. Reserve the serif for short headlines
   (page brand, section titles, diagnosis primary). */
html[lang="ko"] .hero > p.font-serif {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 1.05rem;
  line-height: 1.8;
  letter-spacing: 0;
}
@media (min-width: 768px) {
  html[lang="ko"] .hero > p.font-serif {
    font-size: 1.15rem;
  }
}

/* Korean diagnosis title — bilingual names get long; reduce weight slightly */
html[lang="ko"] .dx-clickable.font-serif,
html[lang="ko"] .font-serif.text-2xl {
  font-size: 1.45rem;
  line-height: 1.4;
}
@media (min-width: 768px) {
  html[lang="ko"] .dx-clickable.font-serif,
  html[lang="ko"] .font-serif.text-2xl {
    font-size: 1.6rem;
  }
}

/* Serif reserved for moments of gravity: page title, section titles,
   confidence summary, diagnosis headline. Not body text.
   Crimson Pro for Latin; Korean glyphs fall back to Pretendard sans per spec. */
.font-serif, h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.25;
}
html[lang="ko"] .font-serif,
html[lang="ko"] h1,
html[lang="ko"] h2,
html[lang="ko"] h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: 0;
}
h1 { letter-spacing: 0; font-weight: 500; }
h2 { letter-spacing: 0; }

/* ─── Cards ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: none;
  border: 1px solid var(--color-border-default);
}
:root[data-theme="light"] .card {
  background: var(--color-bg-primary);
  box-shadow: var(--shadow-sm);
}
@media (max-width: 640px) {
  .card { padding: var(--space-4); }
}

/* Hero card — the confidence summary at top of result view.
   v2 instrument-readout treatment: cyan top-rule signals "primary readout
   active", no gradient, no glow except the focus state. */
.hero {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  border: 1px solid var(--color-border-default);
  border-top: 2px solid var(--color-accent-primary);
  position: relative;
}
:root[data-theme="light"] .hero {
  background: var(--color-bg-primary);
}
/* Hero gets only a cyan top-rule signaling "primary readout active". No
   text badge — the typography hierarchy below carries the meaning. */
.hero > * { position: relative; z-index: 1; }
@media (max-width: 640px) {
  .hero { padding: var(--space-5) var(--space-4); }
}

/* ─── Section numbering (§N notation per Design System v1.0) ─────────────── */

/* Section header — instrument-readout style. §NN in mono (tabular numerals,
   accent-colored) acts as the slot identifier; title in Inter Tight with
   tight uppercase tracking reads like a panel label. */
.section-divider {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin: var(--space-6) 0 var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-default);
}
.section-number {
  display: inline-flex;
  align-items: baseline;
  background: transparent;
  color: var(--color-accent-primary);
  border-radius: 0;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  font-style: normal;
  flex-shrink: 0;
  text-transform: uppercase;
}
.section-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text-primary);
  letter-spacing: 0;
}

/* ─── Badges (confidence + status) — Design System v1.0 ───────────────────
   Spec: 11px Inter 600, uppercase, 3px radius, 2px×8px padding. */

/* Badges — instrument readout style: mono, uppercase, dot indicator on left
   that color-codes the state. Tighter padding than DS v1.0. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}
.badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
  flex-shrink: 0;
}
.badge-confidence-high,         .badge-high         { color: var(--color-success);  background: var(--color-success-bg);  border-color: var(--color-success-border); }
.badge-confidence-moderate,     .badge-moderate     { color: var(--color-warning);  background: var(--color-warning-bg);  border-color: var(--color-warning-border); }
.badge-confidence-low,          .badge-low          { color: var(--color-critical); background: var(--color-critical-bg); border-color: var(--color-critical-border); }
.badge-confidence-insufficient, .badge-insufficient { color: var(--color-text-tertiary); background: var(--color-bg-tertiary); border-color: var(--color-border-default); }

/* ─── Callouts (Design System v1.0; biopsy blocker, insufficient, info) ───
   The .block-warn/.block-danger/.block-info classes are legacy aliases — JS
   still emits them at some sites and gets re-classed in Phase D. */

.callout, .block-warn, .block-danger, .block-info {
  display: flex;
  gap: var(--space-3);
  border-radius: var(--radius-default);
  padding: var(--space-4) var(--space-5);
  border-left: 3px solid;
  box-shadow: none;
  align-items: flex-start;
}
.callout-icon {
  flex-shrink: 0;
  font-size: 1.25rem;
  line-height: 1.4;
  margin-top: 1px;
}
.callout-content { flex: 1; min-width: 0; }
.callout-title {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 4px;
}
.callout-body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--color-text-primary);
}
.callout-inline {
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}
.callout-critical, .block-danger { background: var(--color-critical-bg); border-left-color: var(--color-critical); color: var(--color-text-primary); }
.callout-warning,  .block-warn   { background: var(--color-warning-bg);  border-left-color: var(--color-warning);  color: var(--color-text-primary); }
.callout-success                 { background: var(--color-success-bg);  border-left-color: var(--color-success);  color: var(--color-text-primary); }
.callout-info,     .block-info   { background: var(--color-info-bg);     border-left-color: var(--color-info);     color: var(--color-text-primary); }
@media (max-width: 640px) {
  .callout, .block-warn, .block-danger, .block-info { padding: var(--space-3) var(--space-4); }
}

/* ─── ROI annotation overlay ─────────────────────────────────────────────────
   AI-marked regions on uploaded photos. The frame shrink-wraps the <img>
   (inline-block) and the overlay is positioned inset:0, so percentage-based
   boxes align edge-to-edge with the rendered image — no object-fit math.
   Concern drives color: benign=accent, monitor=amber, suspicious=critical.
   HONEST FRAMING: approximate regions, not precise boundaries. */
.roi-photo-center { text-align: center; }
.roi-frame {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: var(--radius-lg);
}
.roi-img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
}
.roi-frame-large .roi-img { max-height: 420px; }
.roi-tile { text-align: center; }
.roi-tile .roi-img { max-height: 260px; }
.roi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.roi-overlay { position: absolute; inset: 0; pointer-events: none; }
.roi-box {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid;
  border-radius: 3px;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  pointer-events: auto;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.roi-box:hover, .roi-box.roi-active { background: rgba(255, 255, 255, 0.10); }
.roi-box.roi-active { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.30); }
.roi-benign      { border-color: var(--color-accent-primary); }
.roi-monitor     { border-color: var(--color-warning); }
.roi-suspicious  { border-color: var(--color-critical); }

/* Traced outline (optional, when the model returns polygon points). One SVG
   layer fills the frame; non-scaling-stroke keeps the line crisp at any size. */
.roi-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.roi-poly {
  fill: transparent;
  stroke-width: 2;
  stroke-linejoin: round;
  pointer-events: auto;
  cursor: pointer;
  transition: stroke-width var(--transition-fast), fill var(--transition-fast);
}
.roi-poly.roi-benign     { stroke: var(--color-accent-primary); fill: color-mix(in srgb, var(--color-accent-primary) 12%, transparent); }
.roi-poly.roi-monitor    { stroke: var(--color-warning);        fill: color-mix(in srgb, var(--color-warning) 12%, transparent); }
.roi-poly.roi-suspicious { stroke: var(--color-critical);       fill: color-mix(in srgb, var(--color-critical) 16%, transparent); }
.roi-poly:hover          { fill: color-mix(in srgb, #fff 10%, transparent); }
.roi-poly.roi-active     { stroke-width: 3.5; }

.roi-label {
  position: absolute;
  left: -2px;
  top: 0;
  transform: translateY(-100%);
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  border-radius: 3px 3px 0 0;
  color: #0B0C0F;
}
.roi-label-benign     { background: var(--color-accent-primary); }
.roi-label-monitor    { background: var(--color-warning); }
.roi-label-suspicious { background: var(--color-critical); color: #fff; }

.roi-caption {
  font-size: 12px;
  font-style: italic;
  color: var(--color-text-tertiary);
  text-align: center;
}

.roi-legend { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.roi-legend-item {
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: 6px 8px;
}
.roi-legend-item.roi-active {
  border-color: var(--color-border-emphasis);
  background: var(--color-bg-secondary);
}
.roi-legend-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--color-text-primary);
  cursor: pointer;
}
.roi-legend-head .roi-label { position: static; transform: none; border-radius: 4px; }
.roi-legend-label { font-weight: 500; font-size: 13px; }
.roi-legend-finding {
  font-size: 12.5px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin: 4px 0 0 26px;
}

/* Teaching section — physician education, info-toned left accent. */
.teaching-block { border-left: 3px solid var(--color-info); }

/* ─── Dropzone ─────────────────────────────────────────────────────────── */

.dropzone {
  background: var(--color-bg-primary);
  border: 1px dashed var(--color-border-emphasis);
  border-radius: var(--radius-md);
  padding: var(--space-8) var(--space-5);
  text-align: center;
  transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--color-accent-primary);
  background: var(--color-accent-subtle);
  box-shadow: var(--shadow-sm);
}

/* Landing-specific: photo column is a vertical stack of dropzone +
   thumbnail strip + actions row. Empty-state dropzone gets a minimum height
   so it still feels substantial; once thumbnails appear they fall below it. */
.landing-photo-col {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
@media (min-width: 768px) {
  .landing-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 240px;
  }
}

/* Landing form: tighter field spacing so the whole landing fits on one screen */
.landing-form label.field { margin-bottom: 0.7rem; }
.landing-form textarea {
  min-height: 3rem;
  line-height: 1.5;
}
.landing-form-card { padding: 1.5rem 1.75rem; }
@media (max-width: 640px) {
  .landing-form-card { padding: 1.25rem; }
}

/* ─── Form controls ────────────────────────────────────────────────────── */

input[type="text"],
input[type="number"],
textarea,
select {
  font-family: inherit;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-default);
  padding: 8px 12px;
  width: 100%;
  color: var(--color-text-primary);
  font-size: 15px;
  line-height: 1.4;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-accent-primary);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}
textarea { resize: vertical; min-height: 4rem; line-height: 1.55; }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%2378716c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.25rem;
}

label.field { display: block; margin-bottom: 1.1rem; }
.label-text,
label.field > .label-text {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-family: var(--font-sans);
}

/* ─── Buttons (Design System v1.0) ─────────────────────────────────────── */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-primary);
  /* dark text on bright cyan (dark mode), white-ish on deeper cyan (light) */
  color: var(--color-bg-primary);
  padding: 10px 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid var(--color-accent-active);
  border-radius: var(--radius-default);
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.3;
  font-family: var(--font-sans);
}
.btn-primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  box-shadow: var(--glow-accent);
}
.btn-primary:active { background: var(--color-accent-active); }
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
:root[data-theme="light"] .btn-primary {
  color: #FFFFFF;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--color-accent-primary);
  padding: 9px 18px;
  border: 1px solid var(--color-accent-primary);
  border-radius: var(--radius-default);
  font-size: 14px;
  line-height: 1.3;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
  font-family: var(--font-sans);
}
.btn-ghost:hover {
  background: var(--color-accent-subtle);
  border-color: var(--color-accent-hover);
  color: var(--color-accent-hover);
}

/* ─── Scanner loading animation ────────────────────────────────────────── */
/* A central pulsing dot surrounded by sonar-style concentric rings expanding
   outward. Calmer than a horizontal progress bar, on-brand with the
   dermatoscope/scanner clinical metaphor. Pure CSS, no JS. */

.scanner {
  width: 96px;
  height: 96px;
  position: relative;
  margin: 0 auto;
}
.scanner-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  background: var(--accent);
  border-radius: 50%;
  animation: scanner-dot 1.8s ease-in-out infinite;
  box-shadow: 0 0 12px rgba(45, 95, 93, 0.25);
}
.scanner-ring {
  position: absolute;
  inset: 0;
  border: 1.5px solid var(--gold);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.2);
  animation: scanner-ring 2.8s cubic-bezier(0.22, 0.61, 0.36, 1) infinite;
  pointer-events: none;
}
@keyframes scanner-dot {
  0%, 100% {
    transform: scale(1);
    background: var(--accent);
    box-shadow: 0 0 14px rgba(45, 95, 93, 0.3);
  }
  50% {
    transform: scale(1.2);
    background: var(--gold);
    box-shadow: 0 0 20px rgba(184, 147, 90, 0.45);
  }
}
@keyframes scanner-ring {
  0%   { transform: scale(0.18); opacity: 0;   border-color: var(--accent); border-width: 1.5px; }
  10%  { opacity: 0.7; }
  50%  { border-color: var(--gold); }
  100% { transform: scale(1);    opacity: 0;   border-color: var(--gold);   border-width: 0.5px; }
}

/* Reduce motion preference — show static dot only */
@media (prefers-reduced-motion: reduce) {
  .scanner-ring { animation: none; opacity: 0; }
  .scanner-dot  { animation: none; }
}

/* ─── Edited parameter note ────────────────────────────────────────────── */

.param-edited-note {
  font-size: 0.72rem;
  color: var(--gold-dark);
  margin-top: 0.4rem;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  line-height: 1.4;
}
.param-edited-note::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: var(--radius-full);
  background: var(--gold);
  flex-shrink: 0;
}

/* ─── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 1.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg-card);
  padding: 0.75rem 1.4rem;
  font-size: 0.9rem;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* ─── Rules (subtle) ───────────────────────────────────────────────────── */

.rule { border-top: 1px solid var(--rule); }
.rule-thick { border-top: 1px solid var(--rule); }

/* ─── Details/summary polish ───────────────────────────────────────────── */

details > summary {
  list-style: none;
  cursor: pointer;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: "›";
  display: inline-block;
  width: 1em;
  color: var(--muted);
  transition: transform 0.15s ease;
  font-weight: 600;
}
details[open] > summary::before {
  transform: rotate(90deg);
}

/* ─── Disease info modal ───────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2.5rem 1rem;
  overflow-y: auto;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-panel {
  position: relative;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: 2.25rem 2.5rem;
  max-width: 720px;
  width: 100%;
  box-shadow: var(--shadow-emphasis);
  animation: modal-in 0.2s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 640px) {
  .modal { padding: 1rem; }
  .modal-panel { padding: 1.5rem; border-radius: var(--radius-xl); }
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.modal-close:hover { background: var(--rule-soft); color: var(--ink); }

.modal-body {
  margin-top: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.65;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 0.5rem;
}
.modal-body h1, .modal-body h2, .modal-body h3, .modal-body h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  letter-spacing: 0;
}
.modal-body h1 { font-size: 1.5rem; }
.modal-body h2 { font-size: 1.25rem; padding-top: 0.5rem; border-top: 1px solid var(--rule-soft); }
.modal-body h2:first-child { border-top: none; padding-top: 0; }
.modal-body h3 {
  font-size: 0.75rem;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.modal-body p { margin-bottom: 0.65rem; }
.modal-body strong { font-weight: 600; }
.modal-body em { font-style: italic; color: var(--ink-soft); }
.modal-body ul, .modal-body ol {
  margin-left: 1.25rem;
  margin-bottom: 0.75rem;
  padding-left: 0.25rem;
}
.modal-body li { margin-bottom: 0.3rem; }
.modal-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.85rem;
}
.modal-body th, .modal-body td {
  border: 1px solid var(--rule);
  padding: 0.55rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.modal-body th { background: var(--bg-elev); font-weight: 600; }
.modal-body code {
  background: var(--bg-elev);
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius-sm);
  padding: 0.05rem 0.3rem;
  font-size: 0.85em;
}

.modal-references {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.modal-references-heading {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.85rem;
}
.modal-ref-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.modal-ref {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: var(--bg-elev);
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.modal-ref:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.modal-ref-text { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.modal-ref-title { font-weight: 500; font-size: 0.9rem; }
.modal-ref-source { font-size: 0.72rem; color: var(--muted); }
.modal-ref-arrow { color: var(--gold); font-size: 1rem; flex-shrink: 0; }

/* Inline credibility row in the diagnosis section. Always visible, no click
   required to see institutional sources. Visual treatment: small uppercase
   label + dot-separated institution links + "full info" button at the end. */
.dx-refs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 0.85rem;
  background: var(--bg-elev);
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
  font-size: 0.78rem;
}
.dx-refs-label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-right: 0.25rem;
}
.dx-refs-sep {
  color: var(--muted-soft);
  user-select: none;
}
.dx-refs-link {
  color: var(--gold-dark);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  font-weight: 500;
  transition: color 0.15s ease, text-decoration-style 0.15s ease;
}
.dx-refs-link:hover {
  color: var(--accent);
  text-decoration-style: solid;
}
.dx-refs-full {
  background: none;
  border: none;
  padding: 0;
  margin-left: auto;
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 500;
  transition: color 0.15s ease;
}
.dx-refs-full:hover { color: var(--accent-hover); }

/* Audit log status badges — small, scannable, color-coded */
.audit-status {
  display: inline-block;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  margin-right: 0.5rem;
  vertical-align: middle;
}
.audit-status-analyzed  { background: var(--accent-soft); color: var(--accent); }
.audit-status-edited    { background: var(--gold-soft);   color: var(--gold-dark); }
.audit-status-completed { background: var(--ok-soft);     color: var(--ok); }

/* Make the diagnosis primary text look clickable */
.dx-clickable {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  text-align: left;
  border-bottom: 1px dashed var(--gold);
  padding-bottom: 0.1rem;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.dx-clickable:hover {
  color: var(--gold-dark);
  border-bottom-color: var(--gold-dark);
}

/* ─── Photo strip (multi-photo upload thumbnails) ──────────────────────── */

.photo-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--rule-soft);
  box-shadow: var(--shadow-sm);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.2rem 0.4rem;
  background: linear-gradient(to top, rgba(28,25,23,0.65), transparent);
  color: #fff;
  font-size: 0.62rem;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
}
.photo-thumb-remove {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: var(--radius-full);
  background: rgba(28,25,23,0.7);
  color: #fff;
  border: none;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}
.photo-thumb-remove:hover {
  background: var(--danger);
  transform: scale(1.05);
}

/* Pre-flight quality warning badge — amber "!" on flagged thumbnails. */
.photo-thumb-warning {
  position: absolute;
  top: 0.3rem;
  left: 0.3rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: var(--radius-full, 9999px);
  background: #d97706;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
}

/* Per-photo modality selector — bottom of the thumbnail, above the caption. */
.photo-thumb-modality {
  position: absolute;
  bottom: 1.5rem;
  left: 0.3rem;
  right: 0.3rem;
  max-width: calc(100% - 0.6rem);
  font-size: 0.62rem;
  padding: 0.1rem 0.2rem;
  border: none;
  border-radius: var(--radius-sm, 4px);
  background: rgba(28,25,23,0.78);
  color: #fff;
  cursor: pointer;
  pointer-events: auto;
}


/* ─── Device picker (available laser library) ──────────────────────────── */

.device-picker {
  background: var(--bg-elev);
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem 0.7rem;
}
.device-picker-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  flex-wrap: wrap;
}
.device-picker-header .label-text { margin-bottom: 0; }
.device-picker-presets {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.chip {
  background: transparent;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
}
.chip:hover {
  border-color: var(--color-accent-primary);
  color: var(--color-accent-primary);
}
.chip.active {
  background: var(--color-accent-primary);
  color: var(--color-bg-primary);
  border-color: var(--color-accent-primary);
}
:root[data-theme="light"] .chip.active {
  color: #FFFFFF;
}
.device-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.25rem 0.85rem;
}
@media (max-width: 480px) { .device-grid { grid-template-columns: 1fr; } }
.device-checkbox {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  padding: 0.18rem 0;
  cursor: pointer;
  user-select: none;
}
.device-checkbox input[type="checkbox"] {
  width: 0.95rem;
  height: 0.95rem;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.device-checkbox .device-clinic {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin-left: 0.3rem;
}
.device-picker-summary {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.5rem;
  font-style: italic;
}

[hidden] { display: none !important; }

/* ─── Print ────────────────────────────────────────────────────────────── */

@media print {
  @page { margin: 12mm; size: A4; }
  body { background: #fff; color: #000; font-size: 11pt; font-family: var(--font-serif); line-height: 1.4; }
  .no-print { display: none !important; }
  a[href]:after { content: ""; }
  h1, h2, h3 { page-break-after: avoid; }
  section { page-break-inside: avoid; }
  .card, .hero { box-shadow: none !important; border: 1px solid #999 !important; background: #fff !important; }
  .section-divider { border-bottom: 1px solid #999 !important; }
  .section-number, .section-title { color: #000 !important; }
  .badge {
    border: 1px solid #000 !important;
    background: transparent !important;
    color: #000 !important;
  }
  .callout, .block-warn, .block-danger, .block-info, .callout-warning, .callout-critical, .callout-success, .callout-info {
    background: transparent !important;
    border: 1px solid #999 !important;
    border-left: 3px solid #000 !important;
    box-shadow: none !important;
    page-break-inside: avoid;
  }
  .parameter-block {
    background: #f5f5f5 !important;
    border: 1px solid #999 !important;
    page-break-inside: avoid;
  }
  .parameter-value {
    background: transparent !important;
  }
  /* ROI overlays must print with the photo — force visible solid borders. */
  .roi-overlay, .roi-box, .roi-label, .roi-svg, .roi-poly { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .roi-box { background: transparent !important; box-shadow: none !important; }
  .roi-benign     { border-color: #0a6b73 !important; }
  .roi-monitor    { border-color: #b45309 !important; }
  .roi-suspicious { border-color: #b00020 !important; }
  .roi-poly { fill: transparent !important; }
  .roi-poly.roi-benign     { stroke: #0a6b73 !important; }
  .roi-poly.roi-monitor    { stroke: #b45309 !important; }
  .roi-poly.roi-suspicious { stroke: #b00020 !important; }
  .roi-label { color: #fff !important; }
  .roi-label-benign     { background: #0a6b73 !important; }
  .roi-label-monitor    { background: #b45309 !important; }
  .roi-label-suspicious { background: #b00020 !important; }
  details { display: block; }
  details > summary::before { display: none; }
  details > *:not(summary) { display: block !important; }
}

/* ─── Patient handout (on-screen preview + print-only layout) ─────────────── */

.patient-handout {
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  margin-top: var(--space-2);
  font-family: var(--font-serif);
  line-height: 1.6;
}
.handout-lead {
  font-family: var(--font-serif);
  font-size: 17px;
  font-style: italic;
  line-height: 1.5;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-subtle);
}
.handout-subhead {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  color: var(--color-text-primary);
}
.handout-list {
  margin: 0;
  padding-left: 1.25rem;
}
.handout-list li {
  margin-bottom: 4px;
  font-size: 14px;
}
.handout-list-warning li {
  color: var(--color-critical);
  font-weight: 500;
}
.handout-meds {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-2);
}
.handout-med {
  border-left: 3px solid var(--color-accent-primary);
  background: var(--color-bg-secondary);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-default);
}
.handout-med-name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0;
  margin-bottom: 4px;
}
.handout-med-row {
  font-size: 13.5px;
  line-height: 1.5;
  margin-bottom: 2px;
}
.handout-med-warning {
  font-size: 13px;
  margin-top: 4px;
  color: var(--color-warning);
  font-style: italic;
}
.handout-next {
  font-size: 14px;
}
.handout-footer {
  margin-top: var(--space-6);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--color-border-default);
  font-size: 12px;
  color: var(--color-text-tertiary);
  font-style: italic;
}
.handout-footer-line { margin-bottom: 2px; }

/* ─── Print-only mode: body.printing-handout hides everything except the
       .patient-handout block. Multi-page-printing-friendly: hides via
       display:none on siblings rather than absolute-positioning the
       handout, so long content paginates naturally. ─────────────────── */
@media print {
  body.printing-handout {
    background: #fff;
    /* Override the three-column shell — patient handout is a flowing
       document, not the physician's multi-region UI. */
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }
  /* Hide everything by default, then explicitly un-hide the handout chain. */
  body.printing-handout .app-header,
  body.printing-handout .sidebar,
  body.printing-handout .audit-peek,
  body.printing-handout .app-footer,
  body.printing-handout .toast,
  body.printing-handout .modal,
  body.printing-handout #config-banner,
  body.printing-handout #view-landing,
  body.printing-handout #view-loading,
  body.printing-handout #view-audit-log,
  body.printing-handout .no-print {
    display: none !important;
  }
  /* Hide every section in the result view except the one containing the
     patient handout. The handout-bearing section keeps its card chrome
     stripped so the printed page looks like a clean handout, not a card. */
  body.printing-handout #view-result > #result-container > section:not(:has(.patient-handout)),
  body.printing-handout #view-result > #result-container > .callout,
  body.printing-handout #view-result > .card {
    display: none !important;
  }
  body.printing-handout #view-result > #result-container > section:has(.patient-handout) {
    border: none !important;
    box-shadow: none !important;
    background: #fff !important;
    padding: 0 !important;
  }
  body.printing-handout #view-result > #result-container > section:has(.patient-handout) > .section-divider {
    display: none !important;
  }
  body.printing-handout .patient-handout {
    border: none !important;
    background: #fff !important;
    padding: 0 !important;
    font-size: 12pt;
  }
  body.printing-handout .handout-lead {
    font-size: 14pt;
    margin-bottom: 18pt;
    padding-bottom: 10pt;
    border-bottom: 1px solid #999;
  }
  body.printing-handout .handout-subhead {
    font-size: 13pt;
    margin-top: 14pt;
    margin-bottom: 6pt;
  }
  body.printing-handout .handout-med {
    background: #f7f7f7 !important;
    border-left: 3px solid #000 !important;
    page-break-inside: avoid;
  }
  body.printing-handout .handout-list-warning li {
    color: #000 !important;
    font-weight: 600;
  }
  body.printing-handout .handout-footer {
    border-top: 1px solid #999;
    color: #555;
  }
}

/* ─── Tag chips (checkbox-style for history / contraindications) ──────────
   Used in the sidebar form to surface common clinical items as toggleable
   chips above the free-text textarea. Composed into the field value at
   form-read time via readContext(). */
.tag-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 4px 0 6px;
}
.tag-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: var(--color-text-secondary);
  user-select: none;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.tag-chip:hover {
  border-color: var(--color-accent-primary);
  color: var(--color-accent-primary);
}
.tag-chip input[type="checkbox"] {
  /* Hide native checkbox — the chip itself is the visual control */
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.tag-chip:has(input[type="checkbox"]:checked) {
  background: var(--color-accent-primary);
  border-color: var(--color-accent-primary);
  color: var(--color-bg-primary);
}
:root[data-theme="light"] .tag-chip:has(input[type="checkbox"]:checked) {
  color: #FFFFFF;
}
.tag-chip:has(input[type="checkbox"]:focus-visible) {
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

/* ─── Analyze CTA — primary action on the landing view ──────────────────────
   Sized up so it reads as the obvious next step after photo upload, not as
   a peer with the small audit-log text link. */
.analyze-cta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border-subtle);
}
.btn-primary.analyze-cta {
  font-size: 16px;
  font-weight: 600;
  padding: 14px 36px;
  min-width: 180px;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-default);
}
.btn-primary.analyze-cta:hover {
  box-shadow: var(--shadow-emphasis);
}

/* ─── Auth gate (login screen) ──────────────────────────────────────────────
   Shown when body.requires-auth is set. Hides the entire app shell + every
   side panel — a centered card on the canvas. */

body.app-shell-host.requires-auth .app-header,
body.app-shell-host.requires-auth .app-shell,
body.app-shell-host.requires-auth .app-footer,
body.app-shell-host.requires-auth .toast,
body.app-shell-host.requires-auth .modal,
body.app-shell-host.requires-auth .sidebar-backdrop {
  display: none !important;
}
body.app-shell-host.requires-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: auto;
  overflow: auto;
  padding: var(--space-6);
}
.auth-view {
  width: 100%;
  max-width: 460px;
}
.auth-card {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-default);
  border-top: 2px solid var(--color-accent-primary);
  border-radius: var(--radius-md);
  padding: var(--space-8) var(--space-6) var(--space-6);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: var(--space-2);
}
.brand-mark-text {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--color-text-primary);
}
.auth-tagline {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-6);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field .label-text {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin: 0;
}
.auth-field input {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.01em;
  padding: 12px 14px;
  background: var(--color-bg-primary);
}
.auth-submit {
  width: 100%;
  padding: 14px 20px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.auth-message {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-default);
  margin: 0;
}
.auth-message-ok {
  color: var(--color-success);
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
}
.auth-message-error {
  color: var(--color-critical);
  background: var(--color-critical-bg);
  border-color: var(--color-critical-border);
}
.auth-footer {
  line-height: 1.6;
  padding-top: var(--space-4);
  border-top: 1px dashed var(--color-border-subtle);
}

/* ─── Three-column app shell (Design System v1.0) ──────────────────────────
   Sidebar (280 px patient context) | Main (fluid, view router) | Audit peek
   (320 px recent entries / agent panel). Scoped to body.app-shell-host so
   the test harness, which omits that class, renders single-column. */

body.app-shell-host {
  display: flex;
  flex-direction: column;
  height: 100vh;        /* fixed so inner flex children can flex-fill */
  min-height: 100vh;
  margin: 0;
  overflow: hidden;     /* outer page doesn't scroll; inner columns do */
}
body.app-shell-host .app-header {
  background: var(--color-bg-primary);
  border-bottom: 1px solid var(--color-border-default);
  padding: var(--space-3) var(--space-6);
}
body.app-shell-host .app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  max-width: 1600px;
  margin: 0 auto;
}
body.app-shell-host .app-header h1 {
  margin: 0;
  line-height: 1.2;
}
.brand-mark {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--color-text-primary);
}
.brand-glyph {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: var(--color-accent-primary);
  border-radius: 2px;
  box-shadow: 0 0 12px var(--color-accent-primary);
  transform: translateY(-1px);
}
.brand-version {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--color-text-tertiary);
  text-transform: lowercase;
}
.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.header-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-default);
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}
.header-text-btn { text-transform: uppercase; }
.header-icon-btn:hover {
  border-color: var(--color-accent-primary);
  color: var(--color-accent-primary);
  background: var(--color-bg-secondary);
}
.theme-toggle-glyph {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  box-shadow: inset -4px 0 0 0 var(--color-bg-primary);
  transition: transform var(--transition-default), box-shadow var(--transition-fast);
}
:root[data-theme="light"] .theme-toggle-glyph {
  box-shadow: inset 4px 0 0 0 var(--color-bg-primary);
}
.header-icon-btn:hover .theme-toggle-glyph {
  background: var(--color-accent-primary);
}
body.app-shell-host .app-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  align-items: stretch;
  min-height: 0;
}
body.app-shell-host .sidebar,
body.app-shell-host .audit-peek,
body.app-shell-host .main-column {
  min-width: 0;
  min-height: 0;
}
body.app-shell-host .sidebar {
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border-default);
  padding: var(--space-5);
  overflow-y: auto;     /* sidebar scrolls if form is taller than viewport */
}
body.app-shell-host .main-column {
  background: var(--color-bg-primary);
  padding: var(--space-6);
  overflow-y: auto;     /* main column scrolls independently */
}
body.app-shell-host .audit-peek {
  background: var(--color-bg-secondary);
  border-left: 1px solid var(--color-border-default);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  /* No overflow on the peek itself — the agent panel inside owns its own
     scroll region (the messages list), and the recent-list is short. */
  overflow: hidden;
}
/* During result view the agent slot owns the full peek height. The card
   stretches edge-to-edge; messages scroll internally; input pinned bottom. */
body.app-shell-host[data-view="result"] .audit-peek-agent {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.app-shell-host[data-view="result"] .audit-peek-agent #agent-panel-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.app-shell-host[data-view="result"] .audit-peek-agent .agent-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-height: none;
  overflow: hidden;
}
body.app-shell-host[data-view="result"] .audit-peek-agent .agent-messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}
/* Recent-consultations list (shown on landing/loading) gets its own scroll
   so a long history doesn't push the peek-header off-screen. */
body.app-shell-host .audit-peek-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Sidebar form layout — tight, single-column inside 280 px */
body.app-shell-host .sidebar-section-title {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border-subtle);
}
body.app-shell-host .sidebar-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
body.app-shell-host .sidebar-form .field { margin-bottom: 0; }
body.app-shell-host .sidebar-form textarea { min-height: 2.75rem; }
body.app-shell-host .sidebar-section {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border-subtle);
}
body.app-shell-host .sidebar .device-grid {
  grid-template-columns: 1fr;
}
body.app-shell-host .sidebar .device-picker-presets {
  flex-wrap: wrap;
  gap: 4px;
}

/* Audit peek — agent panel and recent list mutually exclusive by view.
   Note: `display: flex` (not block) so child flex-grow chain works for the
   full-height agent panel. */
body.app-shell-host .audit-peek-agent { display: none; }
body.app-shell-host[data-view="result"] .audit-peek-agent { display: flex; }
body.app-shell-host[data-view="result"] .audit-peek-list { display: none; }
body.app-shell-host[data-view="auditLog"] .audit-peek { display: none; }
body.app-shell-host .audit-peek-header {
  margin-bottom: var(--space-3);
}
body.app-shell-host .audit-peek-list-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Footer below the grid */
body.app-shell-host .app-footer {
  border-top: 1px solid var(--color-border-default);
  padding: var(--space-3) var(--space-6);
  font-size: 12px;
  text-align: center;
}

/* Responsive collapse per Design System v1.0 breakpoints */
@media (min-width: 1024px) {
  body.app-shell-host .app-shell {
    grid-template-columns: 280px minmax(0, 1fr) 360px;
  }
  /* On the result view the third column hosts the Dermatoscan Agent chat,
     which warrants real estate for the conversation. Switch to a 1:1 split
     between result content and agent so chat has room to breathe. */
  body.app-shell-host[data-view="result"] .app-shell {
    grid-template-columns: 280px minmax(0, 1fr) minmax(0, 1fr);
  }
}
@media (max-width: 1023px) {
  /* Narrow viewports: let the whole page scroll naturally as content stacks. */
  body.app-shell-host {
    height: auto;
    overflow: auto;
  }
  body.app-shell-host .sidebar,
  body.app-shell-host .main-column,
  body.app-shell-host .audit-peek {
    overflow: visible;
  }
  /* Two-column: sidebar + main; audit-peek wraps to a third row below main. */
  body.app-shell-host .app-shell {
    grid-template-columns: 260px minmax(0, 1fr);
    grid-template-areas:
      "sidebar main"
      "peek    peek";
  }
  body.app-shell-host .sidebar { grid-area: sidebar; }
  body.app-shell-host .main-column { grid-area: main; }
  body.app-shell-host .audit-peek {
    grid-area: peek;
    border-left: none;
    border-top: 1px solid var(--color-border-default);
  }
}
@media (max-width: 767px) {
  /* Mobile: main column owns the full width; sidebar becomes a slide-in
     drawer (toggled by hamburger). Audit-peek stacks below main. */
  body.app-shell-host .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "main"
      "peek";
  }
  body.app-shell-host .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 86%;
    max-width: 360px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--transition-default);
    border-right: 1px solid var(--color-border-default);
    border-bottom: none;
    box-shadow: var(--shadow-emphasis);
  }
  body.app-shell-host.sidebar-open .sidebar { transform: translateX(0); }
  body.app-shell-host .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 29, 26, 0.45);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-default);
  }
  body.app-shell-host.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  body.app-shell-host .app-header { position: sticky; top: 0; z-index: 30; }

  /* Tighten main padding for phone */
  body.app-shell-host .main-column { padding: var(--space-4); }
  body.app-shell-host .audit-peek { padding: var(--space-4); }

  /* Drawer-style header tweaks */
  body.app-shell-host .app-header-title h1 { font-size: 1.25rem; }
  body.app-shell-host .app-header-title p { display: none; }

  /* 44px minimum tap targets on phones */
  .btn-primary, .btn-ghost, .chip, .tag-chip { min-height: 44px; }
  .btn-primary.analyze-cta { min-height: 52px; font-size: 17px; }
}

/* Hamburger toggle — hidden on desktop, shown on mobile. */
.sidebar-toggle {
  display: none;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 10px;
  margin-right: var(--space-2);
  flex-direction: column;
  justify-content: space-around;
  align-items: stretch;
}
.sidebar-toggle-bar {
  display: block;
  height: 2px;
  background: var(--color-text-primary);
  border-radius: 2px;
}
@media (max-width: 1023px) {
  .sidebar-toggle { display: flex; }
}
.sidebar-backdrop { display: none; }
@media (max-width: 767px) {
  .sidebar-backdrop { display: block; }
}
/* Tablet width: sidebar is a normal column but the hamburger also closes/opens
   it for ergonomic single-handed use. */
@media (min-width: 768px) and (max-width: 1023px) {
  body.app-shell-host .sidebar { transition: none; }
}

body.app-shell-host .app-header-title { flex: 1; min-width: 0; }
body.app-shell-host .app-header-title h1 { line-height: 1.2; }

/* The test harness body has no `app-shell-host` class — its content sits in
   a single column at sensible width. Constrain the overall main wrapper. */
body:not(.app-shell-host) > * { max-width: 1200px; margin-left: auto; margin-right: auto; }

/* ─── Parameter block (Design System v1.0) ─────────────────────────────────
   Structured key-value rows for laser parameters (fluence, spot, Hz, pulse).
   Mono tabular values, accent border-left, used by sectionPrimaryProtocol. */

/* Parameter block — terminal-style readout. Dark inset surface, cyan
   left-rule, mono values with tabular numerals, hairline row dividers. */
.parameter-block {
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-default);
  border-left: 2px solid var(--color-accent-primary);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 0;
  font-family: var(--font-mono);
}
:root[data-theme="light"] .parameter-block {
  background: var(--color-bg-secondary);
}
.parameter-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border-subtle);
}
.parameter-row:last-child { border-bottom: none; }
.parameter-row-edited {
  position: relative;
  margin-left: -2px;
  padding-left: 6px;
  border-left: 2px solid var(--color-warning);
}
.parameter-label {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
  color: var(--color-text-tertiary);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.parameter-value {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-accent-primary);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
  cursor: text;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
  word-break: break-word;
  min-width: 0;
}
.parameter-value:hover,
.parameter-value:focus-within {
  background: var(--color-bg-tertiary);
  outline: none;
}
.parameter-value input,
.parameter-value textarea {
  /* Input inside a .parameter-value cell: strip chrome so it reads as
     display text by default; chrome appears on hover/focus via the parent. */
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  text-align: inherit;
  line-height: inherit;
  font-variant-numeric: inherit;
  resize: vertical;
}
.parameter-value input:focus,
.parameter-value textarea:focus {
  outline: none;
  box-shadow: none;
}
.parameter-value-empty {
  color: var(--color-text-disabled);
  font-style: italic;
}
.parameter-edit-note {
  font-family: var(--font-sans);
  font-size: 11px;
  line-height: 1.4;
  color: var(--color-warning);
  margin-top: 2px;
  font-style: italic;
}
.parameter-headline {
  font-family: var(--font-serif);
  font-size: 16px;
  font-style: italic;
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: var(--space-3);
  letter-spacing: 0;
}
.parameter-row-wide {
  flex-direction: column;
  align-items: stretch;
}
.parameter-row-wide .parameter-label {
  margin-bottom: 2px;
}
.parameter-row-wide .parameter-value {
  text-align: left;
  display: block;
  width: 100%;
}
.parameter-row-wide .parameter-value textarea {
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  resize: none;
}
.parameter-edit-marker {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-warning);
  margin-left: 6px;
  vertical-align: middle;
}

/* ─── Result-view layout (results + sticky agent panel) ──────────────────── */
.result-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}
.result-main { min-width: 0; } /* prevents grid blowout on long content */
.result-aside { min-width: 0; }

@media (min-width: 1024px) {
  .result-layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(420px, 1fr);
    gap: 1.5rem;
  }
  .result-aside {
    position: sticky;
    top: 1.25rem;
    align-self: start;
    /* Constrain to viewport so the chat card scrolls internally, not the
       whole sticky column. */
    max-height: calc(100vh - 2.5rem);
  }
  .result-aside .agent-panel {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 2.5rem);
    /* Leave some bottom breathing room when content is short. */
    overflow: hidden;
  }
  .result-aside .agent-messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }
}

/* When printing we hide the aside via .no-print, but ensure the main column
   takes full width if the print stylesheet ever changes. */
@media print {
  .result-layout { display: block; }
}

/* ─── Agent mode chat ─────────────────────────────────────────────────────── */
.agent-panel {
  /* Reuse .card padding/border/shadow via class composition in markup. */
}
.agent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.agent-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.agent-badge {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--color-warning-bg);
  color: var(--color-warning);
  font-weight: 600;
}
.agent-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.35rem;
}
.agent-messages {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 1rem 0 0.75rem;
  max-height: 520px;
  overflow-y: auto;
  padding: 0.25rem;
}
.agent-empty {
  text-align: center;
  font-style: italic;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 1.25rem 1rem;
  border: 1px dashed var(--rule-soft);
  border-radius: var(--radius-md);
  line-height: 1.55;
}
.agent-message {
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-md);
  font-size: 0.94rem;
  line-height: 1.55;
  max-width: 92%;
  word-wrap: break-word;
}
.agent-message-user {
  align-self: flex-end;
  background: var(--color-accent-subtle);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-emphasis);
  white-space: pre-wrap;
}
.agent-message-assistant {
  align-self: flex-start;
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-subtle);
}
.agent-message-assistant > *:first-child { margin-top: 0; }
.agent-message-assistant > *:last-child { margin-bottom: 0; }
.agent-message-assistant p { margin: 0 0 0.55rem; }
.agent-message-assistant ul,
.agent-message-assistant ol {
  margin: 0.4rem 0 0.55rem 1.25rem;
  padding: 0;
}
.agent-message-assistant li { margin-bottom: 0.25rem; }
.agent-message-assistant strong { font-weight: 600; }
.agent-message-assistant em { font-style: italic; color: var(--ink-soft); }
.agent-message-assistant code {
  background: var(--color-bg-tertiary);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  font-size: 0.85em;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.agent-message-assistant h1,
.agent-message-assistant h2,
.agent-message-assistant h3,
.agent-message-assistant h4 {
  font-family: var(--font-serif);
  margin: 0.6rem 0 0.4rem;
  font-weight: 600;
}
.agent-message-assistant h3 { font-size: 1.05rem; }
.agent-message-assistant h4 { font-size: 0.98rem; }
.agent-message-loading {
  color: var(--muted);
  font-style: italic;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.agent-message-loading::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-accent-primary);
  animation: agent-pulse 1.2s ease-in-out infinite;
}
@keyframes agent-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
.agent-form {
  display: flex;
  gap: 0.55rem;
  align-items: stretch;
  margin-top: 0.5rem;
}
.agent-form textarea {
  flex: 1;
  resize: vertical;
  min-height: 5.25rem;
  max-height: 14rem;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  padding: 0.65rem 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  color: var(--ink);
}
.agent-form textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.agent-form .btn-primary {
  flex-shrink: 0;
  align-self: stretch;
  /* Keep send button proportional to the taller textarea — fixed width so it
     reads as a button rather than a giant pill. */
  min-width: 4.5rem;
  padding-left: 1.1rem;
  padding-right: 1.1rem;
}
.agent-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.55rem;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.agent-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
@media (max-width: 540px) {
  .agent-form { flex-direction: column; }
  .agent-form .btn-primary { width: 100%; }
}

/* ─── Apple Clinical Polish ────────────────────────────────────────────────
   Final-layer refinements keep the existing app structure intact while
   changing the feel: softer graphite type, SF-style system typography,
   translucent side rails, flatter controls, and calmer information density. */

:root,
:root[data-theme="light"] {
  --color-bg-primary: #F5F5F7;
  --color-bg-secondary: rgba(255, 255, 255, 0.78);
  --color-bg-tertiary: #ECECF1;

  --color-text-primary: #1D1D1F;
  --color-text-secondary: #515154;
  --color-text-tertiary: #86868B;
  --color-text-disabled: #B7B7BD;

  --color-border-default: rgba(0, 0, 0, 0.10);
  --color-border-emphasis: rgba(0, 0, 0, 0.18);
  --color-border-subtle: rgba(0, 0, 0, 0.065);

  --color-accent-primary: #007AFF;
  --color-accent-hover: #0A84FF;
  --color-accent-active: #006EDB;
  --color-accent-subtle: rgba(0, 122, 255, 0.10);
  --color-accent-emphasis: #003E7E;

  --color-critical: #D70015;
  --color-critical-bg: rgba(255, 59, 48, 0.10);
  --color-critical-border: rgba(215, 0, 21, 0.22);
  --color-warning: #B25A00;
  --color-warning-bg: rgba(255, 149, 0, 0.12);
  --color-warning-border: rgba(178, 90, 0, 0.20);
  --color-success: #248A3D;
  --color-success-bg: rgba(52, 199, 89, 0.12);
  --color-success-border: rgba(36, 138, 61, 0.20);
  --color-info: #006EDB;
  --color-info-bg: rgba(0, 122, 255, 0.10);
  --color-info-border: rgba(0, 110, 219, 0.20);

  --font-serif: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Pretendard", "Apple SD Gothic Neo", sans-serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Pretendard", "Apple SD Gothic Neo", sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Pretendard", "Apple SD Gothic Neo", sans-serif;
  --font-mono: "SF Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-default: 8px;
  --radius-md: 8px;
  --radius-lg: 8px;
  --radius-xl: 8px;
  --radius-2xl: 8px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-default: 0 14px 34px rgba(0, 0, 0, 0.08), 0 1px 0 rgba(255, 255, 255, 0.65) inset;
  --shadow-emphasis: 0 24px 60px rgba(0, 0, 0, 0.14), 0 1px 0 rgba(255, 255, 255, 0.75) inset;
  --glow-accent: 0 0 0 4px rgba(0, 122, 255, 0.14);

  --bg: var(--color-bg-primary);
  --bg-card: #FFFFFF;
  --bg-elev: rgba(255, 255, 255, 0.64);
  --ink: var(--color-text-primary);
  --ink-soft: var(--color-text-secondary);
  --muted: var(--color-text-tertiary);
  --muted-soft: var(--color-text-disabled);
  --rule: var(--color-border-default);
  --rule-soft: var(--color-border-subtle);
  --accent: var(--color-accent-primary);
  --accent-hover: var(--color-accent-hover);
  --accent-soft: var(--color-accent-subtle);
  --gold: var(--color-warning);
  --gold-dark: var(--color-warning);
  --gold-soft: var(--color-warning-bg);
  --ok: var(--color-success);
  --ok-soft: var(--color-success-bg);
  --warn: var(--color-warning);
  --warn-soft: var(--color-warning-bg);
  --danger: var(--color-critical);
  --danger-soft: var(--color-critical-bg);
}

:root[data-theme="dark"] {
  --color-bg-primary: #101012;
  --color-bg-secondary: rgba(30, 30, 32, 0.78);
  --color-bg-tertiary: #2C2C2E;

  --color-text-primary: #F5F5F7;
  --color-text-secondary: #D1D1D6;
  --color-text-tertiary: #8E8E93;
  --color-text-disabled: #636366;

  --color-border-default: rgba(255, 255, 255, 0.12);
  --color-border-emphasis: rgba(255, 255, 255, 0.20);
  --color-border-subtle: rgba(255, 255, 255, 0.08);

  --color-accent-primary: #0A84FF;
  --color-accent-hover: #409CFF;
  --color-accent-active: #007AFF;
  --color-accent-subtle: rgba(10, 132, 255, 0.16);
  --color-accent-emphasis: #D7ECFF;

  --color-critical: #FF453A;
  --color-critical-bg: rgba(255, 69, 58, 0.14);
  --color-critical-border: rgba(255, 69, 58, 0.28);
  --color-warning: #FFD60A;
  --color-warning-bg: rgba(255, 214, 10, 0.13);
  --color-warning-border: rgba(255, 214, 10, 0.25);
  --color-success: #30D158;
  --color-success-bg: rgba(48, 209, 88, 0.13);
  --color-success-border: rgba(48, 209, 88, 0.24);
  --color-info: #64D2FF;
  --color-info-bg: rgba(100, 210, 255, 0.13);
  --color-info-border: rgba(100, 210, 255, 0.24);

  --bg-card: rgba(38, 38, 40, 0.72);
  --bg-elev: rgba(44, 44, 46, 0.64);
  --shadow-default: 0 18px 44px rgba(0, 0, 0, 0.34), 0 1px 0 rgba(255, 255, 255, 0.08) inset;
  --shadow-emphasis: 0 30px 70px rgba(0, 0, 0, 0.44), 0 1px 0 rgba(255, 255, 255, 0.10) inset;
  --glow-accent: 0 0 0 4px rgba(10, 132, 255, 0.22);
}

* {
  letter-spacing: 0 !important;
}

html,
body {
  background:
    linear-gradient(180deg, #FFFFFF 0%, #F5F5F7 46%, #ECECF1 100%);
  color: var(--color-text-primary);
}

:root[data-theme="dark"] body {
  background:
    linear-gradient(180deg, #1C1C1E 0%, #101012 48%, #070708 100%);
}

body.app-shell-host .app-header,
body.app-shell-host .sidebar,
body.app-shell-host .audit-peek,
.card,
.hero,
.auth-card,
.modal-panel,
.agent-panel,
.device-picker {
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
}

body.app-shell-host .app-header {
  background: rgba(255, 255, 255, 0.76);
  border-bottom-color: rgba(0, 0, 0, 0.08);
  padding: 14px 28px;
}

:root[data-theme="dark"] body.app-shell-host .app-header {
  background: rgba(28, 28, 30, 0.72);
  border-bottom-color: rgba(255, 255, 255, 0.10);
}

body.app-shell-host .app-header-inner {
  max-width: 1720px;
}

.brand-mark {
  align-items: center;
  gap: 9px;
  font-size: 18px;
  font-weight: 650;
}

.brand-glyph {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: linear-gradient(135deg, #007AFF, #30D158);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.10);
}

.brand-version {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

.app-header-actions {
  gap: 8px;
}

.header-icon-btn,
.sidebar-toggle {
  background: rgba(255, 255, 255, 0.66);
  border-color: rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-default);
  color: var(--color-text-secondary);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.70) inset;
}

:root[data-theme="dark"] .header-icon-btn,
:root[data-theme="dark"] .sidebar-toggle {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.header-icon-btn:hover,
.sidebar-toggle:hover {
  background: rgba(0, 122, 255, 0.10);
  border-color: rgba(0, 122, 255, 0.20);
  color: var(--color-accent-primary);
}

body.app-shell-host .app-shell {
  max-width: 1720px;
}

body.app-shell-host .sidebar {
  background: rgba(255, 255, 255, 0.58);
  border-right-color: rgba(0, 0, 0, 0.08);
  padding: 26px 22px;
}

body.app-shell-host .main-column {
  background: transparent;
  padding: 30px;
}

body.app-shell-host .audit-peek {
  background: rgba(255, 255, 255, 0.58);
  border-left-color: rgba(0, 0, 0, 0.08);
  padding: 26px 22px;
}

:root[data-theme="dark"] body.app-shell-host .sidebar,
:root[data-theme="dark"] body.app-shell-host .audit-peek {
  background: rgba(28, 28, 30, 0.58);
  border-color: rgba(255, 255, 255, 0.10);
}

@media (min-width: 1024px) {
  body.app-shell-host .app-shell {
    grid-template-columns: 304px minmax(0, 1fr) 348px;
  }

  body.app-shell-host[data-view="result"] .app-shell {
    grid-template-columns: 304px minmax(0, 1.1fr) minmax(360px, 0.9fr);
  }
}

.card,
.hero,
.auth-card,
.modal-panel,
.device-picker,
.agent-panel {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-default);
  box-shadow: var(--shadow-default);
}

:root[data-theme="dark"] .card,
:root[data-theme="dark"] .hero,
:root[data-theme="dark"] .auth-card,
:root[data-theme="dark"] .modal-panel,
:root[data-theme="dark"] .device-picker,
:root[data-theme="dark"] .agent-panel {
  background: rgba(38, 38, 40, 0.72);
  border-color: rgba(255, 255, 255, 0.10);
}

.card {
  padding: 24px;
}

.hero {
  padding: 28px;
  border-top: 0;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, #007AFF, #30D158, #FFD60A);
}

.section-divider {
  margin: 30px 0 16px;
  border-bottom-color: rgba(0, 0, 0, 0.075);
}

:root[data-theme="dark"] .section-divider {
  border-bottom-color: rgba(255, 255, 255, 0.10);
}

.section-title,
body.app-shell-host .sidebar-section-title {
  font-weight: 650;
  color: var(--color-text-primary);
}

.section-number,
.parameter-label,
.label-text,
label.field > .label-text,
.auth-field .label-text {
  color: var(--color-text-tertiary);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 650;
  text-transform: none;
}

.badge,
.agent-badge,
.audit-status {
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-weight: 650;
}

input[type="text"],
input[type="number"],
input[type="email"],
textarea,
select,
.agent-form textarea {
  background: rgba(255, 255, 255, 0.86);
  border-color: rgba(0, 0, 0, 0.10);
  border-radius: var(--radius-default);
  color: var(--color-text-primary);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.78) inset;
}

:root[data-theme="dark"] input[type="text"],
:root[data-theme="dark"] input[type="number"],
:root[data-theme="dark"] input[type="email"],
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] select,
:root[data-theme="dark"] .agent-form textarea {
  background: rgba(58, 58, 60, 0.72);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
textarea:focus,
select:focus,
.agent-form textarea:focus {
  border-color: rgba(0, 122, 255, 0.48);
  box-shadow: var(--glow-accent);
}

.btn-primary {
  background: linear-gradient(180deg, #0A84FF 0%, #007AFF 100%);
  border: 0;
  border-radius: var(--radius-default);
  color: #FFFFFF;
  font-weight: 650;
  box-shadow: 0 12px 28px rgba(0, 122, 255, 0.24), 0 1px 0 rgba(255, 255, 255, 0.24) inset;
}

.btn-primary:hover {
  background: linear-gradient(180deg, #2994FF 0%, #0A84FF 100%);
  box-shadow: 0 16px 34px rgba(0, 122, 255, 0.30), var(--glow-accent);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-ghost,
.chip,
.tag-chip {
  background: rgba(255, 255, 255, 0.58);
  border-color: rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-default);
  color: var(--color-text-secondary);
}

:root[data-theme="dark"] .btn-ghost,
:root[data-theme="dark"] .chip,
:root[data-theme="dark"] .tag-chip {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.10);
}

.btn-ghost:hover,
.chip:hover,
.tag-chip:hover {
  background: var(--color-accent-subtle);
  border-color: rgba(0, 122, 255, 0.24);
  color: var(--color-accent-primary);
}

.chip.active,
.tag-chip:has(input[type="checkbox"]:checked) {
  background: #1D1D1F;
  border-color: #1D1D1F;
  color: #FFFFFF;
}

:root[data-theme="dark"] .chip.active,
:root[data-theme="dark"] .tag-chip:has(input[type="checkbox"]:checked) {
  background: #F5F5F7;
  border-color: #F5F5F7;
  color: #1D1D1F;
}

.dropzone {
  min-height: 260px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.66));
  border: 1.5px dashed rgba(0, 0, 0, 0.16);
  border-radius: var(--radius-default);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.80) inset;
}

:root[data-theme="dark"] .dropzone {
  background:
    linear-gradient(180deg, rgba(58, 58, 60, 0.72), rgba(44, 44, 46, 0.58));
  border-color: rgba(255, 255, 255, 0.18);
}

.dropzone:hover,
.dropzone.dragover {
  background: rgba(0, 122, 255, 0.10);
  border-color: rgba(0, 122, 255, 0.42);
  box-shadow: var(--glow-accent);
}

.analyze-cta-row {
  border-top-color: rgba(0, 0, 0, 0.07);
  justify-content: space-between;
}

.btn-primary.analyze-cta {
  min-width: 192px;
  padding: 15px 38px;
  font-size: 16px;
}

.device-picker {
  padding: 14px;
}

.device-grid {
  gap: 6px;
}

.device-checkbox {
  min-height: 30px;
  padding: 5px 6px;
  border-radius: var(--radius-default);
}

.device-checkbox:hover {
  background: rgba(0, 122, 255, 0.08);
}

.parameter-block {
  background: rgba(255, 255, 255, 0.62);
  border-color: rgba(0, 0, 0, 0.08);
  border-left: 0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.70) inset;
}

:root[data-theme="dark"] .parameter-block {
  background: rgba(28, 28, 30, 0.64);
  border-color: rgba(255, 255, 255, 0.10);
}

.parameter-value {
  color: var(--color-text-primary);
  font-weight: 600;
}

.photo-thumb {
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow-default);
}

.agent-messages {
  gap: 10px;
  padding: 4px 2px;
}

.agent-message {
  border-radius: var(--radius-default);
}

.agent-message-user {
  background: #007AFF;
  border-color: transparent;
  color: #FFFFFF;
}

.agent-message-assistant {
  background: rgba(255, 255, 255, 0.72);
  border-color: rgba(0, 0, 0, 0.07);
}

:root[data-theme="dark"] .agent-message-assistant {
  background: rgba(58, 58, 60, 0.64);
  border-color: rgba(255, 255, 255, 0.10);
}

.auth-card {
  box-shadow: var(--shadow-emphasis);
}

.auth-brand {
  justify-content: center;
}

.auth-tagline {
  text-align: center;
  text-transform: none;
}

.modal-backdrop {
  background: rgba(0, 0, 0, 0.34);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
}

.toast {
  background: rgba(29, 29, 31, 0.88);
  color: #FFFFFF;
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
}

@media (max-width: 767px) {
  body.app-shell-host .app-header {
    padding: 12px 16px;
  }

  body.app-shell-host .main-column,
  body.app-shell-host .audit-peek {
    padding: 18px;
  }

  body.app-shell-host .sidebar {
    background: rgba(255, 255, 255, 0.86);
  }

  :root[data-theme="dark"] body.app-shell-host .sidebar {
    background: rgba(28, 28, 30, 0.90);
  }

  .dropzone {
    min-height: 220px;
  }
}

/* ─── Executive Clinical Dashboard Polish ─────────────────────────────────
   Final visual pass for the production shell: clearer workspace hierarchy,
   quieter glass, sharper typography, and denser but calmer controls. */

:root,
:root[data-theme="light"] {
  --color-bg-primary: #F1F3F6;
  --color-bg-secondary: rgba(255, 255, 255, 0.82);
  --color-bg-tertiary: #E8EBF0;
  --color-text-primary: #171A1F;
  --color-text-secondary: #4B5563;
  --color-text-tertiary: #7C8490;
  --color-border-default: rgba(20, 28, 40, 0.11);
  --color-border-emphasis: rgba(20, 28, 40, 0.18);
  --color-border-subtle: rgba(20, 28, 40, 0.075);
  --color-accent-primary: #2563EB;
  --color-accent-hover: #1D4ED8;
  --color-accent-active: #1E40AF;
  --color-accent-subtle: rgba(37, 99, 235, 0.095);
  --shadow-sm: 0 1px 2px rgba(18, 24, 38, 0.04);
  --shadow-default:
    0 1px 0 rgba(255, 255, 255, 0.84) inset,
    0 1px 2px rgba(18, 24, 38, 0.045),
    0 14px 38px rgba(18, 24, 38, 0.075);
  --shadow-emphasis:
    0 1px 0 rgba(255, 255, 255, 0.88) inset,
    0 22px 64px rgba(18, 24, 38, 0.13);
  --glow-accent: 0 0 0 4px rgba(37, 99, 235, 0.14);
  --bg-card: rgba(255, 255, 255, 0.90);
  --bg-elev: rgba(255, 255, 255, 0.68);
}

:root[data-theme="dark"] {
  --color-bg-primary: #0D1117;
  --color-bg-secondary: rgba(22, 27, 34, 0.82);
  --color-bg-tertiary: #21262D;
  --color-text-primary: #F0F3F6;
  --color-text-secondary: #C6CDD5;
  --color-text-tertiary: #8B949E;
  --color-border-default: rgba(240, 246, 252, 0.12);
  --color-border-emphasis: rgba(240, 246, 252, 0.20);
  --color-border-subtle: rgba(240, 246, 252, 0.075);
  --color-accent-primary: #58A6FF;
  --color-accent-hover: #79C0FF;
  --color-accent-active: #388BFD;
  --color-accent-subtle: rgba(88, 166, 255, 0.14);
  --bg-card: rgba(22, 27, 34, 0.84);
  --bg-elev: rgba(33, 38, 45, 0.62);
  --shadow-default:
    0 1px 0 rgba(255, 255, 255, 0.055) inset,
    0 18px 48px rgba(0, 0, 0, 0.36);
  --shadow-emphasis:
    0 1px 0 rgba(255, 255, 255, 0.07) inset,
    0 28px 72px rgba(0, 0, 0, 0.48);
}

html,
body {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(241, 243, 246, 0.96)),
    repeating-linear-gradient(90deg, rgba(20, 28, 40, 0.028) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(180deg, rgba(20, 28, 40, 0.024) 0 1px, transparent 1px 28px);
}

:root[data-theme="dark"] body {
  background:
    linear-gradient(180deg, rgba(22, 27, 34, 0.96), rgba(13, 17, 23, 0.98)),
    repeating-linear-gradient(90deg, rgba(240, 246, 252, 0.025) 0 1px, transparent 1px 30px),
    repeating-linear-gradient(180deg, rgba(240, 246, 252, 0.022) 0 1px, transparent 1px 30px);
}

body.app-shell-host .app-header {
  min-height: 76px;
  background: rgba(255, 255, 255, 0.84);
  border-bottom-color: rgba(20, 28, 40, 0.085);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.86) inset, 0 12px 32px rgba(18, 24, 38, 0.045);
}

:root[data-theme="dark"] body.app-shell-host .app-header {
  background: rgba(13, 17, 23, 0.82);
  border-bottom-color: rgba(240, 246, 252, 0.10);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.055) inset, 0 16px 40px rgba(0, 0, 0, 0.28);
}

.brand-mark {
  font-size: 19px;
  font-weight: 760;
  color: var(--color-text-primary);
}

.brand-glyph {
  width: 12px;
  height: 12px;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.86), transparent 0 28%),
    linear-gradient(135deg, #2563EB 0%, #14B8A6 58%, #84CC16 100%);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10), 0 8px 18px rgba(20, 184, 166, 0.20);
}

body.app-shell-host .app-header-title p {
  color: var(--color-text-tertiary) !important;
  font-weight: 620;
}

.header-icon-btn,
.sidebar-toggle {
  min-width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.72);
  border-color: rgba(20, 28, 40, 0.095);
}

body.app-shell-host .sidebar,
body.app-shell-host .audit-peek {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(248, 250, 252, 0.62));
}

:root[data-theme="dark"] body.app-shell-host .sidebar,
:root[data-theme="dark"] body.app-shell-host .audit-peek {
  background:
    linear-gradient(180deg, rgba(22, 27, 34, 0.82), rgba(13, 17, 23, 0.70));
}

body.app-shell-host .sidebar {
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.56) inset;
}

body.app-shell-host .audit-peek {
  box-shadow: -1px 0 0 rgba(255, 255, 255, 0.56) inset;
}

:root[data-theme="dark"] body.app-shell-host .sidebar,
:root[data-theme="dark"] body.app-shell-host .audit-peek {
  box-shadow: none;
}

body.app-shell-host .main-column {
  padding: 34px;
}

.card,
.hero,
.auth-card,
.modal-panel,
.device-picker,
.agent-panel {
  background: var(--bg-card);
  border-color: rgba(20, 28, 40, 0.10);
  box-shadow: var(--shadow-default);
}

:root[data-theme="dark"] .card,
:root[data-theme="dark"] .hero,
:root[data-theme="dark"] .auth-card,
:root[data-theme="dark"] .modal-panel,
:root[data-theme="dark"] .device-picker,
:root[data-theme="dark"] .agent-panel {
  border-color: rgba(240, 246, 252, 0.10);
}

.hero {
  box-shadow: var(--shadow-emphasis);
}

.hero::before {
  height: 4px;
  background: linear-gradient(90deg, #2563EB 0%, #14B8A6 46%, #84CC16 72%, #F59E0B 100%);
}

.section-divider {
  align-items: center;
  gap: 10px;
  margin-top: 32px;
  padding-bottom: 12px;
}

.section-number {
  min-width: 42px;
  height: 24px;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-subtle);
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: var(--radius-full);
  color: var(--color-accent-primary);
  font-size: 11px;
}

.section-title,
body.app-shell-host .sidebar-section-title {
  font-weight: 720;
}

body.app-shell-host .sidebar-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom-color: rgba(20, 28, 40, 0.08);
}

body.app-shell-host .sidebar-section-title::before {
  content: "";
  width: 4px;
  height: 16px;
  border-radius: var(--radius-full);
  background: linear-gradient(180deg, #2563EB, #14B8A6);
}

input[type="text"],
input[type="number"],
input[type="email"],
textarea,
select,
.agent-form textarea {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(20, 28, 40, 0.11);
  min-height: 40px;
}

:root[data-theme="dark"] input[type="text"],
:root[data-theme="dark"] input[type="number"],
:root[data-theme="dark"] input[type="email"],
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] select,
:root[data-theme="dark"] .agent-form textarea {
  background: rgba(33, 38, 45, 0.74);
  border-color: rgba(240, 246, 252, 0.11);
}

.tag-chip,
.chip,
.btn-ghost {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.72) inset;
}

.chip.active,
.tag-chip:has(input[type="checkbox"]:checked) {
  background: linear-gradient(180deg, #1F2937, #111827);
  border-color: rgba(17, 24, 39, 0.90);
}

:root[data-theme="dark"] .chip.active,
:root[data-theme="dark"] .tag-chip:has(input[type="checkbox"]:checked) {
  background: linear-gradient(180deg, #F8FAFC, #E5E7EB);
  border-color: rgba(248, 250, 252, 0.90);
}

.btn-primary {
  background: linear-gradient(180deg, #3B82F6 0%, #2563EB 58%, #1D4ED8 100%);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.25), 0 1px 0 rgba(255, 255, 255, 0.26) inset;
}

.btn-primary:hover {
  background: linear-gradient(180deg, #60A5FA 0%, #3B82F6 58%, #2563EB 100%);
}

.dropzone {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(248, 250, 252, 0.78));
  border-color: rgba(20, 28, 40, 0.14);
}

.dropzone:hover,
.dropzone.dragover {
  background:
    linear-gradient(180deg, rgba(239, 246, 255, 0.96), rgba(240, 253, 250, 0.82));
}

.photo-thumb,
.roi-frame {
  box-shadow: 0 16px 34px rgba(18, 24, 38, 0.12);
}

.parameter-block {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(248, 250, 252, 0.68));
}

:root[data-theme="dark"] .parameter-block {
  background:
    linear-gradient(180deg, rgba(33, 38, 45, 0.78), rgba(22, 27, 34, 0.70));
}

.agent-panel {
  border-color: rgba(37, 99, 235, 0.16);
}

.agent-badge {
  background: rgba(20, 184, 166, 0.12);
  color: #0F766E;
}

:root[data-theme="dark"] .agent-badge {
  color: #5EEAD4;
}

.agent-empty {
  background: rgba(248, 250, 252, 0.64);
  border-color: rgba(20, 28, 40, 0.08);
}

:root[data-theme="dark"] .agent-empty {
  background: rgba(22, 27, 34, 0.58);
  border-color: rgba(240, 246, 252, 0.08);
}

.agent-form {
  padding-top: 10px;
  border-top: 1px solid var(--color-border-subtle);
}

.outcome-card {
  border-color: rgba(20, 184, 166, 0.18);
}

.outcome-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border-subtle);
}

.outcome-subtitle {
  margin-top: 5px;
  color: var(--color-text-tertiary);
  font-size: 13px;
  line-height: 1.5;
}

.outcome-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.outcome-field {
  margin-bottom: 0;
}

.outcome-field-wide {
  grid-column: 1 / -1;
}

.outcome-field textarea {
  min-height: 72px;
}

.outcome-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

@media (max-width: 700px) {
  .outcome-form {
    grid-template-columns: 1fr;
  }

  .outcome-field-wide,
  .outcome-actions {
    grid-column: auto;
  }

  .outcome-actions .btn-primary {
    width: 100%;
  }
}

.safety-banner {
  padding: 13px 14px;
  border: 1px solid var(--color-border-subtle);
  border-left-width: 4px;
  border-radius: var(--radius-default);
  background: rgba(255, 255, 255, 0.64);
}

:root[data-theme="dark"] .safety-banner {
  background: rgba(13, 17, 23, 0.42);
}

.safety-banner-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}

.safety-action-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 780;
  line-height: 1.2;
}

.safety-severity {
  color: var(--color-text-tertiary);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.safety-summary {
  margin: 0;
  color: var(--color-text-primary);
  font-size: 14px;
  line-height: 1.6;
  font-weight: 540;
}

.safety-rule-list {
  list-style: none;
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 1.55;
}

.safety-rule-list > li {
  position: relative;
  padding-left: 18px;
}

.safety-rule-list > li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.65em;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
}

.safety-hidden-note {
  margin: 10px 0 0;
  color: var(--color-text-tertiary);
  font-size: 12px;
  font-style: italic;
}

.safety-proceed {
  border-left-color: var(--color-success);
  background: linear-gradient(180deg, var(--color-success-bg), rgba(255, 255, 255, 0.62));
}

.safety-proceed .safety-action-pill {
  color: var(--color-success);
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
}

.safety-caution {
  border-left-color: var(--color-warning);
  background: linear-gradient(180deg, var(--color-warning-bg), rgba(255, 255, 255, 0.62));
}

.safety-caution .safety-action-pill {
  color: var(--color-warning);
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-border);
}

.safety-defer {
  border-left-color: var(--color-warning);
  background: linear-gradient(180deg, rgba(255, 149, 0, 0.16), rgba(255, 255, 255, 0.62));
}

.safety-defer .safety-action-pill {
  color: #7C2D12;
  background: rgba(255, 149, 0, 0.16);
  border: 1px solid rgba(178, 90, 0, 0.28);
}

.safety-biopsy_refer {
  border-left-color: var(--color-critical);
  background: linear-gradient(180deg, var(--color-critical-bg), rgba(255, 255, 255, 0.62));
}

.safety-biopsy_refer .safety-action-pill {
  color: var(--color-critical);
  background: var(--color-critical-bg);
  border: 1px solid var(--color-critical-border);
}

:root[data-theme="dark"] .safety-proceed,
:root[data-theme="dark"] .safety-caution,
:root[data-theme="dark"] .safety-defer,
:root[data-theme="dark"] .safety-biopsy_refer {
  background: rgba(13, 17, 23, 0.48);
}

:root[data-theme="dark"] .safety-defer .safety-action-pill {
  color: #FFD60A;
  background: rgba(255, 214, 10, 0.13);
  border-color: rgba(255, 214, 10, 0.25);
}

/* Result readability: make the clinical answer scan like a ranked note rather
   than a prose essay. Primary diagnosis and differential stay visible at the
   top, with probability chips and short bullet reasons. */
.result-summary-text {
  font-family: var(--font-sans);
  font-size: clamp(17px, 1.5vw, 21px);
  line-height: 1.65;
  color: var(--color-text-primary);
  font-weight: 520;
}

.dx-priority-panel {
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.86), rgba(255, 255, 255, 0.68));
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-default);
  padding: 14px;
}

:root[data-theme="dark"] .dx-priority-panel {
  background:
    linear-gradient(180deg, rgba(33, 38, 45, 0.72), rgba(22, 27, 34, 0.68));
}

.dx-priority-panel-compact {
  padding: 12px;
}

.dx-priority-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--color-text-tertiary);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.dx-priority-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.dx-priority-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-default);
  background: rgba(255, 255, 255, 0.58);
}

:root[data-theme="dark"] .dx-priority-item {
  background: rgba(13, 17, 23, 0.38);
}

.dx-priority-primary {
  border-color: rgba(37, 99, 235, 0.22);
  background: rgba(37, 99, 235, 0.075);
}

:root[data-theme="dark"] .dx-priority-primary {
  background: rgba(88, 166, 255, 0.10);
  border-color: rgba(88, 166, 255, 0.24);
}

.dx-priority-rank {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--color-text-primary);
  color: var(--color-bg-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.dx-priority-body {
  min-width: 0;
}

.dx-priority-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dx-priority-name {
  min-width: 0;
  color: var(--color-text-primary);
  font-size: 15px;
  font-weight: 720;
  line-height: 1.35;
}

button.dx-priority-name {
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.dx-probability {
  flex-shrink: 0;
  border-radius: var(--radius-full);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 720;
  line-height: 1.25;
  color: var(--color-text-secondary);
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-subtle);
}

.dx-probability-primary,
.dx-probability-likely {
  color: var(--color-success);
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
}

.dx-probability-possible {
  color: var(--color-warning);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

.dx-probability-unlikely {
  color: var(--color-text-tertiary);
  background: rgba(124, 132, 144, 0.10);
}

.result-bullet-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--color-text-secondary);
}

.result-bullet-list > li {
  position: relative;
  padding-left: 18px;
}

.result-bullet-list > li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-accent-primary);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.dx-reason-list {
  margin-top: 7px;
  gap: 4px;
  font-size: 13px;
}

.result-bullet-list-readable {
  font-size: 14.5px;
  color: var(--color-text-primary);
}

.result-bullet-list-compact {
  gap: 4px;
}

.result-mini-block {
  padding: 10px 12px;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-default);
  background: rgba(248, 250, 252, 0.62);
}

:root[data-theme="dark"] .result-mini-block {
  background: rgba(22, 27, 34, 0.50);
}

.observation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
}

.observation-grid-item {
  padding: 9px 11px;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-default);
  background: rgba(255, 255, 255, 0.52);
}

:root[data-theme="dark"] .observation-grid-item {
  background: rgba(13, 17, 23, 0.36);
}

.observation-grid-item dt {
  margin-bottom: 3px;
  color: var(--color-text-tertiary);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.observation-grid-item dd {
  margin: 0;
  color: var(--color-text-primary);
  font-size: 13.5px;
  line-height: 1.45;
}

body.app-shell-host .app-footer {
  background: rgba(255, 255, 255, 0.58);
  border-top-color: rgba(20, 28, 40, 0.08);
  color: var(--color-text-tertiary);
}

:root[data-theme="dark"] body.app-shell-host .app-footer {
  background: rgba(13, 17, 23, 0.72);
  border-top-color: rgba(240, 246, 252, 0.09);
}

@media (max-width: 767px) {
  body.app-shell-host .main-column {
    padding: 20px;
  }

  body.app-shell-host .sidebar {
    background: rgba(255, 255, 255, 0.92);
  }

  :root[data-theme="dark"] body.app-shell-host .sidebar {
    background: rgba(13, 17, 23, 0.94);
  }
}

/* Analysis "in progress" indicator — a small, unobtrusive elapsed counter with
   a gently pulsing dot. Only the dot animates so the seconds stay readable. */
.pp-progress {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  font-variant-numeric: tabular-nums;
}
.pp-progress-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent-primary, #22D3EE);
  animation: pp-progress-pulse 1.6s ease-in-out infinite;
}
@keyframes pp-progress-pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50%      { opacity: 1;    transform: scale(1); }
}
/* Loading screen: a faint accent shimmer that glides across, slowly, behind
   the content — a quiet "something is happening" sweep. */
#view-loading { position: relative; overflow: hidden; }
#view-loading > * { position: relative; z-index: 1; }
#view-loading::before {
  content: "";
  position: absolute;
  inset: -20%;
  z-index: 0;
  background: linear-gradient(115deg, transparent 38%, rgba(34, 211, 238, 0.09) 50%, transparent 62%);
  transform: translateX(-120%);
  animation: pp-loading-shimmer 4.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pp-loading-shimmer {
  0%   { transform: translateX(-120%); }
  60%  { transform: translateX(120%); }
  100% { transform: translateX(120%); }
}

/* ChatGPT-style typing caret — only on the headline summary as it types in on
   the result screen (the loading reasoning feed has no caret; the streaming text
   itself signals activity, and a lone blinking block looked distracting). */
@keyframes pp-caret-blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
.tw-typing::after {
  content: "▋";
  margin-left: 1px;
  color: var(--color-accent-primary, #22D3EE);
  animation: pp-caret-blink 1s steps(1) infinite;
}

/* Result sections fade up in a quick stagger so the report feels assembled. */
@keyframes pp-fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.tw-stagger { animation: pp-fade-up 0.4s ease both; }

/* Photo gallery — date-grouped thumbnail grid. */
.gallery-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.gallery-tile {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: var(--color-bg-secondary, #16181d);
  border: 1px solid var(--color-border-subtle, #1f2228);
  aspect-ratio: 1 / 1;
}
.gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-tile:hover { border-color: var(--color-accent-primary, #22d3ee); }
.gallery-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 6px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
}
.gallery-tag-case { background: rgba(14, 116, 144, 0.85); }
.gallery-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0;
  padding: 14px 8px 6px;
  font-size: 11px;
  line-height: 1.3;
  color: #f2f1ed;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.78), transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gallery-del {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.gallery-tile:hover .gallery-del { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .pp-progress-dot { animation: none; opacity: 0.7; }
  #view-loading::before { animation: none; }
  .tw-stagger { animation: none; }
  .tw-typing::after { animation: none; }
}
