@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700&family=Cormorant+Garamond:wght@300;400;500;600&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0a;
  --bg-card: #141414;
  --bg-elevated: #1a1a1a;
  --bg-modal: #111111;
  --gold: #c9a96e;
  --gold-light: #dfc08a;
  --gold-dark: #a88a4e;
  --text: #e8e8e8;
  --text-muted: #888888;
  --text-dim: #555555;
  --border: #2a2a2a;
  --success: #4ecdc4;
  --danger: #e74c3c;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Cormorant Garamond', Georgia, serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* ─── Header ─── */
.header {
  background: linear-gradient(180deg, #111 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 2rem 3rem;
  padding-top: calc(2rem + var(--safe-top));
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-brand {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 3px;
  text-transform: uppercase;
}

.header-brand span { color: var(--text-muted); font-size: 0.5em; letter-spacing: 1px; display: block; text-transform: none; font-family: 'Cormorant Garamond', serif; font-weight: 300; }

.header-stats {
  display: flex;
  gap: 2.5rem;
  align-items: center;
}

.stat {
  text-align: center;
}

.stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 2px;
}

.stat-gain { color: var(--success); }
.stat-loss { color: var(--danger); }

/* ─── Toolbar ─── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 3rem;
  gap: 1rem;
}

.filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1.2rem;
  min-height: 44px;
  border-radius: 20px;
  cursor: pointer;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.95rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-btn:hover { border-color: var(--gold-dark); color: var(--text); }
.filter-btn.active { background: var(--gold); color: var(--bg); border-color: var(--gold); font-weight: 600; }

.btn-add {
  background: linear-gradient(135deg, var(--gold-dark), var(--gold));
  color: var(--bg);
  border: none;
  padding: 0.7rem 1.8rem;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 1px;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-add:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(201,169,110,0.3); }

/* ─── Grid ─── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 0 3rem 3rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}

.card:hover { transform: translateY(-4px); border-color: var(--gold-dark); box-shadow: 0 12px 40px rgba(0,0,0,0.5); }

.card-img {
  width: 100%;
  height: 280px;
  object-fit: cover;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-img img { width: 100%; height: 100%; object-fit: cover; }

.card-img .placeholder {
  color: var(--text-dim);
  font-size: 3rem;
}

.card-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.card-loading .spinner {
  width: 20px;
  height: 20px;
}

.card-brand {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  color: var(--gold);
  padding: 4px 12px;
  border-radius: 4px;
  font-family: 'Playfair Display', serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.card-body { padding: 1rem 1.2rem; }

.card-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.card-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.card-price {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  color: var(--gold);
  font-weight: 600;
}

/* ─── Modal Overlay ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(0,0,0,0.5);
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 10;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.modal-close:hover { background: var(--bg-elevated); color: var(--text); }

/* ─── Add Modal ─── */
.add-modal-content { padding: 2.5rem; }

.add-modal-content h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  color: var(--gold);
  margin-bottom: 1.5rem;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 1.5rem;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-zone:hover { border-color: var(--gold-dark); }
.upload-zone.dragging { border-color: var(--gold); background: rgba(201,169,110,0.05); }

.upload-zone p { color: var(--text-muted); font-size: 1.1rem; }
.upload-zone .icon { font-size: 2.5rem; margin-bottom: 0.5rem; color: var(--gold-dark); }

.upload-zone input { display: none; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }

.form-group label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

.form-group input, .form-group textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.8rem;
  min-height: 44px;
  color: var(--text);
  font-family: 'Cormorant Garamond', serif;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

.form-group input:focus, .form-group textarea:focus { border-color: var(--gold-dark); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

.btn {
  padding: 0.7rem 1.5rem;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Playfair Display', serif;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
}

.btn-primary { background: var(--gold); color: var(--bg); }
.btn-primary:hover { background: var(--gold-light); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--gold-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.9rem; min-height: 44px; }

.parsing-indicator {
  display: none;
  text-align: center;
  padding: 2rem;
  color: var(--gold);
  font-size: 1.1rem;
}

.parsing-indicator.active { display: block; }

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Detail Modal ─── */
.detail-header {
  display: flex;
  gap: 2rem;
  padding: 2rem;
  border-bottom: 1px solid var(--border);
}

.detail-image {
  width: 300px;
  max-height: 400px;
  border-radius: 8px;
  overflow: hidden;
  background: #111111;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.detail-image img { width: 100%; height: 100%; object-fit: contain; max-height: 400px; }
.detail-image .placeholder { color: var(--text-dim); font-size: 4rem; }

.detail-info { flex: 1; display: flex; flex-direction: column; justify-content: center; }

.detail-brand {
  color: var(--gold);
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.detail-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.detail-subtitle { color: var(--text-muted); font-size: 1.1rem; margin-bottom: 1rem; }

.detail-price {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  color: var(--gold);
  font-weight: 600;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 1rem 1.5rem;
  min-height: 44px;
  cursor: pointer;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }

.tab-content { padding: 2rem; display: none; }
.tab-content.active { display: block; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.detail-field label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.detail-field .value {
  font-size: 1.05rem;
  color: var(--text);
}

/* Story tab */
.story-textarea {
  width: 100%;
  min-height: 200px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  color: var(--text);
  font-family: 'Cormorant Garamond', serif;
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  -webkit-appearance: none;
}

.story-textarea:focus { border-color: var(--gold-dark); }

.story-actions { margin-top: 1rem; display: flex; justify-content: flex-end; }

/* Market value tab */
.resale-display {
  text-align: center;
  padding: 2rem 0;
}

.resale-range {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

.resale-source { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.5rem; }
.resale-updated { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1.5rem; }

.resale-comparison { margin-top: 2rem; padding: 1.5rem; background: var(--bg-elevated); border-radius: 8px; }
.resale-comparison .label { color: var(--text-muted); font-size: 0.9rem; }
.resale-comparison .value { font-family: 'Playfair Display', serif; font-size: 1.4rem; margin-top: 4px; }

/* Receipt tab */
.receipt-details { max-width: 600px; }
.receipt-row { display: flex; justify-content: space-between; padding: 0.7rem 0; border-bottom: 1px solid var(--border); min-height: 44px; align-items: center; }
.receipt-row:last-child { border-bottom: none; }
.receipt-label { color: var(--text-muted); font-size: 0.95rem; }
.receipt-value { text-align: right; font-size: 0.95rem; }
.receipt-total { font-weight: 600; color: var(--gold); font-size: 1.1rem; }

/* ─── Image Viewer ─── */
.image-viewer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}

.image-viewer-overlay.active { display: flex; }
.image-viewer-overlay img { max-width: 90vw; max-height: 90vh; object-fit: contain; }

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  padding: 5rem 2rem;
  grid-column: 1 / -1;
}

.empty-state .icon { font-size: 4rem; margin-bottom: 1rem; opacity: 0.3; }
.empty-state h3 { font-family: 'Playfair Display', serif; font-size: 1.5rem; margin-bottom: 0.5rem; color: var(--text-muted); }
.empty-state p { color: var(--text-dim); font-size: 1rem; }

/* ═══════════════════════════════════════════
   MOBILE — max-width 768px
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Header: stack vertically */
  .header {
    flex-direction: column;
    gap: 1.2rem;
    padding: 1.2rem 1rem;
    padding-top: calc(1.2rem + var(--safe-top));
    text-align: center;
  }

  .header-brand { font-size: 1.6rem; letter-spacing: 2px; }

  .header-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem 1.5rem;
    width: 100%;
  }

  .stat-value { font-size: 1.2rem; }
  .stat-label { font-size: 12px; letter-spacing: 1.5px; }

  /* Toolbar */
  .toolbar {
    flex-direction: column;
    gap: 0.8rem;
    padding: 1rem;
    align-items: stretch;
  }

  /* Filters: horizontal scroll */
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    gap: 0.4rem;
  }
  .filters::-webkit-scrollbar { display: none; }

  .filter-btn { padding: 0.5rem 1rem; font-size: 0.9rem; flex-shrink: 0; }

  .btn-add { width: 100%; text-align: center; padding: 0.8rem; font-size: 1rem; }

  /* Grid: single column */
  .grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 0 1rem 1rem;
  }

  .card-img { height: 240px; }
  .card-body { padding: 0.8rem 1rem; }
  .card-name { font-size: 1.05rem; }
  .card-price { font-size: 1.1rem; }

  /* Modals: full-screen on mobile */
  .modal-overlay {
    padding: 0;
    align-items: stretch;
  }

  .modal {
    border-radius: 0;
    max-height: 100vh;
    max-height: 100dvh;
    height: 100%;
    border: none;
  }

  .modal-close {
    top: calc(8px + var(--safe-top));
    right: 8px;
    background: rgba(0,0,0,0.6);
  }

  /* Add modal */
  .add-modal-content {
    padding: 1.2rem;
    padding-top: calc(1.2rem + var(--safe-top));
  }

  .add-modal-content h2 { font-size: 1.3rem; margin-bottom: 1rem; }

  .upload-zone {
    padding: 2.5rem 1.5rem;
    min-height: 200px;
    border-width: 3px;
  }

  .upload-zone .icon { font-size: 3rem; }
  .upload-zone p { font-size: 1.1rem; }

  .form-grid { grid-template-columns: 1fr; gap: 0.8rem; }

  .form-group input, .form-group textarea {
    font-size: 16px; /* prevents iOS zoom */
    padding: 0.75rem 0.8rem;
  }

  .form-actions {
    flex-direction: column;
    gap: 0.8rem;
  }

  .form-actions .btn { width: 100%; text-align: center; }

  /* Detail modal */
  .detail-header {
    flex-direction: column;
    gap: 1rem;
    padding: 1.2rem;
    padding-top: calc(3.5rem + var(--safe-top));
  }

  .detail-image {
    width: 100%;
    max-height: 280px;
    border-radius: 8px;
  }

  .detail-brand { font-size: 0.8rem; }
  .detail-name { font-size: 1.4rem; }
  .detail-subtitle { font-size: 1rem; }
  .detail-price { font-size: 1.3rem; }

  .detail-actions { flex-wrap: wrap; }
  .detail-actions .btn { flex: 1; min-width: 120px; text-align: center; }

  /* Tabs */
  .tabs { padding: 0 1rem; }
  .tab-btn { padding: 0.8rem 1rem; font-size: 0.95rem; }

  .tab-content { padding: 1.2rem; }

  .detail-grid { grid-template-columns: 1fr; gap: 0.8rem; }

  .detail-field .value { font-size: 1rem; }

  .story-textarea { min-height: 160px; font-size: 16px; }

  .resale-range { font-size: 1.5rem; }
  .resale-comparison .value { font-size: 1.2rem; }

  .receipt-details { width: 100%; }

  /* Empty state */
  .empty-state { padding: 3rem 1.5rem; }
  .empty-state .icon { font-size: 3rem; }
  .empty-state h3 { font-size: 1.2rem; }

  /* Image viewer */
  .image-viewer-overlay img { max-width: 100vw; max-height: 100vh; }
}

/* ═══════════════════════════════════════════
   SMALL PHONES — max-width 380px
   ═══════════════════════════════════════════ */
@media (max-width: 380px) {
  .header-brand { font-size: 1.3rem; }
  .header-stats { gap: 0.5rem 1rem; }
  .stat-value { font-size: 1.05rem; }
  .card-img { height: 200px; }
  .detail-image { max-height: 220px; }
  .tab-btn { padding: 0.7rem 0.7rem; font-size: 0.88rem; }
}

/* ─── Delete zone ─── */
.delete-zone {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.btn-delete-subtle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.5rem 1rem;
  min-height: 44px;
  transition: color 0.2s;
}

.btn-delete-subtle:hover {
  color: var(--danger);
}

/* ─── Image Gallery ─── */
.gallery-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gallery-main {
  width: 300px;
  height: 400px;
  border-radius: 8px;
  overflow: hidden;
  background: #111111;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.gallery-main img { max-width: 100%; max-height: 400px; width: auto; height: auto; object-fit: contain; display: block; }
.gallery-main .placeholder { color: var(--text-dim); font-size: 4rem; }

.gallery-thumbs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0;
}

.gallery-thumbs::-webkit-scrollbar { display: none; }

.gallery-thumb {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: border-color 0.2s;
  background: var(--bg-elevated);
}

.gallery-thumb.active { border-color: var(--gold); }
.gallery-thumb:hover { border-color: var(--gold-dark); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Image viewer nav */
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  z-index: 10;
}

.viewer-nav:hover { background: rgba(201,169,110,0.5); }
.viewer-nav.prev { left: 20px; }
.viewer-nav.next { right: 20px; }

.viewer-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  background: rgba(0,0,0,0.6);
  padding: 4px 12px;
  border-radius: 12px;
}

@media (max-width: 768px) {
  .gallery-main { width: 100%; height: 280px; }
  .gallery-main img { max-height: 280px; width: auto; height: auto; }
  .gallery-thumbs { padding-bottom: 4px; }
  .gallery-thumb { width: 48px; height: 48px; }
}
