/* =====================================================================
   Shadowgraph annotation — stylesheet
   One token layer, two themes: light (a quiet contact sheet) and dark (a
   light table for greyscale crops). Hierarchy comes from type size and
   weight; borders separate panes; nothing is decorated. Variable names are
   kept from the previous design so inline styles set by the scripts keep
   working (var(--border-strong), var(--text-muted), …).
   ===================================================================== */
@font-face {
    font-family: "Inter Variable";
    src: url("../assets/fonts/inter-latin-opsz-normal.woff2") format("woff2");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "JetBrains Mono Variable";
    src: url("../assets/fonts/jetbrains-mono-latin-normal.woff2") format("woff2");
    font-weight: 100 800;
    font-style: normal;
    font-display: swap;
    size-adjust: 92%;       /* level with Inter's figures at the same size */
}

/* The look (as in Holon): neutral white, one grotesk for everything with titles
   set apart by weight, counts and codes in a monospace, hairlines, small corners,
   one saturated blue; green, red and amber only for decisions. */
:root {
    color-scheme: light;
    --sans: "Inter Variable", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "JetBrains Mono Variable", ui-monospace, Menlo, monospace;
    --surface: oklch(0.99 0.002 250);
    --surface-raised: oklch(1 0 0);
    --surface-sunken: oklch(0.955 0.004 250);
    --surface-sunken-strong: oklch(0.925 0.005 250);
    --surface-overlay: oklch(0.2 0.01 250 / 0.25);
    --text: oklch(0.18 0.006 260);
    --text-muted: oklch(0.50 0.010 260);
    --text-faint: oklch(0.66 0.008 260);
    --text-invert: oklch(1 0 0);
    --border-soft: oklch(0.905 0.004 250);
    --border-strong: oklch(0.84 0.006 250);
    --shadow-card: none;
    --shadow-pop: 0 0 0 1px var(--border-soft), 0 12px 32px oklch(0.2 0.01 250 / 0.08);
    --shadow-segment: 0 0 0 1px var(--border-soft), 0 1px 2px oklch(0.2 0.01 250 / 0.06);
    --accent: oklch(0.52 0.22 264);
    --accent-soft: oklch(0.935 0.04 262);
    --accent-fg-on-soft: oklch(0.45 0.20 264);
    --tint-confirm-bg: oklch(0.955 0.035 160);
    --tint-confirm-fg: oklch(0.52 0.12 160);
    --tint-reject-bg: oklch(0.95 0.035 27);
    --tint-reject-fg: oklch(0.56 0.21 27);
    --tint-warn-bg: oklch(0.96 0.045 80);
    --tint-warn-fg: oklch(0.64 0.15 70);
    --overlay-confirm: oklch(0.52 0.12 160 / 0.18);
    --overlay-reject: oklch(0.56 0.21 27 / 0.22);
    --radius-sm: 3px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-pill: 999px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --topbar-h: 58px;
    --footer-h: 30px;
    /* legacy aliases used by older component code */
    --bg-primary: var(--surface);
    --bg-secondary: var(--surface-raised);
    --bg-tertiary: var(--surface-sunken);
    --bg-input: var(--surface-raised);
    --text-primary: var(--text);
    --text-secondary: var(--text-muted);
    --text-dim: var(--text-faint);
    --border-color: var(--border-soft);
    --border-hover: var(--border-strong);
    --accent-green: var(--tint-confirm-fg);
    --accent-red: var(--tint-reject-fg);
    --accent-yellow: var(--tint-warn-fg);
    --accent-blue: var(--accent);
    --btn-bg: var(--surface-sunken);
    --btn-hover: var(--surface-sunken-strong);
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --surface: oklch(0.175 0.004 260);
    --surface-raised: oklch(0.20 0.005 260);
    --surface-sunken: oklch(0.225 0.006 260);
    --surface-sunken-strong: oklch(0.26 0.006 260);
    --surface-overlay: oklch(0 0 0 / 0.5);
    --text: oklch(0.95 0.003 260);
    --text-muted: oklch(0.70 0.008 260);
    --text-faint: oklch(0.52 0.008 260);
    --text-invert: oklch(0.175 0.004 260);
    --border-soft: oklch(0.27 0.006 260);
    --border-strong: oklch(0.34 0.006 260);
    --shadow-pop: 0 0 0 1px var(--border-soft), 0 14px 36px oklch(0 0 0 / 0.45);
    --shadow-segment: 0 0 0 1px var(--border-strong);
    --accent: oklch(0.70 0.17 264);
    --accent-soft: oklch(0.28 0.06 264);
    --accent-fg-on-soft: oklch(0.82 0.10 264);
    --tint-confirm-bg: oklch(0.26 0.04 160);
    --tint-confirm-fg: oklch(0.74 0.13 160);
    --tint-reject-bg: oklch(0.27 0.05 27);
    --tint-reject-fg: oklch(0.70 0.18 27);
    --tint-warn-bg: oklch(0.28 0.05 75);
    --tint-warn-fg: oklch(0.78 0.12 75);
    --overlay-confirm: oklch(0.74 0.13 160 / 0.22);
    --overlay-reject: oklch(0.70 0.18 27 / 0.26);
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font: 13.5px/1.45 var(--sans);
    color: var(--text);
    background: var(--surface);
    font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }
/* counts, identifiers, frame names: the monospace (as dates and counts in Holon) */
.stat-chip b, .rail__count, #sidebar-id, #sidebar-frame, #fi-id, #fi-frame, #frame-index-display, .frame-display-title, .frame-count,
#frame-zoom-value, #frame-pad-value, #sidebar-zoom-value, kbd, code { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-pill); }
[hidden] { display: none !important; }
kbd {
    display: inline-block;
    border: 1px solid var(--border-soft);
    border-bottom-width: 2px;
    border-radius: 3px;
    padding: 0 5px;
    font-size: 0.72rem;
    font-family: inherit;
    color: var(--text-muted);
    background: var(--surface-raised);
    margin: 0 1px;
}
.label-cap { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em; color: var(--text-faint); }
.status { font-size: 0.85em; color: var(--text-muted); margin-top: var(--space-2); }
.status.loaded { color: var(--tint-confirm-fg); }
.status.error { color: var(--tint-reject-fg); }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    background: var(--surface-raised);
    color: var(--text);
    font-size: 0.85rem;
    padding: 6px 12px;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-sunken); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--text); color: var(--text-invert); border-color: var(--text); }
.btn--primary:hover { background: var(--text); opacity: 0.88; }
.btn--success { color: var(--tint-confirm-fg); border-color: color-mix(in srgb, var(--tint-confirm-fg) 40%, var(--border-soft)); }
.btn--success:hover { background: var(--tint-confirm-bg); }
.btn--danger { color: var(--tint-reject-fg); border-color: color-mix(in srgb, var(--tint-reject-fg) 40%, var(--border-soft)); }
.btn--danger:hover { background: var(--tint-reject-bg); }
.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--surface-sunken); }
.btn--sm { font-size: 0.8rem; padding: 4px 10px; }
.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-soft);
    background: var(--surface-raised);
    color: var(--text-muted);
    font-size: 0.9rem;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent-fg-on-soft); border-color: transparent; }
.icon-btn--text { width: auto; padding: 0 10px; font-size: 0.8rem; font-weight: 500; }

/* ===== Top bar ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: var(--space-5);
    height: var(--topbar-h);
    padding: 0 var(--space-5);
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border-soft);
}
.brand { font-weight: 650; letter-spacing: -0.015em; }
.view-toggle { display: flex; gap: 2px; padding: 2px; background: var(--surface-sunken); border-radius: var(--radius-lg); }
.view-toggle button { border: none; background: transparent; color: var(--text-muted); font-size: 0.85rem; font-weight: 500; padding: 4px 13px; border-radius: var(--radius-md); }
.view-toggle button:hover { color: var(--text); }
.view-toggle button.active { background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-segment); }
.view-toggle .frame-count { font-size: 0.75rem; opacity: 0.7; margin-left: 4px; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
/* One line whatever the width: labels never wrap, and the save indicator is the
   one item that gives way (its message ellipsized, whole in its tooltip). Narrower
   windows: the brand goes first, then the gaps and the numbers shrink, so the
   buttons at the right end (theme, How to) stay on screen. */
.topbar button, .topbar .btn { white-space: nowrap; }
.topbar > :not(.topbar__right), .topbar__right > :not(.autosave-indicator) { flex-shrink: 0; }
@media (max-width: 1400px) {
    .brand { display: none; }
    .topbar { gap: var(--space-3); }
}
@media (max-width: 1180px) {
    .topbar { padding: 0 var(--space-3); }
    .topbar__right { gap: var(--space-1); }
}

/* The ledger: what has been decided, in numbers big enough to read across the room */
.ledger { display: flex; gap: var(--space-5); align-items: flex-end; }
.stat-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1; }
.stat-chip b { font-size: 24px; font-weight: 500; letter-spacing: -0.01em; color: var(--text); }
.stat-chip span { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.stat-chip--confirm b { color: var(--tint-confirm-fg); }
.stat-chip--reject b { color: var(--tint-reject-fg); }
.stat-chip--flag b { color: var(--tint-warn-fg); }
.stat-chip--deleted b { color: var(--text-muted); }
@media (max-width: 1400px) { .ledger { gap: var(--space-3); } }
@media (max-width: 1180px) { .ledger { gap: var(--space-2); } .stat-chip b { font-size: 18px; } }
@media (max-width: 1040px) { .stat-chip b { font-size: 16px; } .stat-chip span { font-size: 10px; } .view-toggle button { padding: 4px 9px; } }

/* Menus and popovers */
.menu { position: relative; }
.menu__list {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: var(--surface-raised);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
    padding: var(--space-1);
    z-index: 300;
}
.menu.open .menu__list { display: block; }
.menu__list button { display: block; width: 100%; text-align: left; border: none; background: transparent; font-size: 0.85rem; padding: 7px 10px; border-radius: var(--radius-sm); }
.menu__list button:hover { background: var(--surface-sunken); }
.menu__note { font-size: 0.75rem; color: var(--text-faint); padding: 6px 10px; }
.popover {
    display: none;
    position: fixed;
    top: calc(var(--topbar-h) + 8px);
    right: 20px;
    z-index: 400;
    background: var(--surface-raised);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
    padding: var(--space-4);
    max-width: 360px;
}
.popover.open { display: block; }
.popover h4 { margin-bottom: var(--space-3); }
.shortcuts-table { border-collapse: collapse; font-size: 0.82rem; color: var(--text-muted); }
.shortcuts-table td { padding: 3px 8px 3px 0; vertical-align: top; }
.popover--history { width: 360px; max-height: 70vh; overflow-y: auto; }
.history-list { display: flex; flex-direction: column; gap: 2px; }
.history-empty { color: var(--text-faint); font-size: 0.85em; }
.history-row { display: grid; grid-template-columns: 56px 72px 1fr auto; gap: var(--space-2); align-items: center; width: 100%; text-align: left; border: none; background: transparent; font-size: 0.8rem; padding: 5px 8px; border-radius: var(--radius-sm); }
.history-row:hover { background: var(--surface-sunken); }
.history-row__id { font-weight: 600; }
.history-row__state { font-size: 0.72rem; border-radius: var(--radius-sm); padding: 1px 8px; text-align: center; background: var(--surface-sunken); color: var(--text-muted); }
.history-row--confirmed .history-row__state { background: var(--tint-confirm-bg); color: var(--tint-confirm-fg); }
.history-row--rejected .history-row__state { background: var(--tint-reject-bg); color: var(--tint-reject-fg); }
.history-row--flagged .history-row__state { background: var(--tint-warn-bg); color: var(--tint-warn-fg); }
.history-row__class { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.history-row__time { color: var(--text-faint); font-size: 0.72rem; white-space: nowrap; }

/* Autosave indicator */
.autosave-indicator { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-faint); opacity: 0; transition: opacity 0.3s; max-width: 260px; min-width: 0; flex: 0 1 auto; }
.autosave-indicator .text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.autosave-indicator.visible { opacity: 1; }
.autosave-indicator .dot { width: 7px; height: 7px; border-radius: var(--radius-pill); background: var(--text-faint); flex-shrink: 0; }
.autosave-indicator.saving .dot { background: var(--tint-warn-fg); animation: autosave-pulse 1s infinite; }
.autosave-indicator.saved .dot, .autosave-indicator.saved-file .dot { background: var(--tint-confirm-fg); }
.autosave-indicator.saved { color: var(--text-muted); }
.autosave-indicator.saved-file { color: var(--tint-confirm-fg); }
.autosave-indicator.file-error { color: var(--tint-reject-fg); }
.autosave-indicator.file-error .dot { background: var(--tint-reject-fg); }
@keyframes autosave-pulse { 50% { opacity: 0.4; } }

/* Before data is loaded: brand, help and theme only */
body:not(.loaded) .view-toggle, body:not(.loaded) .ledger, body:not(.loaded) .autosave-indicator,
body:not(.loaded) .topbar .menu, body:not(.loaded) #shortcuts-btn, body:not(.loaded) #history-btn,
body:not(.loaded) #sidebar-btn, body:not(.loaded) #classes-btn { display: none; }
body[data-view="frame"] #sidebar-btn { display: none; }
#main-interface { display: none; }

/* ===== Setup screen ===== */
.setup-section { max-width: 760px; margin: 40px auto; padding: 0 var(--space-5) var(--space-5); }
.setup-hero { margin-bottom: var(--space-5); }
.setup-hero h1 { font-size: 26px; letter-spacing: -0.015em; margin-bottom: 4px; }
.setup-hero .subtitle { margin: 0; color: var(--text-muted); }
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: 36px var(--space-5);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
    cursor: pointer;
    text-align: center;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone__icon { font-size: 1.4rem; color: var(--text-muted); }
.dropzone__title { font-weight: 500; }
.dropzone__hint { font-size: 0.8rem; color: var(--text-muted); max-width: 520px; }
.dropzone__step { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: var(--space-2); border-radius: var(--radius-pill); background: var(--text); color: var(--text-invert); font-size: 0.8rem; font-weight: 600; vertical-align: 1px; }
#frames-dropzone { margin-top: var(--space-4); }
.dropzone-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.dropzone-row .link-btn { font-size: 0.85rem; }
#frames-required, #frames-cached { margin-top: var(--space-2); }
.setup-fallback { margin: var(--space-4) 0; }
.setup-fallback summary { cursor: pointer; color: var(--text-muted); font-size: 0.9em; }
.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-3); margin-top: var(--space-3); }
.setup-item { background: var(--surface-raised); border: 1px solid var(--border-soft); padding: var(--space-3); border-radius: var(--radius-md); }
.setup-item label { display: block; margin-bottom: var(--space-2); color: var(--text-muted); font-size: 0.85em; }
.setup-item input[type="file"] { font-size: 0.85em; max-width: 100%; }
.setup-frames { margin: var(--space-4) 0; padding: var(--space-4); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); background: var(--surface-raised); }
.setup-frames label { font-weight: 500; }
.setup-frames p { font-size: 0.85em; color: var(--text-muted); margin: var(--space-1) 0 var(--space-3); }
#load-btn { margin-top: var(--space-4); width: 100%; padding: 12px; font-size: 1rem; }
.progress-bar { height: 4px; background: var(--surface-sunken); border-radius: var(--radius-pill); overflow: hidden; margin-top: var(--space-3); }
.progress-bar .fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

/* ===== Footer ===== */
.site-footer { height: var(--footer-h); display: flex; align-items: center; justify-content: center; padding: 0 var(--space-4); border-top: 1px solid var(--border-soft); background: var(--surface-raised); color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Workspace: rail | stage | inspector ===== */
.workspace {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr) 300px;
    height: calc(100vh - var(--topbar-h) - var(--footer-h));
}
body.sidebar-hidden .workspace { grid-template-columns: 236px minmax(0, 1fr); }
#cluster-view.hidden { display: none; }
.rail { border-right: 1px solid var(--border-soft); background: var(--surface-raised); overflow-y: auto; padding: var(--space-3) var(--space-2); display: flex; flex-direction: column; gap: 2px; }
.rail__head { display: flex; align-items: center; gap: var(--space-2); padding: 2px var(--space-2) var(--space-2); }
.rail__head .label-cap { flex: 1; }
.grouping { display: flex; gap: 2px; padding: 2px; background: var(--surface-sunken); border-radius: var(--radius-lg); }
.grouping button { border: none; background: transparent; color: var(--text-muted); font-size: 0.75rem; font-weight: 500; padding: 2px 9px; border-radius: var(--radius-md); }
.grouping button.active { background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-segment); }
.rail__opt { display: flex; align-items: center; gap: 6px; padding: 0 var(--space-2) var(--space-2); font-size: 0.78rem; color: var(--text-muted); cursor: pointer; }
.rail__opt input { margin: 0; }
.rail__opt-count { color: var(--text-faint); }
.rail__item {
    display: grid;
    grid-template-columns: 10px 1fr auto;
    gap: 3px 8px;
    align-items: center;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 7px var(--space-2);
    border-radius: var(--radius-md);
}
.rail__item:hover { background: var(--surface-sunken); }
.rail__item.is-active { background: var(--accent-soft); color: var(--accent-fg-on-soft); }
.rail__item.is-nomatch { opacity: 0.45; }
/* Hide empty: the groups with no thumbnail left leave the rail (the one on the
   stage stays until another is chosen) and the stack; the Deleted filter shows them */
body.hide-empty-groups:not([data-filter="deleted"]) .rail__item.is-empty:not(.is-active),
body.hide-empty-groups.groups-stacked:not([data-filter="deleted"]) .rail__item.is-empty,
body.hide-empty-groups.groups-stacked:not([data-filter="deleted"]) .cluster-section--empty { display: none; }
.rail__dot { width: 8px; height: 8px; border-radius: var(--radius-pill); }
.rail__name { font-weight: 500; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail__count { font-size: 0.8rem; color: var(--text-muted); }
.rail__item.is-active .rail__count { color: inherit; }
.rail__item.is-filtered:not(.is-nomatch) .rail__count { color: var(--accent-fg-on-soft); font-weight: 600; }
.rail__bar { grid-column: 2 / -1; display: block; height: 3px; background: var(--surface-sunken-strong); border-radius: var(--radius-pill); overflow: hidden; }
.rail__bar b { display: block; height: 100%; background: var(--tint-confirm-fg); }
.rail__item.is-done .rail__name::after { content: " ✓"; color: var(--tint-confirm-fg); }
/* stays in sight under a long list of groups (it sat below all of them) */
.rail__foot { margin-top: auto; padding: var(--space-2); position: sticky; bottom: calc(-1 * var(--space-3)); background: var(--surface-raised); border-top: 1px solid var(--border-soft); }
.rail__foot .btn { width: 100%; justify-content: center; }

.stage { overflow-y: auto; padding: 0 var(--space-5) var(--space-5); position: relative; }
.stage-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    padding: var(--space-3) 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: var(--space-3);
}
.stage-bar__right { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.filter-bar { display: inline-flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.filter-bar .label-cap { margin-right: 6px; }
.filter-bar button { border: none; background: transparent; color: var(--text-muted); font-size: 0.82rem; font-weight: 500; padding: 3px 9px; border-radius: var(--radius-md); }
.filter-bar button:hover { color: var(--text); background: var(--surface-sunken); }
.filter-bar button.active { background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-segment); }
.class-filter { margin-left: 6px; font-size: 0.8rem; border: 1px solid var(--border-soft); border-radius: var(--radius-md); background: var(--surface-raised); color: var(--text-muted); padding: 2px 6px; max-width: 180px; }
.thumb-progress { font-size: 0.8rem; color: var(--text-muted); }

/* Group sections: in the default mode only the selected one is shown; "Show all" stacks them */
.cluster-section { margin-bottom: var(--space-5); }
.cluster-section:not(:has(.cluster-content.active)) { display: none; }
body.groups-stacked .cluster-section { display: block; }
.cluster-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2) var(--space-3); padding: var(--space-2) 0 var(--space-3); border-left: 0 solid transparent; cursor: default; }
body.groups-stacked .cluster-header { cursor: pointer; border-left-width: 4px; padding-left: var(--space-3); }
.cluster-header h2 { font-size: 21px; letter-spacing: -0.015em; display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.cluster-header .class-name { color: var(--text-muted); font-weight: 400; font-size: 15px; }
.cluster-header .count { color: var(--text-muted); font-size: 0.85rem; }
.cluster-header .count.count--done { color: var(--tint-confirm-fg); font-weight: 600; }
.cluster-filter-count { font-size: 0.75rem; color: var(--accent-fg-on-soft); background: var(--accent-soft); border-radius: var(--radius-pill); padding: 1px 8px; }
.cluster-filter-count:empty { display: none; }
.cluster-section--nomatch .cluster-header { opacity: 0.55; }
.cluster-section--nomatch .cluster-content { display: none; }
/* A filter just chosen: the groups without a match leave the stack (the rail still lists them, dimmed) */
body.groups-stacked .cluster-section.filter-hidden { display: none; }
.cluster-chars { display: flex; gap: var(--space-1); flex-wrap: wrap; width: 100%; }
.cluster-char { color: var(--text-muted); font-size: 0.75rem; }
.cluster-char + .cluster-char::before { content: "· "; color: var(--text-faint); }
.purity-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 500; color: var(--text-muted); }
.purity-bar { width: 40px; height: 3px; background: var(--surface-sunken-strong); border-radius: var(--radius-pill); overflow: hidden; }
.purity-bar-fill { height: 100%; }
.purity-badge.high .purity-bar-fill { background: var(--tint-confirm-fg); }
.purity-badge.medium .purity-bar-fill { background: var(--tint-warn-fg); }
.purity-badge.low .purity-bar-fill { background: var(--tint-reject-fg); }
.cluster-content { display: none; }
.cluster-content.active { display: block; }
/* One group on the stage: the stage bar's "all visible" buttons act on it, so the per-group ones only appear when groups are stacked */
.label-buttons { display: none; gap: var(--space-2); margin-bottom: var(--space-3); }
body.groups-stacked .label-buttons { display: flex; }
.label-buttons button { border: 1px solid var(--border-soft); background: var(--surface-raised); border-radius: var(--radius-md); padding: 4px 12px; font-size: 0.8rem; color: var(--text-muted); }
.label-buttons button:hover { background: var(--surface-sunken); }
.label-buttons button.confirm { color: var(--tint-confirm-fg); }
.label-buttons button.reject { color: var(--tint-reject-fg); }

/* ===== Tiles ===== */
.tile-rows { padding: 0 0 var(--space-3); }
.tile-group + .tile-group { margin-top: var(--space-3); }
.tile-group__name { font-size: 0.8rem; color: var(--text-muted); margin-bottom: var(--space-1); }
.tile-group__name:empty { display: none; }
.tile-row { display: flex; flex-wrap: wrap; gap: 6px; }
.detection-overlay { position: absolute; cursor: pointer; box-sizing: border-box; }
.tile { position: relative; display: block; border-radius: var(--radius-md); overflow: hidden; background-color: var(--surface-sunken); }
.tile__img { position: relative; z-index: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
.tile__tint { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.tile.no-thumb::after, .tile.no-frame::after { content: "…"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: 1.1rem; }
.tile.no-frame::after { content: "✎"; }
.detection-overlay:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.detection-overlay.focused { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 5; }
.tile.selected .tile__tint, .tile.confirmed .tile__tint { background: color-mix(in srgb, var(--tint-confirm-fg) 7%, transparent); box-shadow: inset 0 0 0 3px var(--tint-confirm-fg); }
.tile.selected .tile__tint::after, .tile.confirmed .tile__tint::after { content: "✓"; position: absolute; right: 3px; bottom: 3px; background: var(--tint-confirm-fg); color: #fff; font-size: 0.65rem; font-weight: 700; line-height: 1; padding: 2px 4px; border-radius: 3px; }
.tile.rejected .tile__tint { background: color-mix(in srgb, var(--tint-reject-fg) 12%, transparent); box-shadow: inset 0 0 0 3px var(--tint-reject-fg); }
.tile.rejected .tile__img { opacity: 0.6; }
.tile.rejected::after { content: "✕"; position: absolute; right: 3px; bottom: 3px; z-index: 2; background: var(--tint-reject-fg); color: #fff; font-size: 0.65rem; line-height: 1; padding: 2px 4px; border-radius: 3px; }
.tile.flagged .tile__tint { background: color-mix(in srgb, var(--tint-warn-fg) 10%, transparent); box-shadow: inset 0 0 0 3px var(--tint-warn-fg); }
.tile.flagged::before { content: "⚑"; position: absolute; left: 3px; top: 2px; z-index: 2; font-size: 0.7rem; line-height: 1; color: #fff; background: var(--tint-warn-fg); padding: 2px 4px; border-radius: 3px; }
.detection-overlay.relabeled { outline: 2px dashed var(--tint-warn-fg); outline-offset: -2px; }
.detection-overlay.multi-selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.detection-overlay.multi-selected .tile__tint { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.multi-select-active .detection-overlay { cursor: crosshair; }
.detection-overlay.filtered-out { opacity: 0.12; pointer-events: none; }
.detection-overlay.filter-hidden { display: none; }
.detection-overlay.deleted.filtered-out, .frame-detection-box.deleted.filtered-out { display: none; }
.detection-overlay.deleted { outline: 2px solid var(--tint-reject-fg); outline-offset: -2px; opacity: 0.6; }
.detection-overlay.deleted::after { content: "deleted"; position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; text-align: center; background: var(--tint-reject-fg); color: #fff; font-size: 0.6rem; font-weight: 700; pointer-events: none; }
.relabel-badge, .edit-badge, .drawn-badge, .attr-badge {
    position: absolute; z-index: 2; pointer-events: none;
    font-size: 0.6rem; font-weight: 700; line-height: 1.3; padding: 1px 4px; border-radius: 3px;
    max-width: calc(100% - 6px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-sizing: border-box;
}
.relabel-badge { top: 2px; right: 2px; background: var(--tint-warn-fg); color: #fff; }
.edit-badge, .drawn-badge { left: 2px; bottom: 2px; background: var(--accent); color: #fff; }
/* attributes given (image quality, orientation…): the values are in the tooltip */
.attr-badge { top: 2px; left: 50%; transform: translateX(-50%); background: var(--surface-raised); color: var(--accent); font-size: 0.55rem; }
.relabel-tooltip { display: none; position: absolute; top: 100%; left: 0; z-index: 30; background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 3px 8px; font-size: 0.7rem; white-space: nowrap; box-shadow: var(--shadow-pop); }
.detection-overlay.relabeled:hover .relabel-tooltip { display: block; }
.relabel-tooltip .arrow { margin: 0 4px; color: var(--text-faint); }
.relabel-tooltip .new-label { font-weight: 600; }
.selection-rectangle { position: fixed; border: 1.5px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); pointer-events: none; z-index: 500; }

/* Selection toolbar (floating) */
.selection-toolbar {
    position: fixed; bottom: calc(var(--footer-h) + 14px); left: 50%;
    transform: translateX(-50%) translateY(calc(100% + var(--footer-h) + 30px)); /* parked below the window */
    display: flex; align-items: center; gap: var(--space-2);
    background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop); padding: var(--space-2) var(--space-3); z-index: 600; transition: transform 0.2s ease;
}
.selection-toolbar.active { transform: translateX(-50%) translateY(0); }
.selection-count { font-size: 0.85rem; font-weight: 600; margin-right: var(--space-2); }
.selection-toolbar button { border: 1px solid var(--border-soft); background: var(--surface-raised); border-radius: var(--radius-md); padding: 5px 12px; font-size: 0.8rem; color: var(--text-muted); }
.selection-toolbar button:hover { background: var(--surface-sunken); }
.selection-toolbar button.confirm { color: var(--tint-confirm-fg); }
.selection-toolbar button.reject, .selection-toolbar button.delete { color: var(--tint-reject-fg); }
.selection-toolbar button.relabel { color: var(--tint-warn-fg); }

/* ===== Inspector ===== */
.sidebar { border-left: 1px solid var(--border-soft); background: var(--surface-raised); overflow-y: auto; padding: var(--space-4); }
.sidebar.hidden { display: none; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.sidebar-header h3 { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.sidebar-toggle { border: none; background: transparent; color: var(--text-faint); width: 26px; height: 26px; border-radius: var(--radius-md); }
.sidebar-toggle:hover { background: var(--surface-sunken); color: var(--text); }
.sidebar-preview { background: var(--surface-sunken); border-radius: var(--radius-lg); min-height: 140px; display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: var(--space-3); }
.sidebar-preview .no-selection { color: var(--text-faint); font-size: 0.85em; }
.sidebar-preview img { image-rendering: pixelated; max-width: 100%; }
.sidebar-zoom { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); font-size: 0.8rem; color: var(--text-muted); }
.sidebar-zoom input[type="range"] { flex: 1; accent-color: var(--accent); }
.sidebar-context { position: relative; margin-bottom: var(--space-2); border-radius: var(--radius-lg); overflow: hidden; line-height: 0; background: var(--surface-sunken); }
.sidebar-context canvas { width: 100%; display: block; }
.ctx-box { position: absolute; box-sizing: border-box; border: 2px solid var(--accent); cursor: move; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.ctx-box .bbox-handle { width: 10px; height: 10px; }
.sidebar-preview[hidden] { display: none; }
.sidebar-info { margin-bottom: var(--space-3); }
.sidebar-info-row { display: flex; justify-content: space-between; gap: var(--space-2); padding: 5px 0; border-bottom: 1px solid var(--border-soft); font-size: 0.85em; }
.sidebar-info-row:last-child { border-bottom: none; }
.sidebar-info-row .label { color: var(--text-muted); flex-shrink: 0; }
.sidebar-info-row .value { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
#sidebar-frame, #fi-frame { direction: rtl; } /* a long frame name keeps its end (time, image number) */
#sidebar-status { font-weight: 600; }
.sidebar-actions { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-3); }

/* Attributes besides the class, in both inspectors: a row of value chips per set */
.attr-panel { margin-bottom: var(--space-3); padding: var(--space-2) 0; border-top: 1px solid var(--border-soft); }
.attr-panel__head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-1); }
.attr-panel__head .link-btn { margin-left: auto; }
.attr-panel__target { font-size: 0.75rem; color: var(--accent-fg-on-soft); background: var(--accent-soft); border-radius: var(--radius-pill); padding: 0 6px; }
.attr-panel__set { display: flex; flex-direction: column; gap: 3px; padding: 4px 0; }
.attr-panel__name { font-size: 0.78rem; color: var(--text-muted); }
.attr-panel__values { display: flex; flex-wrap: wrap; gap: 4px; }
.attr-panel__empty { font-size: 0.8rem; color: var(--text-faint); }
.attr-chip { border: 1px solid var(--border-soft); border-radius: var(--radius-pill); background: var(--surface-raised); color: var(--text); font-size: 0.78rem; padding: 2px 9px; }
.attr-chip:hover { border-color: var(--border-strong); background: var(--surface-sunken); }
.attr-chip.is-on { border-color: var(--accent); background: var(--accent); color: #fff; }
.attr-chip.is-some { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-fg-on-soft); }
.attr-chip--add { color: var(--text-faint); border-style: dashed; }
.attr-chip__input { font-size: 0.78rem; width: 9em; border: 1px solid var(--accent); border-radius: var(--radius-pill); padding: 2px 9px; background: var(--surface-raised); color: var(--text); }
.sidebar-actions button { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--border-soft); background: var(--surface-raised); border-radius: var(--radius-md); padding: 8px 12px; font-size: 0.85rem; text-align: left; }
.sidebar-actions button::after { content: attr(data-key); font-size: 0.7rem; color: var(--text-faint); }
.sidebar-actions button:hover { background: var(--surface-sunken); }
.sidebar-actions button:disabled { opacity: 0.45; cursor: not-allowed; }
.sidebar-actions .btn-confirm { color: var(--tint-confirm-fg); border-color: color-mix(in srgb, var(--tint-confirm-fg) 45%, var(--border-soft)); }
.sidebar-actions .btn-reject { color: var(--tint-reject-fg); border-color: color-mix(in srgb, var(--tint-reject-fg) 45%, var(--border-soft)); }
.sidebar-actions .btn-delete { color: var(--tint-reject-fg); }
.sidebar-nav { display: flex; gap: var(--space-2); }
.sidebar-nav button { flex: 1; border: 1px solid var(--border-soft); background: transparent; color: var(--text-muted); border-radius: var(--radius-md); padding: 6px; font-size: 0.8rem; }
.sidebar-nav button:hover { background: var(--surface-sunken); }

/* ===== Dialogs (classes, export) ===== */
dialog.dialog { border: 1px solid var(--border-soft); border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text); padding: 0; width: min(960px, calc(100vw - 40px)); max-height: calc(100vh - 40px); box-shadow: var(--shadow-pop); }
dialog.dialog::backdrop { background: var(--surface-overlay); }
.dialog__head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-soft); }
.dialog__head h2 { font-size: 1rem; }
.dialog__body { padding: var(--space-4); overflow-y: auto; max-height: calc(100vh - 120px); }
.class-naming { border: 1px solid var(--border-soft); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }
.class-naming > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: var(--space-2); user-select: none; }
.class-naming > summary::-webkit-details-marker { display: none; }
.class-naming > summary::before { content: "▸"; color: var(--text-faint); }
.class-naming[open] > summary::before { content: "▾"; }
.class-naming__title { font-weight: 600; }
.class-naming__hint { font-size: 0.8rem; color: var(--text-faint); margin-left: auto; }
.class-naming[open] .class-naming__hint { display: none; }
.class-naming p { color: var(--text-muted); font-size: 0.9em; margin: var(--space-3) 0; }
/* one row per cluster: colour, cluster, name (a GBIF search box), count, taxon */
.class-rows-container { display: flex; flex-direction: column; }
.class-row { display: grid; grid-template-columns: 12px 76px minmax(170px, 1fr) 92px minmax(0, 1.7fr) 28px; align-items: center; gap: var(--space-1) var(--space-3); padding: 5px 0; border-top: 1px solid var(--border-soft); }
.class-row:first-child { border-top: none; }
.class-row label { color: var(--text-muted); font-size: 0.85em; white-space: nowrap; }
.class-name-field { position: relative; min-width: 0; }
.class-name-field input { width: 100%; background: var(--surface-sunken); border: 1px solid transparent; border-radius: var(--radius-md); padding: 6px 10px; }
.class-name-field input:focus { outline: none; border-color: var(--accent); background: var(--surface-raised); }
.class-row .count { text-align: right; }
.class-taxon { display: flex; align-items: center; gap: var(--space-2); min-width: 0; font-size: 0.82em; }
.class-taxon__summary { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; }
.class-taxon__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.class-taxon__text--muted { color: var(--text-faint); }
.class-taxon__lineage { color: var(--text-muted); }
.taxon-badge { font-size: 0.7rem; font-weight: 600; border-radius: var(--radius-pill); padding: 1px 7px; flex-shrink: 0; text-decoration: none; }
a.taxon-badge:hover { text-decoration: underline; }
.link-btn { border: none; background: transparent; color: var(--accent); font-size: 0.8rem; padding: 2px 4px; border-radius: var(--radius-sm); flex-shrink: 0; }
.link-btn:hover { text-decoration: underline; }
.class-taxon .link-btn[data-act="edit"] { color: var(--text-faint); }
.class-row:hover .link-btn[data-act="edit"], .class-taxon .link-btn[data-act="edit"]:focus-visible, .class-taxon .link-btn[aria-expanded="true"] { color: var(--accent); }
.taxon-edit { grid-column: 3 / -1; display: grid; grid-template-columns: 1.6fr 120px 1fr auto; gap: var(--space-2); align-items: center; font-size: 0.85em; padding-bottom: 4px; }
.taxon-edit input, .taxon-edit select { min-width: 0; width: 100%; background: var(--surface-sunken); border: 1px solid transparent; border-radius: var(--radius-md); padding: 5px 9px; }
.taxon-edit input:focus, .taxon-edit select:focus { outline: none; border-color: var(--accent); }
.class-suggest { position: absolute; left: 0; top: calc(100% + 4px); z-index: 30; width: max(100%, 380px); max-height: 340px; overflow-y: auto; list-style: none; margin: 0; padding: 4px; background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-md); box-shadow: var(--shadow-pop); }
.class-suggest__item { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.class-suggest__item:hover { background: var(--surface-sunken); }
.class-suggest__item.active { background: var(--surface-sunken); outline: 2px solid var(--accent); outline-offset: -2px; }
.class-suggest__name.is-italic { font-style: italic; }
.class-suggest__meta { font-size: 0.72rem; color: var(--text-muted); }
.class-suggest__note { font-size: 0.75rem; color: var(--text-faint); padding: 6px 10px; }
@media (max-width: 900px) {
    .class-row { grid-template-columns: 12px minmax(0, 1fr) auto 28px; }
    .class-row label { display: none; }
    .class-taxon, .taxon-edit { grid-column: 2 / -1; }
}
.class-row .delete-class { border: none; background: transparent; color: var(--text-faint); font-size: 1rem; border-radius: var(--radius-sm); padding: 2px 6px; }
.class-row .delete-class:hover { color: var(--tint-reject-fg); background: var(--tint-reject-bg); }
.class-row .count { white-space: nowrap; flex-shrink: 0; }
.color-dot { width: 12px; height: 12px; border-radius: var(--radius-pill); flex-shrink: 0; }
.count { color: var(--text-faint); font-size: 0.8em; }
.add-class-btn { margin-top: var(--space-3); border: 1px dashed var(--border-strong); background: transparent; color: var(--text-muted); border-radius: var(--radius-md); padding: 5px 14px; font-size: 0.85em; }
.add-class-btn:hover { border-color: var(--accent); color: var(--accent); }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--space-2) var(--space-4); }
.meta-field { display: flex; align-items: center; gap: var(--space-2); font-size: 0.85em; color: var(--text-muted); }
.meta-field span { min-width: 150px; }
.meta-field input { flex: 1; min-width: 0; width: 0; background: var(--surface-sunken); border: 1px solid transparent; border-radius: var(--radius-md); padding: 5px 9px; }
.meta-field input:focus { outline: none; border-color: var(--accent); background: var(--surface-raised); }
.meta-actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-3); }
/* Classes dialog ▸ Attributes: one row per set, its values editable in place */
.attr-set-row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-2) 0; border-bottom: 1px solid var(--border-soft); }
.attr-set-row input, #attr-set-new { background: var(--surface-sunken); border: 1px solid transparent; border-radius: var(--radius-md); padding: 4px 8px; color: var(--text); font-size: 0.85em; }
.attr-set-row input:focus, #attr-set-new:focus { outline: none; border-color: var(--accent); background: var(--surface-raised); }
.attr-set-row__name { width: 12em; font-weight: 600; }
.attr-set-row__values { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1; }
.attr-set-row__count { font-size: 0.8rem; color: var(--text-faint); }
.attr-value { display: inline-flex; align-items: center; gap: 2px; }
.attr-value__count { font-size: 0.72rem; color: var(--text-faint); }
.attr-value .icon-btn { width: 22px; height: 22px; font-size: 0.85rem; }
.meta-actions .status { margin: 0; }
.meta-actions .add-class-btn { margin-top: 0; }
.taxon-ok { background: var(--tint-confirm-bg); color: var(--tint-confirm-fg); }
.taxon-todo { background: var(--surface-sunken); color: var(--text-muted); }
.export-section h3 { font-size: 0.9rem; margin: var(--space-3) 0 var(--space-2); }
.export-section textarea { width: 100%; min-height: 200px; background: var(--surface-sunken); border: 1px solid transparent; border-radius: var(--radius-md); font-family: var(--mono); font-size: 0.78rem; padding: var(--space-3); resize: vertical; }
.export-section textarea:focus { outline: none; border-color: var(--accent); }
.export-buttons { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }
.bbox-expansion-control { display: flex; align-items: center; gap: var(--space-2); font-size: 0.85rem; color: var(--text-muted); margin-bottom: var(--space-2); }
.bbox-expansion-control input[type="range"] { width: 160px; accent-color: var(--accent); }
.export-option { display: block; font-size: 0.85em; color: var(--text-muted); margin: var(--space-2) 0; }
.export-delta { font-size: 0.82rem; color: var(--text-muted); margin-bottom: var(--space-2); }
.export-delta:empty { display: none; }

/* ===== Overlay, class picker, modals ===== */
.overlay { display: none; position: fixed; inset: 0; background: var(--surface-overlay); z-index: 700; }
.overlay.active { display: block; }
.relabel-popup { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); padding: var(--space-4); z-index: 800; min-width: 320px; }
.relabel-popup.active { display: block; }
.relabel-popup.relabel-popup--inline { transform: none; min-width: 240px; padding: var(--space-3); }
.relabel-popup h3 { font-size: 0.95rem; margin-bottom: var(--space-3); }
.relabel-popup .buttons { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-2); }
.relabel-popup .buttons button { border: 1px solid var(--border-soft); border-radius: var(--radius-md); padding: 6px 14px; font-size: 0.85rem; background: var(--surface-raised); }
.relabel-popup .buttons .btn-apply { background: var(--text); color: var(--text-invert); border-color: var(--text); }
.relabel-popup .btn-cancel { color: var(--text-muted); }
.picker-search { width: 100%; background: var(--surface-sunken); border: 1px solid transparent; border-radius: var(--radius-md); padding: 7px 10px; margin-bottom: var(--space-2); }
.picker-search:focus { outline: none; border-color: var(--accent); background: var(--surface-raised); }
.picker-suggestions { max-height: 220px; overflow-y: auto; margin-bottom: var(--space-2); }
.picker-suggestions:empty { display: none; }
.picker-heading { font-size: 0.72rem; color: var(--text-faint); padding: 4px 8px; }
#new-bbox-class-list { max-height: 260px; overflow-y: auto; margin: var(--space-2) 0; }
.picker-row { display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left; padding: 7px 10px; border: none; background: transparent; border-radius: var(--radius-md); font-size: 0.85rem; }
.picker-row:hover { background: var(--surface-sunken); }
.picker-row.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.picker-row--taxon { flex-direction: column; align-items: flex-start; gap: 1px; }
.picker-taxon__name { font-style: italic; }
.picker-taxon__meta { font-size: 0.72rem; color: var(--text-muted); }
.picker-row__check { margin-left: auto; font-size: 0.7rem; color: var(--tint-confirm-fg); background: var(--tint-confirm-bg); border-radius: var(--radius-pill); padding: 1px 7px; }
.picker-row__count { margin-left: auto; font-size: 0.7rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.picker-row__count + .picker-row__check { margin-left: 0; }
.picker-empty { color: var(--text-faint); font-size: 0.85em; padding: var(--space-2); }
.recovery-modal { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); padding: var(--space-5); z-index: 900; max-width: 440px; }
.recovery-modal.active { display: block; }
.recovery-modal--wide { max-width: 620px; width: calc(100vw - 32px); }
.recovery-modal h3 { margin-bottom: var(--space-2); }
.recovery-modal p { color: var(--text-muted); font-size: 0.9em; }
.recovery-modal .recovery-info { background: var(--surface-sunken); border-radius: var(--radius-md); padding: var(--space-3); font-size: 0.85em; color: var(--text-muted); margin: var(--space-3) 0; }
.recovery-modal .transfer-pass + .transfer-pass { margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--border-soft); }
.recovery-modal #transfer-zip label { display: block; color: var(--text); }
.recovery-modal #transfer-zip input { display: block; margin-top: var(--space-2); }
.recovery-modal .buttons { display: flex; gap: var(--space-2); justify-content: flex-end; }
.recovery-modal .buttons button { border: 1px solid var(--border-soft); border-radius: var(--radius-md); padding: 7px 16px; font-size: 0.85rem; background: var(--surface-raised); }
.recovery-modal .buttons .btn-restore { background: var(--text); color: var(--text-invert); border-color: var(--text); }
.recovery-modal .btn-discard { color: var(--text-muted); }

/* ===== How-to ===== */
.howto { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(920px, calc(100vw - 32px)); height: min(720px, calc(100vh - 32px)); display: grid; grid-template-columns: 200px 1fr; grid-template-rows: auto 1fr; background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); z-index: 900; overflow: hidden; }
.howto__head { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-soft); }
.howto__head h2 { font-size: 1rem; }
.howto__nav { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3); border-right: 1px solid var(--border-soft); overflow-y: auto; }
.howto__nav button { text-align: left; background: none; border: none; border-radius: var(--radius-sm); padding: 6px 8px; font-size: 0.82rem; color: var(--text-muted); }
.howto__nav button:hover { background: var(--surface-sunken); color: var(--text); }
.howto__body { overflow-y: auto; padding: var(--space-4) var(--space-5); font-size: 0.9rem; color: var(--text-muted); line-height: 1.55; max-width: 72ch; }
.howto__body section + section { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border-soft); }
.howto__body h3 { margin-bottom: var(--space-2); font-size: 0.95rem; color: var(--text); }
.howto__body p { margin: var(--space-2) 0; }
.howto__body ul, .howto__body ol { margin: var(--space-2) 0; padding-left: 20px; }
.howto__body li { margin: 4px 0; }
.howto__body li strong, .howto__body p strong { color: var(--text); }
.howto__body code { background: var(--surface-sunken); padding: 0 4px; border-radius: 3px; font-size: 0.85em; }
@media (max-width: 640px) { .howto { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; } .howto__nav { flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border-soft); } }

/* ===== Chips (class strip, pickers) ===== */
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-soft); border-radius: var(--radius-pill); background: var(--surface-raised); font-size: 0.82rem; padding: 4px 12px; white-space: nowrap; }
.chip:hover { border-color: var(--border-strong); background: var(--surface-sunken); }
.chip__swatch { width: 10px; height: 10px; border-radius: var(--radius-pill); flex-shrink: 0; }
.chip__kb { font-size: 0.65rem; color: var(--text-faint); border: 1px solid var(--border-soft); border-radius: 3px; padding: 0 3px; }
.chip__count { font-size: 0.7rem; color: var(--text-faint); }
.chip--active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-fg-on-soft); }
.chip--active .chip__kb { color: var(--accent-fg-on-soft); border-color: var(--accent); }
.chip--add { color: var(--text-faint); font-style: italic; border-style: dashed; }
.chip__close { display: none; border: none; background: transparent; color: var(--text-faint); padding: 0 0 0 2px; font-size: 0.8rem; }
.chip:hover .chip__close { display: inline; }
.chip__close:hover { color: var(--tint-reject-fg); }
.chip__name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

/* ===== Frame View ===== */
:root { --frame-workspace-h: max(420px, calc(100vh - var(--topbar-h) - 150px)); }
#frame-view { display: none; padding: 0 var(--space-4) var(--space-3); }
body[data-view="frame"] #frame-view { display: block; }
.frame-toolbar { position: sticky; top: var(--topbar-h); z-index: 150; display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; background: var(--surface); border-bottom: 1px solid var(--border-soft); padding: var(--space-2) 0; margin-bottom: var(--space-3); }
.frame-toolbar__left { display: flex; align-items: center; gap: var(--space-3); }
.frame-toolbar__tools { display: flex; gap: 2px; padding: 2px; background: var(--surface-sunken); border-radius: var(--radius-lg); }
.tool-btn { display: inline-flex; align-items: center; gap: 6px; border: none; background: transparent; color: var(--text-muted); font-size: 0.82rem; font-weight: 500; padding: 4px 11px; border-radius: var(--radius-md); }
.tool-btn:hover { color: var(--text); }
.tool-btn.active { background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-segment); }
.tool-btn__kb { font-size: 0.65rem; opacity: 0.7; border: 1px solid currentColor; border-radius: 3px; padding: 0 3px; }
.frame-toolbar__title { display: flex; align-items: center; gap: var(--space-3); margin-left: auto; }
.frame-toolbar__title .frame-display-title { font-weight: 600; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frame-display-nav { display: flex; align-items: center; gap: var(--space-2); font-size: 0.85rem; color: var(--text-muted); }
.frame-toolbar__zoom { display: flex; align-items: center; gap: var(--space-2); font-size: 0.85rem; color: var(--text-muted); }
.frame-toolbar__zoom input[type="range"] { width: 110px; accent-color: var(--accent); }
.frame-view-container { display: flex; gap: var(--space-3); align-items: stretch; }
.frame-list { width: 190px; flex-shrink: 0; background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); overflow-y: auto; max-height: var(--frame-workspace-h); scroll-padding-top: 5.5rem; /* the sticky header */ }
.frame-list-header { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--space-1) var(--space-2); font-size: 0.72rem; font-weight: 600; color: var(--text-faint); padding: var(--space-3) var(--space-3) var(--space-1); position: sticky; top: 0; background: var(--surface-raised); z-index: 1; }
.frame-filter { font-size: 0.72rem; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--surface-raised); color: var(--text-muted); padding: 1px 4px; width: 100%; min-width: 0; }
.frame-filter.is-set, .class-filter.is-set { border-color: var(--accent); color: var(--accent-fg-on-soft); background: var(--accent-soft); }
.frame-list-item { padding: var(--space-2) var(--space-3); cursor: pointer; border-left: 3px solid transparent; }
.frame-list-item:hover { background: var(--surface-sunken); }
.frame-list-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
/* cut on the left: frames of one deployment share their prefix, the time and image number tell them apart */
.frame-list-item .frame-name { font-size: 0.82rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.frame-list-item .detection-count { font-size: 0.72rem; color: var(--text-faint); }
.frame-list-item.active .detection-count { color: var(--accent-fg-on-soft); }
.frame-list-item--done .detection-count { color: var(--tint-confirm-fg); }
.frame-display { flex: 1; background: var(--surface-sunken); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); min-height: var(--frame-workspace-h); position: relative; overflow: hidden; }
.frame-no-image { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-faint); }
#frame-content { display: none; height: 100%; }
#frame-content.visible { display: block; }
.frame-image-container { width: 100%; height: var(--frame-workspace-h); overflow: auto; }
.frame-image-inner { position: relative; display: inline-grid; transform-origin: top left; }
.frame-image-inner > img, .frame-image-inner > #frame-detections { grid-area: 1 / 1; }
.frame-image-inner img { display: block; max-width: none; }
#frame-detections { position: relative; width: 100%; height: 100%; pointer-events: none; }
.frame-inspector { width: 230px; flex-shrink: 0; background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); padding: var(--space-3); align-self: flex-start; }
.frame-inspector__empty { color: var(--text-faint); font-size: 0.85em; padding: var(--space-2) 0; }
.frame-inspector__actions { display: flex; flex-direction: column; gap: 6px; margin-top: var(--space-3); }
.fi-class__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.class-strip { position: sticky; bottom: 0; z-index: 150; display: flex; align-items: center; gap: var(--space-3); background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); padding: var(--space-2) var(--space-3); margin-top: var(--space-3); }
.class-strip__chips { display: flex; gap: var(--space-2); flex-wrap: nowrap; overflow-x: auto; flex: 1; min-width: 0; padding-bottom: 2px; scrollbar-width: thin; }
.class-strip .chip--add { flex-shrink: 0; }
body[data-tool="draw"] #frame-image-inner { cursor: crosshair; }
body[data-tool="pan"] #frame-image-inner { cursor: grab; }
body[data-tool="pan"] #frame-image-inner:active { cursor: grabbing; }
.frame-detection-box { position: absolute; box-sizing: border-box; border: 2px solid transparent; cursor: pointer; pointer-events: auto; container-type: size; }
.frame-detection-box:hover { z-index: 5; }
.frame-detection-box.confirmed { background: var(--overlay-confirm); }
.frame-detection-box.rejected { background: var(--overlay-reject); }
.frame-detection-box.rejected::after { content: "✕"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--tint-reject-fg); font-weight: 700; }
.frame-detection-box.flagged { background: color-mix(in srgb, var(--tint-warn-fg) 22%, transparent); box-shadow: inset 0 0 0 2px var(--tint-warn-fg); }
.frame-detection-box.deleted { border-style: dotted; opacity: 0.5; }
.frame-detection-box.relabeled { box-shadow: inset 0 0 0 1px var(--tint-warn-fg); }
.frame-detection-box.filtered-out:not(.selected) { opacity: 0.15; pointer-events: none; }
.frame-detection-box.filtered-out:not(.selected) .box-label { display: none; }
.frame-detection-box .box-label { position: absolute; bottom: 100%; left: -2px; background: var(--surface-raised); border: 1px solid var(--border-soft); border-radius: 4px 4px 4px 0; font-size: 0.7rem; padding: 0 4px; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
@container (max-width: 44px) { .frame-detection-box:not(:hover):not(.selected) .box-label { display: none; } }
.frame-detection-box:hover .box-label, .frame-detection-box.selected .box-label { z-index: 1; }
.frame-detection-box.selected { box-shadow: 0 0 0 2px var(--accent), 0 0 10px color-mix(in srgb, var(--accent) 50%, transparent); z-index: 7; }
.frame-detection-box-original { position: absolute; border: 1px dashed; opacity: 0.5; pointer-events: none; }
.bbox-handle { position: absolute; width: 8px; height: 8px; background: var(--accent); border: 1.5px solid var(--surface-raised); border-radius: 2px; z-index: 8; }
.bbox-handle--nw { top: -4px; left: -4px; cursor: nwse-resize; }
.bbox-handle--n { top: -4px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.bbox-handle--ne { top: -4px; right: -4px; cursor: nesw-resize; }
.bbox-handle--e { top: 50%; right: -4px; transform: translateY(-50%); cursor: ew-resize; }
.bbox-handle--se { bottom: -4px; right: -4px; cursor: nwse-resize; }
.bbox-handle--s { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.bbox-handle--sw { bottom: -4px; left: -4px; cursor: nesw-resize; }
.bbox-handle--w { top: 50%; left: -4px; transform: translateY(-50%); cursor: ew-resize; }
#frame-draw-preview { position: absolute; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); pointer-events: none; display: none; }
