/* public/css/app.css — mobile-first */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Prevent iOS font size inflation on rotate */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

:root {
  --gold: #C9A84C;
  --gold-light: #F0D080;
  --gold-dim: #7A6028;
  --bg: #0E0E0F;
  --bg2: #161618;
  --bg3: #1E1E21;
  --border: rgba(201,168,76,0.18);
  --border-bright: rgba(201,168,76,0.5);
  --text: #F0EDE6;
  --text-dim: #8A8580;
  --danger: #E24B4A;
  --success: #1D9E75;
  --info: #378ADD;
  /* Safe areas for notched phones */
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  /* Bottom padding so FAB doesn't cover last card */
  padding-bottom: calc(80px + var(--safe-bottom));
}

/* ================================================================
   HEADER
================================================================ */
.header {
  padding: 1rem;
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--gold);
  line-height: 1.1;
}
.logo span {
  color: var(--text-dim);
  font-size: 0.65rem;
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  display: block;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 2px;
}
/* SVG logo images — swap dark/light variant with theme */
.logo-img          { display: block; height: 40px; width: auto; }
.logo-light        { display: none; }
[data-theme="light"] .logo-dark  { display: none; }
[data-theme="light"] .logo-light { display: block; }

.header-actions { display: flex; gap: 0.5rem; align-items: center; }

/* Export button hidden on smallest screens, shown on tablet+ */
#exportBtn { display: none; }

/* ================================================================
   BUTTONS — minimum 44px touch target
================================================================ */
.btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 0.5px solid var(--border-bright);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover, .btn:active { background: rgba(201,168,76,0.1); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #0E0E0F; border-color: var(--gold); }
.btn-primary:hover, .btn-primary:active { background: var(--gold-light); border-color: var(--gold-light); }
.btn-sm { font-size: 12px; min-height: 36px; padding: 6px 12px; }
.btn-danger { color: var(--danger); border-color: rgba(226,75,74,0.4); }
.btn-danger:hover, .btn-danger:active { background: rgba(226,75,74,0.1); }

/* ================================================================
   TOOLBAR — horizontal scroll on mobile
================================================================ */
.toolbar {
  padding: 0.75rem 1rem;
  padding-left: calc(0.75rem + var(--safe-left));
  padding-right: calc(0.75rem + var(--safe-right));
  display: flex;
  gap: 0.5rem;
  align-items: center;
  border-bottom: 0.5px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }

/* Filter button active state */
.btn.filter-active {
  background: rgba(201,168,76,0.15);
  border-color: var(--gold);
  color: var(--gold);
}

/* ================================================================
   FILTER PANEL — collapsible, below toolbar
================================================================ */
.filter-panel {
  display: none;
  padding: 0.75rem 1rem;
  padding-left: calc(0.75rem + var(--safe-left));
  padding-right: calc(0.75rem + var(--safe-right));
  border-bottom: 0.5px solid var(--border);
  background: var(--bg2);
  gap: 0.75rem;
  flex-direction: column;
}
.filter-panel.open { display: flex; }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
}

.filter-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.filter-range {
  display: flex;
  align-items: center;
  gap: 4px;
}
.filter-range span { color: var(--text-dim); font-size: 12px; }
.filter-range input {
  width: 70px;
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  outline: none;
  min-height: 36px;
  -webkit-appearance: none;
  appearance: none;
}
.filter-range input:focus { border-color: var(--border-bright); }

.filter-group select {
  min-height: 36px;
  font-size: 13px;
  padding: 6px 28px 6px 8px;
  min-width: 130px;
}

.filter-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filter-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.filter-chip:has(input:checked) {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201,168,76,0.1);
}
.filter-chip input { display: none; }

.search-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 160px;
}
.search-wrap input {
  width: 100%;
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px 10px 32px;
  font-size: 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  outline: none;
  min-height: 44px;
  -webkit-appearance: none;
}
.search-wrap input::placeholder { color: var(--text-dim); }
.search-wrap input:focus { border-color: var(--border-bright); }
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 14px;
  pointer-events: none;
}

select {
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  outline: none;
  cursor: pointer;
  min-height: 44px;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A8580' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.full-width { width: 100%; }

#refreshAllBtn { flex-shrink: 0; min-height: 44px; }

/* ================================================================
   STATS BAR
================================================================ */
.stats-bar {
  padding: 0.75rem 1rem;
  padding-left: calc(0.75rem + var(--safe-left));
  padding-right: calc(0.75rem + var(--safe-right));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-bottom: 0.5px solid var(--border);
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.25rem 0;
  border-right: 0.5px solid var(--border);
}
.stat:last-child { border-right: none; }
.stat-val { font-family: 'Playfair Display', serif; font-size: 1.1rem; color: var(--gold); }
.stat-label { font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; text-align: center; margin-top: 1px; }
.stat-value-card { min-width: 80px; }
.stat-analyzing .stat-label { color: #c9a84c; }
.stat-analyzing .stat-val   { color: #c9a84c; }
.stat-analyzing .stat-label::after { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #c9a84c; margin-left: 4px; vertical-align: middle; animation: analyzing-pulse 1.2s ease-in-out infinite; }
.stat-analyzing-active { background: rgba(201,168,76,0.08); border-radius: 8px; }
@keyframes analyzing-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.3; transform: scale(0.7); }
}

/* ================================================================
   SIDEBAR LAYOUT — two-column on tablet+
================================================================ */
.app-layout {
  display: block; /* single column on mobile */
}

.sidebar {
  display: none; /* hidden on mobile */
}

/* ================================================================
   GRID — 2 cols on mobile, more on larger screens
================================================================ */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  padding: 0.875rem;
  padding-left: calc(0.875rem + var(--safe-left));
  padding-right: calc(0.875rem + var(--safe-right));
}

/* ================================================================
   CARDS
================================================================ */
.card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
}
.card:active { border-color: var(--border-bright); opacity: 0.9; }

.card-img { width: 100%; aspect-ratio: 4/3; object-fit: contain; display: block; background: var(--bg3); }
.card-img-placeholder {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 1.5rem;
}

.card-body { padding: 0.625rem; }
.card-title {
  font-family: 'Playfair Display', serif;
  font-size: 0.8rem;
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta { font-size: 10px; color: var(--text-dim); margin-bottom: 6px; }
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }

.tag {
  font-size: 9px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tag-grade { background: rgba(201,168,76,0.15); color: var(--gold); }
.tag-cat { background: rgba(55,138,221,0.15); color: #5AA5F0; }
.tag-analyzing { background: rgba(55,138,221,0.1); color: #5AA5F0; animation: fadeInOut 1.5s infinite; }
@keyframes fadeInOut { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }

.card-value-label { font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.card-value { font-family: 'Playfair Display', serif; font-size: 0.95rem; color: var(--success); }

.card-meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 4px; }
.card-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(201,168,76,0.15);
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card-badge-rc {
  background: rgba(226,75,74,0.18);
  color: #E86060;
}
.card-badge-auto {
  background: rgba(138,99,210,0.2);
  color: #A87FE8;
}
.card-badge-grade-high {
  background: rgba(29,158,117,0.18);
  color: #2BB88A;
}
.card-badge-grade-mid {
  background: rgba(218,140,30,0.18);
  color: #D4920A;
}
.card-badge-sale {
  background: rgba(34,196,94,0.15);
  color: #1DB954;
}
.card-badge-trade {
  background: rgba(59,130,246,0.15);
  color: #60A5FA;
}
.card-badge-grade-low {
  background: rgba(226,75,74,0.18);
  color: #E86060;
}

.card-meta2 {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 3px;
  min-height: 0;
}
.card-year {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
}
.card-mfr {
  font-size: 10px;
  color: var(--text-dim);
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.card-analyzing {
  font-size: 9px;
  color: #5AA5F0;
  animation: fadeInOut 1.5s infinite;
  margin-top: 2px;
}
.card-queued {
  font-size: 9px;
  color: #9CA3AF;
  margin-top: 2px;
}

/* Tags — grid card pills */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
}
.tag-pill {
  font-size: 9px;
  font-weight: 500;
  color: var(--gold);
  background: rgba(201,168,76,0.12);
  border: 0.5px solid rgba(201,168,76,0.3);
  border-radius: 4px;
  padding: 1px 5px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
}
.tag-pill:hover { background: rgba(201,168,76,0.22); }

/* Tags — detail modal editor */
.tags-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  padding: 6px 0 2px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--gold);
  background: rgba(201,168,76,0.12);
  border: 0.5px solid rgba(201,168,76,0.3);
  border-radius: 5px;
  padding: 2px 7px 2px 8px;
}
.tag-chip-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  margin-left: 1px;
}
.tag-chip-remove:hover { color: var(--gold); }
.tag-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-bright);
  color: var(--text);
  font-size: 11px;
  padding: 2px 4px;
  outline: none;
  width: 110px;
}
.tag-input::placeholder { color: var(--text-dim); }

/* Tags — filter panel tag input */
.filter-tag-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  height: 28px;
}
.filter-tag-icon { font-size: 12px; color: var(--text-dim); }
#filterTag {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 12px;
  width: 120px;
}
#filterTag::placeholder { color: var(--text-dim); }

/* Split suggestion hint on grid card */
.card-split-hint {
  font-size: 9px;
  color: var(--gold);
  margin-top: 2px;
  opacity: 0.85;
}

/* Split suggestion banner in detail modal */
.split-banner {
  background: rgba(201,168,76,0.07);
  border: 0.5px solid rgba(201,168,76,0.35);
  border-radius: 10px;
  padding: 0.875rem 1rem;
  margin-bottom: 1rem;
  grid-column: 1 / -1;
}
.split-banner-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--gold);
  margin-bottom: 0.5rem;
}
.split-banner-list {
  margin: 0 0 0.75rem 1.1rem;
  padding: 0;
  font-size: 12px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.split-banner-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Condition sub-score breakdown in detail view */
.grade-breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.25rem;
}
.grade-sub { }
.grade-sub-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}
.grade-sub-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.grade-sub-score  { font-size: 11px; font-weight: 600; color: var(--gold); }
.grade-sub-note   { font-size: 10px; color: var(--text-dim); margin-top: 3px; line-height: 1.35; }

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 0.5px solid var(--border);
}
.card-actions { display: flex; gap: 4px; }
.img-count { font-size: 9px; color: var(--text-dim); }

/* ================================================================
   FLOATING ACTION BUTTON — mobile-only, thumb-friendly
================================================================ */
.fab {
  display: flex;
  position: fixed;
  bottom: calc(1.25rem + var(--safe-bottom));
  right: calc(1.25rem + var(--safe-right));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gold);
  color: #0E0E0F;
  font-size: 1.6rem;
  font-weight: 300;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 500;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.15s, background 0.15s;
  line-height: 1;
}
.fab:active { transform: scale(0.94); background: var(--gold-light); }

/* ================================================================
   EMPTY STATE
================================================================ */
.empty-state {
  grid-column: 1/-1;
  text-align: center;
  padding: 3rem 1rem;
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.25; }
.empty-state h3 { font-family: 'Playfair Display', serif; color: var(--text-dim); font-size: 1.1rem; margin-bottom: 0.4rem; }
.empty-state p { font-size: 13px; color: var(--text-dim); margin-bottom: 1.25rem; }

/* ================================================================
   MODALS — sheet style on mobile
================================================================ */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 1000;
  /* Mobile: align to bottom like a sheet */
  align-items: flex-end;
  justify-content: stretch;
}
.modal-bg.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 0.5px solid var(--border-bright);
  /* Mobile: full-width bottom sheet */
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--safe-bottom);
}

/* Sheet handle indicator */
.modal::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: var(--border-bright);
  border-radius: 2px;
  margin: 10px auto 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1.25rem;
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 1;
}
.modal-title { font-family: 'Playfair Display', serif; font-size: 1rem; color: var(--gold); }

.close-btn {
  background: var(--bg3);
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.close-btn:active { background: rgba(201,168,76,0.1); color: var(--text); }

.modal-inner { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.875rem; }

/* Detail modal — single column on mobile */
.modal-body {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 0.875rem 1.25rem;
  border-top: 0.5px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  background: var(--bg2);
}
.modal-footer .btn { flex: 1; min-width: 0; }

/* ================================================================
   UPLOAD ZONE — large tap target + camera capture
================================================================ */
.upload-zone {
  border: 1.5px dashed var(--border-bright);
  border-radius: 12px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.upload-zone:active { background: rgba(201,168,76,0.06); }
.upload-zone input[type=file] { display: none; }
.upload-icon { font-size: 2rem; opacity: 0.5; margin-bottom: 0.5rem; }
.upload-zone h3 { font-family: 'Playfair Display', serif; color: var(--gold); margin-bottom: 0.3rem; font-size: 1rem; }
.upload-zone p { font-size: 12px; color: var(--text-dim); }

/* Camera / Gallery buttons for mobile */
.upload-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}
.upload-actions .btn {
  flex: 1;
  font-size: 13px;
  min-height: 48px;
  flex-direction: column;
  gap: 2px;
}
.upload-actions .btn-icon { font-size: 1.2rem; line-height: 1; }

.field-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }

.thumb-row { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 8px;
  border: 1.5px solid transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.thumb.active { border-color: var(--gold); }
.thumb:active { opacity: 0.8; }
.thumb-add {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 1px dashed var(--border-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--gold);
  font-size: 1.4rem;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.thumb-add:active { background: rgba(201,168,76,0.1); }

.thumb-wrap {
  position: relative;
  display: inline-flex;
}
.thumb-extract-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  background: rgba(14,14,15,0.82);
  color: var(--gold);
  font-size: 10px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.thumb-wrap:hover .thumb-extract-btn,
.thumb-wrap:focus-within .thumb-extract-btn { opacity: 1; }
.thumb-cover-btn {
  position: absolute;
  bottom: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  background: rgba(14,14,15,0.82);
  color: var(--gold);
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.thumb-wrap:hover .thumb-cover-btn,
.thumb-wrap:focus-within .thumb-cover-btn { opacity: 1; }
.thumb-edit-btn {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  background: rgba(14,14,15,0.82);
  color: var(--text-dim);
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.thumb-wrap:hover .thumb-edit-btn,
.thumb-wrap:focus-within .thumb-edit-btn { opacity: 1; }
@media (pointer: coarse) {
  .thumb-extract-btn { opacity: 1; }
  .thumb-cover-btn { opacity: 1; }
  .thumb-edit-btn { opacity: 1; }
}
.edit-img-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem 0.5rem;
}
.edit-img-slider-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.edit-img-slider-wrap input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
}
.edit-img-rot-val {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 38px;
  text-align: right;
}
.edit-img-zoom-btns {
  display: flex;
  gap: 4px;
  margin-left: 4px;
}
.edit-img-zoom-btns .btn {
  width: 28px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.merge-item-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s, background 0.15s;
}
.merge-item-row:has(input:checked) {
  border-color: var(--gold);
  background: rgba(212,175,55,0.07);
}
.merge-item-row input[type="radio"] {
  flex-shrink: 0;
  accent-color: var(--gold);
}
.merge-item-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--surface2);
}
.merge-item-info {
  min-width: 0;
  flex: 1;
}
.merge-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.merge-item-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.note-input {
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  resize: vertical;
  min-height: 70px;
  outline: none;
  width: 100%;
  -webkit-appearance: none;
}
.note-input:focus { border-color: var(--border-bright); }

/* ================================================================
   DETAIL VIEW
================================================================ */
.img-gallery { display: flex; flex-direction: column; gap: 0.75rem; }
.main-img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: contain;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--bg3);
}

.detail-col { display: flex; flex-direction: column; gap: 0.875rem; }

.detail-section {
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 0.875rem;
}
.detail-section h4 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 0.625rem;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 6px;
  align-items: baseline;
}
.detail-label { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.detail-val { font-size: 13px; color: var(--text); text-align: right; word-break: break-word; }
.val-gold { color: var(--gold); font-family: 'Playfair Display', serif; font-size: 1rem; }
.val-gain { color: #4caf7d; }
.val-loss { color: #e05c5c; }

/* Paid / purchase price inline edit */
.paid-display {
  cursor: pointer;
  border-bottom: 1px dashed var(--border-bright);
  padding-bottom: 1px;
}
.paid-display:hover { border-bottom-color: var(--gold); color: var(--gold); }
.paid-empty { color: var(--text-dim); font-style: italic; }
.paid-input {
  background: var(--bg3);
  border: 0.5px solid var(--gold);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 2px 6px;
  outline: none;
  width: 90px;
  text-align: right;
}
.loc-input {
  background: var(--bg3);
  border: 0.5px solid var(--gold);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 2px 6px;
  outline: none;
  width: 160px;
}

/* Gain/loss on grid card */
.card-gain { font-size: 10px; color: #4caf7d; margin-top: 2px; }
.card-loss { font-size: 10px; color: #e05c5c; margin-top: 2px; }

/* AI category mismatch nudge button */
.ai-cat-btn {
  display: inline-block;
  font-size: 11px;
  padding: 3px 9px;
  margin-bottom: 0.6rem;
  background: transparent;
  border: 0.5px solid var(--gold);
  color: var(--gold);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.85;
}
.ai-cat-btn:hover { background: rgba(201,168,76,0.1); opacity: 1; }

.ai-notes { font-size: 13px; color: var(--text); line-height: 1.65; }
.ai-notes strong { color: var(--gold-light); }

.grade-bar { height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.grade-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); transition: width 0.6s ease; }

.analyzing-anim { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #5AA5F0; }
.dot-pulse { display: flex; gap: 4px; }
.dot-pulse span { width: 5px; height: 5px; background: #5AA5F0; border-radius: 50%; animation: dp 1.2s infinite ease-in-out; }
.dot-pulse span:nth-child(2) { animation-delay: 0.2s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dp { 0%,80%,100% { opacity: 0.2; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1.1); } }

/* History table */
.history-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.history-table th { color: var(--text-dim); text-align: left; padding: 4px 0; font-weight: 400; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.history-table td { padding: 5px 0; border-top: 0.5px solid var(--border); color: var(--text); }

/* ================================================================
   TOAST — centered on mobile
================================================================ */
.toast {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--bg3);
  border: 0.5px solid var(--border-bright);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  font-size: 13px;
  color: var(--text);
  z-index: 9999;
  transition: opacity 0.25s, transform 0.25s;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 2rem);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: rgba(226,75,74,0.6); color: var(--danger); }
.toast.success { border-color: rgba(29,158,117,0.6); color: var(--success); }

/* ================================================================
   COMBINE TOGGLE — shown in upload modal when 2+ photos selected
================================================================ */
.combine-toggle {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  padding: 0.5rem 0.75rem;
  background: rgba(201,168,76,0.04);
  border: 0.5px solid var(--border);
  border-radius: 8px;
}
.combine-toggle input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--gold);
  cursor: pointer;
}
.combine-toggle strong { color: var(--text); font-weight: 500; }

/* ================================================================
   DUPLICATE WARNING BANNER
================================================================ */
.dup-warning {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: rgba(201, 168, 76, 0.08);
  border: 0.5px solid rgba(201, 168, 76, 0.45);
  border-radius: 8px;
  font-size: 13px;
  color: var(--gold-light);
}
.dup-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}
.dup-dismiss:hover { color: var(--text); }

/* ================================================================
   CATEGORY SELECT — inline in detail view
================================================================ */
/* ================================================================
   ORIGINAL / CORRECTED TOGGLE — shown below main image when skew was applied
================================================================ */
.orig-toggle {
  display: flex;
  gap: 0;
  margin-top: 0.5rem;
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  align-self: flex-start;
}
.orig-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  font-family: inherit;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.orig-btn.active { background: var(--gold-dim); color: var(--text); }
.orig-btn:hover:not(.active) { color: var(--text); }

.detail-cat-select {
  background-color: var(--bg3);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%238A8580' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 3px 24px 3px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  min-height: unset;
}
.detail-cat-select:focus { outline: none; border-color: var(--gold); }

/* ================================================================
   NOTES EDITING
================================================================ */
.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.notes-header h4 { margin-bottom: 0; }
.notes-empty { color: var(--text-dim); font-style: italic; }
.notes-textarea {
  width: 100%;
  background: var(--bg3);
  border: 0.5px solid var(--border-bright);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 0.625rem 0.75rem;
  resize: vertical;
  min-height: 80px;
}
.notes-textarea:focus { outline: none; border-color: var(--gold); }
.notes-edit-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* ================================================================
   MARKET DATA (eBay sold listings)
================================================================ */
.market-query { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }
.market-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 1px 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.market-row:last-of-type { border-bottom: none; }
.market-title {
  grid-column: 1;
  grid-row: 1;
  font-size: 12px;
  color: var(--gold-light);
  text-decoration: none;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.market-title:hover { text-decoration: underline; }
.market-meta { grid-column: 1; grid-row: 2; font-size: 11px; color: var(--text-dim); }
.market-price { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; }

/* ================================================================
   VIEW TOGGLE (toolbar segmented control)
================================================================ */
.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}
.view-btn {
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  padding: 5px 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
  min-height: 32px;
  display: flex;
  align-items: center;
}
.view-btn:last-child { border-right: none; }
.view-btn:hover { background: var(--bg3); color: var(--text); }
.view-btn.active { background: var(--bg3); color: var(--gold); }

/* ================================================================
   COMPACT GRID MODE
================================================================ */
.grid.grid-compact {
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0.625rem;
}
.grid.grid-compact .card-img { aspect-ratio: 1/1; }
.grid.grid-compact .card-img-placeholder { aspect-ratio: 1/1; }
.grid.grid-compact .card-body { padding: 0.4rem 0.5rem; }
.grid.grid-compact .card-title { font-size: 0.7rem; }
.grid.grid-compact .card-meta2 { display: none; }
.grid.grid-compact .card-meta { font-size: 9px; }

@media (min-width: 640px) {
  .grid.grid-compact { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.75rem; }
}
@media (min-width: 900px) {
  .grid.grid-compact { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.875rem; }
}

/* ================================================================
   LIST VIEW MODE
================================================================ */
.grid.grid-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.5rem;
}
.grid.grid-list .card {
  display: flex;
  flex-direction: row;
  align-items: center;
  border-radius: 8px;
  margin-bottom: 4px;
  transform: none !important;
}
.grid.grid-list .card-img {
  width: 56px;
  height: 56px;
  aspect-ratio: unset;
  object-fit: cover;
  flex-shrink: 0;
  border-radius: 7px 0 0 7px;
}
.grid.grid-list .card-img-placeholder {
  width: 56px;
  height: 56px;
  aspect-ratio: unset;
  flex-shrink: 0;
  font-size: 1.1rem;
  border-radius: 7px 0 0 7px;
}
.grid.grid-list .card-body {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 0.625rem;
  padding: 0.5rem 0.75rem;
}
.grid.grid-list .card-title {
  grid-column: 1; grid-row: 1;
  font-size: 0.82rem;
  margin-bottom: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid.grid-list .card-meta2 {
  grid-column: 1; grid-row: 2;
  margin-bottom: 0;
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid.grid-list .card-meta {
  grid-column: 2; grid-row: 1 / span 2;
  align-self: center;
  margin-bottom: 0;
  flex-wrap: nowrap;
}
.grid.grid-list .card-analyzing,
.grid.grid-list .card-queued {
  grid-column: 1 / span 2; grid-row: 3;
  font-size: 9px;
}
.grid.grid-list .card-check {
  left: 4px; top: 50%; transform: translateY(-50%);
}
@media (min-width: 640px) {
  .grid.grid-list { padding: 0.75rem 1.25rem; gap: 0; }
  .grid.grid-list .card-img, .grid.grid-list .card-img-placeholder { width: 64px; height: 64px; }
}
@media (min-width: 900px) {
  .grid.grid-list { padding: 1rem 1.5rem; }
  .grid.grid-list .card-img, .grid.grid-list .card-img-placeholder { width: 72px; height: 72px; }
  .grid.grid-list .card-title { font-size: 0.875rem; }
}

/* ================================================================
   PAGINATION
================================================================ */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 1rem 0 0.5rem;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.page-btn:hover:not(:disabled) { background: var(--bg4, #2a2a2e); border-color: var(--gold); }
.page-btn.active { background: var(--gold); color: var(--bg); border-color: var(--gold); font-weight: 600; }
.page-btn:disabled { opacity: 0.35; cursor: default; }
.page-arrow { font-size: 16px; }
.page-ellipsis { color: var(--text-dim); padding: 0 4px; font-size: 13px; line-height: 34px; }
.page-info { font-size: 12px; color: var(--text-dim); margin-left: 8px; white-space: nowrap; }

/* ================================================================
   WISHLIST
================================================================ */
.wishlist-list { border-bottom: 1px solid var(--border); }
.wishlist-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}
.wishlist-row:hover { background: rgba(201,168,76,0.04); }
.wishlist-info { flex: 1; min-width: 0; }
.wishlist-name { font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 2px; }
.wishlist-meta { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.wishlist-target { color: var(--gold); }
.wishlist-notes { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.wishlist-btns { display: flex; gap: 4px; flex-shrink: 0; align-items: center; }
.wishlist-form {
  padding: 1rem 1.25rem;
  background: var(--bg3);
  border-top: 1px solid var(--border);
}
.wishlist-form-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

/* ================================================================
   TABLET — 640px+
================================================================ */
/* ================================================================
   SIDEBAR — item styles (layout rules in media queries below)
================================================================ */
.sidebar-heading {
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  padding: 0.875rem 1rem 0.5rem;
}

.sidebar-cat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.45rem 1rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s, background 0.15s;
  gap: 0.5rem;
}
.sidebar-cat:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.sidebar-cat.active { color: var(--gold); }
.sidebar-cat.active .sidebar-cat-name { font-weight: 500; }

.sidebar-cat-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-count {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg3);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.sidebar-cat.active .sidebar-count {
  background: rgba(201,168,76,0.15);
  color: var(--gold);
}

.sidebar-divider {
  height: 0.5px;
  background: var(--border);
  margin: 0.625rem 1rem;
}

/* Subcategory group (parent + collapsible children) */
.sidebar-group { display: flex; flex-direction: column; }

.sidebar-chevron {
  flex-shrink: 0;
  font-size: 8px;
  color: var(--text-dim);
  width: 14px;
  text-align: center;
  transition: transform 0.18s;
  margin-right: 2px;
}
.sidebar-group.open .sidebar-chevron { transform: rotate(90deg); }

.sidebar-children {
  display: none;
  flex-direction: column;
}
.sidebar-group.open .sidebar-children { display: flex; }

.sidebar-subcat {
  padding-left: 2rem; /* indent */
  font-size: 12px;
}
.sidebar-subcat .sidebar-count { font-size: 9px; }

@media (min-width: 640px) {
  body { padding-bottom: 0; }

  .header { padding: 1.25rem 1.5rem; }
  .logo { font-size: 1.6rem; }
  .logo-img { height: 44px; }
  #exportBtn { display: inline-flex; }

  /* Sidebar layout */
  .app-layout {
    display: flex;
    align-items: flex-start;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 190px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
    border-right: 0.5px solid var(--border);
    padding-top: 0.375rem;
    padding-bottom: 1rem;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .main-content { flex: 1; min-width: 0; }

  /* Hide the dropdown — sidebar handles category filtering on desktop.
     Exception: share page uses #shareCatFilter (same element, different id) so it stays visible there. */
  #catFilter { display: none; }

  .toolbar { padding: 0.875rem 1.25rem; overflow-x: visible; }
  .search-wrap { flex: 1; max-width: 260px; }

  .stats-bar {
    padding: 0.75rem 1.25rem;
    display: flex;
    gap: 2rem;
  }
  .stat { align-items: flex-start; border-right: none; padding: 0; }
  .stat-val { font-size: 1.25rem; }
  .stat-label { font-size: 10px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; padding: 1.25rem; }

  .card-body { padding: 0.75rem; }
  .card-title { font-size: 0.875rem; }
  .card-meta { font-size: 11px; }
  .tag { font-size: 10px; padding: 2px 7px; }
  .card-value { font-size: 1rem; }

  /* No FAB on tablet+ */
  .fab { display: none; }

  /* Centered modals on tablet+ */
  .modal-bg { align-items: center; justify-content: center; padding: 1rem; }
  .modal { border-radius: 12px; max-width: 520px; }
  .modal::before { display: none; }
  .modal-footer .btn { flex: 0 0 auto; }
}

/* ================================================================
   DESKTOP — 900px+
================================================================ */
@media (min-width: 900px) {
  .header { padding: 1.5rem 2rem 1rem; }
  .logo { font-size: 1.7rem; }
  .logo-img { height: 48px; }

  .sidebar { width: 210px; }

  .toolbar { padding: 0.875rem 1.5rem; gap: 0.75rem; }
  .search-wrap { max-width: 300px; }

  .stats-bar { padding: 0.75rem 1.5rem; gap: 2.5rem; }
  .stat-val { font-size: 1.3rem; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.25rem; padding: 1.5rem; }

  .card-body { padding: 0.875rem; }
  .card-title { font-size: 0.9rem; }
  .card:hover { border-color: var(--border-bright); transform: translateY(-2px); }

  /* Wide detail modal — two-column grid only for .modal-wide */
  .modal-wide { max-width: 880px; }
  .modal-wide .modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
  .detail-col { max-height: 70vh; overflow-y: auto; }
}

/* ================================================================
   Lightbox
   ================================================================ */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.96);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
#lightbox.open { display: flex; }

#lbImgWrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 3rem 3.5rem;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}
#lbImg {
  max-width: 100%;
  max-height: calc(100vh - 6rem);
  object-fit: contain;
  cursor: zoom-in;
  touch-action: pan-x pan-y pinch-zoom;
  border-radius: 4px;
  user-select: none;
  display: block;
}
#lbImg.zoomed {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}
#lbClose {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}
#lbClose:hover { background: rgba(255,255,255,0.25); }
#lbPrev, #lbNext {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
  padding-bottom: 2px;
}
#lbPrev:hover, #lbNext:hover { background: rgba(255,255,255,0.25); }
#lbPrev { left: 0.75rem; }
#lbNext { right: 0.75rem; }
#lbPrev:disabled, #lbNext:disabled { opacity: 0.2; cursor: default; pointer-events: none; }
#lbCounter {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  pointer-events: none;
  white-space: nowrap;
}

/* ================================================================
   Bulk selection
   ================================================================ */
.card-check {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: transparent;
  z-index: 2;
  pointer-events: none;
  backdrop-filter: blur(2px);
  transition: background 0.15s, border-color 0.15s;
}
.card.card-selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold);
}
.card.card-selected .card-check {
  background: var(--gold);
  border-color: var(--gold);
  color: #0E0E0F;
}
#selectBtn.active {
  background: rgba(201,168,76,0.15);
  border-color: var(--gold);
  color: var(--gold);
}
.bulk-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border-bright);
  padding: 0.65rem 1rem;
  padding-bottom: calc(0.65rem + var(--safe-bottom, 0px));
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 600;
  transform: translateY(100%);
  transition: transform 0.2s ease;
  flex-wrap: nowrap;
}
.bulk-bar.show { transform: translateY(0); }
#bulkCount {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 80px;
}
/* Bulk bar select — sized to match .btn-sm but themed as an input.
   The previous `btn btn-sm` class turned the select transparent + gold,
   which read as the wrong color in both the closed control and the
   native options popup (particularly noticeable in dark mode). */
.bulk-select {
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  min-height: 36px;
  padding: 6px 28px 6px 12px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A8580' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.bulk-select:disabled { opacity: 0.4; cursor: not-allowed; }
.bulk-select option { background: var(--bg3); color: var(--text); }

/* ================================================================
   2FA MODAL helper — reuse note-input style for inline inputs
================================================================ */
#twoFAModal .note-input {
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  outline: none;
  min-height: 44px;
  -webkit-appearance: none;
}
#twoFAModal .note-input:focus { border-color: var(--border-bright); }

/* ================================================================
   TIER PICKER — re-analyze quality selector
================================================================ */
.tier-picker {
  display: flex;
  gap: 0.4rem;
}
.tier-btn {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg3);
  color: var(--text-dim);
  font-size: 12px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.tier-btn:hover {
  border-color: var(--border-bright);
  color: var(--text);
}
.tier-btn-active {
  border-color: var(--gold);
  background: rgba(201,168,76,0.12);
  color: var(--gold);
}
.tier-hint {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 4px;
}
.tier-cost {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 400;
  margin-left: 4px;
}
.tier-btn-active .tier-cost {
  color: var(--gold);
  opacity: 0.75;
}

/* ================================================================
   ALBUM FOLDERS — folder view at top of main grid
================================================================ */
#albumFolders:empty { display: none; }

.album-folders-header {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0.5rem 0 0.75rem;
  font-weight: 600;
}

.album-folders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.album-folders-divider {
  border-top: 0.5px solid var(--border);
  margin: 0 0 1.25rem;
}

.album-folder {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
}
.album-folder:hover {
  border-color: var(--border-bright);
  transform: translateY(-2px);
  background: var(--bg3);
}

/* Fanned card thumbnails — rotated + offset for a "hand of cards" look */
.folder-thumbs {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.folder-thumbs-empty {
  background: var(--bg3);
  border-radius: 8px;
  font-size: 2.25rem;
  color: var(--text-dim);
  opacity: 0.5;
}

.folder-thumb {
  position: absolute;
  width: 55%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  border: 1px solid var(--bg);
  background: var(--bg3);
  transition: transform 0.2s;
}
/* Fanning positions — centered base, rotate outward */
.folder-thumbs-1 .folder-thumb-0 { transform: rotate(0deg); z-index: 3; }
.folder-thumbs-2 .folder-thumb-0 { transform: rotate(-8deg) translate(-18%, 0); z-index: 3; }
.folder-thumbs-2 .folder-thumb-1 { transform: rotate(8deg)  translate(18%, 0);  z-index: 2; }
.folder-thumbs-3 .folder-thumb-0 { transform: rotate(-10deg) translate(-28%, 4px); z-index: 2; }
.folder-thumbs-3 .folder-thumb-1 { transform: rotate(0deg)   translate(0, -4px);   z-index: 3; }
.folder-thumbs-3 .folder-thumb-2 { transform: rotate(10deg)  translate(28%, 4px);  z-index: 2; }

.album-folder:hover .folder-thumbs-2 .folder-thumb-0 { transform: rotate(-12deg) translate(-22%, 0); }
.album-folder:hover .folder-thumbs-2 .folder-thumb-1 { transform: rotate(12deg)  translate(22%, 0); }
.album-folder:hover .folder-thumbs-3 .folder-thumb-0 { transform: rotate(-14deg) translate(-32%, 4px); }
.album-folder:hover .folder-thumbs-3 .folder-thumb-2 { transform: rotate(14deg)  translate(32%, 4px); }

.folder-info { display: flex; flex-direction: column; gap: 2px; }
.folder-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-count {
  font-size: 12px;
  color: var(--text-dim);
}

.folder-vis-badge {
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  flex-shrink: 0;
}
.folder-vis-public {
  background: rgba(29,158,117,0.15);
  color: #1D9E75;
}

/* Breadcrumb when drilled into an album */
.album-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 0.5px solid var(--border);
  flex-wrap: wrap;
}

/* ================================================================
   MODAL INPUTS — shared input/textarea styling for modals
================================================================ */
.modal-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg3);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 0.6rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
}
.modal-input:focus { border-color: var(--gold); }

/* ================================================================
   SUPPORT TYPE BUTTONS — feedback/support modal type picker
================================================================ */
.support-type-btn {
  flex: 1;
  text-align: center;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.support-type-btn:hover { border-color: var(--border-bright); color: var(--text); }
.support-type-btn.active {
  border-color: var(--gold);
  background: rgba(201,168,76,0.12);
  color: var(--gold);
}

/* ================================================================
   Stats Modal
   ================================================================ */
.stats-modal-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.25rem;
}

/* Summary strip — big numbers at the top */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.stats-summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.875rem 0.5rem;
  border-right: 0.5px solid var(--border);
}
.stats-summary-item:last-child { border-right: none; }
.stats-summary-val { font-family: 'Playfair Display', serif; font-size: 1.5rem; color: var(--gold); line-height: 1.1; }
.stats-summary-lbl { font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 4px; text-align: center; }

/* Two-column layout for grade + manufacturer charts */
.stats-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* Generic section (title + content) */
.stats-section { display: flex; flex-direction: column; gap: 0.625rem; }
.stats-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  border-bottom: 0.5px solid var(--border);
  padding-bottom: 0.375rem;
}

/* Range toggle (value history chart) */
.range-toggle {
  display: flex;
  gap: 2px;
}
.range-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  padding: 2px 7px;
  transition: background 0.15s, color 0.15s;
}
.range-btn:hover { background: var(--surface2); color: var(--text); }
.range-btn.active { background: var(--gold); border-color: var(--gold); color: #0E0E0F; font-weight: 600; }

/* Horizontal bar chart rows */
.hbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
}
.hbar-label {
  font-size: 12px;
  color: var(--text);
  min-width: 70px;
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.hbar-track {
  flex: 1;
  height: 7px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
}
.hbar-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 4px;
  opacity: 0.85;
}
.hbar-val {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 26px;
  text-align: right;
  flex-shrink: 0;
}

.chart-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 0.75rem 0;
}

.ai-disclaimer {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 0.875rem;
  padding-top: 0.625rem;
  border-top: 0.5px solid var(--border);
  font-style: italic;
}

.month-svg, .value-svg { display: block; }

@media (max-width: 639px) {
  .stats-summary { grid-template-columns: repeat(3, 1fr); }
  .stats-summary-item:nth-child(3) { border-right: none; }
  .stats-summary-item:nth-child(4),
  .stats-summary-item:nth-child(5) { border-top: 0.5px solid var(--border); }
  .stats-charts-row { grid-template-columns: 1fr; }
  .stats-summary-val { font-size: 1.2rem; }
}

/* ================================================================
   LIGHT THEME
================================================================ */
[data-theme="light"] {
  --bg: #F5F1E8;
  --bg2: #ECE7DA;
  --bg3: #E3DCCF;
  --border: rgba(140,108,38,0.22);
  --border-bright: rgba(140,108,38,0.48);
  --text: #1C1916;
  --text-dim: #655C53;
  --gold: #7A5B10;
  --gold-light: #7A5B10;
  --gold-dim: #C9A84C;
}

/* Targeted overrides for hardcoded dark-only values */
[data-theme="light"] .sidebar-cat:hover { background: rgba(0,0,0,0.04); }
[data-theme="light"] .hbar-track        { background: rgba(0,0,0,0.1); }
[data-theme="light"] .site-footer       { border-top-color: var(--border); color: var(--text-dim); }
[data-theme="light"] .modal-bg          { background: rgba(0,0,0,0.6); }

/* Value gain/loss — dark mode greens/reds are too bright on parchment */
[data-theme="light"] .val-gain  { color: #1a6e3c; }
[data-theme="light"] .val-loss  { color: #b52727; }
[data-theme="light"] .card-gain { color: #1a6e3c; }
[data-theme="light"] .card-loss { color: #b52727; }

/* Grade badge tiers — darken for light mode contrast */
[data-theme="light"] .card-badge-grade-high { color: #1a6e3c; background: rgba(29,158,117,0.13); }
[data-theme="light"] .card-badge-grade-mid  { color: #7a4e08; background: rgba(218,140,30,0.15); }
[data-theme="light"] .card-badge-grade-low  { color: #ab2323; background: rgba(226,75,74,0.13); }

/* Theme toggle button (share + profile pages) */
.theme-toggle-btn {
  font-size: 15px;
  line-height: 1;
  padding: 0.3rem 0.5rem;
  font-variant-emoji: text;
}

/* ================================================================
   USER AVATAR CHIP + DROPDOWN MENU
================================================================ */
.user-chip-wrap {
  position: relative;
}

.user-avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg3);
  border: 1.5px solid var(--border-bright);
  color: var(--gold);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  letter-spacing: 0.04em;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
}
.user-avatar-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-avatar-btn:hover {
  border-color: var(--gold);
  background: rgba(201,168,76,0.1);
}

.user-menu-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 196px;
  background: var(--bg2);
  border: 0.5px solid var(--border-bright);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 2000;
  overflow: hidden;
}
.user-menu-dropdown.open { display: block; }

.user-menu-header {
  padding: 0.875rem 1rem 0.75rem;
}
.user-menu-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu-email {
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-divider {
  height: 0.5px;
  background: var(--border);
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
  box-sizing: border-box;
  text-decoration: none;
}
.user-menu-item:hover { background: rgba(201,168,76,0.08); }

.user-menu-item-danger { color: var(--danger); }
.user-menu-item-danger:hover { background: rgba(226,75,74,0.08); color: var(--danger); }

/* Plan badge + usage bar in dropdown */
.user-menu-plan-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.plan-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 20px;
  line-height: 1.6;
}
.plan-badge-free       { background: rgba(138,133,128,0.18); color: #8A8580; }
.plan-badge-collector  { background: rgba(82,148,226,0.18);  color: #5294E2; }
.plan-badge-pro        { background: rgba(201,168,76,0.22);  color: var(--gold); }

.user-menu-usage {
  padding: 0 1rem 0.75rem;
}
.usage-bar-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.usage-bar-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--gold);
  transition: width 0.3s ease;
}
.usage-bar-fill.usage-warn  { background: #DA8C1E; }
.usage-bar-fill.usage-crit  { background: var(--danger); }

[data-theme="light"] .plan-badge-free      { background: rgba(138,133,128,0.15); color: #575150; }
[data-theme="light"] .plan-badge-collector { background: rgba(82,148,226,0.15);  color: #235c9c; }
[data-theme="light"] .plan-badge-pro       { background: rgba(180,140,40,0.15);  color: #745700; }

/* ---- Photo suggestions (detail modal) ---- */
.photo-suggestions {
  margin-top: 0.875rem;
  background: rgba(82,148,226,0.07);
  border: 0.5px solid rgba(82,148,226,0.3);
  border-radius: 8px;
  padding: 0.75rem 0.875rem;
}
.photo-suggestions-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}
.photo-suggestions-list {
  margin: 0 0 0 1.1rem;
  padding: 0;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* ---- Onboarding banner ---- */
.onboarding-banner {
  background: rgba(201,168,76,0.07);
  border: 0.5px solid rgba(201,168,76,0.3);
  border-radius: 10px;
  padding: 1rem 1.125rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}
.onboarding-banner-body { flex: 1; min-width: 0; }
.onboarding-banner-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 0.625rem;
}
.onboarding-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.onboarding-step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  text-decoration: none;
}
.onboarding-step:hover { border-color: var(--gold); color: var(--text); }
.onboarding-step.done {
  color: var(--success, #1d9e75);
  border-color: rgba(29,158,117,0.4);
  text-decoration: line-through;
  cursor: default;
  pointer-events: none;
}
.onboarding-step-icon { font-size: 14px; line-height: 1; }
.onboarding-dismiss {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  margin-top: 1px;
}
.onboarding-dismiss:hover { color: var(--text); }
