:root { color-scheme: dark; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: #0F172A; color: #e2e8f0;
  font: 15px/1.4 system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; }
.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ---- Login ---- */
#loginScreen { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: #111c33; border: 1px solid #1e293b;
  border-radius: 20px; padding: 28px 24px; text-align: center;
}
.login-logo { width: 64px; height: 64px; object-fit: contain; margin-bottom: 8px; }
.login-card h1 { margin: 0; font-size: 22px; color: #fff; }
.login-card .subtitle { margin: 4px 0 6px; font-size: 13px; color: #00BAA1; font-weight: 600; }
.login-card .brand-tag { margin: 0 0 20px; font-size: 11px; color: #64748b; }
#loginForm { display: flex; flex-direction: column; gap: 12px; text-align: left; }
#loginForm label { font-size: 12px; font-weight: 700; color: #94a3b8; display: flex; flex-direction: column; gap: 5px; }
#loginForm input {
  background: #0b1220; border: 1px solid #334155; border-radius: 10px;
  padding: 11px 12px; color: #fff; font-size: 15px; outline: none;
}
#loginForm input:focus { border-color: #00BAA1; }
#loginBtn {
  margin-top: 4px; background: #00BAA1; color: #04211d; border: none; border-radius: 10px;
  padding: 12px; font-weight: 800; font-size: 15px; cursor: pointer;
}
#loginBtn:disabled { opacity: .6; }
.msg { font-size: 13px; margin: 10px 0 0; }
.msg.err { color: #f87171; }
.msg.ok { color: #34d399; }
.login-card .hint { font-size: 11px; color: #64748b; margin-top: 16px; line-height: 1.5; }
.install-btn {
  margin-top: 14px; width: 100%; background: transparent; color: #00BAA1;
  border: 1px solid #00BAA1; border-radius: 10px; padding: 10px;
  font-weight: 700; font-size: 13px; cursor: pointer;
}
.install-btn:active { background: rgba(0, 186, 161, .12); }
.tg-link {
  display: block; margin-top: 14px; text-align: center; text-decoration: none; color: #38bdf8;
  border: 1px solid #38bdf8; border-radius: 10px; padding: 10px; font-weight: 700; font-size: 13px;
}
.tg-link:active { background: rgba(56, 189, 248, .12); }

/* ---- Top bar (shared) ---- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: #0b1220; border-bottom: 1px solid #1e293b; flex: none;
  position: sticky; top: 0; z-index: 5;
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: #00BAA1; }
.topbar .brand img { width: 24px; height: 24px; object-fit: contain; }
.icon-btn {
  background: #1e293b; border: 1px solid #334155; color: #e2e8f0; width: 36px; height: 36px;
  border-radius: 10px; font-size: 16px; cursor: pointer; flex: none;
}
.icon-btn:active { background: #334155; }
.viewer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; font-size: 14px; }
#refreshBtn { margin-left: auto; }

/* ---- Studies list ---- */
.list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.study-row {
  background: #111c33; border: 1px solid #1e293b; border-radius: 14px; padding: 12px 14px;
  cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.study-row:active { background: #16223e; }
.study-row .info { flex: 1; min-width: 0; }
.study-row .name { font-weight: 700; color: #fff; font-size: 14px; }
.study-row .meta { font-size: 12px; color: #94a3b8; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study-row .badge {
  font-size: 10px; font-weight: 800; padding: 3px 8px; border-radius: 999px; flex: none;
}
.badge.has-report { background: rgba(52,211,153,.15); color: #34d399; }
.badge.no-report { background: rgba(148,163,184,.15); color: #94a3b8; }
.empty { text-align: center; color: #64748b; padding: 40px 20px; font-size: 14px; }

/* ---- Viewer ---- */
.image-pane {
  flex: 1; min-height: 0; background: #000; position: relative;
  overflow: hidden; touch-action: none; /* gestures are handled ourselves (pan/zoom/measure) */
}
.zoom-layer { position: absolute; inset: 0; transform-origin: center center; will-change: transform; }
#mainImage { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; -webkit-user-select: none; user-select: none; pointer-events: none; }
.overlay-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.overlay-svg .m-line { stroke: #facc15; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.overlay-svg .m-point { fill: #facc15; }
.overlay-svg .m-ellipse { fill: rgba(250,204,21,.12); stroke: #facc15; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.overlay-svg .m-arc { fill: none; stroke: #facc15; stroke-width: 2; vector-effect: non-scaling-stroke; opacity: .8; }
.overlay-svg .m-line.m-selected, .overlay-svg .m-ellipse.m-selected { stroke: #ef4444; stroke-width: 3.5; }
.overlay-svg .m-point.m-selected { fill: #ef4444; r: 8; }
.overlay-svg .m-label {
  fill: #04211d; font-size: 15px; font-weight: 700; paint-order: stroke; stroke: #facc15; stroke-width: 5px;
}
.img-counter {
  position: absolute; right: 10px; bottom: 8px; font-size: 12px; color: #94a3b8;
  text-shadow: 0 1px 2px #000; pointer-events: none;
}
.nav-btn {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px;
  border-radius: 50%; border: none; background: rgba(15,23,42,.55); color: #fff;
  font-size: 24px; line-height: 1; cursor: pointer;
}
.nav-prev { left: 8px; } .nav-next { right: 8px; }
.frame-slider-wrap {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  height: min(65%, 420px); width: 30px; display: flex; align-items: center; justify-content: center;
}
#frameSlider {
  writing-mode: vertical-lr; direction: rtl; -webkit-appearance: slider-vertical;
  width: 24px; height: 100%; margin: 0; cursor: pointer; accent-color: #00BAA1;
}
.series-thumbs {
  display: flex; gap: 8px; padding: 8px 10px; background: #0b1220;
  border-top: 1px solid #1e293b; overflow-x: auto; flex: none;
}
.series-thumb {
  position: relative; flex: none; width: 64px; height: 64px; padding: 0;
  border-radius: 8px; border: 2px solid #334155; background: #000; overflow: hidden; cursor: pointer;
}
.series-thumb.active { border-color: #00BAA1; }
.series-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.series-thumb .thumb-badge {
  position: absolute; left: 2px; bottom: 2px; font-size: 10px; font-weight: 700; color: #fff;
  background: rgba(15,23,42,.75); border-radius: 4px; padding: 1px 4px; pointer-events: none;
}
.tools-row {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px; background: #0b1220;
  border-top: 1px solid #1e293b; flex: none; flex-wrap: wrap;
}
.tools-row button[data-mtool] {
  background: #1e293b; border: 1px solid #334155; color: #e2e8f0; width: 36px; height: 36px;
  border-radius: 10px; font-size: 16px; cursor: pointer; flex: none;
}
.tools-row button[data-mtool].on { background: #00BAA1; border-color: #00BAA1; }
.measure-hint { font-size: 11px; color: #94a3b8; margin-left: auto; text-align: right; }
.adjust-row {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; background: #0b1220;
  border-top: 1px solid #1e293b; flex: none; flex-wrap: wrap;
}
.adjust-row label { display: flex; align-items: center; gap: 8px; font-size: 11px; color: #94a3b8; flex: 1; min-width: 120px; }
.adjust-row input[type=range] { flex: 1; accent-color: #00BAA1; }
.text-btn { background: none; border: 1px solid #334155; color: #cbd5e1; border-radius: 8px; padding: 6px 10px; font-size: 11px; cursor: pointer; }
.text-btn.danger { border-color: #ef4444; color: #fca5a5; background: rgba(239, 68, 68, .12); }

/* ---- Report ---- */
.report-pane { padding: 12px 14px 20px; background: #0b1220; border-top: 1px solid #1e293b; display: flex; flex-direction: column; gap: 10px; }
.report-pane label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: #94a3b8; }
.report-pane textarea {
  background: #111c33; border: 1px solid #334155; border-radius: 10px; color: #fff;
  padding: 9px 10px; font: inherit; resize: vertical; outline: none;
}
.report-pane textarea:focus { border-color: #00BAA1; }
.report-actions { display: flex; align-items: center; gap: 12px; }
#saveReportBtn {
  background: #00BAA1; color: #04211d; border: none; border-radius: 10px;
  padding: 10px 18px; font-weight: 800; cursor: pointer;
}
#saveReportBtn:disabled { opacity: .6; }

.lmp-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.lmp-row label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: #94a3b8; }
.lmp-row input[type="date"] {
  background: #111c33; border: 1px solid #334155; border-radius: 10px; color: #fff; padding: 8px 10px; font: inherit;
}
.ga-edd-line { font-size: 12px; font-weight: 700; color: #6ee7d0; padding-bottom: 9px; }

.template-row { display: flex; align-items: flex-end; gap: 10px; }
.template-row label { flex: 1; display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: #94a3b8; }
.template-row select {
  background: #111c33; border: 1px solid #334155; border-radius: 10px; color: #fff; padding: 8px 10px; font: inherit;
}
.template-row select:focus { border-color: #00BAA1; outline: none; }

.sr-reports-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.sr-nav-btn {
  background: #1e293b; border: 1px solid #334155; color: #cbd5e1; border-radius: 8px;
  padding: 6px 10px; font-size: 11px; font-weight: 700; cursor: pointer;
}
.sr-nav-btn.active { background: #00BAA1; border-color: #00BAA1; color: #04211d; }

.sr-report-box {
  background: #111c33; border: 1px solid #1e293b; border-radius: 12px; padding: 12px 14px;
  max-height: 46vh; overflow-y: auto;
}
.sr-report-head { margin-bottom: 8px; }
.sr-report-title { font-size: 13px; font-weight: 800; color: #fff; }
.sr-report-meta { font-size: 11px; color: #64748b; margin-top: 2px; }
.sr-empty { font-size: 12px; color: #64748b; margin: 0; }
.sr-section { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid #1e293b; }
.sr-section:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.sr-subsection { margin-top: 8px; padding-left: 10px; border-left: 2px solid #1e293b; }
.sr-heading { font-size: 12px; font-weight: 800; color: #00BAA1; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 4px; }
.sr-subsection .sr-heading { font-size: 11px; color: #94a3b8; }
.sr-context { font-size: 11px; color: #64748b; margin-bottom: 4px; }
.sr-field { padding: 3px 0; }
.sr-field-line { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.sr-field-label { color: #94a3b8; }
.sr-field-value { font-weight: 700; color: #fff; }
.sr-field-input {
  width: 90px; background: #0b1220; border: 1px solid #334155; border-radius: 6px; color: #fff;
  padding: 3px 7px; font: inherit; font-weight: 700;
}
.sr-field-input:focus { border-color: #00BAA1; outline: none; }
.sr-field-unit { font-size: 11px; color: #64748b; }
.sr-qualifier { font-size: 10.5px; color: #64748b; padding-left: 10px; border-left: 1px solid #334155; margin-top: 2px; }

/* ---- Settings ---- */
.settings-pane { padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.settings-pane h3 { font-size: 13px; color: #00BAA1; text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 4px; }
.settings-pane h3:first-child { margin-top: 0; }
.settings-pane label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: #94a3b8; }
.settings-pane input[type="text"], .settings-pane input[type="date"] {
  background: #111c33; border: 1px solid #334155; border-radius: 10px; color: #fff; padding: 9px 10px; font: inherit;
}
.settings-pane input:focus { border-color: #00BAA1; outline: none; }
.settings-save-btn {
  background: #00BAA1; color: #04211d; border: none; border-radius: 10px;
  padding: 10px 18px; font-weight: 800; cursor: pointer; align-self: flex-start;
}
.cs-logo-row { display: flex; align-items: center; gap: 10px; }
.cs-logo-preview { width: 44px; height: 44px; object-fit: contain; background: #111c33; border: 1px solid #334155; border-radius: 8px; }
.cs-logo-upload {
  background: #1e293b; border: 1px solid #334155; color: #cbd5e1; border-radius: 8px;
  padding: 7px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.cs-doctors-list { display: flex; flex-direction: column; gap: 6px; }
.cs-doctor-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #111c33; border: 1px solid #334155; border-radius: 10px; padding: 8px 12px; font-size: 13px;
}
.cs-doctor-row span { color: #64748b; font-size: 11px; }
.cs-add-doctor { display: flex; gap: 8px; }
.cs-add-doctor input {
  flex: 1; background: #111c33; border: 1px solid #334155; border-radius: 10px; color: #fff; padding: 8px 10px; font: inherit;
}
.cs-dicom-info { background: #111c33; border: 1px solid #334155; border-radius: 10px; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.cs-dicom-info b { color: #6ee7d0; }
.cs-templates-list { display: flex; flex-direction: column; gap: 6px; }
.cs-template-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #111c33; border: 1px solid #334155; border-radius: 10px; padding: 8px 12px; font-size: 13px;
}
