@font-face {
  font-family: "Lato";
  src: url("/fonts/Lato-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Lato";
  src: url("/fonts/Lato-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Lato";
  src: url("/fonts/Lato-Black.ttf") format("truetype");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Collectr design tokens (collectr-design/tokens/colors.json) */
  --bg: #000000;
  --surface: #1e5b57;
  --surface-2: rgba(0, 0, 0, 0.28);
  --border: #212121;
  --border-soft: #212121;
  --text: #ffffff;
  --text-muted: #888888;
  --text-faint: rgba(136, 136, 136, 0.75);
  --primary: #7bf1a8;
  --primary-soft: rgba(123, 241, 168, 0.28);
  --danger: #bf000f;
  --danger-soft: rgba(191, 0, 15, 0.14);
  --success: #00c758;
  --warning: #f99c00;
  --radius-sm: 4px;
  --radius-md: 4px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 0 0 1px var(--border), 0 3px 0 var(--border);
  --shadow-modal: rgba(0, 0, 0, 0.05) 0 1px 3px 0;
  --focus-ring: 0 0 0 3px var(--primary-soft);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Lato", Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Visually hidden but announced by screen readers — used to give every
   placeholder-only input a real associated label without changing the
   dense visual layout this admin page relies on. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.screen { min-height: 100vh; }

.pin-form {
  max-width: 340px;
  margin: 18vh auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  text-align: center;
}

.pin-form h1 { font-size: 1.375rem; font-weight: 700; margin: 0 0 4px; }

input, button, select, textarea {
  font-size: 0.875rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:hover, select:hover, textarea:hover { border-color: var(--text-muted); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

textarea { width: 100%; resize: vertical; line-height: 1.5; }

button {
  background: var(--primary);
  border: 1px solid transparent;
  color: var(--bg);
  cursor: pointer;
  font-weight: 700;
}

button:hover { opacity: 0.9; }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
button:disabled { background: var(--text-muted); color: var(--bg); opacity: 1; cursor: not-allowed; transform: none; }

.link-btn {
  background: none;
  border-color: transparent;
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 12px;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.link-btn:hover { background: var(--surface-2); color: var(--text); opacity: 1; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.0625rem; font-weight: 700; margin: 0; }

.page-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 28px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.page-tabs.sub-tabs { padding: 16px 28px 0; }

.page-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  font-weight: 700;
  padding: 8px 4px;
  margin-right: 20px;
}

.page-tab:hover { color: var(--text); background: none; opacity: 1; }
.page-tab.active { color: var(--text); border-bottom-color: var(--primary); }

.header-links { display: flex; align-items: center; gap: 8px; }

.admin-box {
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}

.admin-box h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 0 0 16px;
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.inline-form input, .inline-form select { flex: 1; min-width: 160px; }

#import-textarea {
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.filter-bar {
  display: flex;
  gap: 8px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--surface);
}

.filter-bar input, .filter-bar select { flex: 1; min-width: 160px; background: var(--bg); }

/* Controls row (public Explore) — sort, filter toggle, view, in that order */
.controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap;
}

.sort-control { display: flex; align-items: center; gap: 8px; }
.sort-control select { min-width: 160px; }

.filter-dock-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 700;
}
.filter-dock-toggle:hover { background: var(--surface-2); opacity: 1; }
.filter-dock-chevron { transition: transform 120ms ease; color: var(--text-muted); }
.filter-dock-toggle.open .filter-dock-chevron { transform: rotate(180deg); }

.error {
  color: var(--danger);
  margin: 8px 0 0;
  font-size: 0.85rem;
  font-weight: 500;
}

.status { color: var(--text-muted); margin: 8px 0 0; font-size: 0.85rem; }
.muted { color: var(--text-muted); font-size: 0.85rem; display: block; }

/* --text-muted (#888) only clears WCAG AA against the page's black
   background — against the table's teal --surface it drops to ~2.2:1.
   Table rows need their own, lighter muted tone to stay readable. */
table .muted { color: #c9c9c9; }

main#card-table-container { padding: 20px 28px 40px; overflow-x: auto; }

.empty-state {
  color: var(--text-muted);
  padding: 48px 0;
  text-align: center;
  font-size: 0.9rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0;
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

/* Card identity — "SET POR" / "CARD NO 001/088" — replaces the bare card_no
   text wherever a set has both code and total_cards configured. */
.card-set-code {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  /* Not --text-muted (#888) directly: that only clears WCAG AA against the
     page's black background, and this renders on the table's teal
     --surface — same fix as the "table .muted" rule further down. */
  color: #c9c9c9;
}
.card-number {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th, td {
  text-align: left;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.87rem;
  white-space: nowrap;
}

thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr { transition: background-color 120ms ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable:focus-visible { outline: none; box-shadow: var(--focus-ring); color: var(--text); }

.count-input, .price-input {
  width: 80px;
  text-align: right;
  padding: 8px 8px;
  font-variant-numeric: tabular-nums;
}

.qty-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-stepper .count-input {
  width: 44px;
  text-align: center;
  padding: 8px 4px;
}

.qty-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  flex: 0 0 auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
}

.qty-btn:hover { background: var(--border); opacity: 1; }

.variant-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.variant-actions select, .variant-actions button {
  padding: 8px 8px;
  font-size: 0.82rem;
}

.variant-actions .add-variant-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.variant-actions .add-variant-btn:hover { background: var(--border); opacity: 1; }

.variant-actions .remove-variant-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
}
.variant-actions .remove-variant-btn:hover { background: var(--danger-soft); border-color: var(--danger); opacity: 1; }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--bg);
}

.view-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 700;
  border-radius: 0;
  padding: 8px 16px;
}

.view-btn.active { background: var(--primary); color: var(--bg); }
.view-btn:hover:not(.active) { background: var(--surface-2); color: var(--text); opacity: 1; }

#sort-dir-btn { flex: 0 0 auto; }

/* Small thumbnail used in the list view (public) and admin table */
.thumb-wrap, .admin-thumb-wrap {
  width: 44px;
  height: 60px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.thumb, .admin-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.thumb.missing, .admin-thumb.missing { visibility: hidden; }

.admin-thumb-wrap { display: flex; flex-direction: column; gap: 8px; height: auto; background: none; border: none; }
.admin-thumb-wrap .admin-thumb { height: 60px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }

.image-upload-input {
  width: 100px;
  padding: 4px;
  font-size: 0.75rem;
  border: none;
  background: none;
  color: var(--text-faint);
}

/* Grid view */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 16px;
}

.grid-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.grid-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.grid-img-wrap {
  width: 100%;
  aspect-ratio: 5 / 7;
  background: var(--surface-2);
}

.grid-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.grid-img.missing { visibility: hidden; }

.grid-card-info {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border);
}

.grid-card-name {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: normal;
}

.grid-card-meta {
  color: var(--text-muted);
  font-size: 0.76rem;
  white-space: normal;
}

.grid-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.grid-card-footer span:last-child { color: var(--success); }

/* Set cards (Sets tab) — same shape/treatment as card-grid, but a clickable
   button instead of a static div, and no image upload yet so a placeholder
   glyph stands in for real set art. */
.set-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--surface);
}

/* .grid-card already supplies the border/radius/hover-lift; these just cancel
   the generic <button> background/transform states so it reads as a card,
   not a button. */
.set-card:hover, .set-card:active { background: var(--surface); opacity: 1; transform: translateY(-2px); }

.set-art-placeholder {
  width: 100%;
  aspect-ratio: 5 / 7;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  position: relative;
}

.set-art-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.set-art-img.missing { visibility: hidden; }

/* Set details "Order" column (admin) — up/down arrows for manual set ordering. */
.order-controls { display: flex; gap: 4px; }
.order-controls .order-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
}
.order-controls .order-btn:hover:not(:disabled) { background: var(--border); opacity: 1; }

/* Header cart icon button (public page) */
.cart-header-btn {
  position: relative;
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cart-header-btn:hover { background: var(--surface-2); color: var(--text); opacity: 1; }
.cart-header-btn.active { color: var(--primary); }

.cart-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--primary);
  color: var(--bg);
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}

/* Add-to-cart controls */
.add-cart-control {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.add-cart-qty {
  width: 52px;
  padding: 8px 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.add-cart-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  padding: 8px 10px;
  white-space: nowrap;
}
.add-cart-btn:hover:not(:disabled) { background: var(--border); opacity: 1; }

.in-cart-note {
  color: var(--success);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.grid-card-info .add-cart-control { margin-top: 8px; width: 100%; }
.grid-card-info .add-cart-btn { flex: 1; }

/* Cart view */
.cart-toolbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.cart-total-row { font-weight: 700; }
.cart-total-row td { border-bottom: none; }
.cart-remove-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  font-size: 0.8rem;
  padding: 8px 10px;
}
.cart-remove-btn:hover { background: var(--danger-soft); border-color: var(--danger); opacity: 1; }
.cart-qty-value { min-width: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.cart-checkout { margin-top: 20px; }
.checkout-btn { font-size: 0.95rem; padding: 12px 24px; }
#cart-container { padding: 20px 28px 40px; overflow-x: auto; }

/* Orders tab (admin) */
.orders-list { display: flex; flex-direction: column; gap: 16px; }

.order-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.order-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.order-status-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.order-status-ordered { background: var(--warning); color: var(--bg); }
.order-status-packed { background: var(--primary-soft); color: var(--primary); }
.order-status-shipped { background: var(--success); color: var(--bg); }

.order-items-list {
  margin: 0 0 12px;
  padding-left: 20px;
  font-size: 0.85rem;
}

.order-items-list li { margin-bottom: 4px; }
.order-unmatched { color: var(--warning); font-size: 0.75rem; }

.order-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.order-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.order-action-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  padding: 8px 12px;
}
.order-action-btn:hover:not(:disabled) { background: var(--border); opacity: 1; }

.order-delete-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  font-size: 0.8rem;
  padding: 8px 12px;
}
.order-delete-btn:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); opacity: 1; }

@media (max-width: 700px) {
  header { padding: 16px 16px; }
  .admin-box, .filter-bar { padding: 16px 16px; }
  main#card-table-container { padding: 16px 16px 32px; }
  .filter-bar, .inline-form { flex-direction: column; }
  .filter-bar input, .filter-bar select, .inline-form input, .inline-form select { width: 100%; }
  .view-toggle { width: 100%; }
  .view-btn { flex: 1; }

  /* Sort → Filter → View, stacked full-width in that order on mobile. */
  .controls-row { flex-direction: column; align-items: stretch; padding: 12px 16px; }
  .sort-control { width: 100%; }
  .sort-control select { flex: 1; min-width: 0; }
  .filter-dock-toggle { width: 100%; justify-content: center; }

  /* 16px minimum on real form controls — anything smaller makes iOS Safari
     zoom in on focus, which then doesn't zoom back out on blur. */
  input, select, textarea { font-size: 16px; }

  /* A 10-column nowrap table is unusable on a phone (forces horizontal
     scroll on the page's main content — the one thing this breakpoint
     exists to avoid). Below 700px each <tr> becomes a card instead, with
     the column name rendered from the td's data-label attribute since
     there's no header row to read it from anymore.
     Trade-off: column-header sort is a desktop affordance (click/keyboard
     on <th>) that has nothing to attach to once the header row is hidden,
     so sorting is unavailable in this card view. */
  table { display: block; background: none; border: none; }
  thead { display: none; }
  tbody, tfoot { display: block; }

  tbody tr, tfoot tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 4px 12px;
    margin-bottom: 12px;
  }

  tbody tr:hover { background: var(--surface); } /* no hover state on touch */

  tfoot tr {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  tfoot td { padding: 10px 0; border-bottom: none; }

  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-soft);
    white-space: normal;
  }
  tbody tr:last-child td, td:last-child { border-bottom: none; }

  td::before {
    content: attr(data-label);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    flex: 0 0 auto;
  }

  /* Cells holding more than one control side by side need full width below
     the label, not squeezed next to it. */
  td[data-label="Image"],
  td[data-label="Stock Count"],
  td[data-label="Actions"],
  td[data-label="Add to cart"],
  td[data-label="Qty"],
  td[data-label="Order"] {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .admin-thumb-wrap { flex-direction: row; align-items: center; }
  .admin-thumb-wrap .admin-thumb { width: 44px; flex: 0 0 auto; }

  .count-input, .qty-stepper .count-input { width: 56px; }
  .price-input { width: 96px; }
  .qty-btn, .order-btn { width: 44px; height: 44px; }

  /* A select + two buttons side by side would just recreate the same
     horizontal-overflow problem one level down — let them wrap. */
  .variant-actions { flex-wrap: wrap; }
  .variant-actions select, .variant-actions button { flex: 1 1 auto; }

  /* Tab rows can outgrow narrow viewports (5 admin tabs, e.g.) — scroll
     horizontally instead of wrapping into a ragged second line. */
  .page-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .page-tab { flex: 0 0 auto; }

  .cart-header-btn { min-width: 44px; min-height: 44px; }
  .add-cart-qty { min-height: 44px; }
  .add-cart-btn { min-height: 44px; }
  .add-cart-control { width: 100%; }
  .add-cart-control .add-cart-btn { flex: 1; }

  .checkout-btn { width: 100%; }

  .order-card-header { flex-direction: column; }
  .order-action-btn, .order-delete-btn { min-height: 44px; flex: 1 1 auto; }
}
