:root {
  --bg: #e8eef2;
  --bg-deep: #d5e0e8;
  --panel: #f7fafc;
  --ink: #15202b;
  --muted: #5b6b78;
  --line: #c5d2dc;
  --accent: #0d7c74;
  --accent-soft: #d4efec;
  --danger: #b42318;
  --shadow: 0 18px 40px rgba(21, 32, 43, 0.08);
  --radius: 16px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --display: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow-x: hidden; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 70% 50% at 0% 0%, #c8dde8 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 100% 100%, #c5e4df 0%, transparent 50%),
    linear-gradient(160deg, var(--bg), var(--bg-deep));
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(247, 250, 252, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-btn { align-self: flex-start; padding: 8px 12px; font-size: 13px; }
.mobile-bar { display: none; }
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background:
    linear-gradient(135deg, var(--accent), #1aa39a 55%, #7ec8c2);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }

.patient-form label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.row { display: flex; gap: 8px; }
.row.end { justify-content: flex-end; margin-top: 12px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.danger-ghost { background: transparent; color: var(--danger); border: 1px solid #f0b8b4; }
.btn.primary:hover:not(:disabled),
.btn.secondary:hover:not(:disabled) { filter: brightness(1.05); transform: translateY(-1px); transition: .15s ease; }

.patient-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; flex: 1; }
.patient-item {
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.patient-item:hover { background: #fff; border-color: var(--line); }
.patient-item.active { background: #fff; border-color: var(--accent); box-shadow: var(--shadow); }
.patient-item strong { display: block; }
.patient-item span { color: var(--muted); font-size: 12px; }

.main { padding: 28px 28px 40px; min-width: 0; }
.empty-view {
  max-width: 520px;
  margin: 12vh auto 0;
  text-align: center;
}
.empty-view h1 {
  font-family: var(--display);
  font-size: clamp(32px, 5vw, 48px);
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}
.empty-view p { color: var(--muted); line-height: 1.55; }

.patient-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.patient-header h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.02em;
}
.muted { color: var(--muted); margin: 6px 0 0; }
.header-actions { display: flex; gap: 8px; }

.workspace {
  display: grid;
  grid-template-columns: 268px minmax(0, 1.4fr) minmax(240px, .9fr);
  gap: 14px;
  align-items: start;
}

.panel {
  background: rgba(247, 250, 252, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; font-size: 15px; }
.studies-panel .panel-head .btn { padding: 6px 10px; font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.analysis-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 12px;
  margin: 0 0 10px;
  background: var(--accent-soft);
  border: 1px solid #b7ddd8;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
}
.analysis-banner[hidden] { display: none; }
.analysis-banner p { margin: 0; flex: 1; min-width: 0; }
.analysis-banner .btn { flex-shrink: 0; }

.source-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.source-picker-label {
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: 10px;
}
.source-seg {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.source-option {
  position: relative;
  display: block;
  margin: 0;
  cursor: pointer;
  font-weight: 600;
}
.source-option + .source-option {
  border-left: 1px solid var(--line);
}
.source-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.source-option span {
  display: block;
  padding: 7px 4px;
  text-align: center;
  font-size: 11px;
  line-height: 1.2;
  color: var(--muted);
}
.source-option input:checked + span {
  background: var(--accent-soft);
  color: var(--accent);
}
.source-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.source-option:hover span {
  color: var(--ink);
}
.upload-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 12px;
  padding: 10px 10px 12px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: #fff;
  text-align: center;
  cursor: default;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.upload-drop-zone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.upload-drop-zone.drag-over {
  border-color: var(--accent);
  border-style: solid;
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 4px var(--accent-soft);
  background: #e4f4f1;
}
.upload-drop-zone-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}
.upload-drop-zone-hint {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .02em;
}
.upload-btn { display: inline-flex; margin: 4px 0 0; width: 100%; justify-content: center; padding: 8px 12px; }
.patient-view.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  border-radius: var(--radius);
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: uppercase;
}
.badge.source-qlf { background: #d4efec; color: #0d7c74; }
.badge.source-qlf_rus { background: #e0e8f5; color: #2f5aa8; }
.badge.source-mob { background: #f5e8d4; color: #8a5a12; }
.badge.source-legacy { background: #e8e8e8; color: #555; }

.study-list { display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow: auto; }
.study-item-wrap {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: center;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.study-item-wrap:hover { border-color: #9eb3c0; }
.study-item-wrap:has(.study-item.active) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.study-compare-check {
  margin: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.study-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  min-width: 0;
}
.study-item.active { border: 0; box-shadow: none; }
.study-item img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: #dfe8ee;
}
.study-item-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.study-item-head { margin: 0; }
.study-item strong {
  display: block;
  margin: 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.study-item-body span { color: var(--muted); font-size: 11px; display: block; line-height: 1.3; }
.study-date { margin-top: 0; }

.view-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.view-tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.view-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.view-tab:disabled { opacity: .4; cursor: not-allowed; }

.zoom-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.zoom-bar .btn { padding: 6px 10px; min-width: 36px; }
.zoom-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 4px;
}

.canvas-wrap {
  position: relative;
  background:
    linear-gradient(45deg, #dfe8ee 25%, transparent 25%) -10px 0 / 20px 20px,
    linear-gradient(-45deg, #dfe8ee 25%, transparent 25%) -10px 0 / 20px 20px,
    #eef3f6;
  border-radius: 12px;
  border: 1px solid var(--line);
  overflow: auto;
  max-height: 62vh;
  min-height: 280px;
  user-select: none;
  overscroll-behavior: contain;
  touch-action: none;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.canvas-wrap.panning,
.canvas-wrap.panning #study-canvas,
.canvas-wrap.dragging-point,
.canvas-wrap.dragging-point #study-canvas,
.result-image-wrap.panning,
.result-image-wrap.panning img {
  cursor: grabbing;
}
.canvas-wrap.drag-over {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 4px var(--accent-soft);
  background:
    linear-gradient(45deg, #cfe8e4 25%, transparent 25%) -10px 0 / 20px 20px,
    linear-gradient(-45deg, #cfe8e4 25%, transparent 25%) -10px 0 / 20px 20px,
    #e4f4f1;
}
.empty-view.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
  background: rgba(212, 239, 236, 0.45);
  border-radius: var(--radius);
}
#study-canvas {
  display: block;
  cursor: crosshair;
}
.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  pointer-events: none;
}
.canvas-empty[hidden] {
  display: none;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}
.compare-pane {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  overflow: auto;
  max-height: 62vh;
}
.compare-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  font-size: 12px;
}
.compare-meta strong { font-size: 13px; }
.compare-meta span { color: var(--muted); }
.compare-pane canvas {
  display: block;
  width: 100%;
  height: auto;
}

.analyze-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.status {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.status.error { color: var(--danger); }
.status.ok { color: var(--accent); }

.results-list { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow: auto; }
.result-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
.result-group.active { border-color: var(--accent); }
.result-group.legacy { border-style: dashed; }
.result-group-head {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: #f0f5f8;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
}
.result-group-head strong { display: block; font-size: 13px; }
.result-group-head span { color: var(--muted); font-size: 11px; }
.result-group-items { display: flex; flex-direction: column; gap: 0; }
.result-item {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: 10px 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
  width: 100%;
}
.result-item.active { background: var(--accent-soft); }
.result-item strong { display: block; font-size: 13px; }
.result-item span { color: var(--muted); font-size: 11px; display: block; }
.result-time { margin-top: 2px; }

.result-detail { margin-top: 0; }
.result-image-wrap {
  margin-bottom: 10px;
}
.result-image-wrap img {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #111;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
}
.metrics-summary { margin-bottom: 8px; }
.metrics-kind { margin: 0 0 4px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.metrics-short { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 8px;
}
.metrics-table th,
.metrics-table td {
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
  text-align: left;
  vertical-align: top;
}
.metrics-table th {
  font-weight: 600;
  color: var(--muted);
  width: 55%;
}
.raw-json {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.raw-json summary { cursor: pointer; font-weight: 600; }
.result-detail pre {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 10px;
  background: #132028;
  color: #d7ebe7;
  font-size: 11px;
  overflow: auto;
  max-height: 220px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  width: min(480px, calc(100% - 32px));
  box-shadow: var(--shadow);
  max-height: min(90dvh, 720px);
  overflow: auto;
}
dialog::backdrop { background: rgba(21, 32, 43, 0.35); }
dialog h3 { margin: 0 0 12px; font-family: var(--display); }
dialog label { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 600; }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.dialog-head h3 { margin: 0; }

.angles-heading { margin: 0 0 8px; font-size: 18px; }
.angle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.angle-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  font: inherit;
  color: inherit;
  min-height: 140px;
}
.angle-card:hover { border-color: var(--accent); }
.angle-card img, .angle-card-ph {
  width: 100%;
  height: 88px;
  object-fit: cover;
  background: #dfe8ee;
  display: block;
}
.angle-card-ph { display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.angle-card-body { padding: 10px 12px 12px; }
.angle-card-body strong { display: block; font-size: 14px; }
.angle-card-body span { color: var(--muted); font-size: 12px; }
.panel-head-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.back-angles-btn { padding: 6px 10px; font-size: 12px; }
.capture-actions { margin-bottom: 10px; }
.camera-main-btn { width: 100%; min-height: 44px; }

.angle-settings-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.angle-settings-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  gap: 6px;
  align-items: center;
}
.angle-settings-row input { margin: 0; }
.overlay-photo-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.overlay-pick {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  width: 100%;
}
.overlay-pick img, .overlay-pick-ph {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  background: #dfe8ee;
}
.overlay-pick-ph { display: grid; place-items: center; font-size: 11px; color: var(--muted); }

.camera-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #111;
  color: #fff;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}
.camera-overlay[hidden] { display: none; }
.camera-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  background: #000;
  overflow: hidden;
}
.camera-stage video,
.camera-stage .camera-ghost,
.camera-stage .camera-shot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.camera-ghost { pointer-events: none; }
.camera-hud {
  flex-shrink: 0;
  padding: 10px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.72));
}
.camera-hud-top, .camera-hud-mid, .camera-hud-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.camera-hud-top { justify-content: space-between; }
.camera-hud-bottom { justify-content: center; flex-direction: column; }
.camera-hud .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.camera-device-label { font-size: 13px; display: flex; gap: 8px; align-items: center; }
.camera-device-label select {
  max-width: 160px;
  font-size: 16px;
  border-radius: 8px;
  padding: 6px 8px;
}
.opacity-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  flex: 1;
}
.opacity-label input[type="range"] { flex: 1; min-width: 80px; }
.camera-source { margin: 0; flex: 1; min-width: 200px; background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.2); }
.camera-source .source-picker-label, .camera-source .source-option span { color: #d7ebe7; }
.shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255,255,255,.25);
  cursor: pointer;
}
.shutter-btn:active { transform: scale(0.96); }
.shutter-caption { font-size: 13px; color: #ccc; }
.preview-actions { flex-direction: row; width: 100%; }
.preview-actions .btn { flex: 1; min-height: 48px; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .study-list { max-height: none; flex-direction: row; overflow-x: auto; }
  .study-item-wrap { min-width: 240px; }
  .compare-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--line);
    background: rgba(247, 250, 252, 0.95);
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .mobile-bar-title { font-weight: 700; font-size: 15px; }
  .sidebar {
    display: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    padding-bottom: 16px;
  }
  .sidebar.open { display: flex; }
  .main { padding: 10px 10px 22px; padding-bottom: max(22px, env(safe-area-inset-bottom)); }
  .patient-header { flex-direction: column; gap: 8px; margin-bottom: 12px; }
  .patient-header h1 { font-size: 22px; }
  .angles-heading { font-size: 16px; }
  .angles-view .hint { display: none; }
  .angle-grid { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
  .angle-card { min-height: 0; }
  .angle-card img, .angle-card-ph { height: 72px; }
  .angle-card-body { padding: 8px; }
  .angle-card-body strong { font-size: 13px; }
  .source-seg { min-height: 44px; }
  .source-option span { padding: 10px 4px; }
  .study-list { flex-direction: column; overflow-x: visible; max-height: none; }
  .study-item-wrap { min-width: 0; }
  .toolbar { width: 100%; }
  .toolbar .btn { min-height: 44px; flex: 1; font-size: 13px; padding: 8px 8px; }
  .editor-panel .panel-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .editor-panel .panel-head h2 {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }
  .editor-panel .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .editor-panel .toolbar .btn {
    flex: none;
    width: 100%;
    min-width: 0;
    white-space: normal;
    line-height: 1.25;
    font-size: 12px;
    padding: 10px 8px;
  }
  .editor-panel .toolbar #new-analysis-btn,
  .editor-panel .toolbar #save-points-btn {
    grid-column: 1 / -1;
  }
  .editor-panel .hint {
    font-size: 12px;
    line-height: 1.35;
  }
  .analyze-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .analyze-row .btn {
    width: 100%;
    white-space: normal;
    min-height: 44px;
  }
  .studies-panel .panel-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .panel-head-stack { width: 100%; }
  .header-actions { width: 100%; }
  .header-actions .btn { min-height: 44px; flex: 1; }
  .angle-settings-row { grid-template-columns: 1fr 1fr; }
  .angle-settings-row .btn { min-height: 44px; }
  .panel { padding: 10px; overflow-x: hidden; }
  .workspace { min-width: 0; overflow-x: hidden; }
  .canvas-wrap, .result-image-wrap {
    max-height: 42dvh;
    min-height: 180px;
  }
  .empty-view { margin: 8vh auto 0; padding: 0 8px; }
  .empty-view h1 { font-size: 28px; }
  .camera-hud {
    padding: 8px 10px max(10px, env(safe-area-inset-bottom));
    gap: 8px;
  }
  .camera-source { min-width: 0; width: 100%; }
  .camera-hud-mid { flex-direction: column; align-items: stretch; }
  .shutter-btn { width: 64px; height: 64px; }
  .upload-drop-zone { padding: 8px; }
}

.camera-overlay.camera-overlay--landscape {
  flex-direction: row;
  height: 100dvh;
  width: 100%;
}
.camera-overlay.camera-overlay--landscape .camera-stage { flex: 1; }
.camera-overlay.camera-overlay--landscape .camera-hud {
  width: min(240px, 42vw);
  max-width: 280px;
  padding: 8px 10px;
  padding-right: max(10px, env(safe-area-inset-right));
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.62);
  gap: 8px;
}
.camera-overlay.camera-overlay--landscape .camera-hud-top,
.camera-overlay.camera-overlay--landscape .camera-hud-mid,
.camera-overlay.camera-overlay--landscape .camera-hud-bottom {
  flex-wrap: nowrap;
  width: 100%;
}
.camera-overlay.camera-overlay--landscape .camera-hud-mid {
  flex-direction: column;
  align-items: stretch;
}
.camera-overlay.camera-overlay--landscape .camera-hud-bottom { margin-top: auto; }
.camera-overlay.camera-overlay--landscape .shutter-btn { width: 58px; height: 58px; }
.camera-overlay.camera-overlay--landscape .camera-source { min-width: 0; }

@media (max-width: 800px) and (orientation: landscape) {
  .mobile-bar { padding: 6px 10px; }
  .patient-header h1 { font-size: 18px; }
  .canvas-wrap, .result-image-wrap { max-height: 70dvh; min-height: 140px; }
}
