/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-pill: 999px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;

  --t-xs: 11px;
  --t-sm: 13px;
  --t-base: 15px;
  --t-md: 17px;
  --t-lg: 20px;
  --t-xl: 28px;
  --t-2xl: 36px;

  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 240ms;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --bg: #f5f4fa;
  --surface: #ffffff;
  --surface-2: #f0eef7;
  --border: rgba(20, 18, 40, 0.08);
  --border-strong: rgba(20, 18, 40, 0.14);
  --text: #14122a;
  --text-muted: #6a6783;
  --text-subtle: #95929f;

  --accent: #6e63f5;
  --accent-2: #a259e5;
  --accent-grad: linear-gradient(135deg, #6e63f5 0%, #a259e5 100%);
  --accent-soft: rgba(110, 99, 245, 0.10);

  --silver: #98a2b3;
  --silver-soft: rgba(152, 162, 179, 0.16);
  --gold: #d4a017;
  --gold-soft: rgba(212, 160, 23, 0.16);
  --green: #10b981;
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);

  --shadow-sm: 0 1px 2px rgba(20, 18, 40, .04), 0 1px 3px rgba(20, 18, 40, .06);
  --shadow-md: 0 4px 16px rgba(20, 18, 40, .08);
  --shadow-lg: 0 12px 40px rgba(20, 18, 40, .18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b12;
    --surface: #16151f;
    --surface-2: #1d1c28;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);
    --text: #f3f1ff;
    --text-muted: #9b97b3;
    --text-subtle: #6c697f;
    --accent: #8a7eff;
    --accent-2: #b870ff;
    --accent-grad: linear-gradient(135deg, #8a7eff 0%, #b870ff 100%);
    --accent-soft: rgba(138, 126, 255, 0.16);
    --silver: #c0c8d4;
    --silver-soft: rgba(192, 200, 212, 0.10);
    --gold: #f0c14b;
    --gold-soft: rgba(240, 193, 75, 0.12);
    --warn-soft: rgba(245, 158, 11, 0.16);
    --danger-soft: rgba(239, 68, 68, 0.18);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  }
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f4fa;
  --surface: #ffffff;
  --surface-2: #f0eef7;
  --border: rgba(20, 18, 40, 0.08);
  --border-strong: rgba(20, 18, 40, 0.14);
  --text: #14122a;
  --text-muted: #6a6783;
  --text-subtle: #95929f;
  --accent: #6e63f5;
  --accent-2: #a259e5;
  --accent-grad: linear-gradient(135deg, #6e63f5 0%, #a259e5 100%);
  --accent-soft: rgba(110, 99, 245, 0.10);
  --silver: #98a2b3;
  --silver-soft: rgba(152, 162, 179, 0.16);
  --gold: #d4a017;
  --gold-soft: rgba(212, 160, 23, 0.16);
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b12;
  --surface: #16151f;
  --surface-2: #1d1c28;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f3f1ff;
  --text-muted: #9b97b3;
  --text-subtle: #6c697f;
  --accent: #8a7eff;
  --accent-2: #b870ff;
  --accent-grad: linear-gradient(135deg, #8a7eff 0%, #b870ff 100%);
  --accent-soft: rgba(138, 126, 255, 0.16);
  --silver: #c0c8d4;
  --silver-soft: rgba(192, 200, 212, 0.10);
  --gold: #f0c14b;
  --gold-soft: rgba(240, 193, 75, 0.12);
  --warn-soft: rgba(245, 158, 11, 0.16);
  --danger-soft: rgba(239, 68, 68, 0.18);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The hidden attribute must always win, even over display:flex rules —
   otherwise el.hidden = true silently fails on flex containers. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: var(--t-base);
  line-height: 1.45;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + 88px);
}

button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

a { color: var(--accent); }

/* ============================================================
   App bar
   ============================================================ */
.appbar {
  position: sticky; top: 0; z-index: 30;
  padding: var(--s-3) var(--s-4);
  padding-top: calc(var(--s-3) + var(--safe-top));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur) var(--ease);
}
.appbar.scrolled { border-bottom-color: var(--border); }

.brand { display: flex; align-items: center; gap: var(--s-2); font-weight: 700; font-size: var(--t-md); letter-spacing: -0.01em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent-grad);
  display: grid; place-items: center;
  color: white; font-size: 12px; font-weight: 800;
  letter-spacing: -0.02em;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent);
}

.appbar-actions { display: flex; gap: var(--s-2); }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: grid; place-items: center;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.icon-btn:active { transform: scale(0.94); background: var(--surface-2); }

/* ============================================================
   Search bar (slides down from app bar)
   ============================================================ */
.search-bar {
  position: sticky;
  top: calc(58px + var(--safe-top));
  z-index: 29;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  padding: 0 var(--s-4);
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--dur) var(--ease), padding-top var(--dur) var(--ease), padding-bottom var(--dur) var(--ease);
  border-bottom: 1px solid transparent;
}
.search-bar.open {
  max-height: 64px;
  padding-top: var(--s-2);
  padding-bottom: var(--s-2);
  border-bottom-color: var(--border);
}
.search-inner {
  display: flex; align-items: center; gap: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  color: var(--text-muted);
}
.search-inner input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font-size: var(--t-base);
  padding: 4px 0;
}
.search-clear {
  background: transparent; border: 0;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  display: none;
}
.search-bar.has-text .search-clear { display: inline; }

/* ============================================================
   Hero
   ============================================================ */
.container { padding: 0 var(--s-4); }

.hero {
  margin-top: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-radius: var(--r-lg);
  background: var(--accent-grad);
  color: #fff;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(60% 60% at 100% 0%, rgba(255,255,255,.18), transparent 60%),
    radial-gradient(50% 50% at 0% 100%, rgba(0,0,0,.18), transparent 60%);
  pointer-events: none;
}
.hero > * { position: relative; }
.hero-label { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.85; }
.hero-value { font-size: var(--t-2xl); font-weight: 800; letter-spacing: -0.02em; margin-top: 2px; }

.hero-split {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid rgba(255,255,255,.18);
}
.hero-split .label { font-size: var(--t-xs); opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; }
.hero-split .value { font-size: var(--t-md); font-weight: 700; margin-top: 2px; }
.hero-split .sub { font-size: var(--t-xs); opacity: 0.75; margin-top: 2px; }

.hero-gain {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin-top: var(--s-4);
  padding-top: var(--s-3);
  border-top: 1px solid rgba(255,255,255,.18);
}
.hero-gain .label { font-size: var(--t-xs); opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; }
.hero-gain .delta { font-size: var(--t-sm); font-weight: 700; color: #7df3b1; }
.hero-gain.down .delta { color: #ffb3ab; }
.hero-gain .basis { font-size: var(--t-xs); opacity: 0.75; margin-left: auto; }

/* ============================================================
   Spot prices strip
   ============================================================ */
.spot-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-2);
  margin-top: var(--s-3);
}
.spot-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: var(--t-sm);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  min-width: 0;
}
.spot-pill .label, .spot-pill .price {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spot-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.spot-pill.gold .dot { background: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.spot-pill.silver .dot { background: var(--silver); box-shadow: 0 0 0 3px var(--silver-soft); }
.spot-pill .label { color: var(--text-muted); }
.spot-pill .price { font-weight: 700; }
.spot-pill.ghost {
  background: transparent;
  color: var(--text-muted);
  box-shadow: none;
  cursor: pointer;
}
.spot-pill.ghost:active { transform: scale(0.96); }
.spot-pill.ratio {
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 18%, var(--border));
}
.spot-pill.ratio .label { color: var(--accent); font-weight: 700; }

.spot-updated {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%;
  margin-top: var(--s-2);
  padding: 4px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: var(--t-xs);
  cursor: pointer;
}
.spot-updated:active { opacity: 0.6; }
.spot-updated:disabled { opacity: 0.5; cursor: default; }
.spot-updated.stale { color: var(--gold); font-weight: 600; }

/* ============================================================
   Sections, chips
   ============================================================ */
.section { margin-top: var(--s-6); }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s-1);
  margin-bottom: var(--s-3);
}
.section-title { font-size: var(--t-md); font-weight: 700; letter-spacing: -0.01em; }
.section-meta { color: var(--text-muted); font-size: var(--t-sm); }
.section-tools { display: flex; align-items: center; gap: var(--s-3); }

.sort-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-muted);
  font-size: var(--t-xs); font-weight: 600;
  padding: 4px 24px 4px 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
}

.chips {
  display: flex; gap: var(--s-2);
  overflow-x: auto;
  padding: 0 var(--s-1) var(--s-3);
  margin: 0 calc(-1 * var(--s-1));
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--t-sm); font-weight: 600;
  transition: all var(--dur) var(--ease);
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.chip[aria-selected="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.chip .count {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--r-pill);
  padding: 1px 7px;
  font-size: var(--t-xs);
}
.chip[aria-selected="true"] .count {
  background: rgba(255,255,255,.16);
  color: inherit;
}

/* ============================================================
   Coin list
   ============================================================ */
.coin-list { display: flex; flex-direction: column; gap: var(--s-2); }

/* Swipeable wrapper around each coin */
.coin-item {
  position: relative;
  border-radius: var(--r-md);
  touch-action: pan-y;
}
.coin-item .coin { touch-action: pan-y; }
.coin-item .coin-delete { touch-action: pan-y; }
.coin-actions {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  display: flex;
  align-items: stretch;
  border-radius: var(--r-md);
  overflow: hidden;
  z-index: 0;
}
.coin-regrade,
.coin-sell,
.coin-delete {
  border: 0;
  width: 60px;
  color: white;
  display: grid; place-items: center;
  cursor: pointer;
}
.coin-delete { background: var(--danger); }
.coin-delete:active { background: color-mix(in srgb, var(--danger) 80%, black); }
/* Muted until the coin is on the list, solid once it is — the same button
   toggles the flag back off. */
.coin-regrade { background: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); }
.coin-regrade.on { background: var(--accent); }
.coin-regrade:active { background: color-mix(in srgb, var(--accent) 80%, black); }
.coin-sell { background: color-mix(in srgb, #22a04a 45%, var(--surface-2)); }
.coin-sell.on { background: #22a04a; }
.coin-sell:active { background: color-mix(in srgb, #22a04a 80%, black); }

.coin {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: var(--s-3);
  align-items: center;
  text-align: left;
  width: 100%;
  position: relative;
  z-index: 1;
  transition: transform var(--dur) var(--ease);
}
.coin:active { transform: scale(0.99); }
.coin-item.revealed > .coin { transform: translateX(-180px); }
.coin-item.dragging > .coin { transition: none; }

.coin-avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  color: var(--text-subtle);
}
.coin-avatar svg { display: block; }
.coin-avatar.silver {
  background: color-mix(in srgb, var(--silver) 28%, var(--surface));
  border-color: var(--silver);
  color: color-mix(in srgb, var(--silver) 70%, var(--text));
}
.coin-avatar.gold {
  background: color-mix(in srgb, var(--gold) 32%, var(--surface));
  border-color: var(--gold);
  color: color-mix(in srgb, var(--gold) 70%, var(--text));
}
.coin-avatar.clad {
  background: color-mix(in srgb, #a07b5a 22%, var(--surface));
  border-color: color-mix(in srgb, #a07b5a 60%, var(--border-strong));
  color: color-mix(in srgb, #a07b5a 60%, var(--text-muted));
}
/* Graded coins live in slabs — show as a vertical rounded rectangle */
.coin-avatar.graded {
  width: 30px;
  aspect-ratio: auto;
  border-radius: 5px;
  justify-self: center;
}
/* When a graded coin has a photo, show it inside the slab-shaped avatar */
.coin-avatar.graded.has-photo { padding: 0; overflow: hidden; }
.coin-thumb {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--surface-2) center / cover no-repeat;
  cursor: zoom-in;
}

.coin-body { min-width: 0; }
.coin-title {
  font-size: var(--t-base); font-weight: 600; letter-spacing: -0.005em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.coin-meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--t-sm);
  display: flex; flex-wrap: wrap; gap: 0 8px; align-items: center;
}
.coin-meta .sep { color: var(--text-subtle); }

.coin-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--t-xs); font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-muted);
}
.coin-tag.graded { background: var(--accent-soft); color: var(--accent); }
.coin-tag.tube { background: var(--silver-soft); color: var(--silver); }
.coin-tag.roll { background: var(--gold-soft); color: var(--gold); }
.coin-tag.bag { background: var(--warn-soft); color: var(--warn); }
.coin-tag.goldback { background: rgba(184, 115, 51, 0.14); color: #b87333; }
.coin-tag.cac { background: rgba(34, 160, 74, 0.16); color: #22a04a; }
.coin-tag.regrade { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.coin-tag.sell { background: rgba(34, 160, 74, 0.16); color: #22a04a; }

/* ---- Regrade / Sell lists ---- */
.list-section { margin-bottom: var(--s-4); }
.list-head {
  display: flex; align-items: center; gap: var(--s-2);
  margin: 0 0 var(--s-2);
}
.list-title {
  font-size: var(--t-sm);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.list-title.regrade { color: var(--accent); }
.list-title.sell { color: #22a04a; }
.list-count {
  font-size: var(--t-xs);
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 8px;
}

.coin-trail { text-align: right; min-width: 64px; }
.coin-trail .qty { font-size: var(--t-md); font-weight: 700; letter-spacing: -0.01em; }
.coin-trail .qty-prefix {
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-right: 3px;
}
.coin-trail .sub { font-size: var(--t-xs); color: var(--text-muted); margin-top: 2px; white-space: nowrap; }
.coin-trail .sub.pcgs-flag { color: #d4930a; font-weight: 600; }
.coin-trail .sub.greysheet-flag { color: #7a5cc4; font-weight: 600; }
.coin-trail .sub.redbook-flag { color: #d6423c; font-weight: 600; }
.coin-trail .sub.traderbea-flag { color: #3b9eff; font-weight: 600; }
.coin-trail .sub.witterbrick-flag { color: #14a38b; font-weight: 600; }
/* Named custom value. The name is the user's, so cap it (not the amount)
   rather than push the trail wide. */
.coin-trail .sub.custom-flag { color: #c0469a; font-weight: 600; }
.coin-trail .sub.custom-flag .cf-name { display: inline-block; max-width: 7em; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
/* The value feeding the portfolio total (per the wholesale/retail basis) is
   highlighted behind the text only — zero horizontal padding so the line keeps
   the exact same width and right-edge as the other price rows (no wrap, no inset). */
.coin-trail .sub.counted {
  font-weight: 800;
  display: inline-block;
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 0;
}

/* ============================================================
   Empty state
   ============================================================ */
.empty {
  margin-top: var(--s-4);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--s-7) var(--s-4);
  text-align: center;
  color: var(--text-muted);
}
.empty .big { font-size: 48px; opacity: 0.45; margin-bottom: var(--s-2); }
.empty .msg { font-weight: 600; color: var(--text); }
.empty .hint { font-size: var(--t-sm); margin-top: 4px; }

/* ============================================================
   Bottom tab bar
   ============================================================ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: var(--s-2) var(--s-2) calc(var(--s-2) + var(--safe-bottom));
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--s-1);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  background: transparent;
  border: 0;
  padding: 8px 2px 6px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.01em;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  transition: color var(--dur) var(--ease);
}
.tab svg { width: 20px; height: 20px; flex: 0 0 auto; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] svg { stroke: var(--accent); }

.tab.fab { color: white; overflow: visible; }
.tab.fab .fab-inner {
  width: 50px; height: 50px;
  margin-top: -16px;
  border-radius: 50%;
  background: var(--accent-grad);
  display: grid; place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 50%, transparent);
  transition: transform var(--dur) var(--ease);
}
.tab.fab:active .fab-inner { transform: scale(0.92); }
.tab.fab svg { stroke: white; }

/* ============================================================
   Bottom sheets
   ============================================================ */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 6, 22, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 51;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: var(--s-3) var(--s-4) calc(var(--s-5) + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 320ms var(--ease);
  box-shadow: var(--shadow-lg);
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 38px; height: 4px;
  background: var(--border-strong);
  border-radius: var(--r-pill);
  margin: 4px auto var(--s-3);
}
.sheet-title {
  font-size: var(--t-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 var(--s-1);
}
.sheet-sub {
  color: var(--text-muted);
  font-size: var(--t-sm);
  margin-bottom: var(--s-4);
}

/* ============================================================
   Add menu
   ============================================================ */
.add-grid { display: grid; gap: var(--s-2); }
.add-action {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-align: left;
  width: 100%;
  color: var(--text);
  transition: transform var(--dur) var(--ease);
}
.add-action:active { transform: scale(0.99); }
.add-action .icon {
  width: 44px; height: 44px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  flex: 0 0 auto;
}
.add-action.primary .icon { background: var(--accent-grad); color: white; }
.add-action .body { min-width: 0; flex: 1; }
.add-action .title { display: block; font-weight: 700; font-size: var(--t-base); }
.add-action .desc { display: block; color: var(--text-muted); font-size: var(--t-sm); margin-top: 2px; }
.add-action .chev { color: var(--text-subtle); font-size: 22px; line-height: 1; }

/* ============================================================
   Forms
   ============================================================ */
.form-section { display: grid; gap: var(--s-3); margin-top: var(--s-2); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: var(--t-xs); color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.field input, .field select, .field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px;
  color: var(--text);
  font-size: var(--t-base);
  font-family: inherit;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.field-help { font-size: var(--t-xs); color: var(--text-muted); margin-top: 2px; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px;
  gap: 4px;
}
.seg button {
  background: transparent;
  border: 0;
  padding: 10px 6px;
  border-radius: 6px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: var(--t-sm);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.switch-row .text .title { font-weight: 600; }
.switch-row .text .sub { color: var(--text-muted); font-size: var(--t-sm); margin-top: 2px; }
.switch {
  --w: 44px; --h: 26px;
  width: var(--w); height: var(--h);
  background: var(--border-strong);
  border-radius: var(--r-pill);
  position: relative; flex: 0 0 auto;
  border: 0; padding: 0;
  transition: background var(--dur) var(--ease);
}
.switch::after {
  content: ""; position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: white;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }

.metal-hint {
  font-size: var(--t-xs);
  color: var(--accent);
  background: var(--accent-soft);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  display: flex; gap: 6px;
}

/* Custom combobox for the name field */
.combobox { position: relative; }
.combobox input { padding-right: 44px; }
.combobox-trigger {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px; height: 32px;
  background: transparent;
  border: 0;
  display: grid; place-items: center;
  color: var(--text-muted);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.combobox-trigger:active { background: var(--border); }
.combobox-menu {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
  z-index: 10;
}
.combobox-option {
  display: block;
  width: 100%;
  padding: 12px 14px;
  background: transparent;
  border: 0;
  text-align: left;
  color: var(--text);
  font-size: var(--t-base);
  font-family: inherit;
  cursor: pointer;
}
.combobox-option + .combobox-option { border-top: 1px solid var(--border); }
.combobox-option:active, .combobox-option:hover { background: var(--surface-2); }
.combobox-empty {
  padding: 12px 14px;
  color: var(--text-muted);
  font-size: var(--t-sm);
}

.sheet-actions {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: var(--s-2);
  margin-top: var(--s-5);
}
.btn {
  padding: 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: var(--t-base);
  transition: transform var(--dur) var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: var(--accent-grad);
  color: white;
  border-color: transparent;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.btn:disabled { opacity: 0.55; pointer-events: none; }

/* ============================================================
   Photo flow
   ============================================================ */
.photo-stepper {
  display: flex; align-items: center; gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.photo-step {
  flex: 1;
  display: flex; align-items: center; gap: var(--s-2);
  padding: 8px 12px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--t-sm); font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.photo-step .num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--border-strong);
  color: var(--surface);
  display: grid; place-items: center;
  font-size: var(--t-xs);
}
.photo-step.active { background: var(--accent-soft); color: var(--accent); }
.photo-step.active .num { background: var(--accent); color: white; }
.photo-step.done { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.photo-step.done .num { background: var(--green); color: white; }

.photo-zone {
  aspect-ratio: 4/3;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: center;
  padding: var(--s-4);
  position: relative;
  overflow: hidden;
}
.photo-zone .photo-icon { font-size: 36px; margin-bottom: 8px; }
.photo-zone .photo-zone-title { font-weight: 600; color: var(--text); }
.photo-zone .photo-zone-sub { font-size: var(--t-sm); margin-top: 4px; }
.photo-zone .preview {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: 1fr 1fr;
}
.photo-zone .preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-zone.busy::after {
  content: ""; position: absolute; inset: 0;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(2px);
}

/* ============================================================
   Prices sheet
   ============================================================ */
.price-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.price-card {
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.price-card .head {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--t-sm); color: var(--text-muted); font-weight: 600;
}
.price-card .head .dot { width: 8px; height: 8px; border-radius: 50%; }
.price-card.silver .head .dot { background: var(--silver); box-shadow: 0 0 0 3px var(--silver-soft); }
.price-card.gold .head .dot { background: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.price-card.goldback .head .dot { background: #b87333; box-shadow: 0 0 0 3px rgba(184, 115, 51, 0.16); }
.price-card.wide { grid-column: 1 / -1; }
.price-card .big { font-size: var(--t-xl); font-weight: 800; letter-spacing: -0.02em; margin-top: var(--s-1); }
.price-card .small { font-size: var(--t-xs); color: var(--text-muted); }

.price-portfolio {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
}
.price-portfolio .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  font-size: var(--t-sm);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.price-portfolio .row:last-child { border-bottom: 0; }
.price-portfolio .row b { color: var(--text); font-size: var(--t-base); }
.price-portfolio .row.total { padding-top: var(--s-3); margin-top: var(--s-2); border-top: 1px solid var(--border-strong); border-bottom: 0; font-weight: 700; }
.price-portfolio .row.total b { font-size: var(--t-md); color: var(--text); }

/* ============================================================
   Settings sheet
   ============================================================ */
.info-box {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  padding: var(--s-3);
}
.info-box.warn { background: var(--warn-soft); border-color: var(--warn); }
.info-box .info-title { font-weight: 700; margin-bottom: 4px; }
.info-box .info-body { font-size: var(--t-sm); color: var(--text-muted); }
.info-box .info-body a { color: var(--accent); }

.settings-h {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: var(--s-5) 0 var(--s-2);
}

/* ---- Edit form: section headers + price summary / adjust panel ---- */
.form-h {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-muted);
  margin: var(--s-4) 0 var(--s-2);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
}
.form-section > .form-h:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.price-summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: var(--s-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  margin-bottom: var(--s-2);
}
.ps-cell { display: flex; flex-direction: column; gap: 1px; padding: 6px 8px; border-radius: 6px; }
.ps-cell.ps-full { grid-column: 1 / -1; }
.ps-label { font-size: var(--t-xs); color: var(--text-muted); }
.ps-val { font-size: var(--t-md); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.ps-cell.rb .ps-val { color: #d6423c; }
.ps-cell.gs .ps-val { color: #7a5cc4; }
.ps-cell.tb .ps-val { color: #3b9eff; }
.ps-cell.wb .ps-val { color: #14a38b; }
.ps-cell.cu .ps-val { color: #c0469a; }
.ps-cell.cu .ps-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-cell.pc .ps-val { color: #d4930a; }
.ps-cell.counted { background: var(--accent-soft); }
.ps-cell.counted .ps-val { font-weight: 800; }
.ps-dot { margin-left: 5px; font-size: 0.55em; vertical-align: middle; opacity: 0.9; }
.ps-note { grid-column: 1 / -1; font-size: var(--t-xs); color: var(--text-muted); margin-top: 2px; }
.ps-empty { grid-column: 1 / -1; font-size: var(--t-sm); color: var(--text-muted); line-height: 1.5; }

.price-adjust-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: var(--t-xs); font-weight: 700;
  padding: 2px 0; margin-bottom: var(--s-2);
}
.price-adjust-toggle::before { content: "\25B8  "; }
.price-adjust-toggle[aria-expanded="true"]::before { content: "\25BE  "; }

/* "Metal & content" collapsible section header/toggle */
.more-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 11px 12px; color: var(--text); font-size: var(--t-sm); font-weight: 600; cursor: pointer;
}
.more-toggle .chev { color: var(--text-muted); transition: transform var(--dur) var(--ease); }
.more-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.more-panel { display: grid; gap: var(--s-2); padding-top: var(--s-2); }
.more-panel[hidden] { display: none; }

/* Tighter, cohesive density for the edit form so standard fields match the
   compact pricing block. Scoped to #editForm to leave other sheets untouched. */
#editForm { gap: var(--s-2); }
#editForm .field { gap: 4px; }
#editForm .field input, #editForm .field select { padding: 11px 12px; }
#editForm .switch-row { padding: var(--s-2) var(--s-3); }
#editForm .switch-row .text .sub { font-size: var(--t-xs); margin-top: 1px; }
#editForm .seg { padding: 3px; }
#editForm .seg button { padding: 8px 6px; }
#editForm .form-h { margin: var(--s-3) 0 var(--s-1); padding-top: var(--s-2); }
#editForm .form-h:first-child { padding-top: 0; margin-top: 0; }

.settings-list { display: flex; flex-direction: column; gap: var(--s-2); }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-weight: 600;
  width: 100%;
  text-align: left;
}
.settings-row .left { display: inline-flex; align-items: center; gap: var(--s-3); }
.settings-row .ic {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-size: 16px;
}
.settings-row .chev { color: var(--text-subtle); font-size: 22px; line-height: 1; }

.settings-danger {
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
}
.settings-version {
  margin-top: var(--s-4);
  text-align: center;
  font-size: var(--t-xs);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Photo slots (edit sheet) + storage meters + viewer
   ============================================================ */
.photo-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}
.photo-slot {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px;
}
.photo-slot-img {
  aspect-ratio: 1 / 1;
  border-radius: var(--r-sm);
  background: var(--surface) center / cover no-repeat;
  border: 1px dashed var(--border-strong);
  cursor: zoom-in;
}
.photo-slot-img.has-photo { border-style: solid; }
.photo-slot-label {
  font-size: var(--t-xs);
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.photo-slot-actions { display: flex; gap: 6px; align-items: center; }
.photo-slot-add {
  flex: 1;
  background: var(--accent-soft);
  color: var(--accent);
  border: 0;
  border-radius: var(--r-sm);
  padding: 8px;
  font-weight: 700;
  font-size: var(--t-sm);
}
.photo-slot-crop {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-weight: 700;
  font-size: var(--t-sm);
}
.photo-slot-remove {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  border: 0;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.storage-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--s-3);
}
.storage-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: var(--t-sm);
  margin-bottom: 4px;
}
.storage-label { color: var(--text-muted); font-weight: 600; }
.storage-value { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.storage-bar {
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}
.storage-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width var(--dur) var(--ease);
}
.storage-value.ok { color: var(--green); }
.storage-value.risk { color: var(--warn); }
.storage-note {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}
.storage-bar-fill.warn { background: var(--warn); }
.storage-bar-fill.full { background: var(--danger); }

/* TraderBea offers diff list */
.offers-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
  margin-top: var(--s-2);
}
.offer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  align-items: center;
}
.offer-row .name {
  font-weight: 600;
  font-size: var(--t-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.offer-row .meta {
  font-size: var(--t-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.offer-row .delta {
  font-weight: 700;
  font-size: var(--t-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.offer-row .delta .old { color: var(--text-muted); text-decoration: line-through; margin-right: 6px; }
.offer-row .delta .new { color: var(--green); }
.offers-list[data-source="pcgs"] .offer-row .delta .new { color: #d4930a; }
.offers-list[data-source="greysheet"] .offer-row .delta .new { color: #7a5cc4; }
.offers-list[data-source="traderbea"] .offer-row .delta .new { color: #3b9eff; }
.offers-list[data-source="witterbrick"] .offer-row .delta .new { color: #14a38b; }
/* Greysheet refresh: coin pinned to an entry whose FB/FBL/FH/FS disagrees */
.offer-row.flagged { background: var(--warn-soft); border-color: var(--warn); }
.offer-row.flagged .delta { color: var(--warn); }

/* ============================================================
   Sell-list offers — what buyers have actually bid, under the coin
   ============================================================ */
.list-sub {
  font-size: var(--t-xs);
  color: var(--text-muted);
  margin: -2px 0 var(--s-2);
  font-variant-numeric: tabular-nums;
}

/* Pairs one coin row with its offers panel so the two scroll as a unit. */
.sell-entry { display: flex; flex-direction: column; }

.offers-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: -6px 0 2px;
  padding: 12px 12px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--r-md) var(--r-md);
}

.op-head { display: flex; flex-direction: column; gap: 2px; }
.op-best { display: flex; align-items: baseline; gap: 8px; }
.op-best-amt {
  font-size: var(--t-md);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--green);
}
.op-best-src {
  font-size: var(--t-sm);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.op-compare { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: var(--t-xs); }
.op-spread { font-weight: 700; font-variant-numeric: tabular-nums; }
.op-spread.up { color: var(--green); }
.op-spread.down { color: var(--danger); }
.op-vs { color: var(--text-muted); }
.op-none { font-size: var(--t-sm); color: var(--text-muted); }

.op-rows { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.op-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
}
.op-row:hover { border-color: var(--border-strong); }
.op-row.auto { cursor: default; opacity: 0.9; }
.op-amt { font-weight: 700; font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.op-meta {
  font-size: var(--t-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.op-auto {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.op-date { font-size: var(--t-xs); color: var(--text-subtle); white-space: nowrap; }
.op-del {
  border: none;
  background: none;
  color: var(--text-subtle);
  font-size: var(--t-md);
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.op-del:hover { color: var(--danger); background: var(--danger-soft); }

.op-add {
  align-self: flex-start;
  margin-top: 2px;
  padding: 5px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-pill);
  background: none;
  color: var(--accent);
  font-size: var(--t-xs);
  font-weight: 700;
  cursor: pointer;
}
.op-add:hover { background: var(--accent-soft); border-style: solid; }

/* The offer editor stacks over the lists sheet, same lift as the GS picker. */
#offerEditSheet { z-index: 61; }
.sheet-backdrop[data-backdrop-for="offerEditSheet"] { z-index: 60; }

/* A sheet opened over another one (openSheet with stack:true) has to be lifted:
   all sheets share z-index 51, so DOM order would otherwise decide which paints
   on top, hiding the newer sheet behind the older one. */
.sheet.stacked { z-index: 61; }
.sheet-backdrop.stacked { z-index: 60; }

/* Greysheet candidate picker — stacks above the edit sheet (z-index 51/50) */
#greysheetPickSheet { z-index: 61; }
.sheet-backdrop[data-backdrop-for="greysheetPickSheet"] { z-index: 60; }
.gs-pick-row { cursor: pointer; }
.gs-pick-row:hover { background: var(--surface-2, rgba(127,127,127,0.08)); }
.gs-pick-row .prices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; font-size: var(--t-xs); }
.gs-pick-row .prices .cpg { color: #d6423c; font-weight: 700; }
.gs-pick-row .prices .bid-chip { color: #7a5cc4; font-weight: 600; }
.gs-pick-row .prices .cac-chip { color: #22a04a; font-weight: 600; }
.gs-pick-row .prices span { color: var(--text-muted); }
.offer-flag-high { color: #d4930a; font-size: var(--t-xs); margin-left: 4px; }
.offer-flag-fill { color: #3b9eff; font-size: var(--t-xs); margin-left: 4px; }
.offer-row.empty { color: var(--text-muted); justify-content: center; text-align: center; }

/* Cert number confirmation list (post photo-scan, pre-inventory) */
.cert-confirm-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
  margin-top: var(--s-2);
}
.cert-confirm-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  align-items: center;
}
.cert-confirm-row .ccr-info .name {
  font-weight: 600;
  font-size: var(--t-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cert-confirm-row .ccr-info .meta {
  font-size: var(--t-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.ccr-values {
  margin-top: 4px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ccr-values:empty { display: none; }
.ccr-val {
  font-size: var(--t-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ccr-val.traderbea { color: #3b9eff; }
.ccr-val.witterbrick { color: #14a38b; }
.ccr-val.pcgs { color: #d4930a; }
.ccr-val.greysheet { color: #7a5cc4; }
.ccr-val.redbook { color: #d6423c; }
.ccr-cert-input {
  width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: var(--t-sm);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--dur) var(--ease);
}
.ccr-cert-input:focus {
  outline: none;
  border-color: var(--accent);
}
.ccr-cert-input.error { border-color: var(--danger); }

/* Crop sheet — full-screen, sits above the viewer */
.crop-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #000;
  display: none;
  flex-direction: column;
}
.crop-sheet.open { display: flex; }
.crop-sheet.closing { opacity: 0; pointer-events: none; transition: opacity 160ms ease-out; }
.crop-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  color: white;
  background: rgba(0,0,0,0.55);
}
.crop-bar.top { padding-top: calc(env(safe-area-inset-top, 0) + 12px); }
.crop-bar.bottom { padding-bottom: calc(env(safe-area-inset-bottom, 0) + 12px); justify-content: center; gap: 12px; }
.crop-title {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: var(--t-base);
}
.crop-btn {
  background: rgba(255,255,255,0.14);
  color: white;
  border: 0;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  font-weight: 700;
  font-size: var(--t-sm);
  min-width: 84px;
}
.crop-btn.primary {
  background: var(--accent-grad);
  padding: 12px 28px;
  font-size: var(--t-base);
}
.crop-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.crop-img {
  position: absolute;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.crop-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* The rect's box-shadow paints the dim mask, so this layer just sits above
     the image edges. Kept for future overlays. */
}
.crop-rect {
  position: absolute;
  border: 2px solid white;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  cursor: move;
  touch-action: none;
}
.crop-rect::before,
.crop-rect::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.crop-rect::before {
  border-left: 1px solid rgba(255,255,255,0.4);
  border-right: 1px solid rgba(255,255,255,0.4);
  left: 33.333%;
  width: 33.333%;
  inset: 0;
}
.crop-rect::after {
  border-top: 1px solid rgba(255,255,255,0.4);
  border-bottom: 1px solid rgba(255,255,255,0.4);
  top: 33.333%;
  height: 33.333%;
  inset: 0;
}
.crop-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  background: white;
  border: 2px solid rgba(0,0,0,0.4);
  border-radius: 50%;
  touch-action: none;
}
.crop-handle.nw { top: -14px; left: -14px; cursor: nwse-resize; }
.crop-handle.ne { top: -14px; right: -14px; cursor: nesw-resize; }
.crop-handle.sw { bottom: -14px; left: -14px; cursor: nesw-resize; }
.crop-handle.se { bottom: -14px; right: -14px; cursor: nwse-resize; }

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.photo-viewer.open { display: flex; }
.photo-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--r-sm);
}
.photo-viewer-close,
.photo-viewer-nav {
  position: absolute;
  background: rgba(255,255,255,0.12);
  color: white;
  border: 0;
  border-radius: 999px;
  display: grid; place-items: center;
  font-weight: 700;
  cursor: pointer;
}
.photo-viewer-close {
  top: calc(env(safe-area-inset-top, 0) + 12px);
  right: 12px;
  width: 40px; height: 40px;
  font-size: 22px;
}
.photo-viewer-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  font-size: 28px;
}
.photo-viewer-nav.prev { left: 8px; }
.photo-viewer-nav.next { right: 8px; }
.photo-viewer-caption {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0) + 12px);
  text-align: center;
  color: white;
  font-size: var(--t-sm);
  font-weight: 600;
  opacity: 0.8;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  left: 50%; bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r-pill);
  padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: var(--t-sm);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast.error { background: var(--danger); color: white; }
.toast.success { background: var(--green); color: white; }
.toast .toast-icon { flex: 0 0 auto; }
.toast .toast-text {
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.toast .toast-action {
  background: rgba(255,255,255,0.18);
  border: 0;
  color: inherit;
  padding: 6px 10px;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: var(--t-xs);
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to { opacity: 1; transform: none; }
}
.pop { animation: pop 280ms var(--ease) both; }

@media (max-width: 360px) {
  :root { --t-2xl: 30px; --t-xl: 24px; }
}

/* Buyback dealer picker + WitterBrick lookup sheet */
.add-action .icon.tb-icon,
.add-action .icon.wb-icon { font-weight: 800; font-size: var(--t-sm); letter-spacing: 0.02em; }
.add-action .icon.tb-icon { color: #3b9eff; }
.add-action .icon.wb-icon { color: #14a38b; }
.wb-step { margin: var(--s-4) 0; }
.wb-step .field-help { margin-top: var(--s-2); }
.wb-bookmarklet {
  display: inline-block; padding: 1px 8px; border-radius: var(--r-pill);
  border: 1px dashed var(--border-strong); color: #14a38b; font-weight: 700;
  text-decoration: none; cursor: grab;
}
#wbResultsInput, .wb-bookmarklet-text { font-family: ui-monospace, Consolas, monospace; font-size: var(--t-xs); resize: vertical; }
.wb-waiting {
  display: flex; align-items: center; gap: var(--s-2);
  margin-top: var(--s-2); padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm); background: var(--accent-soft);
  font-size: var(--t-sm); font-weight: 600;
}
.wb-waiting #wbWaitingText { flex: 1; }
.wb-spinner {
  width: 14px; height: 14px; flex: 0 0 auto; border-radius: 50%;
  border: 2px solid #14a38b; border-right-color: transparent;
  animation: wb-spin 0.8s linear infinite;
}
@keyframes wb-spin { to { transform: rotate(360deg); } }
.wb-link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }
.wb-more { margin: var(--s-3) 0; border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); }
.wb-more summary { cursor: pointer; font-weight: 700; font-size: var(--t-sm); padding: var(--s-1) 0; }
.wb-more[open] summary { margin-bottom: var(--s-2); }
.wb-more p { margin: 0 0 var(--s-2); }
.wb-bookmarklet-text {
  width: 100%; margin-top: var(--s-2); padding: var(--s-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text-muted); resize: none;
}
