/* Theme tokens. Light is the default; dark is opt-in via
   `<html data-theme="dark">` (set by public/theme.js and the inline init
   script in views/index.ejs). Every color used in the app should be
   expressed through one of these variables so both themes stay consistent. */
:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --panel-inset: #eef1f5;
  --line: #d5d8de;
  --ink: #1a1d24;
  --ink-dim: #5a6270;
  --accent: #3562d6;
  --accent-ink: #ffffff;
  --backdrop: rgba(20, 24, 34, 0.35);
  --danger-fg: #b3261e;
  --danger-fg-strong: #7a1810;
  --danger-line: #d6a4a0;
  --danger-tint: color-mix(in srgb, #b3261e 8%, transparent);
  --radius: 10px;
}

[data-theme="dark"] {
  --bg: #14161a;
  --panel: #1c1f26;
  --panel-inset: #0e1013;
  --line: #2a2f3a;
  --ink: #e7e9ee;
  --ink-dim: #9aa2b1;
  --accent: #5b8def;
  --accent-ink: #0b0f18;
  --backdrop: rgba(0, 0, 0, 0.65);
  --danger-fg: #f47272;
  --danger-fg-strong: #ffb0b0;
  --danger-line: #6a2b2b;
  --danger-tint: color-mix(in srgb, #f47272 12%, transparent);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ── Top bar ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.app-logo {
  height: 1.75rem;
  width: 1.75rem;
  margin-right: 0.45rem;
  vertical-align: -0.4rem;
}
.topbar h1 .app-version {
  font-size: 0.65rem;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--ink-dim);
}
/* Reserve enough width for the count line — even when it grows to
   "N cards (M total)" with 5-digit values — so the search input to its right
   stays at a fixed x-position instead of shifting with the count text. */
.count {
  color: var(--ink-dim);
  font-size: 0.85rem;
  min-width: 16rem;
  display: inline-block;
}
.count-total { opacity: 0.75; }

/* Search — placeholder vanishes on focus per the spec. */
.search-form {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-end;
}
/* The search field grows into the space the quickfilters used to occupy. */
.search-wrap {
  position: relative;
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 36rem;
}
.search {
  font: inherit;
  color: var(--ink);
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 1.75rem 0.35rem 0.6rem;
  width: 100%;
}
.search::placeholder { color: var(--ink-dim); }
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search:focus::placeholder { color: transparent; }

.search-clear {
  position: absolute;
  top: 50%;
  right: 0.35rem;
  transform: translateY(-50%);
  width: 1.35rem;
  height: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--ink-dim);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.search-clear:hover { color: var(--ink); background: var(--line); }
.search-clear[hidden] { display: none; }

/* Filter menu — a filter icon beside the search input opens a dropdown
   with one checkbox per quickfilter. */
.filter-menu-wrap {
  position: relative;
  display: flex;
}
.filter-toggle-btn {
  position: relative;
  padding: 0.35rem 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.filter-toggle-btn:hover,
.filter-toggle-btn[aria-expanded="true"] { border-color: var(--accent); }
.filter-toggle-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.filter-toggle-btn svg { width: 1.05rem; height: 1.05rem; display: block; }
.filter-badge {
  position: absolute;
  top: -0.4rem;
  right: -0.4rem;
  min-width: 1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  line-height: 1rem;
  text-align: center;
}
.filter-badge[hidden] { display: none; }

.filter-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 11rem;
  padding: 0.3rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.filter-menu[hidden] { display: none; }
.filter-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.filter-toggle:hover { background: var(--panel-inset); }
.filter-toggle input { margin: 0; cursor: pointer; }

/* Right-side action cluster (theme toggle + import). Held together in a
   flex row and pushed to the far right of the topbar — this replaces the
   `margin-left: auto` that used to sit on `.import-trigger` directly. */
.topbar-actions {
  margin-left: auto;
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-end;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle {
  padding: 0.35rem 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Both icons ship inside the button; CSS picks which one to show based on
   the active theme so JS never has to touch the DOM contents. The icon
   shown at any time represents the *action* the click will perform:
   moon in light mode (click → dark), sun in dark mode (click → light). */
.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* Sort button + dropdown. Visually a sibling of the theme toggle; the dropdown
   is absolutely positioned so it hangs below the button without shifting the
   topbar layout when open. */
.sort-menu-wrap {
  position: relative;
  display: inline-block;
}
.sort-toggle {
  padding: 0.35rem 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sort-toggle:hover { border-color: var(--accent); }
.sort-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sort-toggle svg { width: 1.05rem; height: 1.05rem; display: block; }

.sort-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  min-width: 13rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.sort-menu[hidden] { display: none; }
.sort-menu li { margin: 0; }
.sort-menu button {
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.55rem;
  background: transparent;
  color: var(--ink);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sort-menu button:hover { background: var(--panel-inset); }
.sort-menu button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.sort-check {
  width: 0.9rem;
  display: inline-flex;
  justify-content: center;
  color: var(--accent);
  font-weight: 700;
  visibility: hidden;
}
.sort-menu button[aria-checked="true"] .sort-check { visibility: visible; }

/* "+" scan trigger. Same visual weight as the theme + sort buttons so the
   trio reads as one action cluster. Rendered as an <a> because it navigates
   to a full page (/scan), not a modal. */
.pdf-export {
  padding: 0.35rem 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.pdf-export:hover:not(:disabled) { border-color: var(--accent); }
.pdf-export:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pdf-export:disabled { opacity: 0.4; cursor: not-allowed; }
.pdf-export svg { width: 1.05rem; height: 1.05rem; display: block; }

.scan-trigger {
  padding: 0.35rem 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  text-decoration: none;
}
.scan-trigger:hover { border-color: var(--accent); }
.scan-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.scan-trigger svg { width: 1.05rem; height: 1.05rem; display: block; }

/* Main menu (hamburger, left of the title). Hosts Template, Import, theme,
   Sort by (inline sub-menu) and Scan card. */
.main-menu-wrap {
  position: relative;
  align-self: center;
}
.main-menu-toggle {
  padding: 0.35rem 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.main-menu-toggle:hover { border-color: var(--accent); }
.main-menu-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.main-menu-toggle svg { width: 1.05rem; height: 1.05rem; display: block; }

.main-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 20;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  min-width: 14rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.main-menu[hidden], .main-menu-sub[hidden] { display: none; }
.main-menu li { margin: 0; }
.main-menu-sub {
  margin: 0 0 0.2rem 0.9rem;
  padding: 0;
  list-style: none;
}
.main-menu button,
.main-menu a {
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  padding: 0.4rem 0.55rem;
  background: transparent;
  color: var(--ink);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.main-menu button:hover,
.main-menu a:hover { background: var(--panel-inset); }
.main-menu button:focus-visible,
.main-menu a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.main-menu-parent { justify-content: space-between; }
.main-menu-caret { color: var(--ink-dim); transition: transform 0.12s; }
.main-menu-parent[aria-expanded="true"] .main-menu-caret { transform: rotate(90deg); }
.main-menu-sub button[aria-checked="true"] .sort-check { visibility: visible; }

/* ── Grid ─────────────────────────────────────────────────── */
/* The grid sits inside a centered column so it doesn't hug the left edge on
   wide monitors. 1400px is enough headroom for 5 cards + gaps + padding. */
main {
  padding: 1.25rem;
  max-width: 1400px;
  margin: 0 auto;
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 900px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .grid { grid-template-columns: repeat(2, 1fr); } }

/* IntersectionObserver target for lazy-loading the next batch. */
.scroll-sentinel { height: 1px; margin-top: 1rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.12s ease, transform 0.12s ease;
  cursor: pointer;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.thumb {
  position: relative;
  aspect-ratio: 5 / 7;              /* trading-card proportions */
  background: var(--panel-inset);
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.noimg { color: var(--ink-dim); font-size: 0.75rem; }

/* Feature badges — circular indicators pinned to the top-right of the meta
   block. The meta grid puts them in column 2 spanning both text rows so they
   sit next to the name line, top-aligned. Background/border come from theme
   tokens so they stay legible in both light and dark modes. */
.card-badges {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}
.card-badge {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--panel-inset);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.meta {
  padding: 0.55rem 0.65rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 0.5rem;
}
.name { grid-column: 1; font-weight: 600; font-size: 0.9rem; min-width: 0; }
.sub  { grid-column: 1; color: var(--ink-dim); font-size: 0.78rem; margin-top: 0.15rem; min-width: 0; }
.team { color: var(--ink-dim); font-size: 0.72rem; margin-top: 0.1rem; }

.empty { color: var(--ink-dim); }
.empty code { background: var(--panel); padding: 0.1rem 0.35rem; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .flip-inner { transition: none; }
}

/* ── Details modal ────────────────────────────────────────── */
body.modal-open { overflow: hidden; }

.details {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.details[hidden] { display: none; }

.details-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
}

.details-panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: min(1200px, 100%);
  max-height: calc(100vh - 3rem);
  overflow: auto;
  padding: 1.5rem 1.75rem 1.75rem;
}

.details-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: transparent;
  border: none;
  color: var(--ink-dim);
  font-size: 1.75rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius);
}
.details-close:hover { color: var(--ink); background: var(--line); }

/* Print-to-PDF button, left of the close button. Hidden in template mode (no card). */
.details-print {
  position: absolute;
  top: 0.65rem;
  right: 3.25rem;
  background: transparent;
  border: none;
  color: var(--ink-dim);
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius);
  display: inline-flex;
}
.details-print:hover { color: var(--ink); background: var(--line); }
.details-print:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.details-print[hidden] { display: none; }
.details-print svg { width: 1.2rem; height: 1.2rem; display: block; }

.details-grid {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 1.75rem;
  align-items: start;
}

.col { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.col-title {
  margin: 0.35rem 0 0.15rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.col-title:first-child { margin-top: 0; }

.details-col { gap: 0.75rem; }

.field-row {
  display: grid;
  gap: 0.75rem;
  align-items: end;
}
.field-row.cols-1 { grid-template-columns: 1fr; }
.field-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.image-col { align-items: stretch; }
/* eBay "comps" links: how much a card like this one is worth, per current
   for-sale asking prices and (if the owner is signed into eBay in this
   browser) actually-sold prices. */
.comps-links {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.comps-links[hidden] { display: none; }
.comps-link {
  flex: 1;
  text-align: center;
  font-size: 0.78rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-inset);
  color: var(--ink-dim);
  text-decoration: none;
  white-space: nowrap;
}
.comps-link:hover { border-color: var(--accent); color: var(--ink); }
.comps-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.image-flags {
  margin-top: 0.75rem;
  justify-content: flex-start;
}
/* The card image is a 3D flip card: the front fills the frame at its old size,
   and clicking it turns the card over to the back. A small expand icon in the
   top-right corner zooms the visible side. On real-pointer devices it only
   appears on hover so the card is unobstructed at rest. The stack width is
   capped so the image never balloons when the grid collapses to one column. */
.detail-image-stack {
  position: relative;
  max-width: 320px;
}
/* Class-level specificity has to beat the UA [hidden] rule, hence the explicit
   selector — with both faces missing the whole stack is hidden from JS. */
.detail-image-stack[hidden] { display: none; }

.flip-card {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 7;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 1400px;
  cursor: zoom-in;          /* single-face default: a click zooms */
}
.flip-card.flip-enabled { cursor: pointer; }   /* both faces: a click flips */
.flip-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--radius); }

.flip-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
  transform-style: preserve-3d;
}
.detail-image-stack.flipped .flip-inner { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-back { transform: rotateY(180deg); }
.flip-face img { width: 100%; height: 100%; object-fit: contain; display: block; }

.detail-zoom-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: zoom-in;
  opacity: 0.85;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
.detail-zoom-btn svg { width: 1.05rem; height: 1.05rem; }
.detail-zoom-btn:hover { border-color: var(--accent); opacity: 1; }
.detail-zoom-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; opacity: 1; }

/* On devices with a real pointer, keep the card clear at rest and reveal the
   expand icon on hover / keyboard focus. Touch devices (hover: none) skip this
   block, so the control stays faintly visible there. */
@media (hover: hover) {
  .detail-zoom-btn { opacity: 0; }
  .detail-image-stack:hover .detail-zoom-btn { opacity: 0.9; }
  .detail-zoom-btn:focus-visible { opacity: 1; }
}

.col label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.col label input[type="text"],
.col label select,
.col label textarea {
  font: 0.9rem/1.35 inherit;
  color: var(--ink);
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  text-transform: none;
  letter-spacing: normal;
  width: 100%;
  resize: vertical;
}
/* Condition dropdown with its colour-coded symbol badge (MT, NM, EX, …). */
.select-with-badge { display: flex; align-items: center; gap: 0.5rem; }
.select-with-badge select { flex: 1; min-width: 0; }
.condition-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--condition-colour, #7a7f8a);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
}
.condition-badge[hidden] { display: none; }
.condition-badge[data-abbr="GD"] { color: #3a3000; }   /* readable on yellow */
.col label input[readonly],
.col label textarea[readonly] {
  cursor: not-allowed;
  opacity: 0.55;
}
.col label input:focus,
.col label select:focus,
.col label textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.35rem;
}
.flag {
  flex-direction: row !important;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  color: var(--ink) !important;
}

.details-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.details-delete {
  font: inherit;
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--danger-fg);
  border: 1px solid var(--danger-line);
  border-radius: var(--radius);
  cursor: pointer;
}
.details-delete:hover {
  background: var(--danger-tint);
  border-color: var(--danger-fg);
  color: var(--danger-fg-strong);
}
.details-delete:focus-visible {
  outline: 2px solid var(--danger-fg);
  outline-offset: 2px;
}

/* ── Full-size image lightbox ─────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;               /* above the details modal (z-index: 100) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.lightbox[hidden] { display: none; }
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
}
/* The full-size image is a 3D flip card too, so a click turns it over with the
   same rotation as the preview. Sized to fill the padded viewport as a 5:7
   card: height-limited in landscape, width-limited in portrait. */
.lightbox-flip-card {
  position: relative;
  z-index: 1;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 1600px;
  cursor: default;
  height: min(100%, calc((100vw - 4rem) * 7 / 5));
  aspect-ratio: 5 / 7;
  max-width: 100%;
}
.lightbox-flip-card.flip-enabled { cursor: pointer; }
.lightbox-flip-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: var(--radius);
}
.lightbox-flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.lightbox-flip-card .flip-face { box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); }
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  z-index: 1;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { border-color: var(--accent); }
.lightbox-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 900px) {
  .details-grid { grid-template-columns: 1fr; }
}

/* Template mode: the details modal doubles as the scan-template editor. The
   template has no images and can't be deleted, so hide the pictures and the
   delete footer — the flags in the image column stay, since the template can
   set favorite/rookie/autograph/jersey. */
.details.template-mode .detail-image-stack,
.details.template-mode .comps-links,
.details.template-mode .details-footer,
.details.template-mode .price-field { display: none; }

/* Reset button: only meaningful for the template, so hidden for real cards. */
.template-footer { display: none; margin-top: 0.5rem; }
.details.template-mode .template-footer { display: block; }
.template-reset {
  padding: 0.4rem 0.9rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.template-reset:hover { border-color: var(--accent); }
.template-reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Mobile details modal ────────────────────────────────────
   The desktop layout stacks image-on-top / fields-below at ≤900px, which
   works on tablets. On phones the single large image is capped smaller so the
   top of the form (name/team/etc.) stays visible on load — the back stays in
   its PiP corner. */
@media (max-width: 600px) {
  .details { padding: 0.5rem; }
  .details-panel {
    max-height: calc(100vh - 1rem);
    padding: 1rem 0.9rem 1.25rem;
  }
  .details-grid { gap: 0.9rem; }
  .image-col { gap: 0.4rem; }
  /* Center the single large image instead of letting it sit against the left
     edge; the flags below stay left-aligned. An explicit width is needed here
     because align-self:center drops the flex stretch that otherwise gives the
     stack (and its width:100% flip card) a resolved width. */
  .detail-image-stack { width: 55vw; align-self: center; }
  .comps-links { margin-top: 0.4rem; }
  .image-flags { margin-top: 0.4rem; gap: 0.5rem 0.85rem; }
  .details-col { gap: 0.5rem; }
  .col-title { font-size: 0.75rem; margin: 0.25rem 0 0.1rem; }
  .field-row { gap: 0.5rem; }
  /* Three inputs across at 380px is too cramped; drop to two so the
     labels and values stay readable. */
  .field-row.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── Mobile topbar ───────────────────────────────────────────
   Below 600px the topbar stacks: title row, then a full-width search,
   then the filter chips wrap under it. The import button is hidden —
   picking a JSON export on a phone isn't a real workflow. The theme
   toggle stays visible so the user can still switch themes. */
@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    padding: 0.7rem 1rem;
  }
  .topbar h1 { font-size: 1rem; }
  .count { min-width: 0; flex: 1; text-align: right; }
  /* Second row: search, filter, theme, sort and scan share one line. */
  .topbar-actions {
    order: 2;
    flex-basis: 100%;
    gap: 0.4rem;
  }
  .search-form { gap: 0.4rem; }
  .search-wrap { max-width: none; }
  /* The whole Import/Export submenu is desktop-only. */
  .menu-import { display: none; }
}

/* "fixme": fields in the details view that need attention. */
.col label.fixme { color: var(--danger-fg); }
.col label.fixme input[type="text"],
.col label.fixme textarea {
  border-color: var(--danger-fg);
  background: var(--danger-tint);
}
.card-badge-fixme {
  background: var(--danger-tint);
  border-color: var(--danger-fg);
}

/* ── Sold cards: greyed-out image + "Sold" corner banner ─────────────────── */
.sold-banner { display: none; }
.is-sold > .thumb, .detail-image-stack.is-sold, .detail-image-stack { position: relative; }
.is-sold .sold-banner {
  display: block;
  position: absolute;
  top: 0.5rem;
  left: -0.1rem;
  z-index: 3;
  padding: 0.15rem 0.75rem 0.15rem 0.6rem;
  background: #c0392b;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 0 3px 3px 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.is-sold .thumb img,
.detail-image-stack.is-sold .flip-face img { filter: grayscale(1) opacity(0.55); }

/* ── For-sale price tag on the grid tile (top-left, like the Sold banner) ──
   A green hang-tag: clipped top corners, white inner outline, an eyelet. The
   white outline is the element's own background, the green face is ::before. */
.price-tag {
  --tag-cut: 9px;
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  z-index: 3;
  padding: 1.15rem 0.7rem 0.4rem;
  background: #fff;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  clip-path: polygon(0 var(--tag-cut), var(--tag-cut) 0, calc(100% - var(--tag-cut)) 0,
                     100% var(--tag-cut), 100% 100%, 0 100%);
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
  transform: rotate(-6deg);
  transform-origin: top left;
  pointer-events: none;
  isolation: isolate;
}
.price-tag::before {   /* green face inside the white outline */
  content: "";
  position: absolute;
  inset: 2px;
  z-index: -1;
  background: #1e8449;
  clip-path: polygon(0 calc(var(--tag-cut) - 2px), calc(var(--tag-cut) - 2px) 0,
                     calc(100% - var(--tag-cut) + 2px) 0, 100% calc(var(--tag-cut) - 2px), 100% 100%, 0 100%);
}
.price-tag::after {    /* eyelet */
  content: "";
  position: absolute;
  top: 0.32rem;
  left: 50%;
  width: 0.4rem;
  height: 0.4rem;
  margin-left: -0.2rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 1.5px #999;
}
/* ── "Not for sale" padlock (top-left, like the Sold banner and price tag) ── */
.lock-icon {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  z-index: 3;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: #34495e center / 62% no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='2' fill='%23fff'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E");
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.lock-icon[hidden] { display: none; }
.price-suggestion {
  display: flex; align-items: center; gap: 0.5rem;
  margin: -0.25rem 0 0.5rem; font-size: 0.8rem; color: var(--ink-dim);
}
.price-suggestion[hidden] { display: none; }
.price-suggestion-use {
  padding: 0.1rem 0.6rem; border: 1px solid var(--accent); border-radius: 999px;
  background: transparent; color: var(--ink); font: inherit; cursor: pointer;
}
.price-suggestion-use:hover { background: var(--accent); }
.details.template-mode .price-suggestion { display: none; }
/* Online grading certificate link: a full-width button row under the eBay links. */
.cert-links { margin-top: 0.5rem; }
/* The price field is read-only unless the card is for sale. */
.price-field input[readonly] { opacity: 0.55; cursor: not-allowed; }

/* Guests (no owner token): read-only. The server enforces this; these rules only
   hide what cannot work. See lib/auth.js and public/guest-mode.js. */
.role-guest .owner-only { display: none !important; }
.role-owner .guest-only { display: none !important; }
