:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --ink: #2a2a28;
  --muted: #6b6a66;
  --accent: #7a5c3e;
  --accent-light: #ede4d8;
  --border: #e2ded6;
  --radius: 10px;
  --status-complete-bg: #e3ecdf;
  --status-complete-text: #4a7a3e;
  --status-incomplete-bg: #f5e4d0;
  --status-incomplete-text: #a5651a;
  --status-duplicate-bg: #f6dede;
  --status-duplicate-text: #a33a3a;
  --status-voided-bg: #e8e6e2;
  --status-voided-text: #6b6a66;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

header h1 { font-size: 1.25rem; margin: 0; }

main {
  max-width: 900px;
  margin: 1.5rem auto;
  padding: 0 1rem;
  display: grid;
  gap: 1.25rem;
}

section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

h2 { margin-top: 0; font-size: 1.05rem; }
h3 { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.5rem; }

#upload-form {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

input[type="file"] {
  flex: 1;
  min-width: 200px;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

button:disabled { opacity: 0.6; cursor: default; }

#upload-status {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.overall-total {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

table td {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.filters {
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

select {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.csv-export-btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
  text-decoration: none;
}

.csv-export-btn:hover { opacity: 0.9; }

.receipt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.receipt-row img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.receipt-info { flex: 1; min-width: 140px; }
.receipt-vendor { font-weight: 600; }
.receipt-meta { font-size: 0.8rem; color: var(--muted); }
.receipt-total { font-weight: 600; font-variant-numeric: tabular-nums; }

.receipt-row .delete-btn {
  background: transparent;
  color: #b04a4a;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.receipt-row .edit-btn {
  background: transparent;
  color: var(--accent);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.receipt-row .void-btn {
  background: transparent;
  color: var(--muted);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.receipt-row.voided {
  opacity: 0.6;
}

.receipt-thumb { cursor: pointer; }

.status-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.status-complete {
  background: var(--status-complete-bg);
  color: var(--status-complete-text);
}

.status-incomplete {
  background: var(--status-incomplete-bg);
  color: var(--status-incomplete-text);
}

.status-duplicate {
  background: var(--status-duplicate-bg);
  color: var(--status-duplicate-text);
}

.status-voided {
  background: var(--status-voided-bg);
  color: var(--status-voided-text);
}

.hidden { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  display: flex;
  gap: 1.5rem;
  padding: 1.5rem;
}

.modal-image {
  flex: 1;
  min-width: 0;
  height: 80vh;
  max-height: 80vh;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  touch-action: none;
}

.modal-image.zoomed { cursor: grab; }
.modal-image.zoomed.dragging { cursor: grabbing; }

.modal-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.modal-image img.zoom-transition { transition: transform 0.15s ease-out; }

.zoom-controls {
  position: absolute;
  bottom: 0.6rem;
  right: 0.6rem;
  display: flex;
  gap: 0.3rem;
}

.zoom-controls button {
  background: rgba(42, 42, 40, 0.75);
  color: white;
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
  border-radius: 6px;
}

.zoom-controls button:hover { background: rgba(42, 42, 40, 0.9); }

.modal-form {
  flex: 1;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-form h2 { margin: 0; }

.modal-form-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.modal-form-badges {
  display: flex;
  gap: 0.4rem;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.modal-form input,
.modal-form textarea {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--ink);
}

.modal-form-row {
  display: flex;
  gap: 0.75rem;
}

.modal-form-row label { flex: 1; }

.edit-line-items { font-size: 0.85rem; color: var(--muted); }
.edit-line-items h3 { margin-bottom: 0.35rem; }
.edit-line-items ul { margin: 0; padding-left: 1.1rem; }

#edit-status { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; margin: 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.secondary-btn {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

@media (max-width: 700px) {
  .modal { flex-direction: column; }
  .modal-image { height: 50vh; max-height: 50vh; }
}

@media (max-width: 480px) {
  .modal-overlay { padding: 0.5rem; }
  .modal { padding: 1rem; gap: 1rem; }
}

@media (max-width: 600px) {
  .totals-grid { grid-template-columns: 1fr; }
}
