/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg:        #0b0d12;
  --bg-1:      #10131a;
  --bg-2:      #171c27;
  --bg-3:      #1e2435;
  --border:    #28324a;
  --border-2:  #38455e;
  --text:      #e2e8f0;
  --text-2:    #94a3b8;
  --text-3:    #64748b;
  --accent:    #4f7ded;
  --accent-2:  #3462cc;
  --green:     #22c55e;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --mono:      'IBM Plex Mono', monospace;
  --sans:      'IBM Plex Sans', sans-serif;
  --radius:    6px;
  --radius-lg: 10px;
  /* Surface aliases used by editor and modals */
  --surface:   #10131a;
  --surface-2: #171c27;
  --surface-3: #1e2435;
  --shadow:    0 4px 16px rgba(0,0,0,0.5);
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
input, button, select, textarea { font-family: inherit; }

/* ── Nav ───────────────────────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  height: 56px;
}
.nav-inner {
  max-width: 1380px; margin: 0 auto; padding: 0 24px;
  height: 100%; display: flex; align-items: center; gap: 32px;
}
.nav-logo {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.logo-mark {
  width: 32px; height: 32px;
  background-color: transparent;
  background-image: url('/static/img/RubyhallLogo.png');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  border-radius: 0;
  border: none;
  display: block;
  overflow: hidden;
  flex-shrink: 0;
}
.logo-text {
  font-size: 15px; font-weight: 500; color: var(--text);
}
.logo-text-stack {
  display: block;
  width: max-content;
  line-height: 1.05;
  white-space: normal;
}
.logo-text-top {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.logo-text-bottom {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.logo-text em { font-style: normal; color: var(--text-2); font-weight: 300; }
.nav-links {
  flex: 1; align-items: center; gap: 4px;
  display: flex;
}
.nav-link {
  padding: 6px 12px; border-radius: var(--radius);
  color: var(--text-2); font-size: 14px;
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--bg-2); }
.nav-link.active { color: var(--text); background: var(--bg-2); font-weight: 500; position: relative; }
.nav-link.active::after { content: ''; position: absolute; bottom: -2px; left: 12px; right: 12px; height: 2px; background: var(--primary, #6366f1); border-radius: 2px; }
.nav-user {
  display: flex; align-items: center; gap: 12px; margin-left: auto;
}
.nav-user-name { font-size: 13px; color: var(--text-3); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  border: none; cursor: pointer;
  transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-outline  { background: transparent; color: var(--text); border: 1px solid var(--border-2); }
.btn-outline:hover:not(:disabled) { background: var(--bg-2); }
.btn-ghost    { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-2); color: var(--text); }
.btn-danger   { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* Temporary visual states for Save Draft button */
.btn-saved {
  background: transparent !important;
  color: var(--text) !important;
  border-color: var(--green) !important;
}
.btn-saved .btn-icon { color: var(--green); }
.btn-error {
  background: transparent !important;
  color: var(--text) !important;
  border-color: var(--red) !important;
}
.btn-error .btn-icon { color: var(--red); }

/* ── Main layout ───────────────────────────────────────────────────────── */
.main { max-width: 1380px; margin: 0 auto; padding: 32px 24px 72px; }
.page-header { margin-bottom: 32px; }
.page-title { font-size: 22px; font-weight: 600; }
.page-sub { color: var(--text-2); font-size: 14px; margin-top: 4px; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

/* ── Form ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 9px 12px;
  background: var(--bg-2); border: 1px solid var(--border-2);
  border-radius: var(--radius); color: var(--text); font-size: 14px;
  transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-error { font-size: 12px; color: var(--red); margin-top: 4px; }

/* ── Study grid ─────────────────────────────────────────────────────────── */
.study-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.study-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  position: relative;
}
.study-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.study-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.study-modality {
  font-family: var(--mono); font-size: 11px;
  background: var(--bg-3); color: var(--text-2);
  padding: 2px 8px; border-radius: 4px;
}
.study-report-badge {
  font-size: 11px; font-weight: 600;
  background: #14532d; color: var(--green);
  padding: 2px 8px; border-radius: 4px;
}
.study-patient { font-size: 15px; font-weight: 500; margin: 10px 0 4px; }
.study-meta { font-size: 12px; color: var(--text-3); }
.study-footer {
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.study-count { font-size: 12px; color: var(--text-3); font-family: var(--mono); }
.study-status {
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 4px;
}
.status-ready     { background: #1e3a5f; color: #60a5fa; }
.status-reported  { background: #14532d; color: var(--green); }
.status-processing{ background: var(--bg-3); color: var(--text-3); }
.source-badge {
  font-size: 10px; font-weight: 600; font-family: var(--mono);
  padding: 2px 6px; border-radius: 3px; margin-left: 6px;
  vertical-align: middle;
}
.source-dicom { background: #431407; color: #fb923c; }
.source-web   { background: var(--bg-3); color: var(--text-3); }

/* ── Upload ─────────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius-lg);
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent); background: rgba(59,130,246,.04);
}
.drop-icon { font-size: 40px; margin-bottom: 12px; }
.drop-label { font-size: 15px; font-weight: 500; margin-bottom: 6px; }
.drop-hint { font-size: 13px; color: var(--text-3); }
.file-list { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.file-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-2); border-radius: var(--radius);
  padding: 8px 12px; font-size: 13px;
}
.file-item-name { color: var(--text-2); font-family: var(--mono); }
.file-item-size { color: var(--text-3); }
.progress-bar {
  height: 4px; background: var(--bg-3); border-radius: 2px;
  overflow: hidden; margin-top: 16px;
}
.progress-fill {
  height: 100%; background: var(--accent);
  border-radius: 2px; transition: width .3s;
  width: 0%;
}
.upload-status { font-size: 13px; color: var(--text-2); margin-top: 10px; }

/* ── Alert ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 14px; margin-bottom: 16px;
}
.alert-error { background: #450a0a; border: 1px solid #7f1d1d; color: #fca5a5; }
.alert-success { background: #052e16; border: 1px solid #14532d; color: #86efac; }
.alert-info { background: #0c1a2e; border: 1px solid #1e3a5f; color: #93c5fd; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 10px;
  color: var(--text-3); font-weight: 500;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-2); }

/* Report tables keep their full grid, including the last row border. */
.report-prose-view table tr:last-child td,
.report-prose-view table tr:last-child th,
.section-quill-editor table tr:last-child td,
.section-quill-editor table tr:last-child th {
  border-bottom: 1px solid #4a5878;
}

/* ── Powered-by footer ─────────────────────────────────────────────────── */
#page-powered-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 7px 20px;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.3px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
#page-powered-footer .footer-copy { text-align: left; color: var(--text-3); }
#page-powered-footer .footer-copy strong { color: var(--text); font-weight: 600; }
#page-powered-footer .footer-copy .footer-copy-link { color: inherit; text-decoration: none; }
#page-powered-footer .footer-copy .footer-copy-link:hover { text-decoration: underline; text-underline-offset: 2px; }
#page-powered-footer .footer-copy .revue-mark {
  background: linear-gradient(90deg, #5ec2a8, #6aa8c9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#page-powered-footer .footer-copy .aramis-mark { color: #7ab8cf; }
#page-powered-footer .footer-links { text-align: center; }
#page-powered-footer .footer-links a { color: var(--text-3); transition: color .15s; }
#page-powered-footer .footer-links a:hover { color: var(--text-2); }
#page-powered-footer .footer-sep { color: var(--text-3); opacity: .5; margin: 0 6px; }
#page-powered-footer .footer-attrib { text-align: right; }
#page-powered-footer .revue-mark {
  background: linear-gradient(90deg, #5ec2a8, #6aa8c9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 600;
}
#page-powered-footer .aramis-mark { color: #7ab8cf; font-weight: 600; }
@media (max-width: 720px) {
  #page-powered-footer {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 6px 12px;
  }
  #page-powered-footer .footer-copy,
  #page-powered-footer .footer-links,
  #page-powered-footer .footer-attrib { text-align: center; }
}

/* ── Auth page ──────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: calc(100vh - 144px);
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px;
}
.auth-header-logo { display: flex; justify-content: center; align-items: center; }
.auth-title { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.auth-title .logo-text-top { font-size: 12px; font-weight: 500; color: var(--text-2); letter-spacing: 0.01em; text-align: center; }
.auth-title .logo-text-bottom { font-size: 24px; font-weight: 600; color: var(--text); text-align: center; }
.auth-sub { font-size: 13px; color: var(--text-3); margin-bottom: 28px; }
.auth-tabs { display: flex; gap: 2px; margin-bottom: 24px; background: var(--bg-2); border-radius: var(--radius); padding: 3px; }
.auth-tab {
  flex: 1; text-align: center; padding: 7px;
  border-radius: 4px; font-size: 13px; font-weight: 500;
  cursor: pointer; color: var(--text-3); border: none; background: none;
  transition: all .15s;
}
.auth-tab.active { background: var(--bg-3); color: var(--text); }

/* ── Utility ────────────────────────────────────────────────────────────── */
.mono { font-family: var(--mono); }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
.empty-state {
  text-align: center; padding: 64px 32px;
  color: var(--text-3); font-size: 14px;
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ═══════════════════════════════════════════════════════════════════════════ */
/* Report Editor                                                               */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* ── Fixed header wrapper (topbar + toolbar stacked) ────────────────────── */
.editor-fixed-header {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  width: min(1200px, 100%);
  z-index: 50;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.editor-topbar {
  background: #1c1f2e;
  border-bottom: 1px solid var(--border);
  padding: 0;
}
.editor-topbar-inner {
  padding: 9px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.editor-topbar-left  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.editor-topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.editor-patient-info { font-size: 13px; }
.editor-action-row   { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Menubar ─────────────────────────────────────────────────────────────── */
.editor-menubar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 49px;
  z-index: 40;
}
.menubar-group { display: flex; gap: 2px; }
.menubar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}
.mb-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.mb-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border);
}
.mb-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

/* ── Editor Area ─────────────────────────────────────────────────────────── */
.editor-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding-top: 90px; /* fallback; overridden by syncHeaderLayout() in JS */
}
.editor-prose {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 60vh;
  padding: 32px 40px;
  outline: none;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}
.editor-prose .ProseMirror {
  outline: none;
  min-height: 50vh;
}
.editor-prose .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--text-3);
  pointer-events: none;
  height: 0;
}

/* Section blocks */
.editor-prose section[data-section] {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.editor-prose section[data-section]:last-child {
  border-bottom: none;
}
.editor-prose section[data-section] > h3:first-child,
.editor-prose section[data-section] > h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 8px 0;
  padding: 0;
}

/* Inline images — show annotation cursor */
.editor-prose img[data-image-id] {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  transition: border-color 0.15s;
  max-width: 100%;
  display: block;
  margin: 10px 0;
}
.editor-prose img[data-image-id]:hover {
  border-color: var(--accent);
}

/* Tables */
.editor-prose table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 13px;
}
.editor-prose td, .editor-prose th {
  border: 1px solid var(--border);
  padding: 6px 10px;
  min-width: 60px;
}
.editor-prose th {
  background: var(--surface-3);
  font-weight: 600;
}
.editor-prose .selectedCell { background: rgba(var(--accent-rgb, 59,130,246), 0.15); }

/* ── Autosave Bar ────────────────────────────────────────────────────────── */
.autosave-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  padding: 5px 20px;
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 30;
}
.save-indicator {
  font-size: 11px;
  min-width: 120px;
  text-align: center;
  padding: 3px 10px;
  border-radius: 999px;
  transition: background .15s, color .15s, border-color .15s;
}
.save-indicator.saving {
  color: var(--text-3);
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.18);
}
.save-indicator.saved  {
  color: #86efac;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.28);
}
.save-indicator.error  {
  color: var(--red, #f87171);
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.24);
}

/* ── Template Card ───────────────────────────────────────────────────────── */
.template-card {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.template-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

/* ── Annotation Toolbar ──────────────────────────────────────────────────── */
.annotation-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  width: 100%;
  justify-content: center;
}
.ann-tool {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}
.ann-tool:hover  { background: var(--surface-3); color: var(--text); }
.ann-tool.active { background: var(--accent); color: #fff; border-color: transparent; }
.ann-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

/* ── Report Prose View (read-only in report.html) ───────────────────────── */
.report-prose-view section[data-section] {
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.report-prose-view section[data-section] > h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 8px 0;
}
.report-prose-view ol,
.report-prose-view ul { padding-left: 0; list-style-position: inside; }
.report-prose-view li { margin-bottom: 3px; line-height: 1.6; }
.report-prose-view img {
  max-width: 100%;
  border-radius: 4px;
  margin: 8px 0;
  display: block;
}


/* ═══════════════════════════════════════════════════════════════════════════ */
/* Report Editor — Custom toolbar + Quill section layout                       */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* ── Toolbar container ───────────────────────────────────────────────────── */
.editor-quill-toolbar {
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding: 0;
}
.tb-inner {
  padding: 6px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* Each group is a pill-shaped cluster */
.editor-quill-toolbar .ql-formats {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 7px;
  padding: 2px 4px;
  margin-right: 0;
}
.editor-quill-toolbar .ql-formats:last-child { margin-right: 0; }

/* Vertical separator between toolbar groups */
.tb-sep {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.1);
  flex-shrink: 0;
  align-self: center;
}

/* Icon buttons */
.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  user-select: none;
  flex-shrink: 0;
}
.tb-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
.tb-btn.active {
  background: rgba(79,125,237,0.2);
  color: #7ba8f5;
  border-color: rgba(79,125,237,0.35);
}

/* Style select (Normal / H1 / H2 / H3) */
.tb-select {
  height: 28px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748b'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}
.tb-select:hover { background-color: rgba(255,255,255,0.08); color: var(--text); }
.tb-select:focus { border-color: rgba(79,125,237,0.4); color: var(--text); }
.tb-select option { background: #1e2435; color: var(--text); }

/* Action buttons (Image, Template, +Save) */
.tb-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.tb-action-btn:hover {
  background: rgba(79,125,237,0.12);
  border-color: rgba(79,125,237,0.3);
  color: #a5bcf8;
}

/* ── Template dropdown ───────────────────────────────────────────────────── */
.tb-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 220px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 200;
  overflow: hidden;
}
.tb-dropdown-list {
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.tb-dropdown-list::-webkit-scrollbar { width: 4px; }
.tb-dropdown-list::-webkit-scrollbar-track { background: transparent; }
.tb-dropdown-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}
.tb-dropdown-list::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.28); }
.tb-dd-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 8px 12px 4px;
  border-top: 1px solid var(--border);
}
.tb-dd-section:first-child { border-top: none; }
.tb-dd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
  gap: 10px;
}
.tb-dd-item:hover { background: rgba(59,130,246,0.1); }
.tb-dd-name { font-size: 12.5px; color: var(--text); font-weight: 500; }
.tb-dd-mod  {
  font-size: 10px;
  color: var(--text-3);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Quill snow overrides */
.ql-snow.ql-toolbar { display: none; }
.ql-container.ql-snow { border: none !important; }

/* ── Section Layout ──────────────────────────────────────────────────────── */
.editor-sections {
  padding: 0 0 80px;  /* no horizontal padding — sections align flush with header edges */
}

.report-section {
  margin-bottom: 0;
  border-radius: 0;
}

.section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  padding: 12px 16px 6px 13px; /* 13px + 3px border = 16px, aligns with toolbar */
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  margin-top: 0;
  background: var(--surface);
  position: sticky;
  top: 96px;
  z-index: 10;
}
.report-section:first-child .section-label { border-top: none; }

/* Quill editor within each section */
.section-quill-editor { background: var(--surface-2); }
.section-quill-editor .ql-container.ql-snow {
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  font-family: inherit;
}
.section-quill-editor .ql-editor {
  min-height: 88px;
  padding: 14px 16px;   /* 16px left = same baseline as toolbar + section label */
  color: var(--text);
}
.section-quill-editor .ql-editor.ql-blank::before {
  color: var(--text-3);
  font-style: normal;
  font-size: 13px;
  left: 16px;
}
#section-wrap-findings  .ql-editor { min-height: 180px; }
#section-wrap-impression .ql-editor { min-height: 100px; }

/* Quill tooltip */
.ql-tooltip { background: var(--bg-3) !important; color: var(--text) !important;
  border-color: var(--border) !important; box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important; }

/* ── Finalized Banner ────────────────────────────────────────────────────── */
.finalized-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(52,211,153,0.07);
  border-top: 1px solid rgba(52,211,153,0.2);
  border-bottom: 1px solid rgba(52,211,153,0.2);
  color: #6ee7b7;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 16px;  /* same 16px as toolbar/topbar */
}
.editor-wrap.report-is-final .finalized-banner { display: flex; }
.editor-wrap.report-is-final .section-quill-editor .ql-editor {
  opacity: 0.8;
  background: var(--bg-1);
  cursor: default;
}

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop.hidden { display: none !important; }
.modal-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ── Version History Panel ───────────────────────────────────────────────── */
.vh-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  width: min(92vw, 1100px);
  height: 80vh;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}
.vh-sidebar {
  width: 260px;
  min-width: 220px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.vh-sidebar-head {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.vh-sidebar-head h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
}
.vh-sidebar-head p {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.4;
}
.vh-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.vh-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.vh-row:hover   { background: var(--bg-2); }
.vh-row.active  { background: rgba(59,130,246,0.08); border-left-color: var(--accent); }
.vh-row-title   { font-size: 13px; font-weight: 600; color: var(--text); }
.vh-row-meta    { font-size: 11px; color: var(--text-3); }
.vh-sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}
.vh-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.vh-preview-bar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-3);
}
.vh-preview iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}
.vh-preview-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 13px;
  flex-direction: column;
  gap: 8px;
}

/* ── Version History Rows (legacy, kept for other uses) ─────────────────── */
.version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.version-row:last-child { border-bottom: none; }

/* ── Image preview in editor ─────────────────────────────────────────────── */
.section-quill-editor .ql-editor img {
  max-width: min(100%, 560px);
  border-radius: 8px;
  display: block;
  margin: 10px 0;
  box-shadow: 0 3px 12px rgba(0,0,0,0.4);
}
.section-quill-editor .ql-editor img[data-image-id] {
  cursor: pointer;
  border: 2px solid rgba(99,102,241,0.25);
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.12s;
  position: relative;
}
.section-quill-editor .ql-editor img[data-image-id]:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(59,130,246,0.18), 0 6px 20px rgba(0,0,0,0.5);
  transform: translateY(-2px);
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ── Prior Records Panel ─────────────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

.prior-panel {
  position: fixed;
  top: 0; right: 0;
  width: 300px; height: 100vh;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
}
.prior-panel.open { transform: translateX(0); }

.prior-panel-header {
  display: flex;
  align-items: center;
  padding: 9px 10px 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  gap: 4px;
}
.prior-panel-header > span:first-child { flex: 1; display: flex; align-items: center; gap: 6px; }

.prior-count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 15px;
  background: var(--accent);
  color: #fff;
  font-size: 9px; font-weight: 700;
  border-radius: 8px;
  padding: 0 4px;
}

.prior-timeline {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.prior-record-card {
  padding: 7px 8px 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  border-left: 3px solid #888;
  background: var(--surface-1);
  transition: background 0.12s;
}
.prior-record-card:hover { background: var(--bg-elevated, rgba(255,255,255,0.04)); }
.prior-record-card.pinned {
  border-color: rgba(255,200,60,0.35);
  background: rgba(255,200,60,0.04);
}

.prior-record-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.prior-type-tag {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  flex-shrink: 0;
  padding: 2px 6px;
  border-radius: 3px;
  /* background injected inline via JS for per-type color */
}

.prior-record-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.prior-record-date {
  font-size: 10px;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
}

.prior-record-ts {
  font-size: 10px;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
}

.prior-record-meta {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prior-record-actions {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
}

.prior-action-btn {
  width: 22px; height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 4px;
  color: var(--text-3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
  text-decoration: none;
}
.prior-action-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.prior-action-btn.danger:hover { background: rgba(239,68,68,0.12); color: var(--danger, #ef4444); }
.prior-pin-btn { opacity: 0.35; font-size: 11px; }
.prior-pin-btn:hover, .prior-pin-btn.active { opacity: 1; }

/* Tab strip in Add Record modal */
.prior-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.prior-tab {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.prior-tab:hover { border-color: var(--accent); }
.prior-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Study search results in DICOM tab */
.prior-study-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.prior-study-result {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.12s;
}
.prior-study-result:hover { border-color: var(--accent); }
.prior-study-result.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ── Comparison Overlay ──────────────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

.compare-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.compare-overlay.hidden { display: none; }

.compare-header {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.compare-title {
  font-size: 14px;
  font-weight: 600;
}

.compare-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.compare-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.compare-pane-label {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.compare-pane-content {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-1);
}

.compare-iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.compare-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}

.compare-divider {
  width: 4px;
  background: var(--border);
  flex-shrink: 0;
  cursor: col-resize;
}

/* ── Floating Reference Panels ─────────────────────────────────────────────── */
.floating-ref-panel {
  position: fixed;
  z-index: 1200;
  width: 500px;
  height: 620px;
  min-width: 260px;
  min-height: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  resize: both;
  overflow: hidden;
}
.floating-ref-titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--bg-elevated, var(--surface-2));
  border-bottom: 1px solid var(--border);
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}
.floating-ref-title {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-1);
}
.floating-ref-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.floating-ref-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Legal panel tabs ─────────────────────────────────────────────────────── */
.legal-tabs {
  display: flex;
  gap: 0;
  padding: 6px 10px 0;
  background: var(--bg-elevated, var(--surface-2));
  border-bottom: 1px solid var(--border);
}
.legal-tab {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.legal-tab:hover { color: var(--text-2); }
.legal-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* RESPONSIVE / MOBILE STYLES                                                  */
/* Breakpoints: 1024px (tablet), 768px (mobile)                                */
/* NON-DESTRUCTIVE: all rules below override via @media — desktop unchanged.   */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* ── Mobile Warning Banner ───────────────────────────────────────────────── */
.mobile-warning-banner {
  display: none; /* hidden by default; shown via media query below */
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #451a03;
  border-bottom: 1px solid #92400e;
  color: #fde68a;
  font-size: 13px;
  padding: 10px 16px;
  position: relative;
  z-index: 99;
}
.mobile-warning-banner span { flex: 1; line-height: 1.5; }
.mobile-warning-banner button {
  background: transparent;
  border: none;
  color: #fde68a;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
  line-height: 1;
  opacity: 0.7;
}
.mobile-warning-banner button:hover { opacity: 1; }

/* ── Desktop-only notice (shown on mobile instead of desktop-only buttons) ── */
.desktop-only-notice {
  display: none; /* shown in media query below */
  font-size: 12px;
  color: var(--text-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  align-items: center;
  gap: 6px;
}

/* ── Hamburger button (desktop: hidden) ──────────────────────────────────── */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px; height: 36px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  margin-left: auto;
  flex-shrink: 0;
}
.hamburger-btn span {
  display: block;
  width: 20px; height: 2px;
  background: var(--text-2);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}
.hamburger-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn.open span:nth-child(2) { opacity: 0; }
.hamburger-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Nav drawer (mobile full-screen overlay) ──────────────────────────────── */
.nav-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 52px; left: 0;
  width: 80vw; max-width: 300px;
  height: calc(100vh - 52px - 60px);
  padding-bottom: 16px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  z-index: 500;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  box-sizing: border-box;
}
@media (max-width: 1024px) {
  .nav-drawer { display: flex; }
}
.nav-drawer.open { transform: translateX(0); }
.nav-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 499;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.nav-drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.nav-drawer-header {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-drawer-links {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.nav-drawer-links .nav-link {
  display: block;
  padding: 10px 14px;
  font-size: 15px;
  border-radius: var(--radius);
}
.nav-drawer-user {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}
.nav-drawer-user-name {
  font-size: 13px;
  color: var(--text-3);
}

/* ── Prior panel toggle button (mobile only) ──────────────────────────────── */
.prior-panel-toggle-btn {
  display: none; /* shown in media query */
  position: fixed;
  bottom: 20px;
  right: 16px;
  z-index: 140;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  align-items: center;
  gap: 6px;
}

/* ── Dashboard study cards (mobile card view) ────────────────────────────── */
.dash-card-list { display: none; } /* hidden on desktop, shown on mobile */
.dash-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s;
}
.dash-card:hover { border-color: var(--border-2); }
.dash-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}
.dash-card-patient { font-size: 15px; font-weight: 500; color: var(--text); }
.dash-card-meta { font-size: 12px; color: var(--text-3); margin-bottom: 10px; }
.dash-card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.dash-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Filter accordion for mobile ─────────────────────────────────────────── */
.filter-accordion { display: none; } /* shown in mobile media query */
.filter-accordion summary {
  cursor: pointer;
  padding: 10px 14px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 8px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.filter-accordion summary::-webkit-details-marker { display: none; }
.filter-accordion[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.filter-accordion-body {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}


/* ═══════════════════════════════════════════════════════════════════════════ */
/* @media (max-width: 1024px) — Tablet                                         */
/* ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {

  /* Desktop notice — page-scoped only (body.needs-desktop), NOT global.
     Emergency phone use is a first-class path, so most pages show nothing. */
  body.needs-desktop .mobile-warning-banner { display: flex; }

  /* Hamburger visible, regular nav-links hidden */
  .hamburger-btn { display: flex; }
  .nav-links { display: none !important; }
  #nav-guest-links { display: none !important; }
  .nav-drawer { display: flex; }
  .nav-drawer-backdrop { display: block; }

  /* Prior panel toggle button visible */
  .prior-panel-toggle-btn { display: flex; }

  /* Floating reference panels — full width on tablet */
  .floating-ref-panel {
    width: min(95vw, 500px) !important;
    right: 8px !important;
    left: auto !important;
  }

  /* Modal cards — prevent overflow */
  .modal-card {
    max-width: min(600px, 95vw) !important;
  }

  /* Compare overlay — stack panes vertically on tablet */
  .compare-body { flex-direction: column; }
  .compare-divider { width: 100%; height: 4px; cursor: row-resize; }

}


/* ═══════════════════════════════════════════════════════════════════════════ */
/* @media (max-width: 768px) — Mobile                                          */
/* ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Global layout ── */
  /* Extra bottom padding so content clears the fixed powered-by footer (3-row stack on mobile) */
  .main { padding: 16px 12px 80px; }
  /* Stop long inline code / paths / URLs from forcing page-wide horizontal scroll
     (help pages embed paths like DATA_DIR/dcm/... that don't wrap by default). */
  .main { overflow-x: hidden; }
  .main code, .main kbd, .main samp {
    overflow-wrap: anywhere; word-break: break-word; white-space: normal;
  }
  .main pre {
    overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%;
  }
  .nav { height: auto; min-height: 52px; }
  .nav-inner { padding: 0 12px; gap: 8px; flex-wrap: nowrap; }

  /* ═══════════════════════════════════════════════════════════════════════ */
  /* MOBILE TYPE SCALE — tuned to int'l mobile norms (iOS HIG / Material 3).    */
  /* Ramp: caption 12 · body-sm 13 · body 15 · item 15 · subhead 16 · title 20.*/
  /* Balanced density: ~4 list cards per screen, a11y floors kept (body ≥14,   */
  /* tap ≥44). Desktop unaffected (all inside this media block).               */
  /* ═══════════════════════════════════════════════════════════════════════ */

  /* Base body text */
  body { font-size: 15px; line-height: 1.5; }

  /* Display / page titles — slightly lighter & tighter than before */
  .page-title       { font-size: 20px; line-height: 1.25; letter-spacing: -0.01em; }
  .page-header      { margin-bottom: 14px; }
  .page-sub,
  .page-header .page-sub { font-size: 13px; line-height: 1.4; }

  /* Section / card titles */
  .card-title       { font-size: 15.5px; line-height: 1.3; }
  h1 { font-size: 22px; line-height: 1.2; }
  h2 { font-size: 19px; line-height: 1.25; }
  h3 { font-size: 16px; line-height: 1.3; }

  /* Body copy in content cards */
  .card p, .card li, .card td, .main p, .main li { font-size: 15px; line-height: 1.55; }

  /* Labels / captions / meta */
  .form-label       { font-size: 13px; }
  .page-sub .source-badge, .badge, .chip, small { font-size: 12px; }

  /* Dashboard cards — patient name 15px (was 16, stops the 2-line wrap), tighter meta */
  .dash-card-patient { font-size: 15px; line-height: 1.25; }
  .dash-card-meta    { font-size: 12.5px; line-height: 1.4; }

  /* ── Page headings (legacy hook kept) ── */

  /* ── Spacing rhythm: tighter cards (~120px) → ~4 list items per screen ── */
  .card { padding: 16px 14px; margin-bottom: 12px; }
  .card:last-child { margin-bottom: 0; }

  /* ── Tables scroll horizontally ── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Forms ── */
  .form-group { margin-bottom: 12px; }

  /* ── Buttons — ensure 44px touch targets (Apple HIG / Material 48dp) ── */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; padding-left: 12px; padding-right: 12px; }
  /* Small icon buttons get a 44px tap area even when the glyph is smaller */
  .tap-target { min-width: 44px; min-height: 44px; display: inline-flex;
                align-items: center; justify-content: center; }

  /* ── Dashboard card layout — tightened for ~4 cards/screen ── */
  .dash-card-list { display: block; }
  .dash-card { padding: 11px 13px; margin-bottom: 9px; border-radius: var(--radius); }
  .dash-card-top { margin-bottom: 4px; align-items: center; gap: 8px; }
  /* Patient name gets row priority; urgency chip never pushes it to wrap */
  .dash-card-patient { flex: 1 1 auto; min-width: 0; }
  .dash-card-urgency { flex: 0 0 auto; max-width: 50%; }
  .dash-card-urgency .priority-chip,
  .dash-card-urgency .tat-live {
    font-size: 10.5px; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .dash-card-meta { margin-bottom: 8px; }
  /* Table in dashboard hidden; show cards instead */
  .dashboard-table-wrap { display: none; }

  /* ── Filter accordion shown; desktop filter bar hidden ── */
  .filter-accordion { display: block; }
  .dashboard-filters-desktop { display: none; }

  /* ── Desktop-only features: hide buttons, show notice ── */
  .desktop-only-feature { display: none !important; }
  .desktop-only-notice { display: inline-flex; }

  /* ── Auth page ── */
  .auth-card { padding: 24px 20px; }
  .auth-wrap { padding: 16px; }

  /* ── Editor ── */
  .editor-wrap { padding-left: 4px; padding-right: 4px; }
  .editor-fixed-header { width: 100%; left: 0; transform: none; }
  .tb-inner { padding: 4px 8px; gap: 4px; }
  .tb-btn { width: 28px; height: 32px; }
  .tb-action-btn { height: 30px; padding: 0 8px; font-size: 11px; }
  .section-label { top: auto; position: relative; }
  .section-quill-editor .ql-editor { padding: 10px 12px; font-size: 16px; }
  #section-wrap-findings .ql-editor { min-height: 100px; }
  .editor-topbar-inner { padding: 7px 12px; gap: 8px; }

  /* ── Prior panel — full-width on mobile ── */
  .prior-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); }

  /* ── Floating panel — full width on mobile ── */
  .floating-ref-panel {
    width: 100% !important;
    height: 60vh !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    border-radius: 12px 12px 0 0;
    resize: none;
  }

  /* ── Version history panel ── */
  .vh-panel { flex-direction: column; width: 95vw; height: 90vh; }
  .vh-sidebar { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); max-height: 200px; }

  /* ── Autosave bar ── */
  .autosave-bar { flex-wrap: wrap; padding: 4px 12px; gap: 6px; }

  /* ── Inline width overrides for common patterns ── */
  /* These override inline style="width:XXXpx" on inputs/selects inside forms */
  .main input[type="text"],
  .main input[type="email"],
  .main input[type="password"],
  .main input[type="number"],
  .main select,
  .main textarea {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box;
  }

  /* ── Stop iOS Safari auto-zoom on focus: TEXT-ENTRY controls must be >=16px ──
     Only text inputs/textarea trigger the iOS focus-zoom, so only those are
     forced to 16px. Selects/buttons do NOT zoom, so they can stay smaller to
     avoid an oversized filter stack. */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="tel"], input[type="search"],
  input[type="date"], input[type="url"], textarea,
  .auth-card .form-input {
    font-size: 16px !important;
  }
  /* Selects (incl. filter dropdowns) — 14px, more compact than text inputs */
  select, .main select { font-size: 14px !important; }

  /* Touch heights: text inputs 44px; selects a touch shorter at 40px */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="tel"], input[type="search"],
  input[type="date"], .form-input { min-height: 44px; }
  select { min-height: 40px; }

  /* ── Tab bars (admin, settings) — wrap on mobile ── */
  .tab-bar { flex-wrap: wrap; gap: 4px; }
  .tab-btn { flex: 1 1 auto; min-width: 80px; text-align: center; }

  /* ── Flex rows that should stack on mobile ── */
  .mobile-stack { flex-direction: column !important; align-items: stretch !important; }
  .mobile-full { width: 100% !important; max-width: 100% !important; }

  /* ── Modal caps ── */
  .modal-card {
    max-width: 98vw !important;
    padding: 16px 14px;
    border-radius: 10px;
  }
  .modal-backdrop { padding: 8px; }

  /* ── Study grid (index page) ── */
  .study-grid { grid-template-columns: 1fr; }

  /* ── Drop zone ── */
  .drop-zone { padding: 32px 16px; }

  /* ── Upload: local folder notice shown on mobile ── */
  .local-folder-mobile-notice { display: block !important; }

  /* ── Hide desktop-only setting cards on mobile (e.g. RadiAnt download folder —
     RadiAnt is a Windows desktop viewer, irrelevant on a phone) ── */
  .desktop-only-card { display: none !important; }

  /* ── Dashboard filters — stack vertically on mobile ── */
  #filter-bar { flex-direction: column !important; align-items: stretch !important; }
  #filter-bar .form-input { width: 100% !important; max-width: 100% !important; }

  /* ── Collapse filters behind the "Filters" toggle (studies show first) ──
     Search box + the toggle stay visible; everything else hides until open. */
  .filters-toggle-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 14px; width: 100%;
    background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text-2); font-size: 14px; font-weight: 600; cursor: pointer;
  }
  #filter-bar:not(.filters-open) > *:not(#f-search):not(#f-sort):not(.filters-toggle-btn) {
    display: none !important;
  }
  /* Sort is a primary action — keep it visible on phones beside search,
     full width below the search box so the label isn't truncated. */
  #filter-bar #f-sort { width: 100% !important; min-height: 40px; }
  /* When open, restore the children the line above hid (respecting their own
     display rules; the two role-gated selects keep their inline display:none). */
  #filter-bar.filters-open > * { display: flex; }
  #filter-bar.filters-open > select,
  #filter-bar.filters-open > input { display: block; }
  #filter-bar.filters-open > #f-uploader[style*="display:none"],
  #filter-bar.filters-open > #f-assigned[style*="display:none"] { display: none !important; }

  /* ── Dashboard table vs card switching ── */
  .dashboard-table-wrap { display: none !important; }
  .dash-card-list { display: block; }

  /* ── Dark-mode contrast: clinically-important meta must be legible at 3am
     on a dimmed phone. Promote grey-on-dark (--text-3) meta to --text-2 so
     patient ID / modality / study date / priority clear WCAG 4.5:1. ── */
  .dash-card-meta,
  .dash-card-meta * { color: var(--text-2) !important; }
  .study-sub, .study-header-sub { color: var(--text-2) !important; }
}

/* ── Password show/hide toggle ───────────────────────────────────────────────*/
.pw-field { position: relative; }
.pw-field .form-input { padding-right: 44px; width: 100%; box-sizing: border-box; }
.pw-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-3); transition: color .15s;
}
.pw-toggle:hover { color: var(--text-2); }
.pw-toggle.pw-shown { color: var(--accent); }

/* ── Upload page: mobile vs desktop affordances ──────────────────────────────
   webkitdirectory folder picker is dead on iOS / unreliable on Android, so on
   mobile we hide it and lead with multi-file select (which works). */
.upload-label-mobile { display: none; }
/* Desktop: Select Files is the secondary affordance (folder is primary) */
@media (min-width: 769px) {
  .upload-file-btn { background: transparent; color: var(--accent); border: 1px solid var(--border); }

  /* ── Desktop filter bar: keep every control on ONE row ──────────────────────
     The inline pixel widths sum past the container and wrap to a 2nd row. Flex
     them so they share the row: search stays widest, the rest shrink evenly
     down to a readable min before any wrap. Overrides the inline width:NNNpx. */
  #filter-bar { flex-wrap: nowrap; gap: 8px; }
  #filter-bar > .form-input,
  #filter-bar > .upl-dropdown {
    flex: 1 1 0; min-width: 0; width: auto !important;
  }
  #filter-bar > #f-search { flex: 2 1 0; min-width: 160px; }   /* search widest */
  #filter-bar > #f-sort   { flex: 1.4 1 0; min-width: 130px; } /* sort label is long */
  #filter-bar > .upl-dropdown { min-width: 120px; }
  #filter-bar > .upl-dropdown .upl-trigger { width: 100%; }
}
@media (max-width: 768px) {
  .upload-folder-btn { display: none !important; }
  .upload-label-desktop { display: none; }
  .upload-label-mobile { display: inline; }
}

/* ── Report view on phone ────────────────────────────────────────────────────
   Native PDF-in-iframe reads poorly on mobile; lead with a full-screen open
   button and shrink prose side padding so text uses the narrow width. */
.report-open-pdf-btn { display: none; }
@media (max-width: 768px) {
  .report-open-pdf-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; min-height: 48px; font-size: 15px; font-weight: 600;
    margin-bottom: 12px;
  }
  /* De-emphasize the cramped inline iframe; the button is the primary path */
  .report-pdf-card { min-height: 50vh !important; opacity: .95; }
  .report-pdf-card iframe { height: 55vh !important; }
  /* In-app prose: tighten side padding, ensure readable body text */
  .report-prose-view {
    padding: 16px 14px !important;
  }
  .report-prose-view, .report-prose-view p, .report-prose-view li {
    font-size: 16px; line-height: 1.6;
  }
  .report-prose-view table { display: block; overflow-x: auto; }
}

/* Filters toggle button — mobile-only. Hide on tablet/desktop only, so the
   later cascade position doesn't override the ≤768px show rule. */
@media (min-width: 769px) { .filters-toggle-btn { display: none !important; } }

/* ═══════════════════════════════════════════════════════════════════════════ */
/* SKELETON LOADERS — reserve layout while data loads (less CLS than a spinner) */
/* ═══════════════════════════════════════════════════════════════════════════ */
.skel-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 10px;
}
.skel-line {
  height: 12px; border-radius: 6px; margin-bottom: 10px;
  background: linear-gradient(90deg,
    var(--bg-2) 25%, var(--border) 37%, var(--bg-2) 63%);
  background-size: 400% 100%;
  animation: skel-shimmer 1.4s ease infinite;
}
.skel-line:last-child { margin-bottom: 0; }
.skel-w-30 { width: 30%; } .skel-w-40 { width: 40%; }
.skel-w-50 { width: 50%; } .skel-w-60 { width: 60%; }
.skel-w-70 { width: 70%; }
@keyframes skel-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  .skel-line { animation: none; background: var(--bg-2); }
}

/* ── Mobile triage segmented filter (dashboard) — hidden on desktop ─────────── */
.mobile-triage-bar { display: none; }
@media (max-width: 768px) {
  .mobile-triage-bar {
    display: flex; gap: 6px; position: sticky; top: 0; z-index: 30;
    padding: 8px 0 10px; margin-bottom: 4px;
    background: var(--bg);
    overflow-x: auto; scrollbar-width: none;
  }
  .mobile-triage-bar::-webkit-scrollbar { display: none; }
  .triage-seg {
    flex: 1 1 auto; min-height: 40px; padding: 0 14px; white-space: nowrap;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--bg-1); color: var(--text-2);
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
  }
  .triage-seg.active {
    background: var(--accent); color: #fff; border-color: var(--accent);
  }
  .triage-seg.triage-stat { border-color: rgba(239,68,68,.5); color: #f87171; }
  .triage-seg.triage-stat.active { background: #ef4444; color: #fff; border-color: #ef4444; }

  /* Urgency chip top-right of every mobile card (the emergency signal) */
  .dash-card-urgency { flex-shrink: 0; }
  .dash-card-urgency .priority-chip { font-size: 11px; }
}

/* ── Per-viewer launch buttons (study page) ──────────────────────────────────
   Each button = icon + label. Desktop shows both; mobile shows icon only. */
.viewer-pick-btn { display: inline-flex; align-items: center; gap: 5px; }
.viewer-btn-ico {
  height: 15px; width: 15px; flex-shrink: 0; vertical-align: middle;
  display: inline-block;
}
@media (max-width: 768px) {
  /* Demote the multi-viewer row: horizontally scrollable, secondary */
  .viewer-others-row {
    flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; margin-top: 8px !important;
    border-top: none !important; padding-top: 4px !important;
  }
  .viewer-others-row::-webkit-scrollbar { display: none; }
  /* Icon-only: hide text label, square 44px touch target */
  .viewer-others-row .viewer-pick-btn {
    flex-shrink: 0; gap: 0; padding: 0;
    min-width: 44px; width: 44px; height: 44px;
    justify-content: center;
  }
  .viewer-pick-btn .viewer-btn-label { display: none; }
  .viewer-pick-btn .viewer-btn-ico { height: 20px; width: 20px; margin: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* MOBILE BOTTOM TAB BAR — primary nav for one-handed emergency use (<=768px)   */
/* ═══════════════════════════════════════════════════════════════════════════ */
.bottom-tabbar { display: none; }
@media (max-width: 768px) {
  .bottom-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 800;
    display: flex; justify-content: space-around; align-items: stretch;
    background: var(--bg-1); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 12px rgba(0,0,0,.35);
  }
  .bottom-tab {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; padding: 8px 2px 6px;
    min-height: 52px; text-decoration: none;
    color: var(--text-3); font-size: 10px; font-weight: 500;
    transition: color .15s;
  }
  .bottom-tab svg { width: 22px; height: 22px; }
  .bottom-tab.active { color: var(--accent); }
  .bottom-tab:active { background: var(--bg-2); }
  /* Hidden while the nav drawer is open (so it can't cover Logout) */
  .bottom-tabbar.tabbar-hidden { transform: translateY(110%); transition: transform .2s ease; }

  /* On phones the primary links live in the bottom tab bar — drop the
     duplicates from the drawer, leaving only secondary/admin links + Logout. */
  .nav-drawer .drawer-primary { display: none; }

  /* Footer (below .main) now provides the tab-bar clearance, so .main only needs
     a small bottom gap. */
  body.has-bottom-tabbar .main { padding-bottom: 16px; }

  /* Compact footer: un-fix it so it sits at the end of content, just above the
     tab bar (keeps Privacy/Terms + Powered-by reachable on phone). */
  body.has-bottom-tabbar #page-powered-footer {
    position: static;
    z-index: auto;
    background: transparent;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    padding: 12px 12px calc(76px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
    font-size: 11px;
  }
  /* Lift the floating FABs above the tab bar */
  body.has-bottom-tabbar .help-fab-btn { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  body.has-bottom-tabbar .support-fab  { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* SAFE-AREA INSETS (notch / home-indicator) — viewport-fit=cover in base.html  */
/* ═══════════════════════════════════════════════════════════════════════════ */
.nav { padding-top: env(safe-area-inset-top, 0px); }
#page-powered-footer { padding-bottom: env(safe-area-inset-bottom, 0px); }
@media (max-width: 720px) {
  .help-fab-btn { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .support-fab  { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}
/* Drawer uses dynamic viewport height so the Logout row never falls under the
   browser chrome (fixes the scrollTop hack in base.html). */
.nav-drawer { height: calc(100dvh - 52px); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }

/* ── Priority / TAT chips (IEC 60601-1-8 colour semantics) ───────────────────
   Red    = immediate response required  (fast overdue, < 15 min remaining)
   Amber  = prompt response required     (normal overdue, < 1 h remaining)
   Green  = done / safe / on track       (met SLA, > 1 h remaining)
   Violet = done but late                (resolved historical delay — outside alarm spectrum)
   Slate  = queued / neutral             (not an alarm state)
   ─────────────────────────────────────────────────────────────────────────── */
.priority-chip {
  font-size: 12px; min-width: 28px; height: 26px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; cursor: default; letter-spacing: .01em;
  border: 1px solid transparent;
  transition: box-shadow .3s;
}
/* Base idle states (shown when no inline override is applied) */
.chip-fast   { background: linear-gradient(135deg,rgba(16,185,129,.16),rgba(16,185,129,.05));
               color: #34d399; border-color: rgba(16,185,129,.3); }
.chip-normal { background: linear-gradient(135deg,rgba(99,102,241,.15),rgba(99,102,241,.05));
               color: #a5b4fc; border-color: rgba(99,102,241,.28); }
/* Queued / pending payment — slate text pill; NOT an alarm colour per IEC 60601 */
.chip-queued   { background: rgba(100,116,139,.1); color: #64748b;
                 border-color: rgba(100,116,139,.22); padding: 0 10px; }
.chip-refunded { background: rgba(148,163,184,.08); color: #64748b;
                 border-color: rgba(148,163,184,.2); padding: 0 10px; }
/* Live TAT countdown chip — expands to pill when countdown text is present */
.tat-live { width: auto !important; min-width: 28px; border-radius: 999px !important;
            padding: 0 10px; gap: 4px; font-size: 12px; white-space: nowrap;
            transition: background .4s, color .4s, border-color .4s, box-shadow .4s; }
/* Critical pulse — glow animation (IEC red: immediate action required) */
@keyframes tat-pulse {
  0%,100% { box-shadow: 0 0 8px rgba(239,68,68,.25); opacity: 1; }
  50%      { box-shadow: 0 0 22px rgba(239,68,68,.55), 0 0 4px rgba(239,68,68,.8); opacity: .88; }
}
.tat-live[data-crit] { animation: tat-pulse 1.2s ease-in-out infinite; }

.report-chip {
  font-size: 11px; padding: 3px 12px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px;
  font-weight: 600; white-space: nowrap; letter-spacing: .01em;
}
.rchip-draft    { background: rgba(251,191,36,.13);  color: #fbbf24; border: 1px solid rgba(251,191,36,.3);
                  box-shadow: 0 0 7px rgba(251,191,36,.1); }
.rchip-final    { background: rgba(52,211,153,.13);  color: #34d399; border: 1px solid rgba(52,211,153,.3);
                  box-shadow: 0 0 7px rgba(52,211,153,.1); }
.rchip-addendum { background: rgba(99,102,241,.13);  color: #a5b4fc; border: 1px solid rgba(99,102,241,.28);
                  box-shadow: 0 0 7px rgba(99,102,241,.1); }

/* ── IEC Colour Legend panel ─────────────────────────────────────────────── */
#iec-legend { display: none; }
#iec-legend.iec-legend-open { display: block; }

/* ── Floating Support FAB ────────────────────────────────────────────────── */
.support-fab {
  position: fixed; bottom: 52px; right: 28px; z-index: 1000;
  display: none; /* shown via JS when authenticated */
  flex-direction: column-reverse; align-items: flex-end; gap: 8px;
}
.support-fab.visible { display: flex; }
.support-fab-main {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(99,102,241,.45);
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
.support-fab-main:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(99,102,241,.55); }
.support-fab-main.open { transform: rotate(45deg); }
.support-fab-menu {
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  opacity: 0; pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.support-fab-menu.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.support-fab-item {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 99px; padding: 7px 14px 7px 10px;
  font-size: 13px; font-weight: 500; color: var(--text);
  text-decoration: none; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  transition: background 0.15s, border-color 0.15s;
}
.support-fab-item:hover { background: var(--bg-2); border-color: var(--border-2); }
.fab-dot {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0;
}
.fab-dot-support { background: rgba(99,102,241,.15); }
.fab-dot-admin   { background: rgba(249,115,22,.15); }

/* ── Hide table scrollbar (mobile shows cards instead; desktop should fit) ── */
.table-wrap { scrollbar-width: none; }
.table-wrap::-webkit-scrollbar { display: none; }

/* ── Support page ────────────────────────────────────────────────────────── */
.support-hero-cards {
  display: grid; gap: 12px;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 24px;
}
@media (max-width: 700px) { .support-hero-cards { grid-template-columns: 1fr; } }

.support-hero-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 18px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  text-decoration: none; transition: border-color 0.15s, background 0.15s;
}
.support-hero-card:hover { border-color: var(--accent); background: var(--bg-2); }
.support-hero-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(99,102,241,.12); border: 1px solid rgba(99,102,241,.2);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.support-hero-title { font-size: 14px; font-weight: 600; color: var(--text); }
.support-hero-sub   { font-size: 12px; color: var(--text-3); line-height: 1.4; }
.support-hero-arrow { font-size: 12px; color: var(--accent); margin-top: auto; }

.faq-item {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: border-color 0.15s;
}
.faq-item:hover { border-color: var(--border-2); }
.faq-item summary {
  cursor: pointer; padding: 12px 16px;
  font-weight: 600; font-size: 13px; color: var(--text);
  list-style: none; display: flex; align-items: center;
  justify-content: space-between; gap: 8px; user-select: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: '+'; font-size: 16px; color: var(--text-3);
  transition: transform 0.2s; flex-shrink: 0;
}
.faq-item[open] summary::after { content: '−'; }
.faq-item .faq-answer {
  padding: 0 16px 14px; color: var(--text-2); font-size: 13px;
  line-height: 1.65; border-top: 1px solid var(--border);
}

/* ── Support Admin (legacy stubs — layout moved to support_admin.html) ────── */
/* Old .status-tabs, .req-card etc. replaced by sa-* classes in the template. */


/* ── Help panel loading state + scrollbar ────────────────────────────────── */
.help-modal-loading {
  padding: 60px 20px; text-align: center; color: var(--text-3); font-size: 14px;
}
#help-modal-body,
#legal-panel-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
#help-modal-body::-webkit-scrollbar,
#legal-panel-body::-webkit-scrollbar { width: 5px; }
#help-modal-body::-webkit-scrollbar-track,
#legal-panel-body::-webkit-scrollbar-track { background: transparent; }
#help-modal-body::-webkit-scrollbar-thumb,
#legal-panel-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
}
#help-modal-body::-webkit-scrollbar-thumb:hover,
#legal-panel-body::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* Help FAB button — bottom-left, separate from support FAB (bottom-right) */
.help-fab-btn {
  position: fixed; bottom: 48px; left: 20px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer; z-index: 900;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, transform .15s, opacity .2s;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.help-fab-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); transform: scale(1.08); }

@media (max-width: 720px) {
  .help-fab-btn { bottom: 84px; left: 16px; }
  .support-fab { bottom: 84px; right: 16px; }
  /* Auto-hide on scroll-down for mobile — toggled by JS in base.html */
  .help-fab-btn, .support-fab {
    transition: transform .25s ease, opacity .25s ease, background .15s, color .15s, box-shadow .2s;
  }
  .help-fab-btn.fab-hidden { transform: translateY(120%); opacity: 0; pointer-events: none; }
  .support-fab.fab-hidden  { transform: translateY(120%); opacity: 0; pointer-events: none; }
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* ── Report Editor: Table Support (Phases 1–4) ─────────────────────────── */
/* ══════════════════════════════════════════════════════════════════════════ */

/* table selection highlight + resize tools */
.section-quill-editor .ql-table-selection_line {
  border-color: var(--accent) !important;
}
.section-quill-editor .selectedCell,
.section-quill-editor td.selectedCell,
.section-quill-editor th.selectedCell,
.section-quill-editor .ql-table-cell.selectedCell {
  background: rgba(79, 125, 237, 0.22) !important;
}
.section-quill-editor .ql-table-tooltip {
  display: none !important;
}
.section-quill-editor .ql-table-col-header {
  background: #222b3e !important;
  border-color: #4a5878 !important;
}
.section-quill-editor .ql-table-col-separator,
.section-quill-editor .ql-table-drag-line {
  background-color: var(--accent) !important;
}
/* Mobile: wide tables scroll horizontally */
.section-quill-editor {
  overflow-x: auto;
}

/* ── Phase 1: Grid picker popup ─────────────────────────────────────────── */
.table-grid-picker {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  z-index: 1100;
  box-shadow: var(--shadow);
}
.tbl-grid {
  display: grid;
  grid-template-columns: repeat(10, 22px);
  gap: 3px;
}
.tbl-grid-cell {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-1);
  cursor: pointer;
  transition: background .1s, border-color .1s;
}
.tbl-grid-cell.hovered {
  background: #4f7ded33;
  border-color: var(--accent);
}
.tbl-grid-label {
  text-align: center;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 7px;
  min-height: 16px;
}

/* ── Phase 2: Table context menu ─────────────────────────────────────────── */
.tbl-ctx-menu {
  position: fixed;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 170px;
  z-index: 9999;
  box-shadow: 0 8px 28px rgba(0,0,0,.65);
  display: none;
  overflow: visible;
  padding: 4px 0;
}
.tbl-ctx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  position: relative;
  user-select: none;
  white-space: nowrap;
  gap: 8px;
}
.tbl-ctx-item:hover,
.tbl-has-sub.open {
  background: #4f7ded22;
  color: #fff;
}
.tbl-ctx-item.disabled { color: var(--text-3); cursor: default; pointer-events: none; }
.tbl-ctx-arrow { font-size: 8px; color: var(--text-3); flex-shrink: 0; }
.tbl-ctx-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 3px 0;
}
/* Submenu */
.tbl-ctx-sub {
  display: none;
  position: absolute;
  left: 100%;
  top: -4px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 210px;
  z-index: 10000;
  box-shadow: 0 8px 28px rgba(0,0,0,.65);
  padding: 4px 0;
  overflow: hidden;
}
.tbl-has-sub:hover .tbl-ctx-sub,
.tbl-has-sub.open .tbl-ctx-sub { display: block; }
/* Flip submenu to the left when too close to viewport right edge — handled via JS position clamping */

/* ── Phase 3 / Phase 6: Properties modal form tweaks ─────────────────────── */
/* (reuses existing .modal-card + .form-group + .form-input — no extra CSS needed) */

/* ═══════════════════════════════════════════════════════════════════════════ */
/* REDUCED MOTION — respect prefers-reduced-motion (a11y CRITICAL)              */
/* Keep the meaning (colour + text), drop the motion. The red TAT pulse still  */
/* reads as critical via colour; it just stops animating.                      */
/* ═══════════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .tat-live[data-crit] { animation: none !important; } /* keep red, drop pulse */
}
