/* Components. Every value references a token in tokens.css. */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: var(--fs-md);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

/* ---------- shell ---------- */

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: var(--fs-lg); color: var(--brand); }

.nav { display: flex; gap: var(--sp-1); flex: 1; flex-wrap: wrap; }

.nav button {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: var(--sp-2) var(--sp-3);
  min-height: var(--tap);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button.active { background: var(--brand-soft); color: var(--brand); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--muted);
  white-space: nowrap;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--err); }

main { flex: 1; padding: var(--sp-5); max-width: 980px; width: 100%; margin: 0 auto; }

/* ---------- typography ---------- */

.page-title { font-size: var(--fs-xl); margin-bottom: var(--sp-4); }
.screen-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  color: var(--muted);
}
.muted { color: var(--muted); }
.fine { font-size: var(--fs-xs); color: var(--muted); }
.mono { font-family: var(--mono); font-size: var(--fs-xs); color: var(--muted); }

/* ---------- cards / steps ---------- */

.step {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.step h2 {
  font-size: var(--fs-sm);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}
.step h2 .n {
  background: var(--brand);
  color: var(--brand-ink);
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  flex: none;
}

/* ---------- form controls ---------- */

label { font-size: var(--fs-sm); }

.field-row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

input[type=text], input[type=password], input[type=search], select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: var(--tap);
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.grow { flex: 1; min-width: 160px; }

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 10px 18px;
  min-height: var(--tap);
  cursor: pointer;
  transition: background var(--dur-press) var(--ease-out),
              border-color var(--dur-press) var(--ease-out);
}
.btn:hover { background: var(--line); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); background: var(--brand); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger:hover { filter: brightness(1.06); background: var(--err); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.confirm-row { display: flex; align-items: center; gap: var(--sp-2); }
.confirm-row input[type=checkbox] { width: 20px; height: 20px; }

.btn-row { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-3); flex-wrap: wrap; }

/* ---------- dropzone ---------- */

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: var(--sp-5);
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.dropzone:hover, .dropzone.drag { background: var(--brand-soft); border-color: var(--brand); }
.dropzone.hasfile { border-color: var(--ok); background: var(--ok-soft); color: var(--ink); border-style: solid; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th {
  text-align: left;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-weight: 700;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
td { padding: var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr.selectable { cursor: pointer; }
tbody tr.selectable:hover td { background: var(--brand-soft); }
tbody tr.selected td { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
.row-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; }

/* ---------- selected study card ---------- */

.patient-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-3);
  background: var(--surface-2);
}
.patient-card .name { font-size: var(--fs-lg); font-weight: 700; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); margin-top: var(--sp-2); font-size: var(--fs-sm); }
.pgrid .lbl { display: block; font-size: var(--fs-xs); color: var(--muted); }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 10px;
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--err-soft); color: var(--err); }
.badge.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- pagination ---------- */

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: var(--sp-3); gap: var(--sp-3); }
.pager .pbtns { display: flex; gap: var(--sp-2); }

/* ---------- notices ---------- */

.notice { border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); font-size: var(--fs-sm); font-weight: 600; margin-top: var(--sp-3); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--err-soft); color: var(--err); }
.notice.info { background: var(--brand-soft); color: var(--brand); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--ok);
  color: #fff;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: var(--fs-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-med) var(--ease-out), transform var(--dur-med) var(--ease-out);
  z-index: 40;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--err); }

/* ---------- modal ---------- */

.modal-back {
  position: fixed; inset: 0;
  background: light-dark(rgba(15,20,25,.45), rgba(0,0,0,.6));
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-med) var(--ease-out);
  z-index: 50;
  padding: var(--sp-4);
}
.modal-back.show { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 460px; max-width: 100%;
  padding: var(--sp-5);
  box-shadow: var(--shadow);
  transform: scale(0.96);
  transition: transform var(--dur-med) var(--ease-out);
}
.modal-back.show .modal { transform: scale(1); }
.modal h3 { margin-bottom: var(--sp-3); }
.modal p { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--sp-2); }
.modal .verify { background: var(--ok-soft); color: var(--ok); font-size: var(--fs-xs); font-weight: 700; border-radius: var(--radius); padding: var(--sp-2) var(--sp-3); margin: var(--sp-3) 0; }

/* ---------- spinner ---------- */

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- misc ---------- */

.stack > * + * { margin-top: var(--sp-3); }
.hidden { display: none !important; }
.error-card { border: 1px solid var(--err); background: var(--err-soft); color: var(--err); border-radius: var(--radius); padding: var(--sp-4); }
.settings-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); max-width: 520px; }
.settings-grid .lbl { display: block; font-size: var(--fs-xs); color: var(--muted); font-weight: 700; margin-bottom: var(--sp-1); }
.locked { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); }
.locked .tag { font-size: var(--fs-xs); background: var(--brand-soft); color: var(--brand); font-weight: 700; border-radius: 4px; padding: 2px 8px; }

/* ---------- spacing utilities (replace inline style attributes; the CSP
   forbids inline styles, so layout nudges live here) ---------- */
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mr-auto { margin-right: auto; }
.search-hd { margin: var(--sp-3) 0 var(--sp-1); }

/* ---------- guided tech sheet ---------- */
.wiz-head { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-3); flex-wrap: wrap; }
.steps { display: flex; gap: 5px; flex: 1; min-width: 160px; }
.steps span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.steps span.done { background: var(--brand); }

.q { margin-bottom: var(--sp-4); }
.q > label { display: block; font-weight: 600; margin-bottom: var(--sp-2); }

.seg { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.seg-btn {
  flex: 1; min-width: 88px; min-height: var(--tap);
  border: 2px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: var(--radius); font: inherit; font-weight: 600;
  cursor: pointer;
}
.seg-btn:hover { border-color: var(--brand); }
.seg-btn.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.seg-btn.yes.on { border-color: var(--err); background: var(--err-soft); color: var(--err); }
.seg.small .seg-btn { min-width: 56px; min-height: 38px; font-size: var(--fs-xs); flex: none; padding: 0 10px; }

.chips { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 9px 14px; min-height: 40px; font: inherit; cursor: pointer;
}
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.sub { display: none; margin-top: var(--sp-2); padding: var(--sp-2); background: var(--surface-2); border: 1px dashed var(--line); border-radius: var(--radius); }
.sub.show { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; width: 100%; resize: vertical; }

.allnormal {
  display: block; width: 100%; margin-bottom: var(--sp-4);
  border: 2px solid var(--ok); background: var(--ok-soft); color: var(--ok);
  font-weight: 700; min-height: 48px;
}

/* vessel / structure tables */
.rt-row { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2); }
.rt-name { font-weight: 700; font-size: var(--fs-sm); margin-bottom: var(--sp-1); }
.rt-controls { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.rt-col { display: flex; flex-direction: column; gap: 3px; }
.rt-lbl { font-size: var(--fs-xs); color: var(--muted); }
.rt-input { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font: inherit; min-height: 38px; min-width: 120px; background: var(--surface); color: var(--ink); }

/* breast clock */
.lesion-builder { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-3); margin-top: var(--sp-3); }
.lesion-builder > label { display: block; font-weight: 600; margin: var(--sp-3) 0 var(--sp-1); }
.clock { position: relative; width: 220px; height: 220px; margin: var(--sp-2) auto; }
.clock .face { position: absolute; inset: 0; border: 2px solid var(--line); border-radius: 50%; }
.clock .nip { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; background: var(--muted); border-radius: 50%; transform: translate(-50%, -50%); }
.clk-btn { position: absolute; width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; cursor: pointer; transform: translate(-50%, -50%); }
.clk-btn.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.stepper { display: flex; align-items: center; gap: var(--sp-4); }
.step-btn { width: 48px; height: 48px; border-radius: var(--radius); border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font-size: 1.4rem; font-weight: 700; cursor: pointer; }
.step-val { font-size: var(--fs-lg); font-weight: 700; min-width: 80px; text-align: center; }
.lesion-card { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2); font-size: var(--fs-sm); }

.review .rvw-line { display: flex; justify-content: space-between; gap: var(--sp-4); padding: 7px 0; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.review .rvw-line b { color: var(--muted); font-weight: 600; }

.modal-wide { width: 860px; max-width: 96vw; }
.pdf-frame { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

/* Update notice: shown when the server runs a newer build than this page
   loaded (after a git deploy). Persistent, with a Refresh button. */
.update-bar {
  position: fixed;
  left: var(--sp-4);
  right: var(--sp-4);
  bottom: var(--sp-4);
  margin-inline: auto;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--brand);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 60;
  font-size: var(--fs-md);
  animation: update-rise var(--dur-med) var(--ease-out);
}
.update-bar span { font-weight: 500; }
@keyframes update-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
