:root {
  color-scheme: light;

  /* neutral ramp (cool slate) */
  --gray-0: #ffffff;
  --gray-50: #f7f9fc;
  --gray-100: #eef1f7;
  --gray-200: #e3e8f0;
  --gray-300: #cdd5e1;
  --gray-400: #98a4b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f1a2e;

  /* brand (indigo) */
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  /* semantic — names preserved so the whole app re-skins from here */
  --bg: var(--gray-50);
  --card: var(--gray-0);
  --surface-2: var(--gray-100);
  --ink: var(--gray-900);
  --muted: var(--gray-500);
  --text-subtle: var(--gray-400);
  --line: var(--gray-200);
  --border-strong: var(--gray-300);
  --accent: var(--brand-600);
  --accent-ink: #ffffff;
  --accent-soft: var(--brand-50);
  --danger: #dc2626;
  --success: #16a34a;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lift: 0 12px 28px -8px rgba(15, 23, 42, 0.16), 0 4px 10px -6px rgba(15, 23, 42, 0.10);

  /* scales */
  --radius: 10px;
  --r-sm: 7px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-5: 1.5rem; --sp-6: 2rem; --sp-8: 3rem;
  --fs-xs: 0.72rem; --fs-sm: 0.82rem; --fs-base: 0.94rem; --fs-md: 1rem;
  --fs-lg: 1.15rem; --fs-xl: 1.4rem; --fs-2xl: 1.7rem;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;

  --st-storage-bg: #eef2f6; --st-storage-ink: #46566b;
  --st-use-bg: #dcfce7;     --st-use-ink: #15803d;
  --st-active-bg: #fef3c7;  --st-active-ink: #92400e;
  --st-bad-bg: #fee2e2;     --st-bad-ink: #b91c1c;
  --st-retired-bg: #e5e9ef; --st-retired-ink: #6b7a8d;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1420;
  --card: #172030;
  --surface-2: #1e2838;
  --ink: #e9eef6;
  --muted: #94a3b8;
  --text-subtle: #647089;
  --line: #29344a;
  --border-strong: #3a4761;
  --accent: #818cf8;
  --accent-ink: #0e1420;
  --accent-soft: #242c49;
  --danger: #f87171;
  --success: #4ade80;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-lift: 0 14px 32px -8px rgba(0, 0, 0, 0.6), 0 4px 12px -6px rgba(0, 0, 0, 0.5);

  --st-storage-bg: #253041; --st-storage-ink: #a8b6c8;
  --st-use-bg: #14342373;   --st-use-ink: #4ade80;
  --st-active-bg: #3a2e1173; --st-active-ink: #fbbf24;
  --st-bad-bg: #3f1a1a99;   --st-bad-ink: #f87171;
  --st-retired-bg: #232b38; --st-retired-ink: #8494a8;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: -0.006em;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { letter-spacing: -0.02em; }

body, .card, .topbar, .btn, input, textarea, select {
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.mono { font-family: var(--font-mono); font-size: 0.88em; letter-spacing: 0; }
.small { font-size: var(--fs-sm); color: var(--muted); }
time[title] { cursor: help; }

mark { background: var(--st-active-bg); color: var(--st-active-ink); border-radius: 3px; padding: 0 2px; }

.icon { width: 1.15em; height: 1.15em; display: inline-block; vertical-align: -0.18em; flex: 0 0 auto; }
.btn .icon { margin: 0 -0.05em; }

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

#view.fade { animation: view-in 0.18s ease-out; }
@keyframes view-in { from { opacity: 0.35; transform: translateY(3px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---- skeleton loading ---- */
.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--line) 40%, var(--card) 50%, var(--line) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-row { height: 2.2rem; margin-bottom: 0.8rem; }
.sk-card { height: 120px; }
.sk-block { height: 200px; margin-bottom: 1.2rem; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.4rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: var(--shadow);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; letter-spacing: -0.02em; display: inline-flex; align-items: center; gap: 0.55rem; }
.logo-mark { flex: 0 0 auto; display: block; filter: drop-shadow(0 1px 2px rgba(79, 70, 229, 0.25)); }
.logo-mark .lm-bg { fill: var(--accent); }
.brand-name { white-space: nowrap; }
.topbar-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.topbar-actions[hidden] { display: none; }
#search {
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  min-width: 250px;
  font-size: var(--fs-base);
  background: var(--surface-2);
  color: var(--ink);
}
#search::placeholder { color: var(--text-subtle); }
#search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--card); }

/* ---- buttons & inputs ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.48rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: var(--shadow); }
.btn.primary:hover { background: var(--brand-700); border-color: var(--brand-700); color: var(--accent-ink); }
[data-theme="dark"] .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: var(--card); }
.btn.small { padding: 0.34rem 0.7rem; font-size: var(--fs-sm); }
.btn.tiny { padding: 0.1rem 0.45rem; font-size: var(--fs-sm); box-shadow: none; }
.btn.icon { padding: 0.45rem 0.55rem; line-height: 1; border-radius: var(--r-pill); }

select.btn { appearance: auto; }

/* ---- layout ---- */
main { max-width: 1120px; margin: var(--sp-6) auto; padding: 0 var(--sp-5); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin: 0 0 var(--sp-4);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---- dashboard strip (landing page) ---- */
.dash { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); margin-bottom: var(--sp-5); }
@media (max-width: 760px) { .dash { grid-template-columns: 1fr; } }
.dash-panel { margin-bottom: 0; padding: var(--sp-4); }
.dash-row {
  position: relative;
  display: flex; align-items: baseline; gap: 0.5rem;
  padding: 0.35rem 0 0.35rem 1.15rem;
  color: inherit; text-decoration: none;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
}
.dash-row:hover { background: var(--surface-2); }
.dash-row .marker { left: 0.1rem; top: 0.62rem; width: 9px; height: 9px; }
.dash-check { position: absolute; left: 0; top: 0.42rem; color: var(--text-subtle); }
.dash-check .icon { width: 0.85rem; height: 0.85rem; }
.dash-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-meta { flex: 0 0 auto; color: var(--text-subtle); font-size: var(--fs-xs); white-space: nowrap; }

/* ---- science-first card extras ---- */
.coat-line { margin: 0.15rem 0 0.4rem; }
.coat-chip {
  display: inline-flex; align-items: center;
  padding: 0.12rem 0.55rem;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
}
.log-match {
  margin: 0.2rem 0 0.35rem;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.log-match .icon { width: 0.85rem; height: 0.85rem; }

/* ---- list toolbar ---- */
.summary-strip { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.9rem; }
.summary-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--ink);
}
.summary-chip .count { font-weight: 700; }
.summary-chip:hover { border-color: var(--accent); }
.summary-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
[data-theme="dark"] .summary-chip.on { color: var(--ink); }

.list-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.list-tools .spacer { flex: 1; }
.chip {
  padding: 0.28rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.84rem;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
[data-theme="dark"] .chip.on { color: var(--ink); }
.list-tools a.btn { text-decoration: none; }

/* ---- card grid ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.95rem;
}
.electrode-card {
  display: block;
  text-decoration: none;
  color: inherit;
  margin-bottom: 0;
  border-left-width: 3px;
  border-left-style: solid;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.2s;
}
.electrode-card { padding: var(--sp-4) var(--sp-5); }
.electrode-card:hover { box-shadow: var(--shadow-lift); transform: translateY(-2px); border-color: var(--border-strong); }
.card-cover {
  display: block;
  width: calc(100% + 2 * var(--sp-5));
  margin: calc(-1 * var(--sp-4)) calc(-1 * var(--sp-5)) var(--sp-3);
  height: 120px;
  object-fit: cover;
  border-radius: calc(var(--r-lg) - 1px) calc(var(--r-lg) - 1px) 0 0;
  border-bottom: 1px solid var(--line);
}
.card-head { display: flex; justify-content: space-between; gap: 0.6rem; align-items: baseline; }
.card-head strong { font-size: var(--fs-md); letter-spacing: -0.01em; }
.card-meta { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 0.5rem 0; color: var(--muted); font-size: var(--fs-sm); }
.card-foot { font-size: var(--fs-xs); color: var(--text-subtle); }

/* ---- table view ---- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.etable { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.etable thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
.etable th {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.etable th:hover { color: var(--accent); }
.etable td { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); }
.etable tbody tr { cursor: pointer; border-left: 3px solid transparent; }
.etable tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.etable tbody tr:hover { background: var(--accent-soft); }
.etable tbody tr:last-child td { border-bottom: none; }

.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.empty.small { padding: 0.5rem; text-align: left; }
.empty .empty-icon { display: block; margin-bottom: 0.6rem; color: var(--text-subtle); }
.empty .empty-icon .icon { width: 2.6rem; height: 2.6rem; }
.empty .btn { margin-top: 1rem; }
kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.78em;
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.05rem 0.4rem;
}
.error-box { background: var(--st-bad-bg); border: 1px solid var(--st-bad-ink); color: var(--st-bad-ink); padding: 1rem; border-radius: var(--radius); }

/* ---- badges ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.18rem 0.6rem;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.st-storage { background: var(--st-storage-bg); color: var(--st-storage-ink); }
.st-use     { background: var(--st-use-bg);     color: var(--st-use-ink); }
.st-active  { background: var(--st-active-bg);  color: var(--st-active-ink); }
.st-bad     { background: var(--st-bad-bg);     color: var(--st-bad-ink); }
.st-retired { background: var(--st-retired-bg); color: var(--st-retired-ink); }

/* ---- detail ---- */
.detail-head { margin-bottom: 1rem; }
.back { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.back:hover { color: var(--accent); }
.detail-title { display: flex; align-items: center; gap: 0.8rem; margin: 0.4rem 0; flex-wrap: wrap; }
.detail-title h1 { margin: 0; font-size: 1.55rem; letter-spacing: -0.02em; }
.detail-actions { display: flex; gap: 0.5rem; }

/* Quick status change: the title badge is a button with a popover */
.status-wrap { position: relative; display: inline-block; }
button.badge { border: none; cursor: pointer; font: inherit; font-size: 0.75rem; font-weight: 600; }
button.badge::after { content: " ▾"; opacity: 0.6; }
.status-pop[hidden] { display: none; }
.status-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 10;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  padding: 0.35rem;
  display: grid;
  gap: 0.2rem;
  min-width: 10rem;
}
.status-pop button {
  border: none;
  background: none;
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--ink);
}
.status-pop button:hover { background: var(--accent-soft); }
.status-pop button.current { font-weight: 700; }

/* ---- overview card ---- */
.overview { display: flex; gap: 1.6rem; align-items: flex-start; }
.overview-info { flex: 1; min-width: 0; }
.overview-qr { display: flex; flex-direction: column; gap: 0.5rem; align-items: stretch; flex: 0 0 auto; }
.qr-actions { display: flex; gap: 0.4rem; }
.qr-actions .btn { flex: 1; white-space: nowrap; }
@media (max-width: 720px) {
  .overview { flex-direction: column; }
  .overview-qr { flex-direction: row; align-items: center; }
}

.info-groups { display: flex; flex-wrap: wrap; gap: var(--sp-4) var(--sp-6); }
.info-group h3 {
  margin: 0 0 0.45rem;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1rem; margin: 0; }
.info-list dt { color: var(--muted); font-size: 0.88rem; }
.info-list dd { margin: 0; font-size: 0.92rem; overflow-wrap: anywhere; }
.notes { border-top: 1px solid var(--line); margin: 0.9rem 0 0; padding-top: 0.7rem; white-space: pre-wrap; }

/* ---- QR / sticker dialog ---- */
.qr-box { display: inline-block; background: #ffffff; padding: 8px; border-radius: 8px; border: 1px solid var(--line); align-self: center; }
.qr-box .qr { display: block; width: 110px; height: 110px; image-rendering: pixelated; }
.sticker-dlg-body { display: flex; gap: 1.2rem; align-items: flex-start; margin-bottom: 1rem; }
.sticker-dlg-body .qr-box .qr { width: 150px; height: 150px; }
.sticker-controls { display: grid; gap: 0.6rem; flex: 1; }
.sticker-controls label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.84rem; color: var(--muted); justify-content: space-between; margin: 0; }
.sticker-controls select, .sticker-controls input[type="number"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.85rem;
  width: auto;
  margin: 0;
}
.sticker-controls input[type="number"] { width: 4.5rem; }

/* ---- logbook ---- */
.log-form textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
}
.log-form-row { display: flex; gap: 0.6rem; margin-top: 0.5rem; flex-wrap: wrap; align-items: center; }
.log-form-row input:not([type="file"]) {
  flex: 0 1 180px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: var(--card);
  color: var(--ink);
}
.attach-btn input[type="file"] { display: none; }
.log-form-row .spacer { flex: 1; }

.progress { height: 6px; background: var(--line); border-radius: 999px; margin-top: 0.6rem; overflow: hidden; display: none; }
.progress.active { display: block; }
.progress > div { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width 0.15s; }

/* Logbook heading row with filters */
.log-toolbar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; flex-wrap: wrap; }
.log-toolbar h2 { margin: 0; flex: 1; }
.log-toolbar select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.8rem;
}

.timeline { margin-top: 1.2rem; }
.day-sep {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin: 1rem 0 0.4rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Timeline rail: entries of a day sit along a vertical line with markers */
.tl-items { position: relative; padding-left: 1.6rem; }
.tl-items::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--line);
  border-radius: 2px;
}
.log-entry { position: relative; padding: 0.55rem 0; }
.marker {
  position: absolute;
  left: -1.6rem;
  top: 0.95rem;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--card);
  box-sizing: border-box;
  background: var(--muted);
}
.log-head { display: flex; gap: 0.9rem; font-size: 0.8rem; color: var(--muted); align-items: center; }
.log-head .author { font-weight: 600; }
.log-head .edited { font-style: italic; opacity: 0.8; }
.entry-actions { margin-left: auto; display: flex; gap: 0.25rem; opacity: 0; transition: opacity 0.15s; }
.log-entry:hover .entry-actions, .log-system:hover .entry-actions { opacity: 1; }
.log-entry p { margin: 0.3rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-entry p a { color: var(--accent); }
.entry-edit textarea {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
}
.entry-edit-actions { display: flex; gap: 0.4rem; justify-content: flex-end; margin-top: 0.4rem; }

/* Auto-logged status/location changes: compact system events */
.log-system { padding: 0.35rem 0; }
.log-system .marker { background: var(--card); border: 2px solid var(--muted); width: 10px; height: 10px; left: calc(-1.6rem + 1px); top: 0.62rem; }
.sys-line { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: baseline; color: var(--muted); font-size: 0.82rem; }
.sys-line .sys-text { color: var(--ink); opacity: 0.75; }

/* ---- media ---- */
.gallery { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.6rem; }
.media { margin: 0; width: 140px; }
.media img, .media video {
  width: 140px;
  height: 105px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.12s;
}
.media img:hover { transform: scale(1.04); }
.media figcaption { display: flex; justify-content: space-between; align-items: center; gap: 0.3rem; font-size: 0.7rem; color: var(--muted); }
.media figcaption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-doc { width: auto; max-width: 260px; }
.media-doc .doc {
  display: block;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}
.media-doc .doc:hover { border-color: var(--accent); color: var(--accent); }

/* ---- lightbox ---- */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 17, 0.88);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox[hidden] { display: none; }
#lb-stage {
  position: relative;
  transform-origin: center center;
  touch-action: none;
  line-height: 0;
}
#lb-stage img {
  display: block;
  max-width: min(92vw, 1400px);
  max-height: 82vh;
  border-radius: 6px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
}
.lb-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 1rem;
  color: #d5dbe4; font-size: 0.85rem;
  background: linear-gradient(rgba(8,11,17,0.75), transparent);
}
.lb-btn {
  display: inline-flex; align-items: center; justify-content: center;
  position: absolute;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.lb-btn { z-index: 2; }
.lb-btn:hover { background: rgba(255, 255, 255, 0.25); }
.lb-prev { left: 1rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: 1rem; top: 50%; transform: translateY(-50%); }
.lb-caption {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  color: #d5dbe4;
  font-size: 0.85rem;
  background: rgba(8, 11, 17, 0.6);
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- work area: logbook (main) + next-steps sidebar ---- */
.work-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.2rem; align-items: start; }
.work-grid > .card { margin-bottom: 0; }
.steps-aside { position: sticky; top: 4.75rem; }
@media (max-width: 820px) {
  .work-grid { grid-template-columns: 1fr; }
  .steps-aside { position: static; order: -1; }
}
/* stack meta under each step in the narrow sidebar */
.steps-aside .step-row { flex-wrap: wrap; row-gap: 0.1rem; }
.steps-aside .step-check { flex: 1 1 auto; min-width: 55%; }
.steps-aside .entry-actions { order: 2; }
.steps-aside .step-meta { order: 3; flex-basis: 100%; margin-left: 1.6rem; font-size: 0.7rem; }

/* ---- next steps (to-do) ---- */
.step-count {
  display: inline-block; min-width: 1.2rem; text-align: center;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; font-size: 0.72rem; padding: 0 0.35rem; margin-left: 0.3rem; vertical-align: middle;
}
.step-row { display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0; border-bottom: 1px dashed var(--line); }
.step-row:last-child { border-bottom: none; }
.step-drag { cursor: grab; color: var(--muted); font-size: 1rem; line-height: 1; user-select: none; flex: 0 0 auto; }
.step-drag:active { cursor: grabbing; }
.step-row.dragging { opacity: 0.5; background: var(--accent-soft); border-radius: 6px; }
.step-check { display: flex; align-items: center; gap: 0.55rem; flex: 1; cursor: pointer; min-width: 0; }
.step-check input { width: 16px; height: 16px; flex: 0 0 auto; accent-color: var(--accent); cursor: pointer; }
.step-text { overflow-wrap: anywhere; }
.step-text a { color: var(--accent); }
.step-row.done .step-text { text-decoration: line-through; color: var(--muted); }
.step-meta { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.step-row .entry-actions { opacity: 0; }
.step-row:hover .entry-actions { opacity: 1; }
.step-form { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.step-form input {
  flex: 1; padding: 0.5rem 0.7rem; border: 1px solid var(--line);
  border-radius: var(--radius); font: inherit; background: var(--card); color: var(--ink);
}

/* ---- surface captures (Face A/B) ---- */
.capture-check {
  display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
  padding: 0.4rem 0.75rem; border: 1px solid var(--line); border-radius: 999px;
  font-size: 0.85rem; color: var(--muted); cursor: pointer;
}
.capture-check input { accent-color: var(--accent); }
.capture-check:hover { border-color: var(--accent); color: var(--accent); }

.capture-row { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.7rem; padding: 0.8rem; background: var(--bg); border-radius: var(--radius); }
.capture-row[hidden] { display: none; }
.capture-faces { display: flex; gap: 0.8rem; }
@media (max-width: 520px) { .capture-faces { flex-direction: column; } }

.face-drop {
  position: relative; flex: 1 1 0; min-height: 92px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.7rem; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--card); text-align: center; transition: border-color 0.15s, background 0.15s;
}
.face-drop:hover { border-color: var(--accent); }
.face-drop.has-file { border-style: solid; border-color: var(--accent); }
.face-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.face-tag {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--accent);
}
.face-hint { font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }
.face-preview { max-width: 100%; max-height: 70px; border-radius: 6px; border: 1px solid var(--line); }

.capture-stage { display: flex; align-items: center; gap: 0.5rem; font-size: 0.78rem; color: var(--muted); }
.capture-stage .stage-input { flex: 0 1 260px; }

.capture-pair { display: flex; gap: 0.6rem; margin-top: 0.5rem; }
.cap-thumb { margin: 0; width: 150px; }
.cap-thumb img { width: 150px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; }
.cap-thumb.empty { width: 150px; height: 110px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.78rem; border: 1px dashed var(--line); border-radius: 8px; }
.cap-thumb figcaption { display: flex; justify-content: space-between; align-items: center; gap: 0.3rem; font-size: 0.72rem; color: var(--muted); margin-top: 0.15rem; }

/* filmstrip: stage progression of a sample's captures */
/* ---- surface visualisation CTA (on the electrode page) ---- */
.surface-cta { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; }
.surface-cta-text { flex: 1; min-width: 0; }
.surface-cta-text h2 { margin: 0 0 0.2rem; }
.surface-cta .btn { flex: 0 0 auto; }

/* ---- dedicated surface page: capture selection gallery ---- */
.surface-toolbar { display: flex; align-items: center; gap: 0.7rem; margin-bottom: var(--sp-4); flex-wrap: wrap; }
.surface-toolbar .spacer { flex: 1; }
.cap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-4); }
.cap-select {
  position: relative; text-align: left; cursor: pointer;
  padding: 0.5rem; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--card); color: inherit; font: inherit;
  box-shadow: var(--shadow-sm); transition: border-color 0.15s, box-shadow 0.15s;
}
.cap-select:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.cap-select.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.cap-order {
  position: absolute; top: 0.5rem; right: 0.5rem; z-index: 1;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); font-weight: 700;
}
.cap-order[hidden] { display: none; }
.cap-faces { display: flex; gap: 0.4rem; }
.cap-face { flex: 1; display: flex; flex-direction: column; gap: 0.2rem; align-items: center; }
.cap-face img { width: 100%; height: 84px; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--line); }
.cap-face span { font-size: var(--fs-xs); color: var(--text-subtle); }
.cap-face.empty {
  height: 84px; border: 1px dashed var(--line); border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center; color: var(--text-subtle); font-size: var(--fs-xs);
}
.cap-info { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.cap-info strong { font-size: var(--fs-base); }
.marker-badge {
  display: inline-flex; align-items: center; gap: 0.2rem;
  padding: 0.05rem 0.45rem; border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent); font-size: var(--fs-xs); font-weight: 600;
}
.marker-badge .icon { width: 0.8rem; height: 0.8rem; }

.err-msg { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: help; }

/* ---- compare-page marker summary chips ---- */
.mk-stage { margin-bottom: 0.3rem; }
.mk-stage .small { display: block; margin-bottom: 0.15rem; }
.mk-chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.05rem 0.5rem; margin: 0 0.25rem 0.2rem 0;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  font-size: var(--fs-xs); white-space: nowrap;
}
.mk-chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---- sample report ---- */
.rep-faces { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.rep-face { flex: 1; min-width: 260px; margin: 0; }
.rep-face.empty {
  display: flex; align-items: center; justify-content: center; min-height: 120px;
  border: 1px dashed var(--line); border-radius: var(--r-md); color: var(--text-subtle); font-size: var(--fs-sm);
}
.rep-img-box { position: relative; line-height: 0; }
.rep-img-box img { width: 100%; border-radius: var(--r-md); border: 1px solid var(--line); }
.rep-pin {
  position: absolute; transform: translate(-50%, -50%);
  width: 1.35rem; height: 1.35rem; border-radius: 50%;
  background: var(--pin); color: #fff; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.45);
}
.rep-face figcaption { margin-top: 0.35rem; font-size: var(--fs-sm); color: var(--muted); }
.rep-markers { margin-top: var(--sp-3); }
.rep-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.25rem; height: 1.25rem; border-radius: 50%;
  background: var(--pin); color: #fff; font-size: 0.7rem; font-weight: 700;
}
.rep-log { margin-bottom: 0.7rem; }
.rep-log p { margin: 0.1rem 0 0; white-space: pre-wrap; }
.rep-footer { color: var(--text-subtle); }
@media print {
  .rep-head .btn, .rep-head .back { display: none !important; }
  .rep-capture { break-inside: avoid; }
}

/* face toggle in the compare bar */
.cmp-face-toggle { display: inline-flex; border: 1px solid #2b3545; border-radius: 999px; overflow: hidden; }
.cmp-face-toggle[hidden] { display: none; }
.cmp-face-toggle .btn { border: none; border-radius: 0; background: transparent; color: #d5dbe4; }
.cmp-face-toggle .btn.on { background: var(--accent); color: #fff; }
.cmp-hint { color: #8b98ab; font-size: 0.8rem; }

/* ---- surface-image gallery: stages + compare ---- */
.gallery-head { display: flex; align-items: center; gap: 0.7rem; margin: 1.1rem 0 0.4rem; }
.gallery-head h3 { margin: 0; font-size: 0.82rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stage-group { margin-bottom: 0.6rem; }
.stage-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); margin: 0.5rem 0 0.2rem; }
.stage-chip {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 0 0.4rem; margin-right: 0.3rem; font-size: 0.68rem; font-weight: 600;
}
[data-theme="dark"] .stage-chip { color: var(--ink); }
.stage-input {
  flex: 0 1 190px; padding: 0.5rem 0.7rem; border: 1px solid var(--line);
  border-radius: var(--radius); font: inherit; background: var(--card); color: var(--ink);
}
.compare-picking .media { cursor: pointer; }
.compare-picking .media img { outline: 2px dashed transparent; }
.media.picked img { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- side-by-side compare overlay ---- */
#compare-view {
  position: fixed; inset: 0; z-index: 35; background: #0b0e13;
  display: flex; flex-direction: column;
}
#compare-view[hidden] { display: none; }
.cmp-bar {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 1rem;
  color: #d5dbe4; font-size: 0.85rem; background: #141922; border-bottom: 1px solid #222b38;
}
.cmp-bar .spacer { flex: 1; }
.cmp-hint { color: #8b98ab; font-size: 0.8rem; }
.cmp-sync-label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; white-space: nowrap; }
.cmp-panes { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.cmp-pane {
  position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid #222b38; touch-action: none;
}
.cmp-pane:last-child { border-right: none; }
.cmp-pane .zoom-stage { position: relative; transform-origin: center center; line-height: 0; }
.cmp-pane .zoom-stage img { display: block; max-width: 96%; max-height: 92%; }
.cmp-label {
  position: absolute; bottom: 0.6rem; left: 50%; transform: translateX(-50%);
  color: #d5dbe4; font-size: 0.78rem; background: rgba(8, 11, 17, 0.7);
  padding: 0.2rem 0.7rem; border-radius: 999px; max-width: 90%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 640px) { .cmp-panes { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } }

/* ---- surface markers ---- */
/* Non-transformed overlay sibling of the zoom-stage: pins are drawn crisp at
   native resolution and repositioned in JS, so they never pixelate on zoom. */
.marker-layer {
  position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: hidden;
}
.marker-layer.marking { pointer-events: auto; cursor: crosshair; }
.marker-pin {
  position: absolute; pointer-events: auto; cursor: pointer;
  transform: translate(-50%, -100%);
  padding: 0; border: none; background: none;
  width: 22px; height: 26px; line-height: 0;
}
/* teardrop pin in the marker's type colour */
.marker-pin::before {
  content: ""; display: block; width: 18px; height: 18px; margin: 0 auto;
  background: var(--pin, #6366f1);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.marker-pin .pin-dot {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: #fff;
}
.marker-pin:hover::before { filter: brightness(1.15); }

/* marker toolbar toggles + legend (dark overlay chrome) */
.lb-mark, .cmp-mark, .cmp-blink, .cmp-panel-toggle { color: #d5dbe4 !important; background: rgba(255,255,255,0.08) !important; border-color: rgba(255,255,255,0.15) !important; }
.lb-mark.on, .cmp-mark.on, .cmp-blink.on, .cmp-panel-toggle.on { background: var(--accent) !important; color: #fff !important; border-color: var(--accent) !important; }
.mk-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.1rem; padding: 0 0.25rem; border-radius: var(--r-pill);
  background: rgba(255,255,255,0.2); font-size: 0.7rem; font-weight: 700;
}
.mark-legend { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; font-size: 0.72rem; color: #8b98ab; }
.mark-legend .lg {
  display: inline-flex; align-items: center; gap: 0.25rem; cursor: pointer;
  padding: 0.1rem 0.45rem; border: 1px solid transparent; border-radius: var(--r-pill);
  background: none; color: inherit; font: inherit; font-size: 0.72rem;
}
.mark-legend .lg:hover { border-color: rgba(255,255,255,0.25); }
.mark-legend .lg.off { opacity: 0.35; text-decoration: line-through; }
.mark-legend .lg-eye.off { opacity: 0.45; text-decoration: none; }
.mark-legend .lg i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* marker side-panel in the two-pane viewer */
.cmp-body { flex: 1; display: flex; min-height: 0; }
.cmp-body .cmp-panes { flex: 1; }
#mk-panel {
  width: 280px; flex: 0 0 auto; overflow-y: auto; order: 2;
  background: #141922; border-left: 1px solid #222b38;
  padding: 0.8rem; color: #d5dbe4; font-size: var(--fs-sm);
}
#mk-panel[hidden] { display: none; }
.mk-group h3 { margin: 0.2rem 0 0.4rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: #8b98ab; }
.mk-row {
  display: flex; align-items: center; gap: 0.45rem; width: 100%;
  padding: 0.35rem 0.4rem; margin-bottom: 0.15rem;
  border: none; border-radius: var(--r-sm); background: none;
  color: inherit; font: inherit; font-size: var(--fs-sm); text-align: left; cursor: pointer;
}
.mk-row:hover { background: rgba(255,255,255,0.07); }
.mk-row i { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.mk-row-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mk-row-by { color: #8b98ab; font-size: 0.7rem; flex: 0 0 auto; }

/* blink mode: single pane, two stacked registered images.
   The stage shrink-wraps to the image's NATURAL size while the base img is
   %-capped inside it, so CSS percentages cannot express "the base image box"
   — JS sizes/positions the overlay in px (sizeBlinkOverlay). contain keeps a
   different aspect ratio undistorted; Shift-drag/-scroll alignment composes
   on top via transform. */
.cmp-pane .zoom-stage img.blink-img {
  position: absolute;
  max-width: none; max-height: none; object-fit: contain;
  opacity: 0; border-radius: 6px;
  transform-origin: center center;
}
#compare-view.blinking .cmp-pane:last-of-type { display: none; }
#compare-view.blinking .cmp-panes { grid-template-columns: 1fr; }

/* ---- help dialog ---- */
#dlg-help { max-width: 560px; }
#dlg-help h2 { margin: 0 0 0.6rem; font-size: var(--fs-md); }
#dlg-help h2 + .help-keys, #dlg-help .help-flow + h2 { margin-top: 1rem; }
.help-flow { margin: 0; padding-left: 1.2rem; }
.help-flow li { margin-bottom: 0.45rem; font-size: var(--fs-base); }
.help-keys { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
.help-keys td { padding: 0.25rem 0.6rem 0.25rem 0; color: var(--muted); }
.help-keys td:nth-child(odd) { white-space: nowrap; }
#dlg-help .small { margin: 0.8rem 0 0; }

/* pin pulse when jumped-to from the panel */
@keyframes pin-flash { 0%, 100% { filter: none; } 50% { filter: brightness(1.8) drop-shadow(0 0 6px var(--pin)); } }
.marker-pin.flash { animation: pin-flash 0.5s ease-in-out 3; }

/* ---- 🐱 cat easter eggs (cats.js) ---- */
#cat-layer { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.cat { position: absolute; pointer-events: auto; cursor: pointer; line-height: 0; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.25)); }
.cat svg { width: 100%; height: auto; overflow: visible; }
.cat .cat-eye { animation: cat-blink 4.2s infinite; transform-origin: center; transform-box: fill-box; }
@keyframes cat-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.08); } }

/* walker: crosses the viewport; legs alternate, tail swishes */
.cat-walk { bottom: 0; left: 0; animation: cat-cross linear forwards; }
.cat-walk.leftwards { animation-name: cat-cross-rev; }
.cat-walk.leftwards svg { transform: scaleX(-1); }
.cat-walk.scurry { animation-duration: 1.8s !important; }
@keyframes cat-cross { from { transform: translateX(-140px); } to { transform: translateX(calc(100vw + 40px)); } }
@keyframes cat-cross-rev { from { transform: translateX(calc(100vw + 40px)); } to { transform: translateX(-140px); } }
.cat .cat-leg { transform-origin: center 58px; transform-box: view-box; }
.cat .cat-leg-a { animation: cat-step 0.55s ease-in-out infinite; }
.cat .cat-leg-b { animation: cat-step 0.55s ease-in-out infinite reverse; }
@keyframes cat-step { 0%, 100% { transform: rotate(13deg); } 50% { transform: rotate(-13deg); } }
.cat .cat-tail { transform-origin: 22px 46px; transform-box: view-box; animation: cat-swish 1.6s ease-in-out infinite; }
@keyframes cat-swish { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(-14deg); } }

/* peeker: rises from the bottom edge, looks around, retreats */
.cat-peek { bottom: 0; transform: translateY(105%); animation: cat-peek 7s ease-in-out forwards; }
.cat-peek.scurry { animation: cat-peek-out 0.5s ease-in forwards; }
@keyframes cat-peek {
  0% { transform: translateY(105%); } 18% { transform: translateY(26%) rotate(-2deg); }
  40% { transform: translateY(24%) rotate(2deg); } 62% { transform: translateY(26%) rotate(-1deg); }
  84% { transform: translateY(24%); } 100% { transform: translateY(105%); }
}
@keyframes cat-peek-out { to { transform: translateY(105%); } }

/* reduced-motion: a calm cat, opacity only */
.cat-static { bottom: 0; transform: translateY(24%); opacity: 0; transition: opacity 0.9s; }
#cat-layer .cat-static { opacity: 1; }
#cat-layer .cat-static.bye { opacity: 0; }

.cat-bubble {
  position: absolute; top: -1.6rem; left: 55%;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 0.15rem 0.6rem;
  font-size: 0.78rem; font-weight: 700; line-height: 1.2; white-space: nowrap;
  box-shadow: var(--shadow); animation: cat-bubble-pop 0.25s ease-out;
}
@keyframes cat-bubble-pop { from { transform: scale(0.4); opacity: 0; } }
.cat-heart {
  position: absolute; top: -0.4rem; color: #e5484d; font-size: 1rem; line-height: 1;
  animation: cat-heart-float 1.3s ease-out forwards; pointer-events: none;
}
@keyframes cat-heart-float { to { transform: translateY(-2.6rem) scale(1.4); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .cat, .cat * { animation: none !important; }
  .cat-static { transition: opacity 0.9s !important; }
}
@media print { #cat-layer { display: none !important; } }

/* marker add/edit popover */
#marker-pop {
  position: fixed; z-index: 40; width: min(300px, 90vw);
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lift); padding: 0.8rem;
}
#marker-pop[hidden] { display: none; }
#marker-form { display: grid; gap: 0.5rem; }
#marker-form input, #marker-form textarea {
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--line);
  border-radius: var(--r-sm); font: inherit; background: var(--card); color: var(--ink);
}
#marker-form input[name="title"] { font-weight: 600; }
#marker-form textarea { resize: vertical; }
.marker-pop-actions { display: flex; align-items: center; gap: 0.4rem; }
.marker-pop-actions .spacer { flex: 1; }

/* ---- sample compare bar + table ---- */
.compare-bar {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 25;
  display: flex; align-items: center; gap: 0.7rem; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow-lift);
  padding: 0.5rem 0.9rem; border-radius: 999px; font-size: 0.88rem;
}
.electrode-card.picked, .etable tbody tr.picked { outline: 3px solid var(--accent); outline-offset: -1px; }
.cmp-table td, .cmp-table th { vertical-align: top; }
.cmp-table .cmp-field { color: var(--muted); font-weight: 600; white-space: nowrap; }
.cmp-cover { width: 130px; height: 100px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; }
.cmp-nocover { width: 130px; height: 100px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.78rem; border: 1px dashed var(--line); border-radius: 6px; }

/* ---- dialog ---- */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 1.4rem;
  width: min(560px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  background: var(--card);
  color: var(--ink);
}
dialog::backdrop { background: rgba(10, 14, 20, 0.55); }
dialog h2 { margin: 0 0 1rem; font-size: 1.15rem; }
dialog label { display: block; margin-bottom: 0.7rem; font-size: 0.88rem; color: var(--muted); }
dialog label .req { color: var(--danger); }
dialog input, dialog textarea {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: var(--card);
  color: var(--ink);
}
dialog input:disabled { background: var(--bg); color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 0.9rem; }
legend { font-size: 0.82rem; color: var(--muted); padding: 0 0.3rem; }
.meta-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.4rem; margin-bottom: 0.4rem; align-items: center; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.5rem; }

/* ---- confirm dialog ---- */
.confirm-message { color: var(--muted); margin: 0 0 1.2rem; overflow-wrap: anywhere; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.danger-solid:hover { filter: brightness(1.1); color: #fff; }

/* ---- print: clean electrode report ---- */
@media print {
  .topbar, .detail-actions, .back, .overview-qr .qr-actions, .log-form,
  .entry-actions, .list-tools, .summary-strip, [data-del-media], .toast,
  .log-toolbar .chip, .log-toolbar select, .status-pop,
  .dash, .surface-cta .btn, .step-form, .step-drag { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .print-url { display: block !important; font-family: ui-monospace, monospace; font-size: 9pt; color: #444; }
  .media img, .media video { max-height: 60mm; }
  a { color: #000; text-decoration: none; }
}
.print-url { display: none; }

/* ---- auth (login / setup) ---- */
.auth-wrap { display: flex; justify-content: center; padding: 8vh 1rem 2rem; }
.auth-card { width: min(400px, 94vw); text-align: center; padding: 2rem 1.8rem; }
.auth-brand { margin-bottom: 0.5rem; color: var(--accent); }
.auth-brand .icon { width: 3rem; height: 3rem; }
.auth-card h1 { margin: 0 0 0.3rem; font-size: 1.35rem; letter-spacing: -0.01em; }
.auth-card p { margin-top: 0; }
.auth-card label { display: block; text-align: left; margin: 0.8rem 0; font-size: 0.88rem; color: var(--muted); }
.auth-card input {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: var(--card);
  color: var(--ink);
}
.auth-card .btn { width: 100%; margin-top: 0.6rem; padding: 0.65rem; }
.auth-error { color: var(--danger); min-height: 1.2em; margin: 0.7rem 0 0; }

/* ---- user chip & menu ---- */
.user-wrap { position: relative; }
#user-chip { border-radius: 999px; }
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  padding: 0.35rem;
  min-width: 11rem;
  display: grid;
  gap: 0.15rem;
}
.user-menu[hidden] { display: none; }
.user-menu-head { padding: 0.4rem 0.6rem; font-size: 0.78rem; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 0.2rem; }
.user-menu button {
  border: none;
  background: none;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink);
}
.user-menu button:hover { background: var(--accent-soft); }

/* ---- users admin ---- */
.add-user-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.add-user-row input, .add-user-row select {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--ink);
  flex: 1 1 140px;
}
.add-user-row select { flex: 0 1 110px; }
.user-actions { display: flex; gap: 0.3rem; white-space: nowrap; }
.etable select {
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.85rem;
}

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 40;
  animation: toast-in 0.2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
