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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --success: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  padding: .75rem 0;
  white-space: nowrap;
}

nav { display: flex; gap: .25rem; }

.tab-btn {
  background: none;
  border: none;
  padding: .85rem .9rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

main { max-width: 680px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }

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

/* Upload area */
.upload-area {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-bottom: 1.5rem;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.upload-hint { color: var(--muted); font-size: .95rem; margin-bottom: .75rem; }
.upload-hint-small { color: var(--muted); font-size: .8rem; margin-top: .75rem; }

.upload-buttons { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem 1.1rem;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; font-size: .8rem; padding: .35rem .7rem; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

/* Upload progress */
.upload-progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.progress-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
}
.progress-item .filename { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-item .status { white-space: nowrap; color: var(--muted); }
.progress-item.done .status { color: var(--success); }
.progress-item.error .status { color: var(--danger); }

/* Receipts list */
.receipts-list { display: flex; flex-direction: column; gap: .75rem; }

.receipt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow .15s;
}
.receipt-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }

.receipt-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
}
.receipt-vendor { font-weight: 600; font-size: 1rem; }
.receipt-total { font-size: 1.1rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.receipt-meta { display: flex; gap: .75rem; margin-top: .35rem; font-size: .8rem; color: var(--muted); flex-wrap: wrap; align-items: center; }
.receipt-status { font-size: .75rem; padding: .15rem .45rem; border-radius: 4px; background: #fef3c7; color: #92400e; font-weight: 500; }
.receipt-status.processed { background: #d1fae5; color: #065f46; }

.loading-msg { text-align: center; color: var(--muted); padding: 2.5rem 0; font-size: .95rem; }
.empty-msg { text-align: center; color: var(--muted); padding: 2.5rem 0; }
.empty-msg p { margin-bottom: .5rem; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  margin: auto;
}
.modal-close {
  position: absolute;
  top: .75rem; right: .75rem;
  background: var(--border); border: none;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 1;
}
.modal-close:hover { background: #cbd5e1; }

.modal-img { width: 100%; max-height: 320px; object-fit: contain; border-radius: var(--radius) var(--radius) 0 0; background: #f1f5f9; }

.modal-body { padding: 1.25rem; }
.modal-vendor { font-size: 1.25rem; font-weight: 700; margin-bottom: .25rem; }
.modal-totals { display: flex; gap: 1.5rem; margin: .75rem 0; flex-wrap: wrap; }
.modal-total-item { display: flex; flex-direction: column; }
.modal-total-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.modal-total-value { font-size: 1.1rem; font-weight: 600; }

.line-items-table { width: 100%; border-collapse: collapse; font-size: .875rem; margin-top: .75rem; }
.line-items-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
.line-items-table td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.line-items-table tr:last-child td { border-bottom: none; }
.category-badge { font-size: .72rem; padding: .1rem .4rem; border-radius: 4px; background: #e0f2fe; color: #0369a1; white-space: nowrap; }

.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Summary */
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.summary-card-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .25rem; }
.summary-card-value { font-size: 1.5rem; font-weight: 700; }

.summary-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: .75rem; box-shadow: var(--shadow); }
.summary-section h3 { font-size: .9rem; font-weight: 600; margin-bottom: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.summary-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.summary-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
.summary-table td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); }
.summary-table tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }

/* Utilities */
.hidden { display: none !important; }
.text-muted { color: var(--muted); }
.mt-1 { margin-top: .5rem; }

@media (max-width: 480px) {
  header h1 { font-size: 1rem; }
  .modal-totals { gap: 1rem; }
  .line-items-table th:nth-child(2),
  .line-items-table td:nth-child(2) { display: none; }
}
