/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --bg4: #252d3d;
  --border: #2a3347;
  --border2: #364059;
  --text: #e8eaf0;
  --text2: #8b92a8;
  --text3: #5a6178;
  --accent: #ffcb05;
  --accent2: #f5a623;
  --blue: #3b82f6;
  --blue2: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --purple: #a855f7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);
  --sidebar-w: 220px;
  --transition: 0.18s ease;
}

html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  gap: 8px;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.logo-icon { font-size: 22px; }
.logo-text { font-size: 17px; font-weight: 700; color: var(--accent); letter-spacing: -0.3px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-align: left;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--bg4); color: var(--accent); }
.nav-icon { font-size: 16px; }

.sidebar-stats {
  margin-top: auto;
  padding: 14px 12px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-item { display: flex; justify-content: space-between; align-items: center; }
.stat-label { font-size: 12px; color: var(--text3); }
.stat-value { font-size: 14px; font-weight: 600; color: var(--text); }

/* ── Main ── */
.main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.view { display: none; padding: 28px 32px; min-height: 100%; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.view-header h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.view-subtitle { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover:not(:disabled) { background: var(--blue2); border-color: var(--blue2); }
.btn-ghost { background: transparent; color: var(--text2); border-color: var(--border2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #ef444420; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-yellow { background: var(--accent); color: #1a1a1a; font-weight: 600; }
.btn-yellow:hover:not(:disabled) { background: var(--accent2); }

/* ── Inputs ── */
.input-text, .input-search, .input-select {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition);
}
.input-text:focus, .input-search:focus { border-color: var(--blue); }
.input-text { width: 100%; }
.input-lg { font-size: 15px; padding: 12px 16px; }
.input-select { cursor: pointer; }
.input-select option { background: var(--bg3); }

/* ── Portfolio Tabs ── */
.portfolio-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.portfolio-tab {
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
}
.portfolio-tab:hover { border-color: var(--blue); color: var(--text); }
.portfolio-tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* Portfolio type colors */
:root {
  --type-pokemon: #3b82f6;   /* blue */
  --type-set:     #22c55e;   /* green */
  --type-artist:  #a855f7;   /* purple */
}
.portfolio-tab[data-ptype="pokemon"].active { background: var(--type-pokemon); border-color: var(--type-pokemon); }
.portfolio-tab[data-ptype="set"].active     { background: var(--type-set);     border-color: var(--type-set); }
.portfolio-tab[data-ptype="artist"].active  { background: var(--type-artist);  border-color: var(--type-artist); }
.portfolio-tab[data-ptype="pokemon"] { border-color: var(--type-pokemon); }
.portfolio-tab[data-ptype="set"]     { border-color: var(--type-set); }
.portfolio-tab[data-ptype="artist"]  { border-color: var(--type-artist); }
.portfolio-type-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  flex-shrink: 0;
}
.portfolio-type-dot.pokemon { background: var(--type-pokemon); }
.portfolio-type-dot.set     { background: var(--type-set); }
.portfolio-type-dot.artist  { background: var(--type-artist); }

/* Portfolio type badge (shown in toolbar) */
.portfolio-type-badge-row { margin-bottom: 10px; }
.portfolio-type-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.03em;
}
.portfolio-type-badge.type-pokemon { background: rgba(59,130,246,0.18); color: var(--type-pokemon); border: 1px solid var(--type-pokemon); }
.portfolio-type-badge.type-set     { background: rgba(34,197,94,0.18);  color: var(--type-set);     border: 1px solid var(--type-set); }
.portfolio-type-badge.type-artist  { background: rgba(168,85,247,0.18); color: var(--type-artist);  border: 1px solid var(--type-artist); }

/* Type picker in modal */
.portfolio-type-picker {
  display: flex;
  gap: 8px;
}
.portfolio-type-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border2);
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all var(--transition);
}
.portfolio-type-btn .portfolio-type-icon { font-size: 20px; }
.portfolio-type-btn[data-type="pokemon"] { border-color: var(--type-pokemon); }
.portfolio-type-btn[data-type="set"]     { border-color: var(--type-set); }
.portfolio-type-btn[data-type="artist"]  { border-color: var(--type-artist); }
.portfolio-type-btn[data-type="pokemon"].active { background: var(--type-pokemon); color: #fff; }
.portfolio-type-btn[data-type="set"].active     { background: var(--type-set);     color: #fff; }
.portfolio-type-btn[data-type="artist"].active  { background: var(--type-artist);  color: #fff; }

/* ── Portfolio Toolbar ── */
.portfolio-toolbar { margin-bottom: 20px; }
.toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar-left { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 200px; flex-wrap: wrap; }
.toolbar-left .input-search { flex: 1; max-width: 220px; min-width: 120px; }
.toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.view-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.view-toggle-btn { padding: 5px 10px; background: none; border: none; color: var(--text3); cursor: pointer; font-size: 14px; transition: background var(--transition), color var(--transition); }
.view-toggle-btn:hover { background: var(--bg3); color: var(--text); }
.view-toggle-btn.active { background: var(--blue); color: #fff; }

.sidebar-currency { padding: 10px 16px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.currency-label { font-size: 11px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.input-select-sm { padding: 4px 8px; font-size: 12px; }

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

.card-tile {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  position: relative;
}
.card-tile:hover {
  transform: translateY(-4px);
  border-color: var(--blue);
  box-shadow: var(--shadow);
}
.card-tile-img {
  width: 100%;
  aspect-ratio: 2.5/3.5;
  object-fit: cover;
  background: var(--bg3);
  display: block;
}
.card-tile-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  aspect-ratio: 2.5/3.5;
  background: linear-gradient(135deg, var(--bg3), var(--bg4));
}
.card-tile-body { padding: 10px; }
.card-tile-name { font-size: 12.5px; font-weight: 600; color: var(--text); line-height: 1.3; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tile-set { font-size: 11px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tile-price { font-size: 12px; font-weight: 600; color: var(--green); margin-top: 4px; }
.card-tile-badge {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,0.75);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}
.card-tile-remove {
  position: absolute;
  top: 6px; left: 6px;
  background: rgba(239,68,68,0.85);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 12px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.card-tile:hover .card-tile-remove { display: flex; }
.card-tile-remove:hover { background: var(--red); }

/* ── Card List View ── */
.card-list { display: flex; flex-direction: column; gap: 6px; }
.card-row {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color var(--transition);
  position: relative;
}
.card-row:hover { border-color: var(--blue); }
.card-row-img { width: 42px; height: 58px; object-fit: cover; border-radius: 4px; flex-shrink: 0; background: var(--bg3); }
.card-row-info { flex: 1; min-width: 0; }
.card-row-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-row-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.card-row-artist { font-size: 11px; color: var(--text3); margin-top: 2px; }
.card-row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.card-row-price { font-size: 13px; font-weight: 700; color: var(--green); }
.card-row-rarity { font-size: 11px; color: var(--text3); white-space: nowrap; }
.card-row-condition { font-size: 11px; color: var(--text3); }
.card-row .card-tile-remove { position: static; display: none; margin-left: 8px; }
.card-row:hover .card-tile-remove { display: flex; }

/* ── Empty States ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px;
  gap: 12px;
  color: var(--text2);
}
.empty-icon { font-size: 48px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); }
.empty-state p { font-size: 13px; max-width: 280px; }

/* ── Scan Panel (inline in search view) ── */
.scan-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.scan-panel-inner {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  min-height: 260px;
}
.scan-panel-img-wrap {
  background: var(--bg3);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
#previewImg { width: 100%; max-height: 300px; object-fit: contain; border-radius: 6px; display: none; }

/* ── Camera (fullscreen overlay) ── */
.camera-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  display: flex;
  flex-direction: column;
}
.camera-view video { width: 100%; flex: 1; object-fit: cover; }
.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.camera-frame {
  width: 200px;
  height: 280px;
  border: 2px solid rgba(255,203,5,0.7);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
}
.camera-controls {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

/* ── Scan Result ── */
.scan-result {
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}
.result-idle { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text3); text-align: center; font-size: 13px; }
.result-loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--text2); font-size: 13px; }
.result-error { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.error-icon { font-size: 32px; }

.result-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
.result-header h3 { font-size: 18px; font-weight: 700; flex: 1; }
.confidence-badge {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; margin-top: 3px;
}
.confidence-high { background: #22c55e22; color: var(--green); border: 1px solid #22c55e40; }
.confidence-medium { background: #f5a62322; color: var(--accent2); border: 1px solid #f5a62340; }
.confidence-low { background: #ef444422; color: var(--red); border: 1px solid #ef444440; }

.result-fields { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.result-field { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.result-field-label { color: var(--text3); }
.result-field-value { color: var(--text); font-weight: 500; text-align: right; max-width: 180px; }

.result-section-title { font-size: 12px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.tcg-matches { display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow-y: auto; margin-bottom: 16px; }
.tcg-match {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition);
}
.tcg-match:hover { border-color: var(--blue); }
.tcg-match.selected { border-color: var(--blue); background: #3b82f615; }
.tcg-match img { width: 32px; height: 44px; object-fit: cover; border-radius: 4px; }
.tcg-match-info { flex: 1; min-width: 0; }
.tcg-match-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcg-match-sub { font-size: 11px; color: var(--text2); }
.tcg-match-price { font-size: 12px; color: var(--green); font-weight: 600; white-space: nowrap; }

.result-multi-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: var(--text2); }
#resultCardList { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; overflow-y: auto; max-height: 420px; }
.scan-card-item { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.scan-card-item-header { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.scan-card-check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.scan-card-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; flex-shrink: 0; }
.scan-card-name { font-size: 14px; font-weight: 600; flex: 1; }
.scan-card-item-body { padding: 12px 14px; }
.scan-card-item-body .result-fields { margin-bottom: 10px; }
.scan-card-item-body .tcg-matches { max-height: 130px; }
.result-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.result-actions .input-select { flex: 1; min-width: 140px; }

/* ── Search ── */
.search-bar { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.source-toggle { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.source-label { font-size: 12px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; }
.search-bar .input-search { flex: 1; }
.btn-icon { padding: 8px 12px; font-size: 18px; }
.pagination { display: flex; align-items: center; gap: 16px; justify-content: center; padding: 24px 0; color: var(--text2); font-size: 13px; }

/* ── Spinner ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modals ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
}
.modal-wide { max-width: 760px; }
.modal h2 { font-size: 18px; font-weight: 700; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; color: var(--text2);
  font-size: 16px; cursor: pointer; padding: 4px 8px;
  border-radius: 4px; transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--text2); margin-bottom: -8px; text-transform: uppercase; letter-spacing: 0.4px; }

/* ── Card Detail Modal ── */
.card-detail-layout { display: flex; gap: 24px; }
@media (max-width: 600px) { .card-detail-layout { flex-direction: column; } }
.card-detail-img { flex-shrink: 0; width: 220px; }
.card-detail-img img { width: 100%; border-radius: 10px; box-shadow: var(--shadow); }
.card-detail-info { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.card-detail-info h2 { font-size: 22px; font-weight: 700; line-height: 1.2; }
.detail-set { font-size: 13px; color: var(--text2); }
.detail-artist { font-size: 13px; color: var(--text3); margin-top: -8px; }
.detail-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 4px;
  background: var(--bg4); color: var(--text2); border: 1px solid var(--border2);
}
.badge-type-fire { background: #f9731622; color: #fb923c; border-color: #f9731640; }
.badge-type-water { background: #3b82f622; color: #60a5fa; border-color: #3b82f640; }
.badge-type-grass { background: #22c55e22; color: #4ade80; border-color: #22c55e40; }
.badge-type-electric { background: #eab30822; color: #fbbf24; border-color: #eab30840; }
.badge-type-psychic { background: #a855f722; color: #c084fc; border-color: #a855f740; }
.badge-type-dark { background: #6b728022; color: #9ca3af; border-color: #6b728040; }
.badge-type-dragon { background: #6d28d922; color: #a78bfa; border-color: #6d28d940; }
.badge-rarity { background: #f5a62322; color: var(--accent2); border-color: #f5a62340; }

.price-table { background: var(--bg3); border-radius: var(--radius-sm); border: 1px solid var(--border); overflow: hidden; }
.price-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
.price-row:last-child { border-bottom: none; }
.price-row-label { color: var(--text2); }
.price-row-value { font-weight: 600; color: var(--text); }
.price-row-value.market { color: var(--green); font-size: 15px; }

.detail-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta-chip { font-size: 12px; color: var(--text3); background: var(--bg3); padding: 4px 10px; border-radius: 4px; }

.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.detail-actions .input-select { min-width: 140px; }

/* ── Virtual Binder ── */
.binder-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.binder-meta { display: flex; align-items: center; gap: 10px; }
.binder-grid-badge {
  font-size: 12px; font-weight: 700; padding: 4px 10px;
  background: var(--bg4); border: 1px solid var(--border2);
  border-radius: 6px; color: var(--accent); letter-spacing: 0.3px;
}
.binder-page-info { font-size: 13px; color: var(--text2); }
.binder-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.binder-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
}
.binder-nav-btn {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.binder-nav-btn:hover:not(:disabled) { background: var(--bg4); border-color: var(--blue); }
.binder-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
/* Mobile arrow row hidden on desktop */
.binder-nav-arrows { display: none; }

.binder-page-wrap {
  flex: 1;
  max-width: 1100px;
  display: flex;
  gap: 0;
  align-items: stretch;
}

/* Spine between the two pages */
.binder-spread-spine {
  width: 10px;
  flex-shrink: 0;
  background: linear-gradient(to right, var(--border), var(--bg3), var(--border));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.binder-page {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 14px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
}
/* Left page: rounded left corners only */
#binderPageLeft {
  border-radius: var(--radius) 0 0 var(--radius);
  border-right: none;
}
/* Right page: rounded right corners only */
#binderPageRight {
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: none;
}
/* Empty right page placeholder */
#binderPageRight.binder-page-empty {
  opacity: 0.35;
  pointer-events: none;
}
.binder-page.grid-2x2 { grid-template-columns: repeat(2, 1fr); }
.binder-page.grid-3x3 { grid-template-columns: repeat(3, 1fr); }
.binder-page.grid-4x4 { grid-template-columns: repeat(4, 1fr); }

.binder-slot {
  aspect-ratio: 2.5 / 3.5;
  border-radius: 10px;
  border: 2px dashed var(--border2);
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.binder-slot:hover { border-color: var(--blue); transform: translateY(-3px); box-shadow: var(--shadow); }
.binder-slot:hover .slot-hover-overlay { opacity: 1; }

.binder-slot.filled { border-style: solid; border-color: transparent; }
.binder-slot.owned { border-color: transparent; }
.binder-slot.not-owned img { filter: grayscale(70%) brightness(0.6); }
.binder-slot.placeholder-slot { border-style: dashed; border-color: var(--accent2); }
.binder-slot.placeholder-slot::after {
  content: 'Placeholder';
  position: absolute;
  bottom: 5px; left: 50%;
  transform: translateX(-50%);
  font-size: 9px; font-weight: 700;
  color: var(--accent2);
  background: rgba(0,0,0,0.65);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}
.binder-slot.not-owned::after {
  content: 'Not owned';
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: rgba(0,0,0,0.7);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}

.binder-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.slot-empty-icon {
  font-size: 28px;
  opacity: 0.25;
  pointer-events: none;
}

.slot-hover-overlay {
  position: absolute;
  inset: 0;
  background: rgba(59,130,246,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
  border-radius: 8px;
  font-size: 22px;
}

.slot-remove-btn {
  position: absolute;
  top: 5px; right: 5px;
  width: 20px; height: 20px;
  background: rgba(239,68,68,0.9);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.binder-slot:hover .slot-remove-btn { display: flex; }

.binder-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}
.binder-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border2);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.binder-dot.active { background: var(--blue); transform: scale(1.3); }

/* ── Grid Size Picker ── */
.grid-size-picker {
  display: flex;
  gap: 10px;
}
.grid-size-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 10px;
  border: 2px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
  font-weight: 600;
}
.grid-size-btn small { font-size: 11px; font-weight: 400; color: var(--text3); }
.grid-size-btn:hover { border-color: var(--blue); color: var(--text); }
.grid-size-btn.selected { border-color: var(--blue); background: #3b82f615; color: var(--text); }

.grid-preview {
  display: grid;
  gap: 2px;
  width: 44px; height: 44px;
}
.grid-preview span {
  background: var(--border2);
  border-radius: 2px;
}
.grid-2x2 { grid-template-columns: repeat(2, 1fr); }
.grid-3x3 { grid-template-columns: repeat(3, 1fr); }
.grid-4x4 { grid-template-columns: repeat(4, 1fr); }

/* ── Card Picker Modal ── */
.picker-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 14px;
}
.picker-tab {
  flex: 1;
  padding: 7px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.picker-tab.active { background: var(--bg4); color: var(--text); }

.picker-panel { min-height: 200px; }
.picker-loading { display: flex; justify-content: center; padding: 24px; }

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding: 2px;
}
.picker-card {
  aspect-ratio: 2.5/3.5;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition), transform var(--transition);
  position: relative;
  background: var(--bg3);
}
.picker-card:hover { border-color: var(--blue); transform: translateY(-2px); }
.picker-card.selected { border-color: var(--accent); }
.picker-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.picker-card-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--text3);
}
.manual-placeholder {
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  background: linear-gradient(135deg, var(--bg3), var(--bg4));
}
.manual-card-name {
  font-size: 9px;
  font-weight: 600;
  color: var(--text2);
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
  max-height: 40px;
  overflow: hidden;
}

/* Manual card image upload */
.manual-img-upload {
  border: 2px dashed var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition);
}
.manual-img-upload:hover { border-color: var(--blue); }
.manual-img-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px;
  min-height: 90px;
}
.manual-img-preview {
  position: relative;
  width: 100%;
}
.manual-img-preview img {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  display: block;
  background: var(--bg3);
}
.manual-img-remove {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,0.6);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 24px; height: 24px;
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.manual-img-remove:hover { background: var(--red); }
.picker-card .owned-dot {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px var(--bg3);
}

/* ── App wrap ── */
.app-wrap { display: contents; }
.app-wrap.hidden { display: none; }

/* ── Auth Screen ── */
.auth-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 24px;
}
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 14px;
}
.auth-logo {
  font-size: 20px; font-weight: 700;
  color: var(--accent); margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
.auth-logo span { font-size: 22px; }
.auth-card h2 { font-size: 20px; font-weight: 700; }
.auth-sub { font-size: 13px; color: var(--text2); margin-top: -8px; }
.btn-full { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.auth-error { font-size: 13px; color: #fca5a5; background: #ef444420; border: 1px solid #ef444440; padding: 8px 12px; border-radius: 6px; }

/* ── Sidebar user section ── */
.sidebar-user {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg3); border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-top: 8px;
}
.user-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--blue); color: #fff;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}
.user-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Users Table ── */
.users-table { display: flex; flex-direction: column; gap: 8px; max-width: 600px; }
.user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.user-row-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg4); color: var(--text2);
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}
.user-row-avatar.admin { background: #3b82f620; color: var(--blue); }
.user-row-info { flex: 1; min-width: 0; }
.user-row-name { font-size: 14px; font-weight: 600; }
.user-row-meta { font-size: 12px; color: var(--text2); margin-top: 1px; }
.user-row-actions { display: flex; gap: 6px; }

/* ── Loading Overlay ── */
.loading-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.loading-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; color: var(--text2); font-size: 14px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; z-index: 300;
  animation: slideInToast 0.2s ease, fadeOutToast 0.3s ease 3.2s forwards;
  max-width: 320px;
}
.toast-error { background: #ef444422; border: 1px solid #ef444460; color: #fca5a5; }
.toast-success { background: #22c55e22; border: 1px solid #22c55e60; color: #86efac; }
@keyframes slideInToast { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeOutToast { to { opacity: 0; transform: translateY(4px); } }

/* ── Utilities ── */
.hidden { display: none !important; }

/* ══════════════════════════════════════════
   MOBILE TOP BAR
══════════════════════════════════════════ */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 52px;
}
.mobile-topbar-left {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--accent);
}
.mobile-topbar-user { font-size: 13px; color: var(--text2); font-weight: 500; }
.mobile-topbar-right { display: flex; align-items: center; gap: 8px; }

/* ══════════════════════════════════════════
   MOBILE NAV
══════════════════════════════════════════ */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 6px 0 env(safe-area-inset-bottom, 0);
}
.mobile-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  background: none;
  border: none;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition);
}
.mobile-nav-btn span:first-child { font-size: 20px; }
.mobile-nav-btn.active { color: var(--accent); }

/* ══════════════════════════════════════════
   RESPONSIVE — TABLET & MOBILE
══════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Show mobile nav + topbar, hide sidebar */
  .mobile-nav { display: flex; }
  .mobile-topbar { display: flex; }
  .sidebar { display: none; }

  /* App layout — body is flex row; sidebar hidden so main fills width */
  .main { padding-bottom: 68px; padding-top: 52px; }
  .view { padding: 12px 14px; }
  .view-header { flex-wrap: wrap; gap: 10px; }
  .view-header h1 { font-size: 18px; }

  /* Toolbar wraps */
  .toolbar-row { flex-direction: column; align-items: stretch; }
  .toolbar-left { flex-wrap: wrap; }
  .toolbar-left .input-search { max-width: 100%; }
  .toolbar-right { justify-content: flex-end; }

  /* Card grid — 2 columns on mobile */
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  /* Card detail modal */
  .card-detail-layout { flex-direction: column; }
  .card-detail-img { width: 100%; max-width: 220px; margin: 0 auto; }

  /* Scan panel stacks vertically */
  .scan-panel-inner { grid-template-columns: 1fr; }
  .scan-panel-img-wrap { border-right: none; border-bottom: 1px solid var(--border); max-height: 200px; }
  #previewImg { max-height: 180px; }

  /* Search bar — keep on one line, just shrink */
  .search-bar { flex-wrap: nowrap; }
  .search-bar .input-search { min-width: 0; flex: 1; }
  .search-bar .btn { flex-shrink: 0; }

  /* Binder */
  .binder-layout { flex-direction: column; }
  /* Tighter binder spread on mobile */
  .binder-page { padding: 6px; gap: 5px; }
  .binder-spread-spine { width: 6px; }
  /* Stack: spread on top, arrows below centered */
  .binder-nav { flex-direction: column; gap: 8px; align-items: stretch; }
  .binder-page-wrap { max-width: 100%; }
  .binder-nav-arrows { display: flex; justify-content: center; gap: 24px; }
  .binder-nav-btn { width: 38px; height: 38px; min-width: 38px; font-size: 20px; }
  /* In desktop flex-row, hide the arrows-row; in mobile, hide side buttons */
  .binder-nav-btn.side-btn { display: none; }
  .binder-nav-arrows { display: flex; }

  /* Modals from bottom */
  .modal-backdrop { align-items: center; padding: 12px; padding-bottom: 80px; }
  .modal { border-radius: var(--radius); max-height: calc(100vh - 140px); overflow-y: auto; width: 100%; max-width: 100%; }
  .modal-wide { max-width: 100%; }

  /* Portfolio tabs scroll */
  .portfolio-tabs { overflow-x: auto; flex-wrap: nowrap; }

  /* Toast above mobile nav */
  .toast { bottom: 76px; right: 12px; left: 12px; max-width: 100%; text-align: center; }
}

@media (max-width: 420px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .binder-page.grid-3x3 { grid-template-columns: repeat(2, 1fr); }
  .binder-page.grid-4x4 { grid-template-columns: repeat(2, 1fr); }
}
