/* ==========================================================================
   Beaufort Camera-Trap ID Portal
   Art direction: field research instrument. Dark-first (photo review),
   warm charcoal surfaces, moss-green accent, amber for machine suggestions.
   ========================================================================== */

:root {
  /* type scale */
  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.84rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.3125rem);
  --text-xl: clamp(1.5rem, 1.3rem + 0.9vw, 1.875rem);

  /* spacing */
  --space-1: 0.25rem; --space-2: 0.5rem;  --space-3: 0.75rem;
  --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;    --space-10: 2.5rem; --space-12: 3rem;
  --space-16: 4rem;

  --radius: 8px;
  --radius-lg: 14px;
  --font-body: 'Satoshi', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

/* ---- dark (default) ---- */
:root, [data-theme='dark'] {
  --bg: #14150f;
  --surface: #1b1d16;
  --surface-2: #22251c;
  --surface-3: #2b2e24;
  --border: #363a2c;
  --border-strong: #4a4f3c;
  --text: #eceadf;
  --text-muted: #9d9f8e;
  --text-faint: #6d7062;
  --accent: #8fb865;
  --accent-strong: #a6cf7a;
  --accent-dim: #2e3a22;
  --ai: #d9a441;
  --ai-dim: #3a2f18;
  --danger: #d1685c;
  --danger-dim: #3b211d;
  --info: #6ba8c4;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --img-mat: #0c0d09;
}

/* ---- light ---- */
[data-theme='light'] {
  --bg: #f6f5ef;
  --surface: #fffffb;
  --surface-2: #f0efe6;
  --surface-3: #e6e5d9;
  --border: #d8d7c8;
  --border-strong: #bfbfab;
  --text: #21231a;
  --text-muted: #61644f;
  --text-faint: #8b8d78;
  --accent: #4b6b2c;
  --accent-strong: #3a5620;
  --accent-dim: #e3ebd6;
  --ai: #8a5f10;
  --ai-dim: #f4e8cf;
  --danger: #9c3b2f;
  --danger-dim: #f6dfda;
  --info: #2e6a86;
  --shadow: 0 1px 2px rgba(30,32,20,.06), 0 8px 24px rgba(30,32,20,.08);
  --img-mat: #e4e3d7;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-base); }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent-strong); }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

/* ==================== app shell ==================== */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

header.top {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand svg { color: var(--accent); flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font-size: var(--text-sm); font-weight: 700; letter-spacing: 0.01em;
  white-space: nowrap;
}
.brand-sub {
  font-size: var(--text-xs); color: var(--text-faint);
  letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}

nav.tabs { display: flex; gap: var(--space-1); margin-left: var(--space-4); flex-wrap: wrap; }
nav.tabs button {
  background: none; border: 1px solid transparent; color: var(--text-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 500;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius);
  cursor: pointer; transition: color .15s var(--ease), background .15s var(--ease);
  white-space: nowrap;
}
nav.tabs button:hover { color: var(--text); background: var(--surface-2); }
nav.tabs button[aria-current='page'] {
  color: var(--text); background: var(--surface-3); border-color: var(--border);
}

.top-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); }
.whoami { text-align: right; line-height: 1.25; min-width: 0; }
.whoami .nm { font-size: var(--text-sm); font-weight: 600; }
.whoami .og { font-size: var(--text-xs); color: var(--text-faint); }

main { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
main > section { flex: 1 0 auto; }
main > #view-review { flex: 1 1 auto; min-height: 0; }
.wrap { max-width: 1180px; margin: 0 auto; padding: var(--space-8) var(--space-5) var(--space-16); }

/* ==================== controls ==================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  font: inherit; font-size: var(--text-sm); font-weight: 600;
  padding: var(--space-2) var(--space-4); min-height: 38px;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: transform .12s var(--ease), background .15s var(--ease), border-color .15s var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #10130c; font-weight: 700;
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
[data-theme='light'] .btn-primary { color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { min-height: 30px; padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-icon { padding: var(--space-2); min-width: 38px; }
.btn-danger { color: var(--danger); border-color: var(--danger-dim); background: var(--danger-dim); }

.fl { display: block; font-size: var(--text-xs); font-weight: 600;
  color: var(--text-muted); letter-spacing: .04em; text-transform: uppercase;
  margin-bottom: var(--space-1); }

/* Explanatory line under a control, for the cases where the label alone does
   not say why the field behaves the way it does. */
.fl-help { margin-top: var(--space-2); font-size: var(--text-xs);
  line-height: 1.5; color: var(--text-faint); }

input[type='text'], input[type='email'], input[type='password'], input[type='number'],
select, textarea {
  width: 100%; font: inherit; font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color .15s var(--ease);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
textarea { resize: vertical; min-height: 68px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }

.field { margin-bottom: var(--space-4); }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.row > * { min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  box-shadow: var(--shadow);
}

.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-family: var(--font-mono); font-size: var(--text-xs);
  padding: 2px var(--space-2); border-radius: 5px;
  background: var(--surface-3); color: var(--text-muted);
  border: 1px solid var(--border); white-space: nowrap;
}
.chip-accent { background: var(--accent-dim); color: var(--accent-strong); border-color: var(--accent-dim); }
.chip-ai { background: var(--ai-dim); color: var(--ai); border-color: var(--ai-dim); }
.chip-danger { background: var(--danger-dim); color: var(--danger); border-color: var(--danger-dim); }

.banner {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius);
  font-size: var(--text-sm); border: 1px solid var(--border);
  background: var(--surface-2); margin-bottom: var(--space-5);
}
.banner-ai { background: var(--ai-dim); border-color: var(--ai); color: var(--text); }
.banner-err { background: var(--danger-dim); border-color: var(--danger); }
/* Import warnings (camera-clock mismatches) use the same amber as AI output:
   it means "a human needs to look at this", not "the operation failed". */
.banner-warn { background: var(--ai-dim); border-color: var(--ai); color: var(--text); }
.chip-warn {
  background: var(--ai-dim); color: var(--ai); border-color: var(--ai);
  font-variant-numeric: tabular-nums;
}
/* Native date inputs ship a light-mode calendar widget that fights the dark
   theme, so match them to the other inputs and invert the picker glyph. */
input[type="date"] {
  width: 100%;
  color-scheme: dark;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
[data-theme='light'] input[type="date"] { color-scheme: light; }

/* Explains the declared-metadata block in the import form. */
.fieldset-note {
  margin: var(--space-5) 0 var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
  color: var(--muted);
  max-width: 62ch;
  line-height: 1.5;
}

/* ==================== login ==================== */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: var(--space-6);
  background:
    radial-gradient(58% 46% at 50% 8%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 70%),
    radial-gradient(50% 40% at 84% 96%, color-mix(in srgb, var(--ai) 9%, transparent), transparent 72%);
}
.login-card { width: 100%; max-width: 460px; }
.login-card .lede {
  font-size: var(--text-sm); color: var(--text-muted); line-height: 1.6;
  text-align: center; margin: 0 0 var(--space-6);
}
.login-card .brand { justify-content: center; margin-bottom: var(--space-6); }
.demo-creds {
  margin-top: var(--space-5); padding-top: var(--space-4);
  border-top: 1px solid var(--border); font-size: var(--text-xs);
  color: var(--text-muted); line-height: 1.7;
}
.demo-creds code {
  font-family: var(--font-mono); background: var(--surface-2);
  padding: 1px 5px; border-radius: 4px; color: var(--text);
  white-space: nowrap;
}
.demo-creds table { width: 100%; border-collapse: collapse; margin-top: var(--space-2); }
.demo-creds td { padding: 3px 0; vertical-align: top; }
.demo-creds td:first-child { padding-right: var(--space-3); white-space: nowrap; color: var(--text-faint); }

.sugg-note {
  border: 1px solid color-mix(in srgb, var(--ai) 34%, var(--border));
  background: color-mix(in srgb, var(--ai) 9%, transparent);
  border-radius: var(--radius); padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); line-height: 1.55;
}
.sugg-note strong { color: var(--ai); }

/* ==================== batches ==================== */
.page-head {
  display: flex; align-items: flex-end; gap: var(--space-4);
  margin-bottom: var(--space-6); flex-wrap: wrap;
}
.page-head .sub { color: var(--text-muted); font-size: var(--text-sm); margin: var(--space-1) 0 0; }

.batch-grid { display: grid; gap: var(--space-4); }
.batch {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  display: grid; gap: var(--space-4);
  grid-template-columns: minmax(0,1fr) auto; align-items: start;
}
.batch h3 { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.batch-meta {
  display: flex; gap: var(--space-2) var(--space-4); flex-wrap: wrap;
  font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-2);
}
.batch-actions { display: flex; flex-direction: column; gap: var(--space-2); align-items: stretch; }

/* The sharing editor drops out of the batch card itself, so the batch it
   applies to stays visible while an administrator changes the wall. */
.share-panel {
  grid-column: 1 / -1; border-top: 1px solid var(--border);
  padding-top: var(--space-4); margin-top: var(--space-1);
}
.share-grid {
  display: flex; gap: var(--space-5); flex-wrap: wrap; align-items: flex-start;
}
.share-grid .field { flex: 1 1 260px; min-width: 240px; }
.share-checks { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.share-check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--text-sm); cursor: pointer;
}
.share-check input { width: auto; margin: 0; }

/* Inline table controls: full-width inputs would blow the column apart. */
select.sel-sm {
  width: auto; min-width: 104px; max-width: 168px;
  padding: 3px var(--space-2); font-size: var(--text-xs);
}

/* The accounts table carries two dropdowns and two buttons per row, which is
   wider than a narrow window. Scrolling it sideways keeps every control
   reachable instead of clipping the last one off the card. */
.table-scroll { overflow-x: auto; }
.t-accounts th, .t-accounts td {
  white-space: nowrap; padding-left: var(--space-2); padding-right: var(--space-2);
}
.t-accounts select.sel-sm { min-width: 92px; max-width: 150px; }
.tablecard .t-accounts th:first-child, .tablecard .t-accounts td:first-child {
  padding-left: var(--space-4);
}
.tablecard .t-accounts th:last-child, .tablecard .t-accounts td:last-child {
  padding-right: var(--space-4);
}
.t-accounts .btn { padding-left: var(--space-2); padding-right: var(--space-2); }
.t-accounts td:nth-child(2) { font-size: var(--text-xs); }

.progress {
  height: 6px; border-radius: 3px; background: var(--surface-3);
  overflow: hidden; margin-top: var(--space-3);
  display: flex;
}
.progress i { display: block; height: 100%; background: var(--accent); transition: width .4s var(--ease); }
.progress i.ai { background: var(--ai); }

/* ==================== review workspace ==================== */
.review {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 0;
  height: 100%;
}
@media (max-width: 1080px) {
  .review { grid-template-columns: 1fr; height: auto; }
  main { overflow-y: auto; }
}

.stage {
  background: var(--img-mat); display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
}
.stage-bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface); flex-wrap: wrap;
}
.stage-bar .grow { flex: 1; min-width: 120px; }

.canvas-hold {
  flex: 1; min-height: 320px; position: relative;
  display: grid; place-items: center; padding: var(--space-4);
  overflow: hidden;
}
.canvas-hold img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 4px; display: block;
}
.imgbox { position: relative; display: inline-block; max-width: 100%; max-height: 100%; }
.bbox {
  position: absolute; border: 2px solid var(--ai);
  border-radius: 2px; pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,.5);
}
.bbox span {
  position: absolute; top: -20px; left: -2px;
  background: var(--ai); color: #1a1405;
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
  padding: 1px 5px; border-radius: 3px; white-space: nowrap;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.filmstrip {
  display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border); background: var(--surface);
  overflow-x: auto; align-items: center; min-height: 78px;
}
.filmstrip img {
  height: 52px; width: 69px; object-fit: cover; border-radius: 4px;
  border: 2px solid transparent; cursor: pointer; flex: none;
  transition: border-color .15s var(--ease), opacity .15s var(--ease);
  opacity: .65;
}
.filmstrip img:hover { opacity: 1; }
.filmstrip img[aria-current='true'] { border-color: var(--accent); opacity: 1; }
.filmstrip-label {
  font-size: var(--text-xs); color: var(--text-faint); flex: none;
  margin-right: var(--space-2); letter-spacing: .04em; text-transform: uppercase;
}

/* ---- right panel ---- */
.panel {
  background: var(--surface); border-left: 1px solid var(--border);
  overflow-y: auto; padding: var(--space-4) var(--space-5) var(--space-10);
  min-width: 0;
}
@media (max-width: 1080px) { .panel { border-left: none; border-top: 1px solid var(--border); } }

.panel section { padding-bottom: var(--space-5); margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--border); }
.panel section:last-child { border-bottom: none; }
.panel h3 {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin-bottom: var(--space-3); font-weight: 700;
}

.kv { display: grid; grid-template-columns: 96px minmax(0,1fr); gap: var(--space-1) var(--space-3);
  font-size: var(--text-sm); }
.kv dt { color: var(--text-faint); font-size: var(--text-xs); padding-top: 2px; }
.kv dd { margin: 0; font-family: var(--font-mono); font-size: var(--text-xs);
  overflow-wrap: anywhere; }

.sugg { display: flex; flex-direction: column; gap: var(--space-2); }
.sugg button {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; text-align: left; font: inherit; font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--ai-dim); color: var(--text);
  border: 1px solid var(--ai); border-radius: var(--radius); cursor: pointer;
  transition: transform .12s var(--ease);
}
.sugg button:hover { transform: translateX(2px); }
.sugg button .nm { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.sugg button .sc { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ai); }
.sugg .oov { font-size: var(--text-xs); color: var(--text-muted); }

.quickgrid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: var(--space-2); }
.quickgrid button {
  font: inherit; font-size: var(--text-xs); font-weight: 600; line-height: 1.25;
  padding: var(--space-2); min-height: 52px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; text-align: left; position: relative;
  transition: background .15s var(--ease), border-color .15s var(--ease);
  overflow-wrap: anywhere;
}
.quickgrid button:hover { background: var(--surface-3); border-color: var(--accent); }
.quickgrid button b {
  position: absolute; top: 3px; right: 5px;
  font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); font-weight: 700;
}

.picked {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3); border-radius: var(--radius);
  background: var(--accent-dim); border: 1px solid var(--accent);
  font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-3);
  overflow-wrap: anywhere;
}
.picked .x { margin-left: auto; white-space: nowrap; flex: none; }

.seg { display: flex; gap: 0; border: 1px solid var(--border-strong);
  border-radius: var(--radius); overflow: hidden; }
.seg button { white-space: nowrap;
  flex: 1; font: inherit; font-size: var(--text-xs); font-weight: 600;
  padding: var(--space-2) var(--space-3); background: var(--bg); color: var(--text-muted);
  border: none; border-right: 1px solid var(--border); cursor: pointer;
  transition: background .15s var(--ease);
}
.seg button:last-child { border-right: none; }
.seg button:hover { background: var(--surface-2); color: var(--text); }
.seg button[aria-pressed='true'] { background: var(--accent-dim); color: var(--accent-strong); }

.save-row { display: flex; gap: var(--space-2); align-items: center; }
.save-row .btn-primary { flex: 1; }

.keyhint {
  font-family: var(--font-mono); font-size: 10px; padding: 1px 4px;
  border-radius: 3px; background: var(--surface-3); border: 1px solid var(--border);
  color: var(--text-faint);
}

.otherrec {
  font-size: var(--text-xs); padding: var(--space-2) var(--space-3);
  background: var(--surface-2); border-radius: var(--radius);
  border-left: 3px solid var(--info); margin-bottom: var(--space-2);
  overflow-wrap: anywhere;
}

/* ==================== dashboard ==================== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3); margin-bottom: var(--space-6); }
.kpi { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-4); }
.kpi .v { font-family: var(--font-mono); font-size: var(--text-lg); font-weight: 700; }
.kpi .l { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px;
  line-height: 1.35; }

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { text-align: left; padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border); }
th { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); font-weight: 700; }
td.num, th.num { text-align: right; font-family: var(--font-mono); }
tbody tr:hover { background: var(--surface-2); }
.tablecard { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; margin-bottom: var(--space-6); }
.tablecard > h2 { padding: var(--space-4) var(--space-5) var(--space-2); font-size: var(--text-base); }
.tablecard table { margin: 0; }
.tablecard th:first-child, .tablecard td:first-child { padding-left: var(--space-5); }
.tablecard th:last-child, .tablecard td:last-child { padding-right: var(--space-5); }

.bar { height: 6px; border-radius: 3px; background: var(--accent); min-width: 2px; }

.empty {
  text-align: center; padding: var(--space-16) var(--space-5); color: var(--text-muted);
}
.empty svg { color: var(--text-faint); margin-bottom: var(--space-4); }

.toast-hold { position: fixed; bottom: var(--space-5); left: 50%;
  transform: translateX(-50%); z-index: 90;
  display: flex; flex-direction: column; gap: var(--space-2); align-items: center; }
.toast {
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong);
  padding: var(--space-2) var(--space-4); border-radius: 999px;
  font-size: var(--text-sm); box-shadow: var(--shadow);
  animation: rise .25s var(--ease);
  max-width: min(90vw, 520px); text-align: center;
}
.toast.err { border-color: var(--danger); background: var(--danger-dim); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

details.help { margin-top: var(--space-4); }
details.help summary {
  cursor: pointer; font-size: var(--text-sm); font-weight: 600; color: var(--accent-strong);
}
details.help .body { margin-top: var(--space-3); font-size: var(--text-sm);
  color: var(--text-muted); line-height: 1.65; }
details.help code { font-family: var(--font-mono); font-size: var(--text-xs);
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px; color: var(--text); }

ul.tight { margin: 0 0 var(--space-3); padding-left: var(--space-5); }
ul.tight li { margin-bottom: var(--space-1); }

/* ==================== small screens ==================== */
@media (max-width: 760px) {
  header.top { flex-wrap: wrap; row-gap: var(--space-2); padding: var(--space-2) var(--space-4); }
  .brand-sub { display: none; }
  .tabs {
    order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; }
  .top-right { margin-left: auto; gap: var(--space-2); }
  .whoami .og { display: none; }
  .stage-bar { row-gap: var(--space-2); }
  .stage-bar .grow { display: none; }
  .canvas-hold { min-height: 260px; padding: var(--space-2); }
  .panel { border-left: none; border-top: 1px solid var(--border); }
  .wrap { padding: var(--space-6) var(--space-4) var(--space-12); }
  .page-head { align-items: flex-start; }
  .page-head .btn, .page-head select { margin-left: 0 !important; }
  .batch { grid-template-columns: 1fr; }
  .batch-actions { flex-direction: row; flex-wrap: wrap; }
  .quickgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .statrow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* The pool's filter row is four controls with desktop minimum widths; on a
     phone they stack instead of forcing the page sideways. */
  /* main is a flex container, so a screen holding wide tables would otherwise
     size itself to their max-content and push the whole page sideways. */
  #view-flag, #view-admin { width: 100%; min-width: 0; }
  #view-flag .tablecard, #view-flag table { min-width: 0; }
  #view-flag .row .field { flex: 1 1 100% !important; min-width: 0 !important; }
  #fl-reason { flex-wrap: wrap; }
  .tablecard { overflow-x: auto; }
  /* The reviewers screen carries the same problem: the accounts table holds two
     dropdowns and two buttons per row, so it scrolls inside its own card rather
     than stretching the screen it sits on. */
  #view-admin .wrap, #view-admin .tablecard, #view-admin .card { min-width: 0; }
  #view-admin .row .field { flex: 1 1 100% !important; min-width: 0 !important; }
  #view-admin .table-scroll { max-width: 100%; }
}

/* ---- same as previous ---------------------------------------------------- */
/* Sized and placed like a primary action because in a 3-frame burst it is the
   most-used control in the whole portal. */
.same-prev {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  margin-bottom: var(--space-3);
  text-align: left;
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.same-prev:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
}
.same-prev .sp-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.same-prev .sp-name {
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.same-prev .sp-sub {
  font-size: var(--text-xs); color: var(--muted); font-weight: 400;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- taxonomic rank badge ----------------------------------------------- */
.rank-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: middle;
  white-space: nowrap;
}
/* Species is the goal, so it is the only calm colour; anything coarser is
   amber to keep the incompleteness visible while reviewing. */
.rank-species { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.rank-coarse  { background: color-mix(in srgb, var(--ai) 20%, transparent); color: var(--ai); }
.rank-process { background: var(--surface-3); color: var(--muted); }

/* ---------- gallery / contact sheet ---------- */
.gallery-hold {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.gallery-bar {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.gallery {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  /* An explicit row height. A percentage-width image with an aspect-ratio
     contributes nothing to an auto track, so auto rows collapse and the tiles
     overlap each other. */
  grid-auto-rows: 152px;
  gap: var(--space-3);
  align-content: start;
}
.gtile {
  position: relative;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-2);
  user-select: none;
  height: 100%;
}
.gtile img {
  pointer-events: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.92;
  transition: opacity var(--dur-2) var(--ease);
}
.gtile:hover img { opacity: 1; }
.gtile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.gtile[aria-selected='true'] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
.gtile[aria-selected='true'] img { opacity: 1; }
.gtile-check {
  /* Overlays are decoration; the tile itself owns every click. */
  pointer-events: none;
  position: absolute;
  top: 6px;
  left: 6px;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: transparent;
  line-height: 1;
}
.gtile[aria-selected='true'] .gtile-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #10140c;
}
.gtile-foot {
  pointer-events: none;
  position: absolute;
  inset: auto 0 0 0;
  padding: 4px 6px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0));
  color: #fff;
  font-size: 10.5px;
  font-family: var(--font-mono);
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: space-between;
}
.gtile-tags {
  pointer-events: none;
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-end;
}
.gtag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  max-width: calc(100% - 30px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gtag.mine { background: var(--accent); color: #10140c; }
.gtag.coarse { background: var(--ai); color: #1a1206; }
.gtag.flag { background: #c2643c; color: #fff; }
.gtag.blank { background: rgba(255, 255, 255, 0.22); }

/* In the light theme the accent and AI colours darken, so badge text has to
   flip to white or it sits dark-on-dark. */
[data-theme='light'] .gtag.mine,
[data-theme='light'] .gtag.coarse,
[data-theme='light'] .gtile[aria-selected='true'] .gtile-check { color: #fff; }

/* ---- flagged pool ---- */
/* The reviewer's gallery is a flex child that scrolls inside the stage; the one
   on the flag screen sits in a normal card and grows with its content. */
.statrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-3); margin-bottom: var(--space-6); }
.statrow .kpi .l { line-height: 1.4; }
#fl-gallery { flex: none; min-height: 0; overflow: visible; padding: 0;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
/* The tiles take their height from the grid's explicit row, so they must not
   also carry an aspect ratio: that would size them wider than their column and
   each tile would overlap (and clip) its neighbour's labels. */
#fl-gallery { grid-auto-rows: 128px; }
/* Species labels on the flagged tiles are long ("Unknown / unidentifiable"), so
   the badge column is pinned to both edges of the tile and each badge truncates
   inside it instead of running off the photo. */
#fl-gallery .gtile-tags { left: 6px; right: 6px; align-items: flex-end; }
#fl-gallery .gtag { max-width: 100%; }

/* Count of waiting flags, carried on the nav tab so it is visible from any
   screen without opening the pool. */
.tabcount { display: inline-block; margin-left: 6px; padding: 1px 5px;
  border-radius: 999px; font-family: var(--font-mono); font-size: 10px;
  font-weight: 700; background: #c2643c; color: #fff; vertical-align: 1px; }
/* Numeric headers in the pool tables are short phrases; letting them wrap makes
   the header three lines tall and the row hard to read across. */
#fl-org-card th.num, #fl-batch-rows th.num,
.tablecard th.num { white-space: nowrap; }
