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

:root {
  --bg: #0a0a0f;
  --bg2: #12121a;
  --bg3: #1a1a28;
  --surface: #1e1e30;
  --surface-hover: #2a2a40;
  --border: #2a2a3e;
  --text: #e8e8f0;
  --text2: #9898b0;
  --text3: #686880;
  --accent: #6c5ce7;
  --accent-hover: #7c6cf7;
  --green: #00d68f;
  --red: #ff6b6b;
  --orange: #ffa726;
  --blue: #5b8def;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app { height: 100%; overflow: hidden; }

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  position: absolute;
  inset: 0;
  background: var(--bg);
}
.screen.active { display: flex; }

/* Splash */
#splash {
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: linear-gradient(135deg, #0a0a0f 0%, #12121a 50%, #1a1030 100%);
}
.splash-icon { font-size: 64px; margin-bottom: 16px; }
#splash h1 { font-size: 28px; font-weight: 700; background: linear-gradient(135deg, #6c5ce7, #a78bfa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.splash-sub { color: var(--text2); margin-top: 8px; }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin-top: 32px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  padding-top: env(safe-area-inset-top, 16px);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 60px;
}
header h1.logo { font-size: 20px; font-weight: 700; }
header h2 { font-size: 18px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; }

/* Buttons */
.btn-icon {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--surface); color: var(--text); font-size: 18px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover, .btn-icon:active { background: var(--surface-hover); transform: scale(1.05); }
.btn-back {
  background: none; border: none; color: var(--accent); font-size: 16px;
  cursor: pointer; padding: 8px; font-weight: 500;
}
.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: var(--radius);
  background: var(--accent); color: white; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.btn-primary:hover, .btn-primary:active { background: var(--accent-hover); transform: scale(1.01); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-sm {
  background: var(--surface); border: none; color: var(--text2); 
  border-radius: var(--radius-sm); padding: 4px 10px; cursor: pointer; font-size: 12px;
}

/* Search bar */
.search-bar {
  display: flex; gap: 8px; padding: 12px 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.search-bar input {
  flex: 1; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); font-size: 14px; outline: none;
  transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar select {
  padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); font-size: 13px; outline: none;
  cursor: pointer;
}

/* Stats bar */
.stats-bar {
  display: flex; align-items: center; gap: 20px; padding: 12px 16px;
  background: linear-gradient(135deg, #1a1030, #12121a); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.stats-bar.hidden { display: none; }
.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }
.stat span:last-child { font-size: 18px; font-weight: 700; color: var(--green); }

/* Receipt list */
.receipt-list {
  flex: 1; overflow-y: auto; padding: 8px 16px;
  -webkit-overflow-scrolling: touch;
}

.receipt-list::-webkit-scrollbar { width: 4px; }
.receipt-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 60%; text-align: center;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.6; }
.empty-state h3 { font-size: 20px; margin-bottom: 8px; }
.empty-state p { color: var(--text2); }

/* Receipt card */
.receipt-card {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px; margin-bottom: 10px;
  background: var(--surface); border-radius: var(--radius);
  cursor: pointer; transition: all 0.2s;
  border: 1px solid transparent;
}
.receipt-card:hover, .receipt-card:active {
  background: var(--surface-hover); border-color: var(--border);
  transform: translateY(-1px);
}
.receipt-card .rc-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  background: var(--bg3); display: flex; align-items: center;
  justify-content: center; font-size: 20px; flex-shrink: 0;
}
.cat-groceries { background: #1a3a2a !important; }
.cat-dining { background: #3a2a1a !important; }
.cat-transport { background: #1a2a3a !important; }
.cat-shopping { background: #2a1a3a !important; }
.cat-entertainment { background: #3a1a2a !important; }
.cat-health { background: #1a3a3a !important; }
.cat-travel { background: #2a3a1a !important; }

.receipt-card .rc-info { flex: 1; min-width: 0; }
.receipt-card .rc-merchant { font-size: 15px; font-weight: 600; margin-bottom: 3px; }
.receipt-card .rc-date { font-size: 12px; color: var(--text3); }
.receipt-card .rc-items { font-size: 12px; color: var(--text2); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receipt-card .rc-total {
  font-size: 17px; font-weight: 700; color: var(--green);
  text-align: right; flex-shrink: 0;
}
.receipt-card .rc-cat {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text3); text-align: right; margin-top: 2px;
}

/* FAB */
.fab {
  position: fixed; bottom: 24px; right: 24px;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--accent); color: white; font-size: 28px; font-weight: 300;
  cursor: pointer; box-shadow: 0 4px 20px rgba(108,92,231,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; z-index: 10;
}
.fab:hover, .fab:active { transform: scale(1.1); box-shadow: 0 6px 28px rgba(108,92,231,0.6); }

/* Scan view */
.scan-body {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px; gap: 20px;
}
.scan-options { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 320px; }
.scan-btn {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 18px 20px; border-radius: var(--radius); border: 2px dashed var(--border);
  background: var(--surface); color: var(--text); font-size: 16px;
  cursor: pointer; transition: all 0.2s;
}
.scan-btn:hover, .scan-btn:active {
  border-color: var(--accent); background: var(--surface-hover);
}
.scan-btn-icon { font-size: 28px; }
.scan-preview { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.scan-preview.hidden { display: none; }
.scan-preview img { width: 100%; max-height: 400px; object-fit: contain; border-radius: var(--radius); border: 1px solid var(--border); }
.scan-status {
  text-align: center; padding: 20px; color: var(--text2);
}
.scan-status.hidden { display: none; }
.scan-status.loading { color: var(--accent); }
.scan-status.error { color: var(--red); }
.scan-status.success { color: var(--green); }

/* Detail view */
.detail-body {
  flex: 1; overflow-y: auto; padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.detail-header { text-align: center; margin-bottom: 20px; }
.detail-merchant { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.detail-date { font-size: 13px; color: var(--text2); }
.detail-cat { display: inline-block; margin-top: 8px; padding: 4px 12px; border-radius: 20px; background: var(--surface); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text2); }

.detail-totals {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px;
}
.detail-total-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  text-align: center;
}
.detail-total-card .ttl-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }
.detail-total-card .ttl-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.detail-total-card .ttl-value.green { color: var(--green); }
.detail-total-card .ttl-value.blue { color: var(--blue); }
.detail-total-card .ttl-value.orange { color: var(--orange); }

.detail-section { margin-bottom: 20px; }
.detail-section h3 { font-size: 13px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }

.detail-items { display: flex; flex-direction: column; gap: 8px; }
.detail-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--surface); border-radius: var(--radius-sm);
}
.detail-item .di-name { font-size: 14px; }
.detail-item .di-qty { font-size: 11px; color: var(--text3); margin-left: 6px; }
.detail-item .di-price { font-size: 14px; font-weight: 500; color: var(--text2); }

.detail-edit-field { margin-bottom: 14px; }
.detail-edit-field label { display: block; font-size: 12px; color: var(--text3); margin-bottom: 6px; font-weight: 500; }
.detail-edit-field input, .detail-edit-field select, .detail-edit-field textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); font-size: 14px; outline: none;
}
.detail-edit-field input:focus, .detail-edit-field select:focus, .detail-edit-field textarea:focus {
  border-color: var(--accent);
}
.detail-edit-field textarea { resize: vertical; min-height: 60px; font-family: inherit; }

.detail-actions { display: flex; gap: 10px; margin-top: 20px; }
.detail-actions button { flex: 1; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200; backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border-radius: 20px 20px 0 0; padding: 24px;
  width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 12px;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h2 { font-size: 18px; text-align: center; margin-bottom: 8px; }
.modal-btn {
  padding: 14px; border-radius: var(--radius); border: none;
  background: var(--surface); color: var(--text); font-size: 15px;
  cursor: pointer; transition: all 0.2s; text-align: center;
}
.modal-btn:hover, .modal-btn:active { background: var(--surface-hover); }
.modal-btn.secondary { background: transparent; color: var(--text2); }

/* Toast */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--surface); color: var(--text); padding: 12px 20px;
  border-radius: var(--radius); font-size: 14px; z-index: 300;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  animation: toastIn 0.3s ease; pointer-events: none;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* Responsive */
@media (min-width: 600px) {
  #main-view { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  #scan-view { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  #detail-view { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
