/* =========================================================================
   Toy Collector — Apple-style refresh
   16pt base font, SF font stack, rounded surfaces, translucent navigation,
   subtle shadows, larger spacing. Light + dark themes.
   ========================================================================= */

:root {
  --accent: #007aff;          /* iOS blue */
  --accent-strong: #0064d4;
  --gold: #ffb627;
  --green: #34c759;
  --red:   #ff3b30;
  --orange:#ff9500;
  --pink:  #ff2d55;
  --purple:#af52de;

  --bg-shell: #f2f2f7;        /* iOS systemGroupedBackground */
  --bg-content: #f2f2f7;
  --panel: #ffffff;
  --panel-alt: #f7f7fa;
  --bar: rgba(255, 255, 255, 0.78);
  --bar-border: rgba(60, 60, 67, 0.18);

  --ink: #1c1c1e;
  --ink-soft: #3c3c43;
  --ink-muted: #8e8e93;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow:    0 6px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.18);

  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 22px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.dark {
  --bg-shell: #000000;
  --bg-content: #1c1c1e;
  --panel: #1c1c1e;
  --panel-alt: #2c2c2e;
  --bar: rgba(28, 28, 30, 0.82);
  --bar-border: rgba(84, 84, 88, 0.45);
  --ink: #ffffff;
  --ink-soft: #ebebf0;
  --ink-muted: #8e8e93;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow:    0 6px 16px rgba(0,0,0,0.6);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.7);
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }
html, body, #root { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px;            /* requested 16pt baseline */
  background: var(--bg-shell);
  color: var(--ink);
  overflow: hidden;
  letter-spacing: -0.01em;
}

button { font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: var(--ink); }

/* ----------- App shell --------------------------------------------- */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;        /* fallback for older browsers */
  height: 100dvh;       /* dynamic: shrinks when mobile browser chrome appears */
}

/* iOS-style translucent top bar */
.top-bar {
  background: var(--bar);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
          backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--bar-border);
  padding: 10px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
.top-bar .title-block { display: flex; align-items: center; gap: 10px; }
.top-bar .title-link {
  background: transparent;
  border: 0;
  padding: 4px 10px;
  margin-left: -10px;
  border-radius: 8px;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--ink);
  cursor: pointer;
}
.top-bar .title-link:hover { background: var(--panel-alt); }
.search-bar {
  position: relative;
  flex: 1;
  max-width: 520px;
}
.search-bar input {
  width: 100%;
  background-color: var(--panel-alt);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 16px 16px;
  border: 0.5px solid var(--bar-border);
  border-radius: 10px;
  padding: 9px 14px 9px 38px;
  color: var(--ink);
  outline: none;
}
.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.18);
}
.scan-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
.scan-btn:hover { background: var(--accent-strong); }

.sort-toggle {
  display: inline-flex;
  background: var(--panel-alt);
  border: 0.5px solid var(--bar-border);
  border-radius: 10px;
  padding: 3px;
}
.sort-toggle button {
  background: transparent;
  border: 0;
  color: var(--ink-soft);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.sort-toggle button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
body.dark .sort-toggle button.active { background: #3a3a3c; }

.view-toggle { display: inline-flex; gap: 6px; }
.view-toggle button {
  background: var(--panel-alt);
  border: 0.5px solid var(--bar-border);
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.view-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.role-tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  margin-left: 6px;
  border-radius: 8px;
  background: var(--panel-alt);
  color: var(--ink-soft);
  font-weight: 600;
  letter-spacing: 0.2px;
}
.role-tag.admin { background: var(--gold); color: #000; }

.sync-badge {
  font-size: 11px;
  margin-left: 6px;
  padding: 3px 8px;
  background: var(--panel-alt);
  border-radius: 8px;
  color: var(--ink-muted);
}
.sync-badge.saving { background: var(--gold); color: #000; }
.sync-badge.saved  { background: var(--green); color: #fff; }
.sync-badge.error  { background: var(--red); color: #fff; }

/* ----------- Main layout ------------------------------------------- */
.main {
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
  background: var(--bg-shell);
}
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

.sidebar {
  background: var(--panel);
  color: var(--ink);
  overflow-y: auto;
  border-right: 0.5px solid var(--bar-border);
}
.sidebar-inner { padding: 18px; }
.sidebar h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-muted);
  margin: 4px 0 14px;
}
.gauge-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 16px;
  background: var(--panel-alt);
  padding: 12px;
  border-radius: var(--radius);
}
.gauge-pct { font-size: 22px; font-weight: 700; color: var(--ink); }
.gauge-range { font-size: 11px; color: var(--ink-muted); display: flex; justify-content: space-between; width: 200px; }

.totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.total-card {
  background: var(--panel-alt);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
}
.total-card .label {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.total-card .count { font-size: 12px; color: var(--ink-muted); }
.total-card .value { font-size: 22px; font-weight: 700; margin-top: 4px; color: var(--ink); }

.showcase {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.showcase .item { text-align: center; font-size: 11px; }
.showcase .item .kicker { color: var(--ink-muted); display: block; margin-bottom: 6px; }
.showcase img {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

/* ----------- Content area ------------------------------------------ */
.content-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  overflow: hidden;
}
.content {
  background: var(--bg-shell);
  overflow-y: auto;
  padding: 16px;
}
.brand-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.brand-chip {
  background: var(--panel);
  color: var(--ink);
  border: 0.5px solid var(--bar-border);
  padding: 7px 14px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.brand-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ----------- Card grid ---------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  border: 0.5px solid var(--bar-border);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card .cover {
  width: 100%;
  aspect-ratio: 5 / 7;
  background: var(--panel-alt);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.card .cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;          /* show whole image; neutral letterbox if needed */
  display: block;
}
.card .caption {
  padding: 8px 10px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.25;
  min-height: 38px;
}
.card .pill {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.55);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 8px;
  font-weight: 600;
}
.card.wanted { box-shadow: 0 0 0 2px var(--gold), var(--shadow-sm); }
.card.owned  { box-shadow: 0 0 0 2px var(--green), var(--shadow-sm); }
.card.excluded { opacity: 0.35; }

/* ----------- List view ---------------------------------------------- */
.list-view {
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  border: 0.5px solid var(--bar-border);
}
.list-row {
  display: grid;
  grid-template-columns: 56px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--bar-border);
  cursor: pointer;
  background: var(--panel);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--panel-alt); }
.list-row .thumb {
  width: 48px; height: 64px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-alt);
}
.list-row .thumb img { width: 100%; height: 100%; object-fit: contain; background: var(--panel); }
.list-row .meta { min-width: 0; }
.list-row .meta .name { font-weight: 600; font-size: 15px; color: var(--ink); }
.list-row .meta .sub  { font-size: 12px; color: var(--ink-muted); }
.list-row .price { font-weight: 700; color: var(--ink); }

/* ----------- Alphabar (right side) --------------------------------- */
.alpha-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  user-select: none;
  background: transparent;
  border-left: 0.5px solid var(--bar-border);
  min-width: 36px;
  gap: 1px;
}
.alpha-bar button {
  background: transparent;
  border: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1.15;
  min-width: 28px;
  text-align: center;
}
.alpha-bar button.active {
  background: var(--accent);
  color: #fff;
}
.alpha-bar button.empty { opacity: 0.25; cursor: default; }

/* ----------- Tab bar ----------------------------------------------- */
.tab-bar {
  background: var(--bar);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
          backdrop-filter: blur(20px) saturate(180%);
  border-top: 0.5px solid var(--bar-border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.tab-bar button {
  background: transparent;
  border: 0;
  padding: 8px 4px 12px;
  font-size: 11px;
  cursor: pointer;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-weight: 500;
}
.tab-bar button.active { color: var(--accent); }
.tab-bar button .icon { font-size: 22px; line-height: 1; }

/* ----------- "More" tile grid -------------------------------------- */
.more-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin: 8px 0;
}
.more-tile {
  background: var(--panel);
  color: var(--ink);
  border: 0.5px solid var(--bar-border);
  border-radius: var(--radius);
  padding: 22px 14px;
  cursor: pointer;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}
.more-tile .glyph {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
  font-size: 22px;
  background: var(--accent);
  color: #fff;
}
.more-tile.primary .glyph { background: var(--gold); color: #000; }
.more-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

/* ----------- Modal -------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius-lg);
  max-width: 880px;
  width: 100%;
  max-height: 92vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  background: var(--bar);
  -webkit-backdrop-filter: blur(20px);
          backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--bar-border);
  color: var(--ink);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head .close {
  background: var(--panel-alt);
  border: 0;
  color: var(--ink-soft);
  font-size: 20px;
  width: 28px; height: 28px;
  border-radius: 14px;
  cursor: pointer;
}
.modal-body {
  overflow-y: auto;
  padding: 18px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 18px;
}
@media (max-width: 640px) {
  .modal-body { grid-template-columns: 1fr; }
}
.detail-cover {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--panel-alt);
  aspect-ratio: 5 / 7;
  object-fit: contain;
}

/* ----------- Pricing table ----------------------------------------- */
.pricing-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel-alt);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
  margin-bottom: 12px;
  border: 0.5px solid var(--bar-border);
}
.pricing-table th, .pricing-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 0.5px solid var(--bar-border);
}
.pricing-table th {
  font-weight: 600;
  color: var(--ink-muted);
  background: transparent;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.4px;
}

.ext-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.ext-btn {
  border: 0;
  padding: 11px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}
.ext-btn.youtube { background: #cc0000; }
.ext-btn.ebay    { background: var(--accent); }

.toggle-row, .condition-row {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--panel-alt);
  border-radius: var(--radius);
  margin-bottom: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.switch input { display: none; }
.switch .track {
  width: 51px; height: 31px;
  background: #d1d1d6;
  border-radius: 20px;
  position: relative;
  transition: background 0.18s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
  transition: transform 0.18s;
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }

.condition-chip {
  border: 0;
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s;
}
.condition-chip:hover { transform: scale(1.04); }

.notes {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  border-radius: var(--radius);
  border: 0.5px solid var(--bar-border);
  background: var(--panel-alt);
  color: var(--ink);
  resize: vertical;
  margin-bottom: 10px;
}

.txn-log { margin-top: 10px; }
.txn {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 6px;
  color: #fff;
  font-size: 14px;
}
.txn.purchase { background: var(--red); }
.txn.sale     { background: var(--green); }

/* ----------- Pages -------------------------------------------------- */
.page {
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 auto;
  max-width: 920px;
  border: 0.5px solid var(--bar-border);
  box-shadow: var(--shadow-sm);
}
.page h2 {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.sub-tabs {
  display: inline-flex;
  background: var(--panel-alt);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 16px;
}
.sub-tabs button {
  background: transparent;
  border: 0;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink-soft);
}
.sub-tabs button.active {
  background: var(--accent);
  color: #fff;
}

.kv-row {
  display: flex; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--bar-border);
  align-items: center;
}
.kv-row:last-child { border-bottom: 0; }

.stat-line {
  display: flex; justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}
.stat-line .val { font-weight: 700; }

/* ----------- Buttons ----------------------------------------------- */
.btn {
  border: 0;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
  font-size: 14px;
}
.btn:hover { background: var(--accent-strong); }
.btn.secondary {
  background: var(--panel-alt);
  color: var(--ink);
  border: 0.5px solid var(--bar-border);
}
.btn.secondary:hover { background: var(--panel); }
.btn.danger { background: var(--red); }
.btn-row { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ----------- Forms ------------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-soft);
}
input[type=text], input[type=number], input[type=password], select, textarea, input:not([type]) {
  padding: 9px 12px;
  border-radius: 10px;
  border: 0.5px solid var(--bar-border);
  background: var(--panel-alt);
  color: var(--ink);
  font-family: inherit;
}
input[type=text]:focus, input[type=number]:focus, input[type=password]:focus,
select:focus, textarea:focus, input:not([type]):focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.18);
}

/* ----------- Pie / brand overview legend --------------------------- */
.pie-wrap {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: center;
}
@media (max-width: 640px) { .pie-wrap { grid-template-columns: 1fr; } }
.legend-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--bar-border);
}
.legend-swatch {
  width: 14px; height: 14px;
  border-radius: 4px;
  display: inline-block;
  margin-right: 8px;
  vertical-align: middle;
}

/* ----------- Trophy room ------------------------------------------- */
.trophy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.trophy-card {
  background: var(--panel-alt);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: center;
  padding-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.trophy-card .cover { aspect-ratio: 5/7; overflow: hidden; }
.trophy-card .cover img { width: 100%; height: 100%; object-fit: contain; background: var(--panel); display: block; }
.trophy-card .name { font-size: 13px; padding: 8px 8px 2px; font-weight: 600; }
.trophy-card .val  { font-size: 12px; color: var(--ink-muted); padding-bottom: 4px; }

/* ----------- Brand admin row --------------------------------------- */
.brand-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px;
  background: var(--panel-alt);
  border-radius: var(--radius);
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.brand-row input, .brand-row select { padding: 6px 10px; }

.series-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0; }
.series-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 0.5px solid var(--bar-border);
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 13px;
}
.series-tag button {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 1;
}

/* ----------- Catalog admin row ------------------------------------- */
.catalog-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--bar-border);
}
.catalog-row:last-child { border-bottom: 0; }

/* ----------- Auth screen ------------------------------------------- */
.auth-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(0,122,255,0.18), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(175,82,222,0.18), transparent 50%),
    var(--bg-shell);
  padding: 16px;
}
.auth-card {
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  border: 0.5px solid var(--bar-border);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.auth-logo {
  width: 48px; height: 48px;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 26px;
}
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-soft);
}
.auth-err {
  background: var(--red);
  color: #fff;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}

/* ----------- Scanner modal ----------------------------------------- */
.scan-area {
  width: 100%;
  max-width: 400px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 auto;
}
#qr-reader { width: 100%; }
#qr-reader video { width: 100% !important; }

/* ----------- Lightbox (click figure image to enlarge) ----------------- */
.lightbox-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: zoom-out;
}
.lightbox-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  background: var(--panel-alt);
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 20px; right: 20px;
  width: 40px; height: 40px;
  border-radius: 20px;
  background: rgba(255,255,255,0.18);
  border: 0;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
}
.lightbox-close:hover { background: rgba(255,255,255,0.32); }

/* ----------- Clear (x) button on search inputs ----------------------- */
.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 11px;
  background: rgba(120, 120, 128, 0.32);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}
.clear-btn:hover { background: rgba(120, 120, 128, 0.55); }
.search-bar input { padding-right: 36px; }

/* =========================================================================
   Mobile — 640px and below
   ========================================================================= */
@media (max-width: 640px) {

  /* --- Top bar: title+controls row 1, search full-width row 2 --- */
  .top-bar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    padding: 8px 12px;
    gap: 8px;
  }
  /* search-bar is the 2nd child — push it to row 2, full width */
  .top-bar > *:nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: 100%;
  }
  /* controls div is the 3rd child — keep it on row 1 col 2 */
  .top-bar > *:nth-child(3) {
    grid-row: 1;
    grid-column: 2;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  /* hide role tag and sync badge — too much noise on small screens */
  .role-tag, .sync-badge { display: none; }

  /* sort toggle: smaller text so buttons don't overflow */
  .sort-toggle button { padding: 6px 8px; font-size: 12px; }

  /* --- Hide alpha bar — fingers can't hit 11px letters --- */
  .alpha-bar { display: none; }
  .content-wrap { grid-template-columns: 1fr; }

  /* --- Cards: slightly smaller min so 2 fit comfortably --- */
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  /* --- List rows: drop the last price column to avoid overflow --- */
  .list-row { grid-template-columns: 48px 1fr auto; padding: 10px; }

  /* --- Forms: single column --- */
  .form-grid { grid-template-columns: 1fr; }

  /* --- Pie wrap already has a 640px query, just in case --- */
  .pie-wrap { grid-template-columns: 1fr; }

  /* --- Content padding --- */
  .content { padding: 10px; }
  .page { padding: 12px; }
  .sidebar-inner { padding: 12px; }

  /* --- Modal: slide up as a bottom sheet --- */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: 94vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  /* --- Tab bar: fixed to bottom so viewport height bugs can't hide it --- */
  .tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .tab-bar button {
    padding: 10px 4px 12px;
  }

  /* --- Content needs bottom padding so nothing hides behind fixed tab bar --- */
  .content {
    padding-bottom: 75px;
  }

  /* --- Ensure all interactive elements meet 44px touch target --- */
  .btn, .brand-chip, .condition-chip, .scan-btn { min-height: 44px; }
  input[type=text], input[type=number], input[type=password],
  select, textarea, input:not([type]) { min-height: 44px; }
}
