:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #17202a; --muted: #5f6b7a; --line: #e2e6ea;
  --accent: #0f766e; --accent-ink: #fff; --danger: #b42318; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1.25rem;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1.1rem; }
.brand span { color: var(--accent); }
.bar nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.bar nav a { text-decoration: none; }
.who { color: var(--muted); font-size: .9rem; }
main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); background: #fef3f2; border: 1px solid #fecdca; padding: .6rem .8rem; border-radius: var(--radius); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.narrow { max-width: 420px; margin: 3rem auto; }
.stack { display: grid; gap: .9rem; }
label { display: grid; gap: .35rem; font-size: .9rem; color: var(--muted); }
input, select { font: inherit; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: .55rem .9rem; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
.bar form { margin: 0; }
.search { display: flex; gap: .5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.search input[type=search] { flex: 1 1 260px; }
table.log { width: 100%; border-collapse: collapse; background: var(--panel); font-size: .9rem; }
table.log th, table.log td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); }
.results { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.result { display: flex; gap: .9rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem; text-decoration: none; color: var(--ink); }
.result:hover { border-color: var(--accent); }
.result img, .nothumb { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; background: #eef1f4; flex: none; }
.nothumb { display: grid; place-items: center; font-size: .75rem; color: var(--muted); }
.info { display: grid; gap: .2rem; align-content: start; font-size: .92rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { background: #e6f4f2; color: #0b5c56; border-radius: 999px; padding: .1rem .55rem; font-size: .78rem; }
.pager { display: flex; gap: 1rem; margin-top: 1rem; }
.back { text-decoration: none; }
.patient-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.patient-head p { margin: .25rem 0; }
h2.visit { font-size: 1rem; color: var(--muted); margin: 1.5rem 0 .6rem; border-bottom: 1px solid var(--line); padding-bottom: .3rem; }
.grid { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile { position: relative; }
.tile img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: #eef1f4; }
figure.full { margin: 0; text-align: center; }
figure.full img { max-width: 100%; max-height: 82vh; border-radius: 8px; image-orientation: from-image; }
/* uploads */
a.button { display: inline-block; text-decoration: none; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); padding: .55rem .9rem; white-space: nowrap; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.upload { max-width: 560px; margin: 0 auto; }
.upload input, .upload select, .upload button { width: 100%; min-height: 2.75rem; }
.upload input[type=file] { padding: .5rem; background: var(--panel); }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }
.upload .error p, .upload .error ul { margin: .25rem 0; }
.upload .error ul { padding-left: 1.2rem; overflow-wrap: anywhere; }
@media (max-width: 600px) { .upload .card { padding: 1rem; } }

/* comparison */
.tile .pick { position: absolute; top: .35rem; left: .35rem; display: block; padding: .35rem; background: rgba(255,255,255,.85);
  border-radius: 6px; line-height: 0; }
.tile .pick input { width: 1.25rem; height: 1.25rem; margin: 0; padding: 0; accent-color: var(--accent); }
.compare [hidden] { display: none !important; }
.modes { display: flex; gap: .5rem; margin-bottom: .75rem; }
.modes button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.pair figure.side { margin: 0; display: grid; gap: .35rem; align-content: start; }
.pair figure.side img { width: 100%; max-height: 75vh; object-fit: contain; border-radius: 8px; background: #eef1f4;
  image-orientation: from-image; }
.slider { --reveal: 50%; display: grid; gap: .6rem; justify-items: center; }
.stage { position: relative; max-width: 100%; line-height: 0; border-radius: 8px; overflow: hidden; background: #eef1f4; }
.stage img { display: block; max-width: 100%; max-height: 75vh; image-orientation: from-image; }
.stage .over { position: absolute; inset: 0; clip-path: inset(0 calc(100% - var(--reveal)) 0 0);
  border-right: 2px solid #fff; }
.stage .over img { width: 100%; height: 100%; object-fit: contain; }
.stage .tag { position: absolute; top: .4rem; background: rgba(23,32,42,.7); color: #fff; font-size: .78rem;
  line-height: 1.3; padding: .15rem .45rem; border-radius: 6px; }
.stage .tag.left { left: .4rem; }
.stage .tag.right { right: .4rem; }
.slider input[type=range] { width: min(100%, 640px); padding: 0; border: 0; accent-color: var(--accent); }
.strip { list-style: none; padding: 0 0 .4rem; margin: 0; display: flex; gap: .6rem; overflow-x: auto; }
.strip li { flex: none; width: 116px; display: grid; gap: .2rem; font-size: .8rem; text-align: center; }
.strip li img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #eef1f4; }
.strip li.current img { outline: 3px solid var(--accent); outline-offset: -3px; }
.strip a { text-decoration: none; padding: .15rem 0; }
.strip .now { font-weight: 600; color: var(--accent); }
@media (max-width: 600px) {
  .pair { gap: .35rem; }
  .pair figure.side figcaption { font-size: .85rem; }

/* admin */
.setup-link { margin-bottom: 1.25rem; border-color: var(--accent); }
.setup-link p { margin: 0 0 .6rem; }
.setup-link input.copy { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
table.staff tr.inactive td { color: var(--muted); }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { margin: 0; }
.row-actions button { padding: .3rem .6rem; font-size: .85rem; }
.log-filters { align-items: flex-end; }
.log-filters label { flex: 0 1 auto; }
.log-filters .download { align-self: center; margin-left: auto; }
figure.qr { margin: 0; text-align: center; }
figure.qr img { width: 200px; height: 200px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.key code { display: block; word-break: break-all; background: #eef1f4; padding: .5rem .6rem; border-radius: 8px; font-size: .85rem; }
details summary { cursor: pointer; font-size: .85rem; }
@media (max-width: 640px) {
  table.log { font-size: .8rem; }
  table.log th, table.log td { padding: .35rem .4rem; }
  .row-actions { justify-content: flex-start; }
}

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
