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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #059669;
  --success-hover: #047857;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

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

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 60px;
}
header h1 { font-size: 1.2rem; font-weight: 700; white-space: nowrap; }
nav { display: flex; gap: 4px; }
.nav-btn {
  background: none;
  border: none;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-muted);
  font-weight: 500;
  transition: all .15s;
}
.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active { background: var(--primary); color: #fff; }

/* Views */
.view { display: none; max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.view.active { display: block; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-full { width: 100%; justify-content: center; margin-top: 16px; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1.1rem; padding: 4px; border-radius: 6px; }
.btn-icon:hover { background: var(--bg); }

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.drop-zone.drag-over { border-color: var(--primary); background: #f0f0ff; }
.drop-content { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.drop-icon { font-size: 3rem; }
.drop-content p { color: var(--text-muted); font-size: .95rem; }
.upload-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.preview-img {
  max-width: 100%;
  max-height: 340px;
  border-radius: 8px;
  object-fit: contain;
}
.hidden { display: none !important; }

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result panel */
.result-grid { display: grid; grid-template-columns: 1fr 1.6fr; gap: 24px; }
@media (max-width: 640px) { .result-grid { grid-template-columns: 1fr; } }

.result-receipt-img {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.field-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field-row label { font-size: .8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.field-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.field-input:focus { border-color: var(--primary); }

.items-section { margin-bottom: 16px; }
.items-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; font-size: .9rem; }
.items-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }

.item-row {
  display: grid;
  grid-template-columns: 1fr 120px 90px 32px;
  gap: 6px;
  align-items: center;
}
.item-row input, .item-row select { padding: 6px 8px; font-size: .85rem; }
.item-delete { color: var(--danger); background: none; border: none; cursor: pointer; font-size: 1rem; padding: 4px; border-radius: 4px; }
.item-delete:hover { background: #fee2e2; }

.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 2px solid var(--border);
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 16px;
}
.total-input { width: 120px; text-align: right; font-weight: 700; }

.action-buttons { display: flex; gap: 10px; justify-content: flex-end; }

/* Overview */
.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-row .field-input { width: auto; }

.receipt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: box-shadow .15s;
}
.receipt-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.12); }
.receipt-card-info { display: flex; flex-direction: column; gap: 2px; }
.receipt-card-store { font-weight: 700; font-size: 1rem; }
.receipt-card-date { font-size: .85rem; color: var(--text-muted); }
.receipt-card-items { font-size: .8rem; color: var(--text-muted); }
.receipt-card-total { font-size: 1.15rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.receipt-card-actions { display: flex; gap: 6px; }
.empty-state { text-align: center; color: var(--text-muted); padding: 60px 0; font-size: 1rem; }

/* Summary */
.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.summary-total { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.summary-sub { font-size: .85rem; color: var(--text-muted); }

.category-row {
  display: grid;
  grid-template-columns: 1fr auto 80px;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.category-row:last-child { border-bottom: none; }
.category-name { font-weight: 600; }
.category-bar-wrap { width: 120px; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.category-bar { height: 100%; background: var(--primary); border-radius: 3px; }
.category-amount { font-weight: 700; text-align: right; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}
#modal-body { padding: 20px 24px 24px; }

.modal-receipt-img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.modal-meta { display: flex; gap: 20px; margin-bottom: 20px; }
.modal-meta-item { display: flex; flex-direction: column; gap: 2px; }
.modal-meta-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; letter-spacing: .04em; }
.modal-meta-value { font-size: 1rem; font-weight: 600; }

.modal-items-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.modal-items-table th {
  text-align: left;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 6px 8px;
  border-bottom: 2px solid var(--border);
}
.modal-items-table td { padding: 8px 8px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.modal-items-table tr:last-child td { border-bottom: none; }
.modal-items-table .amount-col { text-align: right; font-weight: 600; }
.modal-total-row { display: flex; justify-content: space-between; padding: 12px 0; border-top: 2px solid var(--border); font-weight: 700; font-size: 1.05rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Category badge */
.cat-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  background: #ede9fe;
  color: #5b21b6;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
  animation: slide-in .25s ease;
}
@keyframes slide-in { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
