:root {
  --bg: #EEE9E0;
  --card: #FFFFFF;
  --primary: #003D8F;
  --primary-light: #0050AA;
  --yellow: #FFD100;
  --yellow-dark: #E6BC00;
  --text: #1A1A1A;
  --muted: #6B6560;
  --border: #D5D0C8;
  --red: #C0392B;
  --green-disc: #27AE60;
  --shadow: 0 2px 12px rgba(0, 0, 0, .10);
  --shadow-lg: 0 6px 32px rgba(0, 0, 0, .14);
  --radius: 14px;
  --radius-sm: 8px;

  /* Fixed distinct colors by person slot */
  --color-p1: #1D4ED8;
  /* blue  */
  --color-p2: #B91C1C;
  /* red   */
  --color-cm: #047857;
  /* green */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html,
body {
  height: 100%;
  font-family: 'Barlow', sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
header h1 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .5px;
}
.header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
header .subtitle {
  font-size: 12px;
  opacity: .7;
  font-weight: 400;
}
.btn-icon {
  background: rgba(255, 255, 255, .15);
  border: 1px solid rgba(255, 255, 255, .25);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: background .15s;
}
.btn-icon:hover {
  background: rgba(255, 255, 255, .25);
}

/* Inline SVG icons */
svg.lucide {
  display: inline-block;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
h1 svg.lucide {
  width: 22px;
  height: 22px;
}
.btn-icon svg.lucide {
  width: 18px;
  height: 18px;
}
.btn svg.lucide {
  width: 18px;
  height: 18px;
}
.nav-btn svg.lucide {
  width: 16px;
  height: 16px;
  vertical-align: -2px;
}
.settle-hero svg.lucide {
  width: 48px;
  height: 48px;
  stroke: #fff;
  stroke-width: 1.5;
  display: block;
  margin: 0 auto 12px;
}
.modal h2 svg.lucide {
  width: 20px;
  height: 20px;
  vertical-align: -3px;
}

main {
  flex: 1;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

/* ── Screens ── */
.screen {
  display: none;
}
.screen.active {
  display: block;
}

/* ── Paste Screen ── */
.paste-hero {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.paste-hero h2 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}
.paste-hero p {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 14px;
}

textarea {
  width: 100%;
  height: 220px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.55;
  color: var(--text);
  background: #FAFAF8;
  resize: vertical;
  transition: border-color .15s;
  outline: none;
}
textarea:focus {
  border-color: var(--primary);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Barlow', sans-serif;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.btn:active {
  transform: scale(.97);
}
.btn-primary {
  background: var(--yellow);
  color: var(--primary);
  box-shadow: 0 3px 10px rgba(255, 209, 0, .4);
  margin-top: 12px;
}
.btn-primary:hover {
  background: var(--yellow-dark);
}
.btn-secondary {
  background: var(--primary);
  color: #fff;
  margin-top: 10px;
}
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  margin-top: 10px;
}

.error-box {
  background: #FEF2F2;
  border: 1.5px solid #FCA5A5;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--red);
  font-size: 14px;
  margin-top: 12px;
  display: none;
}
.error-box.visible {
  display: block;
}

.steps {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.steps h3 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .5px;
  margin-bottom: 12px;
  text-transform: uppercase;
}
.step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.step:last-child {
  margin-bottom: 0;
}
.step-num {
  width: 24px;
  height: 24px;
  min-width: 24px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.step p {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Settings Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open {
  display: flex;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.modal h2 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
}
.form-group {
  margin-bottom: 14px;
}
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Barlow', sans-serif;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
input[type="text"]:focus {
  border-color: var(--primary);
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions .btn {
  flex: 1;
  margin: 0;
}

/* ── Assign Screen ── */
.receipt-meta {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.receipt-meta .store {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 18px;
  font-weight: 700;
}
.receipt-meta .date {
  font-size: 13px;
  opacity: .75;
}
.receipt-meta .totals {
  text-align: right;
}
.receipt-meta .total-amount {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px;
  font-weight: 500;
  color: var(--yellow);
}
.receipt-meta .total-label {
  font-size: 11px;
  opacity: .7;
}

.progress-bar-wrap {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.progress-track {
  background: var(--bg);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 99px;
  transition: width .3s ease;
}

.totals-bar {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.totals-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.totals-chip .chip-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.totals-chip .chip-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 500;
  margin-top: 2px;
}

/* Item cards */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 140px;
}

.item-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 11px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  border-left: 5px solid transparent;
  transition: border-color .12s, background .12s, transform .08s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.item-card:active {
  transform: scale(.985);
}

/* Selected: blue ring */
.item-card.selected {
  border-color: var(--primary) !important;
  border-left-color: var(--primary) !important;
  background: #EFF6FF;
}
/* Assigned: coloured left bar, subtle bg tint */
.item-card.assigned {
  border-left-color: var(--person-color) !important;
  background: color-mix(in srgb, var(--person-color) 6%, white);
}
.item-card.assigned.selected {
  background: #EFF6FF;
  border-color: var(--primary) !important;
  border-left-color: var(--person-color) !important;
}

.item-info {
  flex: 1;
  min-width: 0;
}
.item-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-detail {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.item-price {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  font-weight: 500;
}

.assignment-badge {
  height: 22px;
  border-radius: 99px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.assignment-badge.filled {
  background: var(--person-color);
}
.assignment-badge.empty {
  background: #D1D5DB;
  color: #6B7280;
}

.section-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin: 16px 0 8px;
}
.discount-row {
  background: #F0FDF4;
  border: 1.5px solid #BBF7D0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.discount-row .d-name {
  font-size: 14px;
  color: #166534;
}
.discount-row .d-amount {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--green-disc);
  font-weight: 500;
}

/* ── FAB bar ── */
.fab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1.5px solid var(--border);
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0, 0, 0, .10);
  z-index: 99;
}

/* Person buttons — grid-template-columns is set dynamically by JS */
.person-btns {
  display: grid;
  gap: 7px;
  margin-bottom: 8px;
}
.person-btn {
  padding: 12px 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Barlow', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1.15;
  min-width: 0;
  overflow: hidden;
}
.person-btn:active {
  transform: scale(.95);
  opacity: .85;
}
.person-btn .btn-num {
  font-size: 10px;
  font-weight: 600;
  opacity: .75;
  letter-spacing: .2px;
}
.person-btn .btn-name,
.person-btn .btn-abbr {
  width: 100%;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Few-person layout (≤2 people → 3 buttons): bigger padding, full name */
.person-btns.few .person-btn {
  padding: 14px 6px;
  font-size: 15px;
}

/* Settings person rows */
.settings-person-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.settings-person-num {
  width: 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}
.settings-person-input {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Barlow', sans-serif;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
.settings-person-input:focus {
  border-color: var(--primary);
}
.settings-remove-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: #FEE2E2;
  color: #B91C1C;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.settings-remove-btn:hover {
  background: #FECACA;
}
.btn-add-person {
  display: block;
  width: 100%;
  padding: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--primary);
  font-family: 'Barlow', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: border-color .15s, background .15s;
}
.btn-add-person:hover {
  border-color: var(--primary);
  background: #EFF6FF;
}

/* Back + Done row */
.nav-btns {
  display: flex;
  gap: 8px;
}
.nav-btn {
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-family: 'Barlow', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  transition: background .15s;
}
.nav-btn:hover {
  background: var(--border);
}
.nav-btn.done {
  flex: 1;
  background: var(--yellow);
  color: var(--primary);
  border-color: var(--yellow);
  font-size: 15px;
  font-weight: 700;
}
.nav-btn.done:hover {
  background: var(--yellow-dark);
}

/* ── Settle Screen ── */
.settle-hero {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  text-align: center;
}
.settle-hero h2 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 24px;
  font-weight: 700;
}
.settle-hero p {
  font-size: 14px;
  opacity: .75;
  margin-top: 4px;
}

.payer-select {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.payer-select h3 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}
/* payer-buttons — grid-template-columns set dynamically by JS */
.payer-buttons {
  display: grid;
  gap: 8px;
}
.payer-btn {
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: 'Barlow', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  color: var(--text);
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.payer-btn.selected {
  color: #fff;
  border-color: transparent;
}

.settlement-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.settlement-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settlement-header h3 {
  font-size: 16px;
  font-weight: 700;
}
.owes-amount {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 500;
}
.settlement-items {
  border-top: 1.5px solid var(--border);
  padding: 10px 18px;
}
.settle-item-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--bg);
}
.settle-item-row:last-child {
  border-bottom: none;
}
.settle-item-price {
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
}
.settle-subtotal {
  display: flex;
  justify-content: space-between;
  padding: 8px 0 4px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.settle-common {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
}

.hint-text {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 80px;
  padding: 0 16px;
  line-height: 1.5;
}
.hint-text strong {
  color: var(--text);
}

.settle-fab {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1.5px solid var(--border);
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, .10);
  z-index: 99;
}
.settle-fab .nav-btn {
  padding: 13px 18px;
}
.settle-fab .nav-btn.done {
  flex: 1;
  font-size: 15px;
}