:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1f2733;
  --border: #30363d;
  --accent: #2ea8ff;
  --accent-hover: #58bdff;
  --danger: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --text: #e6edf3;
  --muted: #8b949e;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.logo:hover { opacity: 0.85; }

.disclaimer {
  font-size: 0.72rem;
  background: #5a1e1e;
  color: #ff9090;
  border: 1px solid #7a3030;
  border-radius: 4px;
  padding: 3px 8px;
}

nav { margin-left: auto; display: flex; gap: 6px; }

.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); border-color: var(--accent); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* 3D Model button in nav */
.model3d-btn {
  margin-left: 10px;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid #a855f7;
  background: linear-gradient(135deg, #1e1040 0%, #2d1a5e 100%);
  color: #d8b4fe;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  box-shadow: 0 0 10px rgba(168,85,247,0.25);
}
.model3d-btn:hover {
  background: linear-gradient(135deg, #2d1a5e 0%, #4c1d95 100%);
  color: #fff;
  box-shadow: 0 0 18px rgba(168,85,247,0.55);
  transform: translateY(-1px);
}

/* 3D Modal overlay */
.modal3d-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.88);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
  padding: 16px;
}
.modal3d-overlay.hidden { display: none; }

.modal3d-box {
  background: var(--surface);
  border: 1px solid #a855f7;
  border-radius: 14px;
  width: 100%; max-width: 980px;
  display: flex; flex-direction: column;
  box-shadow: 0 0 60px rgba(168,85,247,0.3);
  overflow: hidden;
}

.modal3d-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.modal3d-title {
  font-weight: 700; font-size: 0.95rem;
}
.modal3d-hint {
  font-size: 0.73rem; color: var(--muted);
  flex: 1;
}
.modal3d-close {
  background: transparent; border: none;
  color: var(--muted); font-size: 1.2rem;
  cursor: pointer; line-height: 1;
  padding: 2px 6px; border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.modal3d-close:hover { color: var(--danger); background: rgba(248,81,73,0.12); }

.modal3d-body {
  position: relative;
  background: #0a0a12;
}
.modal3d-three {
  width: 100%;
  height: clamp(360px, 64vh, 620px);
  cursor: grab;
}
.modal3d-three:active { cursor: grabbing; }
.modal3d-three canvas { display: block; }
/* Badge showing fibroid count / status */
.modal3d-badge {
  position: absolute; top: 12px; left: 14px;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.modal3d-badge-chip {
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.72rem; color: #ddd;
  display: flex; align-items: center; gap: 5px;
}

.modal3d-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem; color: var(--muted);
}
.modal3d-footer a { color: #a855f7; text-decoration: none; }
.modal3d-footer a:hover { text-decoration: underline; }

@media (max-width: 600px) {
  .modal3d-hint { display: none; }
  .model3d-btn { margin-left: 4px; padding: 6px 10px; font-size: 0.8rem; }
}

/* ── Tab panels ─────────────────────────────────── */
.tab-panel { display: none; padding: 28px; max-width: 1200px; margin: 0 auto; width: 100%; }
.tab-panel.active { display: block; }
.hidden { display: none !important; }

/* ── Upload zone ────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface);
  margin-bottom: 20px;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: #0d1f30;
}
.upload-zone.has-file { border-color: var(--success); background: #0d1f16; }

.upload-icon { font-size: 2.8rem; margin-bottom: 10px; }
.upload-zone p { color: var(--muted); font-size: 1rem; }
.upload-zone small { color: var(--border); font-size: 0.8rem; }

.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: inherit; text-decoration: underline;
}
.link-btn:hover { color: var(--accent-hover); }

/* ── Controls ───────────────────────────────────── */
.controls {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.controls label {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 0.9rem;
}
.controls input[type="number"] {
  width: 80px; padding: 7px 10px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 0.9rem;
}

.primary-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 22px; border-radius: 6px; font-size: 0.92rem;
  cursor: pointer; font-weight: 600; transition: background 0.15s;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Analyzer toggle ─────────────────────────────── */
.analyzer-toggle {
  display: flex; align-items: center; gap: 6px;
}
.toggle-label { color: var(--muted); font-size: 0.88rem; }
.toggle-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); padding: 6px 14px; border-radius: 6px;
  cursor: pointer; font-size: 0.85rem; transition: all 0.15s;
}
.toggle-btn:hover { border-color: var(--accent); color: var(--text); }
.toggle-btn.active {
  background: #0d2b40; border-color: var(--accent);
  color: var(--accent); font-weight: 600;
}
.toggle-btn.active.gpt { background: #1a2a0d; border-color: #4caf50; color: #4caf50; }

/* ── GPT-4o extras ───────────────────────────────── */
.clinical-notes {
  background: var(--surface2); border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0; padding: 12px 16px;
  font-size: 0.87rem; color: var(--text); margin-top: 14px;
  line-height: 1.6;
}
.clinical-notes .notes-label {
  font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted); margin-bottom: 6px;
}
.modality-badge {
  display: inline-block; background: #1a2a3a;
  border: 1px solid #2a4a6a; color: #58a6ff;
  border-radius: 4px; padding: 2px 8px;
  font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.5px; margin-right: 6px;
}
.quality-badge {
  display: inline-block; border-radius: 4px;
  padding: 2px 8px; font-size: 0.75rem; text-transform: uppercase;
}
.quality-good  { background: #0d2b1a; border: 1px solid #3fb950; color: #3fb950; }
.quality-fair  { background: #2b1f0d; border: 1px solid #d29922; color: #d29922; }
.quality-poor  { background: #2b0d0d; border: 1px solid #f85149; color: #f85149; }
.analyzer-badge {
  font-size: 0.72rem; color: var(--muted);
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
}

.secondary-btn {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); padding: 9px 22px;
  border-radius: 6px; font-size: 0.92rem; cursor: pointer;
  transition: border-color 0.15s;
}
.secondary-btn:hover:not(:disabled) { border-color: var(--accent); }
.secondary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Results ────────────────────────────────────── */
.results { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.result-columns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
}
@media (max-width: 800px) { .result-columns { grid-template-columns: 1fr; } }

.result-left h3, .result-right h3 {
  font-size: 0.95rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.result-left img {
  width: 100%;
}

/* ── Report card ────────────────────────────────── */
.report-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}

.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 20px;
}
.stat-box {
  background: var(--surface2); border-radius: 8px; padding: 14px;
  text-align: center;
}
.stat-box .value {
  font-size: 1.7rem; font-weight: 700; color: var(--accent);
}
.stat-box .label {
  font-size: 0.75rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-top: 2px;
}

.detected-yes { color: var(--danger) !important; }
.detected-no  { color: var(--success) !important; }

.detection-list { display: flex; flex-direction: column; gap: 10px; }
.detection-item {
  background: var(--surface2); border-radius: 8px;
  padding: 12px 16px; border-left: 3px solid var(--accent);
  font-size: 0.88rem;
}
.detection-item.submucosal  { border-left-color: #ff5050; }
.detection-item.intramural  { border-left-color: #50a0ff; }
.detection-item.subserosal  { border-left-color: #50ff82; }
.detection-item .det-label  { font-weight: 700; text-transform: capitalize; }
.detection-item .det-meta   { color: var(--muted); margin-top: 4px; }

/* Scientific badges */
.sci-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sci-badge  {
  font-size: 0.75rem; padding: 2px 8px; border-radius: 20px;
  font-weight: 600; border: 1px solid transparent;
}
.echo-hypoechoic  { background: #1a2a3a; color: #58bdff; border-color: #2ea8ff; }
.echo-isoechoic   { background: #1a2a20; color: #3fb950; border-color: #3fb950; }
.echo-hyperechoic { background: #2a2010; color: #d29922; border-color: #d29922; }
.vasc-central     { background: #2a1010; color: #f85149; border-color: #f85149; }
.vasc-peripheral  { background: #2a1a08; color: #e37820; border-color: #e37820; }
.vasc-avascular   { background: var(--surface2); color: var(--muted); border-color: var(--border); }

/* ── Anatomical 3D view ──────────────────────────── */
.uterus-section {
  margin-top: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.uterus-section h3 {
  font-size: 0.9rem; font-weight: 600;
  color: var(--text); margin-bottom: 14px;
}

/* Two-column layout: iframe model + fibroid panel */
.uterus-3d-layout {
  display: flex; gap: 16px; align-items: flex-start;
}

/* Model container — iframe + canvas stacked */
.uterus-model-wrap {
  flex: 1; position: relative;
  border-radius: 8px; overflow: hidden;
  background: #0d1117; min-height: 300px;
}
.uterus-model-wrap iframe {
  display: block; width: 100%; height: 340px; border: none;
}
/* Three.js container — inline results section */
.uterus-three-container {
  width: 100%; height: 400px;
  border-radius: 8px; overflow: hidden;
  cursor: grab;
  background: #0d1117;
}
.uterus-three-container:active { cursor: grabbing; }
.uterus-three-container canvas { display: block; }

/* Fibroid annotation panel */
.uterus-fibroid-panel {
  width: 220px; min-width: 200px;
  display: flex; flex-direction: column; gap: 10px;
}
.ufp-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 12px;
}
.ufp-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 4px;
}
.ufp-num {
  font-size: 0.72rem; font-weight: 700;
  padding: 1px 6px; border-radius: 20px;
}
.ufp-label { font-weight: 600; font-size: 0.85rem; text-transform: capitalize; flex: 1; }
.ufp-conf  { font-size: 0.75rem; color: var(--muted); }
.ufp-depth {
  font-size: 0.75rem; color: var(--muted);
  margin-bottom: 8px; cursor: default;
}
.ufp-metrics { display: flex; flex-wrap: wrap; gap: 6px; }
.ufp-metric  {
  background: var(--surface); border-radius: 5px;
  padding: 3px 7px; display: flex; flex-direction: column; gap: 1px;
}
.ufp-mval { font-size: 0.78rem; font-weight: 600; color: var(--text); }
.ufp-mkey { font-size: 0.65rem; color: var(--muted); }

@media (max-width: 700px) {
  .uterus-3d-layout { flex-direction: column; }
  .uterus-fibroid-panel { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .ufp-card { flex: 1; min-width: 160px; }
}

/* ── Loader ─────────────────────────────────────── */
.loader {
  display: flex; flex-direction: column; align-items: center;
  gap: 16px; padding: 60px; color: var(--muted);
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stream ─────────────────────────────────────── */
.stream-controls {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.stream-controls label {
  display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem;
}
.stream-controls input[type="text"] {
  padding: 7px 10px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.9rem; width: 200px;
}

.stream-container {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; min-height: 420px;
  display: flex; align-items: center; justify-content: center;
}
.stream-placeholder {
  color: var(--muted); font-size: 1.1rem;
  display: flex; align-items: center; gap: 10px;
}
#streamImg { width: 100%; border-radius: var(--radius); }

/* ── Assign patient bar ──────────────────────────── */
.assign-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px 18px; margin-bottom: 20px;
  animation: fadeIn 0.3s ease;
}
.assign-label { font-size: 0.88rem; color: var(--text); font-weight: 600; }
.assign-or    { font-size: 0.8rem; color: var(--muted); }
.assign-bar select {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; color: var(--text);
  font-size: 0.85rem; min-width: 180px;
}
.assign-status { font-size: 0.82rem; color: var(--success); }
.assign-status.error { color: var(--danger); }

/* ── Patients tab ───────────────────────────────── */
.patients-layout {
  display: grid; grid-template-columns: 260px 1fr; gap: 0;
  height: calc(100vh - 60px); overflow: hidden;
}

.patient-sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 0.9rem;
}
.small-btn { padding: 5px 12px; font-size: 0.8rem; }

.patient-list { overflow-y: auto; flex: 1; padding: 8px; }
.patient-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s; margin-bottom: 4px;
  border: 1px solid transparent;
}
.patient-item:hover  { background: var(--surface2); }
.patient-item.active { background: #0d1f30; border-color: var(--accent); }
.patient-item .p-name  { font-weight: 600; font-size: 0.9rem; }
.patient-item .p-meta  { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.patient-main {
  overflow-y: auto; padding: 24px;
}
.patient-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; color: var(--muted); gap: 12px;
}

/* Patient detail */
.patient-detail-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.patient-name-block .p-fullname { font-size: 1.4rem; font-weight: 700; }
.patient-name-block .p-info     { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.patient-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Exam cards */
.exam-timeline { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
.exam-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.exam-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface2); flex-wrap: wrap; gap: 8px;
}
.exam-card-header .exam-date  { font-weight: 600; font-size: 0.9rem; }
.exam-card-header .exam-badges { display: flex; gap: 6px; align-items: center; }
.exam-card-body { padding: 14px 16px; }

.badge {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600;
}
.badge-detected  { background: #2b0d0d; color: #f85149; border: 1px solid #7a1e1e; }
.badge-clear     { background: #0d2b1a; color: #3fb950; border: 1px solid #1e7a3a; }
.badge-modality  { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }

.finding-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.finding-chip  {
  font-size: 0.78rem; padding: 3px 10px; border-radius: 12px;
  background: var(--surface2); border: 1px solid var(--border);
}
.finding-chip.submucosal { border-color: #ff5050; color: #ff5050; }
.finding-chip.intramural  { border-color: #50a0ff; color: #50a0ff; }
.finding-chip.subserosal  { border-color: #50ff82; color: #50ff82; }

.exam-download-row { display: flex; gap: 8px; margin-top: 10px; }
.download-btn {
  font-size: 0.78rem; padding: 4px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  text-decoration: none; transition: border-color 0.15s;
}
.download-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Growth section */
.growth-section { margin-top: 24px; }
.growth-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 12px; }
.growth-alert { background: #2b1a0d; border: 1px solid #d29922; border-radius: 8px; padding: 10px 14px; font-size: 0.85rem; color: #d29922; margin-bottom: 12px; }
.growth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px; margin-bottom: 10px;
}
.growth-card .g-label  { font-weight: 700; margin-bottom: 6px; }
.growth-card .g-trend  { font-size: 0.8rem; margin-bottom: 8px; }
.growth-card .g-trend.growing  { color: #f85149; }
.growth-card .g-trend.stable   { color: #3fb950; }
.growth-card .g-trend.shrinking { color: var(--accent); }
.growth-bar-row { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--muted); }
.growth-bar { flex: 1; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.growth-bar-fill { height: 100%; border-radius: 4px; background: var(--accent); transition: width 0.4s; }

/* Upload exam area */
.upload-exam-zone {
  border: 2px dashed var(--border); border-radius: 8px;
  padding: 16px; text-align: center; cursor: pointer;
  transition: border-color 0.2s; margin-top: 16px;
}
.upload-exam-zone:hover { border-color: var(--accent); }
.upload-exam-zone.has-file { border-color: var(--success); }

/* ── Image Lightbox ──────────────────────────────── */
.lightbox-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,0.92);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.lightbox-overlay.hidden { display: none; }

.lightbox-toolbar {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  background: rgba(22,27,34,0.95); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; z-index: 3001;
}
.lightbox-tool {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; width: 34px; height: 34px;
  font-size: 18px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: background .15s;
}
.lightbox-tool:hover { background: var(--accent); color: #fff; }
.lightbox-zoom-label {
  font-size: 13px; color: var(--muted); min-width: 44px; text-align: center;
}
.lightbox-close {
  background: transparent; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; margin-left: 6px; padding: 4px 8px;
  border-radius: 6px; transition: color .15s;
}
.lightbox-close:hover { color: var(--danger); }

.lightbox-stage {
  width: 100vw; height: 100vh;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: grab;
}
.lightbox-stage.dragging { cursor: grabbing; }
#lbImg {
  max-width: none; max-height: none;
  transform-origin: 0 0;
  user-select: none; pointer-events: none;
  border-radius: 4px;
}
.lightbox-hint {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--muted);
  background: rgba(22,27,34,0.85); padding: 5px 14px; border-radius: 20px;
  pointer-events: none;
}

/* Make annotated image show as clickable */
.annotated-img-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
}
#annotatedImg {
  cursor: zoom-in;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  transition: opacity .15s;
}
#annotatedImg:hover { opacity: 0.85; }
.annotated-zoom-hint {
  position: absolute; bottom: 10px; right: 10px;
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 11px; padding: 4px 9px; border-radius: 20px;
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
.annotated-img-wrap:hover .annotated-zoom-hint { opacity: 1; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; width: 480px; max-width: 95vw;
}
.modal-box h3 { margin-bottom: 16px; font-size: 1.1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label, .modal-box label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 0.82rem; color: var(--muted);
}
.form-grid input, .form-grid select,
.modal-box input, .modal-box select, .modal-box textarea {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; color: var(--text);
  font-size: 0.88rem; width: 100%;
}
.modal-box textarea { resize: vertical; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.empty-msg { color: var(--muted); text-align: center; padding: 20px; font-size: 0.85rem; }

/* ── Learning tab ────────────────────────────────── */
.learn-header { margin-bottom: 24px; }
.learn-header h2 { font-size: 1.4rem; margin-bottom: 6px; }
.learn-subtitle { color: var(--muted); font-size: 0.9rem; }

.learn-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
@media (max-width: 700px) { .learn-grid { grid-template-columns: 1fr; } }

.learn-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.learn-card-title {
  font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted); margin-bottom: 16px;
}

/* Progress bar */
.progress-wrap { display: flex; flex-direction: column; gap: 8px; }
.progress-bar {
  height: 12px; background: var(--surface2);
  border-radius: 6px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #58bdff);
  border-radius: 6px; transition: width 0.5s ease;
}
.progress-fill.done { background: linear-gradient(90deg, var(--success), #58ff90); }
.progress-label { font-size: 0.85rem; color: var(--muted); text-align: right; }

/* Training status badge */
.training-status {
  display: inline-block; padding: 8px 16px;
  border-radius: 6px; font-size: 0.9rem; font-weight: 600;
  margin-bottom: 16px;
}
.training-status.idle     { background: var(--surface2); color: var(--muted); }
.training-status.training { background: #1a2b0d; color: #3fb950; border: 1px solid #3fb950; }
.training-status.ready    { background: #0d1f30; color: var(--accent); border: 1px solid var(--accent); }

.weights-info {
  font-size: 0.8rem; color: var(--success);
  background: #0d2b1a; border-radius: 6px;
  padding: 8px 12px; margin-bottom: 14px;
}

.learn-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* History table */
.train-history { display: flex; flex-direction: column; gap: 10px; }
.history-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px; align-items: center;
  background: var(--surface2); border-radius: 8px; padding: 10px 14px;
  font-size: 0.83rem;
}
.history-row .run-id { color: var(--accent); font-weight: 600; }
.history-row .run-meta { color: var(--muted); }

/* Flow steps */
.flow-steps {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap; justify-content: center; padding: 10px 0;
}
.flow-step {
  text-align: center; font-size: 0.82rem; color: var(--text);
  background: var(--surface2); border-radius: 8px;
  padding: 12px 16px; line-height: 1.6; min-width: 80px;
}
.flow-arrow { color: var(--muted); font-size: 1.2rem; }

/* ── BBox Editor Modal ───────────────────────────── */
.editor-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 96vw; max-width: 1100px;
  max-height: 92vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.editor-header {
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.editor-header h3 { font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.editor-hint { font-size: 0.78rem; color: var(--muted); }
.editor-body {
  display: flex; flex: 1; overflow: hidden;
}
.editor-canvas-wrap {
  flex: 1; overflow: auto; background: #000;
  display: flex; align-items: center; justify-content: center;
  cursor: crosshair;
}
#editorCanvas { display: block; max-width: 100%; }
.editor-sidebar {
  width: 200px; min-width: 200px;
  background: var(--surface2);
  border-left: 1px solid var(--border);
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
}
.editor-no-sel {
  text-align: center; color: var(--muted);
  font-size: 0.82rem; padding: 20px 8px; line-height: 1.6;
}
.editor-field { display: flex; flex-direction: column; gap: 4px; }
.editor-field label { font-size: 0.78rem; color: var(--muted); }
.editor-field select, .editor-field input[type=range] { width: 100%; }
.editor-field select {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 4px 6px; font-size: 0.82rem;
}
.editor-box-list {
  flex: 1; display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
}
.editor-box-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 0.78rem;
  cursor: pointer; transition: border-color 0.15s;
}
.editor-box-item.selected { border-color: var(--accent); }
.editor-box-item .ebi-label { font-weight: 600; color: var(--text); }
.editor-box-item .ebi-size  { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }
.editor-pix {
  border-top: 1px solid var(--border);
  padding-top: 10px; font-size: 0.78rem;
}
.editor-pix label { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.editor-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.editor-train-toggle {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.82rem; color: var(--muted); cursor: pointer;
}
/* Edit button on result card */
.edit-detections-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 5px 12px;
  font-size: 0.82rem; cursor: pointer; transition: border-color 0.15s;
}
.edit-detections-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Video Progress Bar ──────────────────────────────────────────────────── */
.video-progress {
  margin: 16px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.vp-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.vp-title { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.vp-stats { font-size: 0.8rem; color: var(--muted); }
.vp-bar-wrap {
  width: 100%; height: 8px; background: var(--surface2);
  border-radius: 4px; overflow: hidden;
}
.vp-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #7c3aed);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.vp-frames-live {
  margin-top: 10px; font-size: 0.78rem; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.vp-live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  animation: livePulse 1.2s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

/* ── Filmstrip ───────────────────────────────────────────────────────────── */
.filmstrip-section {
  margin: 0 0 20px 0;
}
.filmstrip-section h3 {
  font-size: 0.95rem; font-weight: 600; margin-bottom: 12px;
  color: var(--text);
}
.filmstrip {
  display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.filmstrip::-webkit-scrollbar { height: 5px; }
.filmstrip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.film-frame {
  flex-shrink: 0; width: 160px; cursor: pointer;
  border: 2px solid var(--border); border-radius: 8px; overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
  background: var(--surface);
}
.film-frame:hover  { border-color: var(--accent); transform: translateY(-2px); }
.film-frame.active { border-color: var(--accent); box-shadow: 0 0 10px rgba(46,168,255,0.35); }
.film-frame img { width: 100%; height: 100px; object-fit: cover; display: block; }
.film-label {
  padding: 5px 8px; display: flex; justify-content: space-between; align-items: center;
}
.film-num   { font-size: 0.72rem; color: var(--muted); }
.film-score { font-size: 0.72rem; color: var(--accent); font-weight: 600; }

/* ── Annotated Upload (Learning tab) ────────────────────────────────────── */
.annotate-card { padding: 20px; }

.annotate-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .annotate-layout { grid-template-columns: 1fr; }
}

/* Drop zone */
.annotate-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface2);
}
.annotate-drop:hover,
.annotate-drop.drag-over { border-color: var(--accent); background: rgba(46,168,255,0.06); }
.annotate-drop .upload-icon { font-size: 2.6rem; margin-bottom: 10px; }
.annotate-drop p { font-size: 0.9rem; color: var(--muted); }
.annotate-drop small { font-size: 0.78rem; color: var(--muted); margin-top: 6px; display: block; }

/* Canvas area */
.annotate-canvas-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  cursor: crosshair;
  user-select: none;
}
#annotateCanvas { display: block; max-width: 100%; }
.annotate-hint {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 5px 10px;
  background: rgba(0,0,0,0.65);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

/* Sidebar fields */
.annotate-sidebar { display: flex; flex-direction: column; gap: 16px; }

.annotate-field-group { display: flex; flex-direction: column; gap: 8px; }
.annotate-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Fibroid type buttons */
.fibroid-type-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.ftype-btn {
  flex: 1; min-width: 80px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.ftype-btn:hover { border-color: var(--accent); color: var(--text); }
.ftype-btn.active {
  border-color: var(--accent);
  background: rgba(46,168,255,0.12);
  color: var(--accent);
  font-weight: 600;
}

/* Scale detection row */
.scale-detect-row { display: flex; flex-direction: column; gap: 8px; }
.scale-status {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.scale-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.scale-dot.idle      { background: var(--muted); }
.scale-dot.detecting { background: var(--warning); animation: livePulse 1s infinite; }
.scale-dot.found     { background: var(--success); }
.scale-dot.not-found { background: var(--danger); }

.scale-override {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.82rem; color: var(--muted);
}
.scale-override input {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px;
}

/* Measurement row */
.measure-row { display: flex; gap: 10px; }
.measure-input { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.measure-input label { font-size: 0.78rem; color: var(--muted); }
.measure-input input {
  width: 100%;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 0.88rem;
}

/* Bbox preview */
.annotate-bbox-preview {
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.bbox-preview-title { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.bbox-preview-vals { font-size: 0.82rem; color: var(--text); font-family: monospace; }

/* Save result banner */
.annotate-save-result {
  margin-top: 10px; padding: 10px 14px;
  border-radius: 6px; font-size: 0.84rem; line-height: 1.5;
}
.annotate-save-result.success {
  background: rgba(63,185,80,0.12); border: 1px solid var(--success); color: var(--success);
}
.annotate-save-result.error {
  background: rgba(248,81,73,0.12); border: 1px solid var(--danger); color: var(--danger);
}

/* ── Training Control Center ──────────────────────────────────────────────── */
.training-status.running { background: #1a2b0d; color: #3fb950; border: 1px solid #3fb950; }

.tr-gauge { text-align: center; padding: 10px 0 4px; }
.tr-gauge-value { font-size: 44px; font-weight: 700; color: var(--accent); line-height: 1.1; }
.tr-gauge-target { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.tr-gauge-bar { height: 10px; }

.tr-start-opts { display: flex; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.tr-start-opts label { color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.tr-start-opts input {
  width: 90px; padding: 6px 8px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}

.tr-msg { margin-top: 10px; font-size: 13px; min-height: 18px; }

.tr-table-wrap { max-height: 320px; overflow-y: auto; }
.tr-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tr-table th, .tr-table td { padding: 7px 10px; text-align: center; }
.tr-table thead th {
  position: sticky; top: 0; background: var(--surface2);
  color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border);
}
.tr-table tbody tr { border-bottom: 1px solid var(--border); }
.tr-table tbody tr:hover { background: var(--surface2); }
.tr-table tr.tr-best td { color: #3fb950; font-weight: 600; }

/* ── Exam (trainee) — mobile-friendly ─────────────────────────────────────── */
#tab-exam { direction: rtl; max-width: 760px; margin: 0 auto; padding: 12px; }
.exam-intro { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; text-align: center; }
.exam-field { display: block; margin: 12px auto; max-width: 320px; text-align: right; color: var(--muted); font-size: 14px; }
.exam-field input { width: 100%; padding: 10px 12px; margin-top: 4px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 16px; }

.exam-topbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 4px; color: var(--muted); font-weight: 600; }
.exam-stage { position: relative; width: 100%; height: 56vh; max-height: 560px; background: #000; border-radius: 12px; overflow: hidden; touch-action: none; }
#examCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; }

.exam-controls { margin-top: 12px; }
.exam-q { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.exam-q > span { font-size: 17px; font-weight: 600; }
.exam-yesno { display: flex; gap: 10px; }
.exam-btn { padding: 12px 28px; font-size: 17px; font-weight: 700; border-radius: 10px; border: 2px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer; }
.exam-btn.sel { border-color: var(--accent); background: var(--accent); color: #fff; }
.exam-hint { background: var(--surface2); border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.exam-hint b { color: var(--text); }
.exam-hint .secondary-btn { margin-top: 8px; }
.exam-nav { display: flex; gap: 12px; }
.exam-nav button { flex: 1; padding: 14px; font-size: 16px; }
.exam-done { text-align: center; padding: 48px 16px; }

@media (max-width: 600px) {
  .exam-stage { height: 48vh; }
  .exam-q { flex-direction: column; align-items: stretch; }
  .exam-btn { flex: 1; }
}

/* ── Doctor review tab ────────────────────────────────────────────────────── */
#tab-doctor { direction: rtl; }
.doctor-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
.doctor-list { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; max-height: 80vh; overflow-y: auto; }
.doctor-list-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 10px; }
.doc-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid var(--border); margin-bottom: 8px; background: var(--surface2); }
.doc-item:hover { border-color: var(--accent); }
.doc-item.reviewed { opacity: .65; }
.doc-item-name { font-weight: 600; }
.doc-item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.doctor-main { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.doctor-empty { color: var(--muted); text-align: center; padding: 60px 16px; }
.doctor-info { margin-bottom: 10px; color: var(--text); font-size: 14px; }
.doctor-stage { height: 50vh; }
.doctor-legend { display: flex; gap: 14px; align-items: center; margin: 10px 0; font-size: 13px; flex-wrap: wrap; }
.lg-cyan { color: #00c8ff; } .lg-green { color: #2ecc40; }
.doctor-form label { display: block; margin: 8px 0; color: var(--muted); font-size: 13px; }
.doctor-form input, .doctor-form textarea { width: 100%; padding: 8px 10px; margin-top: 4px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 15px; }
.doctor-actions { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
@media (max-width: 700px) { .doctor-layout { grid-template-columns: 1fr; } }

/* ── Auth overlay (login / register) ──────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 20, 0.78); backdrop-filter: blur(4px);
}
#auth-overlay .auth-card {
  width: 340px; max-width: 90vw; background: #161b22;
  border: 1px solid #2a3340; border-radius: 12px; padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45); color: #e6edf3;
  font-family: system-ui, sans-serif;
}
#auth-overlay h2 { margin: 0 0 16px; font-size: 1.25rem; text-align: center; }
#auth-overlay label { display: block; font-size: .8rem; color: #9fb0c0; margin: 12px 0 4px; }
#auth-overlay input {
  width: 100%; box-sizing: border-box; padding: 10px 12px;
  background: #0d1117; border: 1px solid #30363d; border-radius: 8px;
  color: #e6edf3; font-size: .95rem;
}
#auth-overlay input:focus { outline: none; border-color: #2f81f7; }
#auth-overlay button {
  width: 100%; margin-top: 18px; padding: 11px; border: 0; border-radius: 8px;
  background: #2f81f7; color: #fff; font-size: .95rem; font-weight: 600; cursor: pointer;
}
#auth-overlay button:hover { background: #4090ff; }
#auth-overlay .auth-toggle { margin: 14px 0 0; text-align: center; font-size: .85rem; color: #9fb0c0; }
#auth-overlay .auth-toggle a { color: #2f81f7; text-decoration: none; }
#auth-overlay .auth-error {
  background: #3d1418; border: 1px solid #6e2730; color: #ffb3ba;
  padding: 8px 10px; border-radius: 7px; font-size: .82rem; margin-bottom: 4px;
}

/* ── Logged-in user badge + logout (injected by auth.js) ──────────────────── */
#user-badge {
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: auto; padding-left: 12px; font-size: .85rem;
}
#user-badge .ub-name { color: #e6edf3; font-weight: 600; }
#user-badge .ub-role {
  text-transform: uppercase; font-size: .68rem; letter-spacing: .04em;
  background: #1f6feb; color: #fff; padding: 2px 7px; border-radius: 10px;
}
#user-badge #ub-logout {
  background: transparent; border: 1px solid #30363d; color: #9fb0c0;
  padding: 4px 12px; border-radius: 7px; cursor: pointer; font-size: .8rem;
}
#user-badge #ub-logout:hover { border-color: #f85149; color: #f85149; }
/* On pages without a flex header (e.g. admin), pin it to the corner */
body > #user-badge { position: fixed; top: 14px; right: 18px; margin: 0; z-index: 50; }
