:root {
  --accent: #6b4423;
  --accent-light: #f4ece3;
  --ink: #2a221b;
  --muted: #7a6a5c;
  --border: #e6ddd3;
  --bg: #f7f4f0;
  --card: #ffffff;
  --danger: #b3492f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #f5efe8 0%, #faf8f6 100%);
  color: var(--ink);
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 16px 80px;
}

.app-header {
  text-align: center;
  margin-bottom: 22px;
}

.app-header h1 {
  margin: 0;
  font-size: 26px;
}

.subtitle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 14px;
}

.card-stack {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(60, 40, 25, 0.09);
  padding: 24px;
}

h2 {
  margin-top: 0;
  font-size: 19px;
}

.hidden { display: none !important; }

.text-input, .num-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  /* 16px keeps iOS from zooming the whole page in when a field is tapped. */
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}

.text-input:focus, .num-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  grid-template-columns: 1fr 1fr;
}

.field-grid > div.full { grid-column: 1 / -1; }

/* Pinned to the bottom of the screen while there are receipts waiting, so the
   count and the File button can't be scrolled past and forgotten. A batch was
   entered and left unfiled on 4 August precisely because this sat below the
   fold on a phone. */
.nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: var(--card);
  border-top: 1px solid var(--border);
  margin-left: -24px;
  margin-right: -24px;
  padding: 14px 24px calc(14px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -6px 18px rgba(60, 40, 25, 0.08);
}

/* The count is the thing that says "you still have work here" -- give it more
   weight than an ordinary hint once anything is actually waiting. */
#batch-count.waiting {
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
}

/* A date that isn't this year is usually a misread, not a deliberate old
   receipt -- one wrong digit on 4 August put a row in the wrong year and
   created a whole stray folder. Asked as a question, not flagged as an error,
   because filing something genuinely old is legitimate. */
.date-notice {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fdf3e0;
  border: 1px solid #e8c99a;
  color: #8a5a12;
  font-size: 13px;
  line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
  .date-notice { background: #33240f; border-color: #6b4f22; color: #f0cf95; }
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn.primary { background: var(--accent); color: white; }
.btn.primary:disabled { background: #cbbcae; cursor: not-allowed; }

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

.btn:hover:not(:disabled) { opacity: 0.9; }

/* Phone-first capture buttons: big enough to hit with a thumb. */
.camera-btn {
  display: block;
  width: 100%;
  font-size: 17px;
  padding: 16px;
  margin-bottom: 10px;
}

.or-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 18px 0;
}

.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.or-divider span { padding: 0 12px; }

.hint {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.status-line {
  margin-top: 14px;
  font-size: 14px;
}

.status-line.error { color: var(--danger); }
.status-line.success { color: var(--accent); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 26px 18px;
  text-align: center;
  cursor: pointer;
  background: #fdfbf9;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone p { margin: 4px 0; }

.dropzone.dragover,
.dropzone:focus-within {
  border-color: var(--accent);
  background: var(--accent-light);
}

.filed-log {
  background: var(--accent-light);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 18px;
  font-size: 14px;
}

.filed-log ul { margin: 8px 0 0; padding-left: 20px; }
.filed-log li { margin-bottom: 4px; }

.receipt-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  gap: 16px;
}

.receipt-card.filed { opacity: 0.6; }

.receipt-card-thumb-col {
  flex: 0 0 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.receipt-thumb {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fdfbf9;
}

.receipt-thumb-doc {
  width: 84px;
  height: 84px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fdfbf9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

.receipt-card-body { flex: 1; min-width: 0; }

.receipt-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.receipt-card-name {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.receipt-checkbox-label input { width: 18px; height: 18px; }

.receipt-card .card-status { margin-top: 10px; }

/* The links between the two pages are real buttons. They're the only way
   across, and a line of underlined text is a poor thing to hit with a thumb. */
.nav-btn {
  display: block;
  width: 100%;
  max-width: 22rem;
  margin: 0 auto 20px;
  padding: 14px 20px;
  text-align: center;
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(60, 40, 25, 0.06);
  transition: border-color 0.15s, background 0.15s;
}

.nav-btn:hover,
.nav-btn:focus-visible {
  border-color: var(--accent);
  background: var(--accent-light);
}

.nav-btn:active { opacity: 0.85; }

/* --- The spreadsheet view --- */

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.sheet-total {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.entry-list { display: flex; flex-direction: column; margin-top: 10px; }

/* A row is a button: the whole line is the tap target, which on a phone matters
   more than it looking like one. */
.entry {
  display: grid;
  grid-template-columns: 4.6rem 1fr auto;
  gap: 10px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 12px 4px;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

.entry:last-child { border-bottom: none; }
.entry:hover, .entry:focus-visible { background: var(--accent-light); }

.entry-date {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* min-width:0 plus per-line truncation: a grid column won't shrink below its
   content otherwise, and one long description ("April and May board, shoes,
   lessons, shows...") would push the amount off the side of a phone. */
.entry-main { display: flex; flex-direction: column; min-width: 0; }

.entry-who,
.entry-what {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.entry-who { font-weight: 600; }
.entry-what { font-size: 13px; color: var(--muted); }

.entry-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.undo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 14px;
}

/* The edit panel sits over the list rather than replacing it, so the line being
   corrected stays in view behind it. */
.edit-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 25, 18, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 12px;
}

.edit-panel {
  background: var(--card);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 32rem;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(30, 20, 12, 0.3);
}

.edit-panel h2 { margin-top: 0; }

.edit-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.edit-actions .btn.primary { margin-left: auto; }

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

@media (min-width: 620px) {
  .edit-backdrop { align-items: center; }
}

.meal-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  background: var(--accent-light);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  cursor: pointer;
}

.meal-toggle input { width: 18px; height: 18px; }

@media (max-width: 620px) {
  .field-grid { grid-template-columns: 1fr; }
  .receipt-card { flex-direction: column; }
  .receipt-card-thumb-col { flex-direction: row; align-items: center; gap: 14px; }
  .nav-row .btn { width: 100%; }
}
