/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --paper: #EDF1E3;
  --slip: #FBFCF6;
  --ink: #23301D;
  --muted: #6B7A5E;
  --rule: #C9D4B6;
  --red: #B5382D;
  --pen: #2B4E9E;
}

/* ── Reset / Base ──────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Public Sans', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

main { max-width: 720px; margin: 0 auto; padding: 16px; }

a { color: var(--pen); }

input, select, button { font: inherit; }

input[type="text"],
input[type="number"],
input:not([type]) {
  background: var(--slip);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px;
  min-height: 44px;
  width: 100%;
  color: var(--ink);
}

input[type="text"]:focus-visible,
input[type="number"]:focus-visible,
input:not([type]):focus-visible,
select:focus-visible {
  outline: 2px solid var(--pen);
  outline-offset: 2px;
}

input[type="number"] {
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* ── Focus-visible global ──────────────────────────────────── */
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

/* ── Header ────────────────────────────────────────────────── */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

/* wordmark: red stamp band */
.app-title {
  font-family: 'Fjalla One', sans-serif;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  background: var(--red);
  color: var(--paper);
  border-radius: 3px;
  padding: 4px 10px;
}
.app-title:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

/* identity button: quiet outlined pill */
.identity-btn {
  background: var(--slip);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 44px;
  cursor: pointer;
  font-size: 14px;
  transition: background 120ms ease;
}
.identity-btn:hover { background: var(--paper); }
.identity-btn:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

/* ── Section + h2 labels ───────────────────────────────────── */
section {
  background: var(--slip);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(35,48,29,.06);
}

h2 {
  font-family: 'Fjalla One', sans-serif;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red);
  margin: 0 0 12px;
  font-weight: 400;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--rule);
  background: var(--slip);
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 120ms ease;
}
.btn:hover { background: var(--paper); }
.btn:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn-primary:hover { background: #2d3d25; border-color: #2d3d25; }

.btn-big { width: 100%; font-size: 18px; padding: 18px; }

.btn-small {
  min-height: 44px;
  min-width: 44px;
  padding: 6px;
  font-size: 14px;
}

/* ✕ remove/destructive buttons: red on hover */
.chip-remove {
  border: 0;
  background: none;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
  color: var(--muted);
  transition: color 120ms ease;
}
.chip-remove:hover { color: var(--red); }
.chip-remove:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

/* ✕ btn-small in table/fees: red text treatment */
.fee-row .btn-small { color: var(--muted); }
.fee-row .btn-small:hover { color: var(--red); background: var(--slip); }

table.items .btn-small:last-child { color: var(--muted); }
table.items .btn-small:last-child:hover { color: var(--red); background: var(--slip); }

/* ── Home ──────────────────────────────────────────────────── */
.home .btn-big { margin: 24px 0; }

.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li { border-bottom: 1px solid var(--rule); }
.recent-list li:last-child { border-bottom: 0; }
.recent-list a {
  display: block;
  padding: 12px 4px;
  text-decoration: none;
  color: var(--pen);
  min-height: 44px;
  transition: color 120ms ease;
}
.recent-list a:hover { text-decoration: underline; }
.recent-list a:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

/* ── Bill top bar ──────────────────────────────────────────── */
.top-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }

.bill-name { font-size: 18px; font-weight: 600; flex: 1; }

.save-indicator {
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

/* ── People chips ──────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 2px 2px 2px 12px;
}

.chip-name {
  border: 0;
  background: none;
  min-height: 40px;
  cursor: pointer;
  color: var(--ink);
}
.chip-name:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; border-radius: 4px; }

.chip-edit { max-width: 120px; min-height: 40px; }

.chip-add { max-width: 160px; }

/* ── Items table ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin-bottom: 12px; }

table.items { border-collapse: collapse; min-width: 100%; }

table.items th,
table.items td {
  padding: 6px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  white-space: nowrap;
  background: var(--slip);
}

table.items th {
  font-family: 'Public Sans', system-ui, sans-serif;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

table.items th:first-child,
table.items td:first-child {
  position: sticky;
  left: 0;
  width: 140px;
  min-width: 140px;
  z-index: 1;
  background: var(--slip);
}

table.items th:nth-child(2),
table.items td:nth-child(2) {
  position: sticky;
  left: 140px;
  width: 100px;
  min-width: 100px;
  z-index: 1;
  background: var(--slip);
}

table.items input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--pen);
}

table.items td input { min-width: 90px; }

.num {
  text-align: right;
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* ── Charges ───────────────────────────────────────────────── */
.money-field { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.money-field input { max-width: 140px; }

.fee-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.fee-row select {
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--slip);
  color: var(--ink);
  padding: 0 8px;
}

/* ── Summary ───────────────────────────────────────────────── */
.summary-list { margin-bottom: 8px; }

.summary-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
}

/* dotted leader between name and amount */
.summary-row::after {
  content: '';
  order: 1;
  flex: 1;
  border-bottom: 2px dotted var(--rule);
}

.summary-row > span:first-child { order: 0; white-space: nowrap; }
.summary-row > .num { order: 2; white-space: nowrap; }

/* Grand total line — double red rule, Fjalla One label */
.summary-row.grand {
  border-top: 3px double var(--red);
  margin-top: 4px;
  padding-top: 8px;
  font-weight: 700;
}
.summary-row.grand > span:first-child {
  font-family: 'Fjalla One', sans-serif;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.summary-row.grand > .num {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
}

/* Perforated bottom edge on the summary section — semicircular
   notches punched into the slip, so the check reads as torn off the pad */
#summary {
  position: relative;
  padding-bottom: 28px;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}
#summary::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 12px;
  background: radial-gradient(circle at 8px 12px, var(--paper) 6px, transparent 6.5px);
  background-size: 16px 12px;
  background-repeat: repeat-x;
}

/* ── Reconcile / Warning ───────────────────────────────────── */
.warning {
  color: var(--red);
  background: #F7E9E7;
  border: 1px solid #e8b0aa;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.reconcile { font-size: 13px; margin-top: 4px; }
.reconcile.ok { color: #4A7042; }
.reconcile.warning {
  color: var(--red);
  background: #F7E9E7;
  border: 1px solid #e8b0aa;
  border-radius: 8px;
  padding: 8px 12px;
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(35,48,29,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal {
  background: var(--slip);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 20px;
  max-width: 360px;
  width: 100%;
}
.modal h2 {
  font-family: 'Public Sans', system-ui, sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
}

.modal-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }

.field-error { color: var(--red); font-size: 13px; }

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
