/* ---- OPSEYA design tokens ----
   Values come from opseya/access, frontend/customer-portal/src/app/globals.css
   (shadcn "neutral" greys + the OPSEYA primary blue, radius 0.5rem). The short
   legacy names (--bg, --panel, …) are kept so every rule below themes through
   them. Three theme states, like access's next-themes defaultTheme="system":
   bare :root = light; the OS dark preference unless the viewer chose light;
   and an explicit data-theme="dark" (static/js/theme.js sets the attribute). */
:root {
  color-scheme: light;
  --radius: 0.5rem;
  --radius-md: calc(var(--radius) - 2px);
  --radius-sm: calc(var(--radius) - 4px);

  --bg: hsl(0 0% 100%);             /* --background */
  --panel: hsl(0 0% 100%);          /* --card */
  --panel-2: hsl(0 0% 96.1%);       /* --muted / --secondary */
  --hover: hsl(0 0% 96.1%);         /* --accent (hover surface) */
  --hover-strong: hsl(0 0% 92%);
  --border: hsl(0 0% 89.8%);
  --input: hsl(0 0% 89.8%);
  --text: hsl(0 0% 3.9%);           /* --foreground */
  --muted: hsl(0 0% 45.1%);         /* --muted-foreground */
  --accent: hsl(216 85% 58%);       /* --primary: the OPSEYA blue */
  --accent-2: hsl(216 85% 50%);     /* --primary, hover */
  --accent-fg: hsl(0 0% 100%);
  --ring: hsl(216 85% 58%);
  --danger: hsl(0 74% 42%);         /* --destructive */
  --danger-solid: hsl(0 72% 51%);   /* --danger-solid: filled backgrounds */
  --warn: hsl(32 95% 33%);          /* --warning */
  --success: hsl(120 86.3% 34.3%);  /* --status-good */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-tab: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);

  /* Status scale: fixed, never themed (as in access). */
  --status-good: hsl(120 86.3% 34.3%);
  --status-warning: hsl(40.8 95.7% 53.9%);
  --status-neutral: hsl(0 0% 45.1%);
  --overlay-all: hsl(248.8 48.4% 44.1%);       /* --chart-7 */
  --overlay-all-hover: hsl(248.8 48.4% 38%);

  /* The image well stays dark in both themes: fundus photos read best on black.
     Stamps and badges drawn over the photo use fixed, bright colours for the
     same reason. */
  --canvas-bg: hsl(0 0% 7%);
  --canvas-well: hsl(0 0% 4%);
  --canvas-text: hsl(0 0% 64%);
  --image-good: #2ecc71;
  --image-bad: #ff5f52;
  --image-warn: #f5b83d;

  /* Annotation colours drawn on the image (read by app.js) — unchanged. */
  --grid-fill: rgba(46, 204, 113, 0.5);
  --grid-stroke: rgba(46, 204, 113, 0.95);
  --bbox-stroke: #f1c40f;
  --bbox-fill: rgba(241, 196, 15, 0.18);
  --polygon-stroke: #c084ff;
  --polygon-fill: rgba(192, 132, 255, 0.22);
}

/* Dark: access's .dark block. Repeated for the OS preference and the explicit
   choice — CSS cannot share one declaration block between the two selectors
   without also catching an explicit "light" choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: hsl(0 0% 9%);
    --panel: hsl(0 0% 12%);
    --panel-2: hsl(0 0% 18%);
    --hover: hsl(0 0% 18%);
    --hover-strong: hsl(0 0% 24%);
    --border: hsl(0 0% 22%);
    --input: hsl(0 0% 22%);
    --text: hsl(0 0% 98%);
    --muted: hsl(0 0% 63.9%);
    --accent-2: hsl(216 85% 52%);
    --danger: hsl(0 91% 71%);
    --warn: hsl(45 97% 65%);
    --success: hsl(120 55% 52%);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-tab: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: hsl(0 0% 9%);
  --panel: hsl(0 0% 12%);
  --panel-2: hsl(0 0% 18%);
  --hover: hsl(0 0% 18%);
  --hover-strong: hsl(0 0% 24%);
  --border: hsl(0 0% 22%);
  --input: hsl(0 0% 22%);
  --text: hsl(0 0% 98%);
  --muted: hsl(0 0% 63.9%);
  --accent-2: hsl(216 85% 52%);
  --danger: hsl(0 91% 71%);
  --warn: hsl(45 97% 65%);
  --success: hsl(120 55% 52%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-tab: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  /* access uses Tailwind's default sans stack — the platform UI font. The
     emoji faces are left out on purpose: listed explicitly they win over text
     glyphs such as the Tinder ↩, which then renders as a colour emoji. */
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

/* ---- Login (access's auth page: logo header + one card) ---- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 16px;
  background: var(--bg);
}
.login-shell {
  width: 100%; max-width: 448px;
  display: flex; flex-direction: column; gap: 24px;
}
/* White in both themes, exactly like access's AuthLogoHeader. */
.login-logo {
  display: flex; align-items: center; justify-content: center;
  height: 180px;
  border-radius: var(--radius);
  background: #fff;
}
.login-logo img { width: 180px; height: 130px; object-fit: contain; display: block; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  text-align: center;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 24px; font-weight: 600; letter-spacing: -0.025em;
}
.login-card .muted { margin: 0 0 20px; }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 40px; padding: 0 16px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--input); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  text-decoration: none; font-weight: 500; font-size: 14px;
  transition: background-color .15s ease;
}
.btn-google:hover { background: var(--hover); }

/* ---- Brand (OPSEYA logo · product name) ---- */
.brand { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-logo-topbar { display: block; height: 20px; width: auto; }
.brand-divider { width: 1px; height: 18px; background: var(--border); }
.brand-product { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
/* access ships a separate dark-mode logo; swap the artwork, not a backing chip
   (same pure-CSS approach as access's components/ui/logo.tsx). */
.logo-dark { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none !important; }
  :root:not([data-theme="light"]) .logo-dark { display: block !important; }
}
:root[data-theme="dark"] .logo-light { display: none !important; }
:root[data-theme="dark"] .logo-dark { display: block !important; }

/* ---- Top bar ---- */
.topbar {
  height: 52px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
/* Never let a topbar item wrap onto a second line inside the fixed 52px bar.
   Whatever still does not fit scrolls inside the bar, never the whole page. */
.topbar { gap: 12px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.topbar-left, .topbar-right { flex-shrink: 0; }
.topbar-left > *, .topbar-right > * { flex-shrink: 0; white-space: nowrap; }
/* Shed the least useful text first as the window narrows. */
@media (max-width: 1440px) { .user-name { display: none; } }
@media (max-width: 1366px) { .brand-divider, .brand-product { display: none; } }
@media (max-width: 1300px) { .counter { display: none; } }
/* Segmented control in the style of access's tabs: a muted track, the active
   option raised onto the page background. Four modes share the fixed-height
   topbar, so the group must not shrink or let a label wrap out of the bar. */
.mode-toggle {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--panel-2);
  flex-shrink: 0;
}
.mode-btn {
  background: transparent; color: var(--muted);
  border: 0; border-radius: var(--radius-md);
  padding: 4px 12px; cursor: pointer;
  font-size: 13px; font-weight: 500;
  white-space: nowrap;
  transition: color .15s ease, background-color .15s ease;
}
.mode-btn.active { background: var(--bg); color: var(--text); box-shadow: var(--shadow-tab); }
.mode-btn:hover:not(.active) { color: var(--text); }

.grid-control { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.grid-control input[type=range] { accent-color: var(--accent); }
#grid-value { min-width: 38px; display: inline-block; text-align: center; color: var(--muted); }

.counter {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.user { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.user img { width: 26px; height: 26px; border-radius: 50%; }
.logout { color: var(--muted); text-decoration: none; }
.logout:hover { color: var(--text); }

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
}
.theme-toggle svg { width: 16px; height: 16px; display: none; }
.theme-toggle[data-choice="system"] .icon-system,
.theme-toggle[data-choice="light"] .icon-light,
.theme-toggle[data-choice="dark"] .icon-dark { display: block; }
/* Before theme.js has run (or if it cannot), show the system icon. */
.theme-toggle:not([data-choice]) .icon-system { display: block; }

.project-select {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 4px 8px;
}
.project-select-icon { color: var(--muted); font-size: 12px; }
.project-select select {
  background: transparent; color: var(--text);
  border: 0; font-size: 13px; font-weight: 500;
  cursor: pointer; outline: none;
  max-width: 240px;
}
.project-select:focus-within { outline: 2px solid var(--ring); outline-offset: 1px; }
.project-select select option { background: var(--panel); color: var(--text); }

.role-badge {
  font-size: 10px; text-transform: uppercase;
  padding: 1px 6px; border-radius: var(--radius-sm);
  letter-spacing: 0.05em; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted);
}
.role-badge:empty { display: none; }
.role-badge.role-admin { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.role-badge.role-lead { background: var(--status-warning); border-color: var(--status-warning); color: hsl(0 0% 9%); }

/* ---- Layout ---- */
.layout {
  display: grid;
  /* minmax(0, 1fr): without the 0 minimum, a deeply zoomed (huge) image would
     grow the centre track past its share and push the side panels off-screen. */
  grid-template-columns: 240px minmax(0, 1fr) 280px;
  height: calc(100vh - 52px);
  height: calc(100dvh - 52px);
  min-height: 0;
  overflow: hidden;
}
.sidebar-left, .sidebar-right {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar-left { padding: 12px; overflow-y: auto; }
.sidebar-right { border-right: 0; border-left: 1px solid var(--border); padding: 0; }

.sidebar-left h3, .panel-header h3 {
  font-size: 12px; text-transform: uppercase; color: var(--muted);
  margin: 8px 0 8px 4px; letter-spacing: 0.05em; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
}
.count-pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 1px 8px; border-radius: var(--radius-md);
  font-size: 11px; color: var(--text);
  text-transform: none; letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.class-list { display: flex; flex-direction: column; gap: 4px; }
.class-list input[type=radio],
.class-list input[type=checkbox] { accent-color: var(--accent); }

/* Whole-image mode swaps the radios for checkboxes: several labels can be true
   about one image at the same time. */
.class-hint {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
}
/* Whole-image mode carries a real risk of being mistaken for the single-select
   list, so mark the whole column, not just the row controls. */
.class-list-multi .class-group { border-left: 3px solid var(--accent); }

/* One finding per row: its name plus a Present / Absent / Not-assessable
   segmented control. A row with no verdict is deliberately dim — "not rated" is
   a real state, distinct from Absent. */
.verdict-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 8px; border-radius: var(--radius-md);
}
.verdict-row:hover { background: var(--hover); }
.verdict-row.rated .verdict-name { color: var(--text); font-weight: 500; }
.verdict-name {
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.verdict-buttons {
  display: inline-flex; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
}
.verdict-btn {
  background: transparent; color: var(--muted);
  border: 0; border-left: 1px solid var(--border);
  padding: 2px 7px; font-size: 11px; font-weight: 700;
  line-height: 1.6; cursor: pointer;
}
.verdict-btn:first-child { border-left: 0; }
.verdict-btn:hover:not(.active) { background: var(--hover-strong); color: var(--text); }
.verdict-btn.active { color: #fff; }
.verdict-btn.verdict-present.active { background: var(--status-good); }
.verdict-btn.verdict-absent.active { background: var(--status-neutral); }
.verdict-btn.verdict-not_assessable.active { background: var(--status-warning); color: hsl(0 0% 9%); }
/* An untouched row still saves a verdict — its group's default. Show which one,
   faded, so it never reads as a choice a human actually made. */
.verdict-btn.default { color: #fff; opacity: 0.4; }
.verdict-btn.verdict-present.default { background: var(--status-good); }
.verdict-btn.verdict-absent.default { background: var(--status-neutral); }
.verdict-btn.verdict-not_assessable.default { background: var(--status-warning); color: hsl(0 0% 9%); }

.class-group {
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.class-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  user-select: none;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.class-group.collapsed .class-group-header { border-bottom-color: transparent; }
.class-group-header:hover { background: var(--hover-strong); }
.class-group-arrow {
  display: inline-block;
  width: 10px;
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.1s ease;
}
.class-group.collapsed .class-group-arrow { transform: rotate(-90deg); }
.class-group-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
}
.class-group-count {
  font-size: 10px;
  font-weight: 500;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 0 6px; border-radius: 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.class-group-body {
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px 4px;
}
.class-group.collapsed .class-group-body { display: none; }
.class-group-body label {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-md); cursor: pointer;
  user-select: none;
}
.class-group-body label:hover { background: var(--hover); }
.class-group-body label.selected { background: var(--accent); color: var(--accent-fg); }

/* ---- Canvas area ---- */
.canvas-area {
  display: flex; flex-direction: column;
  background: var(--canvas-bg);
  position: relative;
  min-height: 0;
  /* Let this grid item shrink below its content width so the giant zoomed
     stage scrolls inside .canvas-wrap instead of stretching the layout. */
  min-width: 0;
}
.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: auto;
  background: var(--canvas-well);
  min-height: 0;
}
.stage {
  position: relative;
  margin: 0 auto;
}
.stage img,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.stage canvas {
  cursor: crosshair;
  pointer-events: auto;
}
/* Whole-image mode captures no geometry, so a drawing cursor would promise
   something the canvas ignores. */
.stage canvas.no-draw { cursor: default; }
.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--canvas-text);
  pointer-events: none;
}
.canvas-toolbar {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.toolbar-spacer { flex: 1 1 auto; }

/* access's outline / default (primary) buttons. */
.btn {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--input);
  padding: 7px 14px; border-radius: var(--radius-md); cursor: pointer;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
/* Links styled as buttons (Progress, Back to annotating). */
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.active:hover { background: var(--accent-2); border-color: var(--accent-2); }
/* Overlay showing other annotators too — a distinct tint from the own-work state
   so it is obvious at a glance that foreign regions are on screen. */
.btn.active.overlay-all { background: var(--overlay-all); border-color: var(--overlay-all); }
.btn.active.overlay-all:hover { background: var(--overlay-all-hover); border-color: var(--overlay-all-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-block { display: block; text-align: center; width: 100%; }

.zoom-controls {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.zoom-display {
  min-width: 48px; text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted); font-size: 12px;
}

.status-line {
  margin: 0; padding: 6px 16px;
  font-size: 12px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--border);
  min-height: 24px;
  flex-shrink: 0;
  /* One clipped line: a long joined label list used to wrap, which re-fitted the
     image and made the canvas jump. Full text is in the title attribute. */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- Right sidebar panels ---- */
.panel {
  flex: 1 1 50%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.panel:last-child { border-bottom: 0; }
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px 4px;
  flex-shrink: 0;
}
.upload-btn {
  background: var(--accent); color: var(--accent-fg);
  padding: 4px 10px; border-radius: var(--radius-md); cursor: pointer;
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--accent);
  box-shadow: var(--shadow-sm);
}
.upload-btn:hover { background: var(--accent-2); border-color: var(--accent-2); }

.image-list, .annotation-list {
  list-style: none; padding: 4px 8px 8px; margin: 0;
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 1px;
}
.annotation-list li {
  position: relative;
  padding: 6px 28px 6px 8px; border-radius: var(--radius-md);
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  white-space: nowrap; overflow: hidden;
}
.annotation-list li:hover { background: var(--hover); }
.annotation-list li.active { background: var(--accent); color: var(--accent-fg); }

/* ---- Git-style image tree ---- */
.image-list .tree-node { padding: 0; cursor: default; }
.image-list .tree-row {
  position: relative;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 28px 5px 6px;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  white-space: nowrap; overflow: hidden;
  color: var(--text);
}
.image-list .tree-row:hover { background: var(--hover); }
.image-list .tree-arrow {
  flex: 0 0 auto;
  display: inline-block;
  width: 10px;
  font-size: 9px;
  color: var(--muted);
  transition: transform 0.1s ease;
  text-align: center;
}
.image-list .tree-row.collapsed .tree-arrow { transform: rotate(-90deg); }
.image-list .tree-icon {
  flex: 0 0 auto;
  display: inline-block;
  width: 14px;
  font-size: 11px;
  text-align: center;
  color: var(--muted);
}
.image-list .tree-icon-project { color: var(--accent); }
.image-list .tree-icon-folder { color: var(--warn); }
.image-list .tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.image-list .tree-row-project .tree-label {
  font-weight: 700;
  letter-spacing: 0.2px;
}
.image-list .tree-row-folder .tree-label {
  font-weight: 600;
  color: var(--muted);
}
.image-list .tree-row-folder:hover .tree-label { color: var(--text); }
.image-list .tree-count {
  flex: 0 0 auto;
  font-size: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 0 6px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.image-list .tree-row-project .tree-count {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

/* Children get indent + a Git-style vertical guide line. */
.image-list .tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}
.image-list .tree-children.collapsed { display: none; }
.image-list .tree-node > .tree-children {
  margin-left: 14px;
  padding-left: 10px;
  border-left: 1px dashed var(--border);
}

/* File row: badge instead of arrow, file-style label colour. */
.image-list .tree-row-file {
  padding-left: 8px;
}
.image-list .tree-badge {
  flex: 0 0 auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.image-list .tree-file.done .tree-badge { background: var(--success); }
.image-list .tree-file.done-by-others .tree-badge { background: var(--warn); }
.image-list .tree-file .tree-file-name { color: var(--text); }
.image-list .tree-file.active > .tree-row {
  background: var(--accent);
  color: var(--accent-fg);
}
.image-list .tree-file.active .tree-file-name { color: var(--accent-fg); }
.image-list .tree-file.active .tree-badge { background: var(--accent-fg); }

.image-list .tree-empty {
  padding: 6px 8px;
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  cursor: default;
}

.annotation-list li {
  flex-direction: column; align-items: stretch; gap: 2px;
  padding: 6px 28px 6px 8px;
}
.annotation-list .ann-row {
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden;
}
.annotation-list .ann-class {
  font-weight: 600; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.annotation-list .ann-tag {
  font-size: 10px; padding: 1px 6px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted);
  flex: 0 0 auto;
}
.annotation-list li.active .ann-tag { background: rgba(255,255,255,0.18); border-color: transparent; color: white; }
.annotation-list .ann-meta {
  font-size: 10px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.annotation-list li.active .ann-meta { color: rgba(255,255,255,0.8); }
.annotation-list .ann-author {
  font-size: 10px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 4px;
}
.annotation-list .ann-author.others { color: var(--warn); }
.annotation-list li.active .ann-author { color: rgba(255,255,255,0.8); }
.annotation-list li.others-only {
  background: hsl(40.8 95.7% 53.9% / 0.08);
}
.annotation-list .empty-hint {
  cursor: default; color: var(--muted); font-style: italic;
  padding: 6px 8px;
}
.annotation-list .empty-hint:hover { background: transparent; }

.row-delete {
  position: absolute;
  right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--muted);
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: none;
}
.image-list .tree-row-file:hover .row-delete,
.annotation-list li:hover .row-delete {
  display: inline-block;
}
.row-delete:hover {
  background: var(--danger-solid);
  color: white;
}
.image-list .tree-file.active .row-delete,
.annotation-list li.active .row-delete {
  color: rgba(255,255,255,0.85);
  display: inline-block;
}
.image-list .tree-file.active .row-delete:hover,
.annotation-list li.active .row-delete:hover {
  background: var(--danger-solid);
}

/* ---- Annotation groups (by annotator) ---- */
.annotation-list > li.ann-group {
  display: block;
  padding: 0;
  border-radius: var(--radius-md);
  cursor: default;
  overflow: visible;
  white-space: normal;
}
.annotation-list > li.ann-group:hover { background: transparent; }
.ann-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  cursor: pointer;
  user-select: none;
  /* Stay pinned to the top of the scroll area while scrolling this group's
     items, so you always see whose annotations you are looking at. */
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.ann-group-header:hover { background: var(--hover); }
.ann-group-arrow {
  flex: 0 0 auto;
  width: 10px; font-size: 9px; color: var(--muted);
  transition: transform 0.1s ease; text-align: center;
}
.ann-group.collapsed .ann-group-arrow { transform: rotate(-90deg); }
.ann-group-name {
  flex: 1; font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ann-group.mine .ann-group-name { color: var(--accent); }
.ann-group-count {
  flex: 0 0 auto;
  font-size: 10px; background: var(--panel-2);
  border: 1px solid var(--border); padding: 0 6px;
  border-radius: var(--radius-sm); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ann-group-body {
  list-style: none; margin: 0 0 0 9px;
  padding: 0 0 2px 12px;
  border-left: 1px dashed var(--border);
}
.ann-group.collapsed .ann-group-body { display: none; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(720px, 94vw);
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header, .modal-footer {
  display: flex; align-items: center;
  padding: 14px 18px;
  flex-shrink: 0;
}
.modal-header { justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.modal-footer { justify-content: flex-end; gap: 10px; border-top: 1px solid var(--border); }
.modal-close {
  background: transparent; border: 0; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { overflow-y: auto; padding: 8px 18px 16px; }

/* ---- Admin panel ---- */
.admin-section { margin-top: 16px; }
.admin-section-head {
  display: flex; align-items: center; justify-content: space-between;
}
.admin-section-head h3 {
  font-size: 12px; text-transform: uppercase; color: var(--muted);
  letter-spacing: 0.5px; margin: 8px 0;
}
.admin-hint { font-size: 11px; color: var(--muted); margin: 2px 0 8px; }
.admin-hint code {
  background: var(--panel-2); padding: 0 4px; border-radius: var(--radius-sm);
  font-size: 11px;
}
.admin-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.admin-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  flex-wrap: wrap;
}
.admin-input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--input); border-radius: var(--radius-md);
  padding: 5px 8px; font-size: 12px;
  flex: 1; min-width: 120px;
}
.admin-input-id { flex: 0 0 140px; font-family: monospace; }
.admin-input-role { flex: 0 0 110px; cursor: pointer; }
.admin-del { flex: 0 0 auto; color: var(--danger); }
.admin-del:hover { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.admin-projects-pick {
  display: flex; flex-wrap: wrap; gap: 8px;
  flex: 1 1 100%;
}
.admin-chk {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: var(--radius-md);
  cursor: pointer;
}
.admin-chk input { accent-color: var(--accent); }
.admin-status { flex: 1; font-size: 12px; color: var(--muted); }
.admin-doctor-alias { flex: 0 0 34px; font-family: monospace; font-weight: 600; }
.admin-doctor-who { flex: 1 1 200px; min-width: 0; font-size: 12px; overflow-wrap: anywhere; }
.admin-doctor-project { flex: 0 0 auto; font-size: 11px; }
.admin-doctor-progress { flex: 0 0 auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.admin-doctor-form { margin-top: 6px; }

/* ---- Tinder view ---- */
/* The Classic layout stays in the DOM (its state is the annotator's work in
   progress) — Tinder only covers it. */
body.tinder-active .layout { display: none; }
body.tinder-active .mode-toggle:not(.app-style-toggle),
body.tinder-active .grid-control { display: none; }

.tinder-view {
  height: calc(100vh - 52px);
  /* Where supported, track iOS Safari's collapsing chrome so the action row
     is never hidden behind it; the 100vh line above is the fallback. */
  height: calc(100dvh - 52px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
}

.tinder-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  width: min(680px, 100%);
}
.tinder-class-pick {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 6px 10px;
  flex: 1; min-width: 0;
}
.tinder-class-pick:focus-within { outline: 2px solid var(--ring); outline-offset: 1px; }
.tinder-class-label {
  font-size: 11px; text-transform: uppercase; font-weight: 600;
  color: var(--muted); letter-spacing: 0.05em;
}
#tinder-class {
  background: transparent; color: var(--text);
  border: 0; outline: none;
  font-size: 15px; font-weight: 600;
  cursor: pointer; outline: none;
  flex: 1; min-width: 0;
}
#tinder-class option, #tinder-class optgroup { background: var(--panel); color: var(--text); }
.tinder-progress {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tinder-card-area {
  position: relative;
  flex: 1; min-height: 0;
  width: min(680px, 100%);
  display: flex; align-items: center; justify-content: center;
}
.tinder-card {
  position: relative;
  width: 100%; height: 100%;
  border-radius: calc(var(--radius) * 1.5);
  background: #000;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  /* The card IS the gesture surface — never let the browser scroll instead. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.tinder-card.dragging { transition: none; cursor: grabbing; }
.tinder-card.loading { opacity: 0.55; }
.tinder-card.enter { animation: tinder-pop 0.16s ease; }
@keyframes tinder-pop {
  from { transform: scale(0.96); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}
#tinder-img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  /* Pinch zoom animates this transform on every move. */
  will-change: transform;
}
.tinder-card.pinching { cursor: zoom-in; }

.tinder-stamp {
  position: absolute; top: 26px;
  font-size: 34px; font-weight: 800; letter-spacing: 2px;
  padding: 6px 14px;
  border: 4px solid; border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
}
.tinder-stamp-present { left: 22px; color: var(--image-good); border-color: var(--image-good); transform: rotate(-14deg); }
.tinder-stamp-absent { right: 22px; color: var(--image-bad); border-color: var(--image-bad); transform: rotate(14deg); }

.tinder-badge {
  position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: var(--radius-md);
  font-size: 12px; font-weight: 600;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  pointer-events: none;
  white-space: nowrap;
}
.tinder-badge.badge-present { border-color: var(--image-good); color: var(--image-good); }
.tinder-badge.badge-absent { border-color: var(--image-bad); color: var(--image-bad); }
.tinder-badge.badge-not_assessable { border-color: var(--image-warn); color: var(--image-warn); }

.tinder-filename {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 14px 14px 10px;
  font-size: 12px; color: #dfe3ea;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.tinder-message {
  max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}
.tinder-message p { margin: 0; }

.tinder-actions {
  display: flex; align-items: center;
  gap: 26px;
  padding: 4px 0;
}
.tinder-btn {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 26px; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.08s ease, background 0.12s ease;
  /* Rapid ✓/✕ tapping must not trigger the browser's double-tap zoom. */
  touch-action: manipulation;
}
.tinder-btn:hover:not(:disabled) { transform: scale(1.07); background: var(--hover); }
.tinder-btn:active:not(:disabled) { transform: scale(0.95); }
.tinder-btn:disabled { opacity: 0.35; cursor: default; }
.tinder-btn-back { width: 52px; height: 52px; font-size: 20px; color: var(--warn); border-color: var(--warn); }
.tinder-btn-no { color: var(--danger); border-color: var(--danger); }
.tinder-btn-yes { color: var(--success); border-color: var(--success); }

.tinder-status {
  margin: 0;
  min-height: 18px;
  width: min(680px, 100%);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Phone-sized screens: bigger touch targets, quieter topbar. */
@media (max-width: 640px) {
  .topbar { padding: 0 8px; }
  .topbar-left, .topbar-right { gap: 8px; }
  /* The full topbar is wider than a phone. Decorations go (they were pushing
     the actual controls off-screen and overlapping them — the Tinder toggle
     was untappable), and whatever still overflows scrolls instead of stacking. */
  .brand,
  .counter,
  .user { display: none; }
  .topbar { overflow-x: auto; }
  .topbar-left, .topbar-right { flex-shrink: 0; }
  .project-select select { max-width: 110px; }
  .tinder-view { padding: 8px 10px calc(12px + env(safe-area-inset-bottom)); }
  .tinder-stamp { top: 18px; font-size: 26px; }
  .tinder-actions { gap: 30px; }
  .tinder-btn { width: 72px; height: 72px; font-size: 30px; }
  .tinder-btn-back { width: 56px; height: 56px; font-size: 22px; }
}

/* ---- Admin progress page (/progress) ---- */
.progress-body { min-height: 100%; }
.progress-body .topbar { position: sticky; top: 0; z-index: 5; }
.brand-link { color: inherit; text-decoration: none; }
/* The meter track is a lighter step of the fill's own hue, so the whole bar reads as one measure. */
:root { --meter-track: hsl(216 85% 58% / 0.14); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --meter-track: hsl(216 85% 58% / 0.22); } }
:root[data-theme="dark"] { --meter-track: hsl(216 85% 58% / 0.22); }

.progress-page { max-width: 1120px; margin: 0 auto; padding: 28px 20px 48px; }
.progress-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.progress-head h1 { margin: 2px 0 0; font-size: 28px; font-weight: 600; letter-spacing: -0.025em; }
.progress-eyebrow {
  margin: 0; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted);
}
.progress-updated { margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-updated.stale { color: var(--warn); font-weight: 500; }
.progress-message {
  margin: 24px 0; padding: 14px 16px; font-size: 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2);
}
.progress-message.error { border-color: var(--danger); color: var(--danger); }

.kpi-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px;
  margin: 20px 0 8px;
}
.kpi-tile {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
  padding: 14px 16px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.progress-section { margin-top: 28px; }
.progress-section h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.progress-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.progress-hint { margin: 6px 0 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.progress-sort { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.progress-sort select {
  background: var(--bg); color: var(--text); border: 1px solid var(--input);
  border-radius: var(--radius-md); padding: 4px 8px; font-size: 13px;
}
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* Meter list: a name, a bar and its figures per row, every bar on one baseline. */
.meter-list-head, .meter-row {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(120px, 1fr) 120px 56px 120px;
  align-items: center; gap: 14px;
}
.meter-list-head {
  padding: 0 10px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); border-bottom: 1px solid var(--border);
}
.meter-list { list-style: none; margin: 0; padding: 0; }
.meter-row { padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.meter-row:hover, .meter-row:focus-visible { background: var(--hover); }
.meter-name { min-width: 0; overflow-wrap: anywhere; }
.meter-bar { position: relative; display: block; height: 8px; border-radius: 4px; background: var(--meter-track); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.meter-fig { color: var(--muted); white-space: nowrap; }
.meter-fig strong { color: var(--text); font-weight: 600; }
.meter-pct { font-weight: 600; }
.meter-left { color: var(--muted); white-space: nowrap; }
.meter-left.short { color: var(--warn); }
.meter-reached {
  display: inline-block; margin-left: 8px; padding: 0 6px;
  font-size: 11px; font-weight: 600; border-radius: var(--radius-sm);
  color: var(--success); border: 1px solid currentColor;
}
.meter-note { grid-column: 2 / -1; color: var(--muted); font-size: 13px; }
.doctor-alias {
  display: inline-block; min-width: 28px; margin-right: 4px; padding: 0 5px;
  font-size: 11px; font-weight: 600; text-align: center;
  border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--border);
}
.progress-empty { padding: 10px; color: var(--muted); }

.extra-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  border-top: 1px solid var(--border); border-left: 1px solid var(--border);
}
.extra-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 12px; font-size: 13px;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.extra-row .num { font-weight: 600; }
.progress-foot { margin: 28px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* Narrow: the bar drops under the name, the figures stay on the name's line. */
@media (max-width: 760px) {
  .meter-list-head { display: none; }
  .meter-row {
    grid-template-columns: 1fr auto auto;
    grid-template-areas: "name fig pct" "bar bar bar" "left left left";
    row-gap: 6px;
  }
  .meter-name { grid-area: name; }
  .meter-bar { grid-area: bar; }
  .meter-fig { grid-area: fig; }
  .meter-pct { grid-area: pct; }
  .meter-left { grid-area: left; text-align: left; font-size: 12px; }
  .meter-left::before { content: "Candidates left: "; }
  .meter-list-doctors .meter-left::before { content: ""; }
  .meter-note { grid-column: 1 / -1; }
  .progress-page { padding: 20px 16px 40px; }
}

/* WCAG 2.3.3 — honour reduced motion, as access does app-wide. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
