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

:root {
  --bg:          #0f0f11;
  --bg-card:     #18181c;
  --bg-raised:   #1f1f25;
  --bg-input:    #26262e;
  --border:      #2e2e38;
  --border-soft: #222228;
  --accent:      #e8c547;
  --accent-dim:  rgba(232,197,71,0.12);
  --accent-glow: rgba(232,197,71,0.25);
  --text:        #f0f0f2;
  --text-muted:  #7a7a8c;
  --text-soft:   #a0a0b4;
  --red:         #ff5a5a;
  --green:       #4ade80;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:   0 12px 48px rgba(0,0,0,0.6);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: rgba(15,15,17,0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-soft);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { font-family: 'Syne', sans-serif; font-size: 1.1rem; font-weight: 600; letter-spacing: -0.02em; }
.logo-text strong { color: var(--accent); font-weight: 800; }

.user-switcher { display: flex; gap: 6px; background: var(--bg-raised); border-radius: 50px; padding: 4px; }
.user-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 50px; border: none;
  background: transparent; color: var(--text-muted);
  font-family: 'DM Sans', sans-serif; font-size: 0.78rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
}
.user-btn.active { background: var(--accent); color: #000; font-weight: 700; }
.user-avatar { font-size: 0.72rem; font-weight: 700; }

.upload-fab-top {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 50px; border: none;
  background: var(--accent); color: #000;
  font-family: 'DM Sans', sans-serif; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.upload-fab-top:hover { background: #f0d060; transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }

/* ── Main ────────────────────────────────────────────────────────────── */
.main { max-width: 1280px; margin: 0 auto; padding: 28px 24px 80px; }

/* ── Stats ───────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color 0.2s;
}
.stat-card:hover { border-color: var(--border); }
.stat-card.accent { border-color: var(--accent); background: var(--accent-dim); }

.stat-label { font-size: 0.72rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-family: 'Syne', sans-serif; font-size: 1.7rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card.accent .stat-value { color: var(--accent); }

/* ── Filter Bar ──────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 20px;
}

.search-wrap {
  position: relative; display: flex; align-items: center;
}
.search-icon { position: absolute; left: 14px; color: var(--text-muted); pointer-events: none; }
.search-input {
  width: 100%;
  padding: 12px 40px 12px 42px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: 'DM Sans', sans-serif; font-size: 0.9rem;
  outline: none; transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }
.clear-btn {
  position: absolute; right: 12px;
  background: none; border: none; color: var(--text-muted);
  font-size: 1.2rem; cursor: pointer; line-height: 1; padding: 4px;
}

.filter-chips {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}

.filter-select, .filter-date {
  padding: 8px 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: 'DM Sans', sans-serif; font-size: 0.82rem;
  outline: none; cursor: pointer; transition: border-color 0.2s;
}
.filter-select:focus, .filter-date:focus { border-color: var(--accent); }
.filter-select option { background: var(--bg-card); }

.date-sep { color: var(--text-muted); font-size: 0.85rem; padding: 0 2px; }

/* ── Results Meta ────────────────────────────────────────────────────── */
.results-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.results-count { font-size: 0.8rem; color: var(--text-muted); font-family: 'DM Mono', monospace; }
.view-toggle { display: flex; gap: 4px; }
.view-btn {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-muted); cursor: pointer; transition: all 0.2s;
}
.view-btn.active { background: var(--accent); border-color: var(--accent); color: #000; }

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

.receipt-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  animation: fadeUp 0.3s ease both;
}
.receipt-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 8px 32px rgba(0,0,0,0.3), 0 0 0 1px var(--accent-glow); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-img-wrap {
  position: relative; height: 140px; overflow: hidden;
  background: var(--bg-raised);
}
.card-img { width: 100%; height: 100%; object-fit: cover; }
.card-img-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; background: var(--bg-raised);
}
.card-category-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(8px);
  border-radius: 6px; padding: 3px 8px;
  font-size: 0.7rem; font-weight: 600; color: var(--text);
}

.card-body { padding: 14px 16px; }
.card-store { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 0.95rem; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-date { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 10px; }
.card-footer { display: flex; justify-content: space-between; align-items: center; }
.card-total { font-family: 'DM Mono', monospace; font-size: 1rem; font-weight: 500; color: var(--accent); }
.card-person { font-size: 0.7rem; color: var(--text-muted); background: var(--bg-raised); border-radius: 4px; padding: 2px 7px; }

/* ── Receipt List ────────────────────────────────────────────────────── */
.receipt-list { display: flex; flex-direction: column; gap: 8px; }

.list-row {
  display: grid;
  grid-template-columns: 48px 1fr 140px 90px 80px 80px;
  gap: 16px; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  cursor: pointer; transition: border-color 0.2s;
  animation: fadeUp 0.3s ease both;
}
.list-row:hover { border-color: var(--accent); }
.list-thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--bg-raised); }
.list-thumb-placeholder { width: 40px; height: 40px; border-radius: 6px; background: var(--bg-raised); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.list-store { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-cat { font-size: 0.78rem; color: var(--text-muted); }
.list-date { font-size: 0.8rem; color: var(--text-soft); }
.list-total { font-family: 'DM Mono', monospace; font-size: 0.9rem; color: var(--accent); }
.list-person { font-size: 0.75rem; color: var(--text-muted); }

/* ── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 80px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-icon { font-size: 3.5rem; margin-bottom: 8px; }
.empty-state h3 { font-family: 'Syne', sans-serif; font-size: 1.3rem; font-weight: 700; }
.empty-state p { color: var(--text-muted); font-size: 0.9rem; max-width: 300px; }

/* ── Load More ───────────────────────────────────────────────────────── */
.load-more-wrap { text-align: center; padding: 28px 0; }
.load-more-btn {
  padding: 10px 28px; border: 1px solid var(--border); border-radius: 50px;
  background: transparent; color: var(--text-soft); font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem; cursor: pointer; transition: all 0.2s;
}
.load-more-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Modals ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px; overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
  max-height: 90vh; display: flex; flex-direction: column;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 24px 28px 0;
}
.modal-header h2 { font-family: 'Syne', sans-serif; font-size: 1.3rem; font-weight: 700; }
.modal-sub { font-size: 0.82rem; color: var(--text-muted); margin-top: 3px; }
.modal-header-actions { display: flex; gap: 8px; align-items: center; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.6rem; cursor: pointer; line-height: 1; padding: 0 4px; transition: color 0.2s; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px 28px; overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 28px 24px; border-top: 1px solid var(--border-soft); }

/* Upload Modal */
.upload-modal { width: 100%; max-width: 480px; }
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius); padding: 40px 24px;
  text-align: center; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 20px;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); background: var(--accent-dim); }
.drop-icon { margin-bottom: 12px; }
.drop-text { font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; }
.drop-sub { font-size: 0.78rem; color: var(--text-muted); }

.upload-preview { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; padding: 12px; background: var(--bg-raised); border-radius: var(--radius-sm); }
.upload-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.preview-info { flex: 1; min-width: 0; }
.preview-filename { font-size: 0.82rem; color: var(--text-soft); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.upload-meta { display: flex; align-items: center; gap: 12px; }
.meta-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.meta-user-display { font-size: 0.85rem; font-weight: 700; color: var(--accent); background: var(--accent-dim); border-radius: 6px; padding: 4px 12px; }

.upload-progress { margin-top: 20px; }
.progress-bar { height: 4px; background: var(--bg-raised); border-radius: 2px; overflow: hidden; margin-bottom: 8px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; width: 0%; transition: width 0.4s ease; }
.progress-text { font-size: 0.82rem; color: var(--text-muted); text-align: center; }

/* Detail Modal */
.detail-modal { width: 100%; max-width: 900px; }
.detail-body { display: grid; grid-template-columns: 320px 1fr; gap: 28px; }
.detail-left { position: relative; }
.detail-img { width: 100%; border-radius: 12px; border: 1px solid var(--border); }

.detail-right { display: flex; flex-direction: column; gap: 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.detail-field { display: flex; flex-direction: column; gap: 6px; }
.detail-field label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.detail-field.full-width { grid-column: 1 / -1; }

.detail-input {
  padding: 9px 12px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: 'DM Sans', sans-serif; font-size: 0.88rem;
  outline: none; transition: border-color 0.2s;
}
.detail-input:focus { border-color: var(--accent); }
.detail-textarea { resize: vertical; min-height: 70px; }
.detail-select { cursor: pointer; }
.detail-select option { background: var(--bg-card); }

.detail-items { background: var(--bg-raised); border-radius: var(--radius-sm); padding: 14px; }
.items-title { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }
.item-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border-soft); font-size: 0.83rem; }
.item-row:last-child { border-bottom: none; }
.item-name { color: var(--text-soft); flex: 1; margin-right: 8px; }
.item-qty { color: var(--text-muted); margin-right: 8px; }
.item-price { font-family: 'DM Mono', monospace; color: var(--accent); }

.extraction-badge { font-size: 0.72rem; font-family: 'DM Mono', monospace; padding: 4px 10px; border-radius: 4px; width: fit-content; }
.extraction-badge.success { background: rgba(74,222,128,0.1); color: var(--green); }
.extraction-badge.error { background: rgba(255,90,90,0.1); color: var(--red); }
.extraction-badge.skipped { background: var(--bg-raised); color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 50px; border: none;
  background: var(--accent); color: #000;
  font-family: 'DM Sans', sans-serif; font-size: 0.88rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
}
.btn-primary:hover { background: #f0d060; box-shadow: 0 4px 16px var(--accent-glow); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-ghost {
  padding: 10px 20px; border-radius: 50px;
  border: 1px solid var(--border); background: transparent; color: var(--text-soft);
  font-family: 'DM Sans', sans-serif; font-size: 0.88rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
}
.btn-ghost:hover { border-color: var(--text-soft); color: var(--text); }
.btn-ghost.small { padding: 6px 12px; font-size: 0.78rem; }
.btn-ghost.danger { color: var(--red); border-color: transparent; }
.btn-ghost.danger:hover { border-color: var(--red); background: rgba(255,90,90,0.08); }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 999; padding: 12px 24px; border-radius: 50px;
  background: var(--bg-raised); border: 1px solid var(--border);
  font-size: 0.85rem; font-weight: 500; box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
}
.toast.success { background: rgba(74,222,128,0.15); border-color: var(--green); color: var(--green); }
.toast.error { background: rgba(255,90,90,0.15); border-color: var(--red); color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(12px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── Mobile FAB ──────────────────────────────────────────────────────── */
.mobile-fab {
  display: none;
  position: fixed; bottom: 24px; right: 24px; z-index: 150;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--accent); color: #000;
  box-shadow: 0 6px 24px var(--accent-glow);
  cursor: pointer; align-items: center; justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.mobile-fab:hover { transform: scale(1.08); }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .detail-body { grid-template-columns: 1fr; }
  .detail-left { max-height: 240px; overflow: hidden; border-radius: 12px; }
  .detail-img { width: 100%; height: 240px; object-fit: contain; background: var(--bg-raised); }
}

@media (max-width: 720px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  .upload-fab-top span { display: none; }
  .upload-fab-top { padding: 8px 10px; }
  .mobile-fab { display: flex; }
  .main { padding: 20px 16px 100px; }
  .topbar { padding: 0 16px; }
  .filter-chips { flex-wrap: wrap; }
  .list-row { grid-template-columns: 40px 1fr 80px; }
  .list-cat, .list-date, .list-person { display: none; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 1.3rem; }
  .receipt-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .detail-grid { grid-template-columns: 1fr; }
}

/* ── Current User Chip ───────────────────────────────────────────────── */
.current-user-chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 50px; padding: 5px 14px 5px 10px;
  font-size: 0.82rem; font-weight: 600; color: var(--text-soft);
}
.user-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
  box-shadow: 0 0 6px var(--accent-glow);
}

/* ── Source Chooser ──────────────────────────────────────────────────── */
.source-chooser {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 20px;
}
.source-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 24px 16px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--bg-raised);
  cursor: pointer; transition: all 0.2s; text-align: center;
}
.source-btn:hover { border-color: var(--accent); background: var(--accent-dim); transform: translateY(-2px); }
.source-icon { font-size: 2rem; line-height: 1; }
.source-label { font-family: 'Syne', sans-serif; font-size: 0.88rem; font-weight: 700; color: var(--text); }
.source-sub { font-size: 0.72rem; color: var(--text-muted); }


::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
