:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #1d4e89;
  --accent-fg: #ffffff;
  --gold: #c9a64b;
  --danger: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
  padding-bottom: 48px;
}

header {
  text-align: center;
  padding: 20px 8px 12px;
}

h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

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

.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

label.field {
  display: block;
  margin-bottom: 12px;
}

label.field:last-child { margin-bottom: 0; }

label.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

label.field small { color: var(--muted); font-weight: 400; }

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  background: white;
  -webkit-appearance: none;
  appearance: none;
  color: var(--text);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px;
  padding-right: 36px;
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.amount-input { position: relative; }
.amount-input::before {
  content: "$";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.amount-input input { padding-left: 26px; }

.tip-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.tip-buttons button {
  padding: 12px 0;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
}

.tip-buttons button.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

#custom-tip-row { margin-top: 10px; }

ul.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

ul.list li:last-child { margin-bottom: 0; }

ul.list .name-input { flex: 1; }

.icon-btn {
  background: white;
  border: 1px solid var(--border);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  color: var(--muted);
  flex-shrink: 0;
  font-family: inherit;
  line-height: 1;
}

.icon-btn:hover { border-color: var(--danger); color: var(--danger); }

ul.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.checklist li { margin-bottom: 4px; }
ul.checklist li:last-child { margin-bottom: 0; }

ul.checklist label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin: 0;
  border: 1px solid transparent;
}

ul.checklist label:hover { background: var(--bg); }

ul.checklist input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}

ul.checklist .name { flex: 1; font-size: 16px; }

.field-note {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

button.ghost {
  background: transparent;
  border: 1px dashed var(--border);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  margin-top: 4px;
}

button.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.totals {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  margin: 0 0 14px;
}

.totals dt {
  color: var(--muted);
  font-size: 14px;
}

.totals dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.totals .grand {
  font-size: 22px;
  font-weight: 700;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.totals dt.grand { color: var(--text); }

#result-people {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-bottom: 14px;
}

.person-row {
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.person-row:last-child { border-bottom: none; }

.person-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 12px;
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.bd-label {
  color: var(--muted);
}

.bd-value {
  color: var(--muted);
  text-align: right;
}

.person-row .left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.person-row .name {
  font-weight: 500;
  font-size: 16px;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--bg);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.badge.gold { background: #fef6e0; color: #8a6a13; }
.badge.paid { background: #e6f0ff; color: var(--accent); }

.person-row .amount {
  font-weight: 600;
  font-size: 18px;
  margin-left: 8px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px 8px;
  margin: 0;
  font-size: 14px;
}

.error {
  color: var(--danger);
  text-align: center;
  padding: 12px 8px;
  margin: 0;
  font-size: 14px;
}

textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: white;
  color: var(--text);
  resize: vertical;
  -webkit-appearance: none;
}

textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.actions {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.actions-primary {
  grid-template-columns: 1fr 1fr;
}

.actions-secondary {
  grid-template-columns: 1fr auto;
}

.actions button {
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--border);
  background: white;
  font-weight: 500;
  color: var(--text);
}

#save-result {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

#share-result {
  background: white;
  border-color: var(--accent);
  color: var(--accent);
}

#copy-result {
  background: white;
}

.actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.history-link {
  text-align: center;
  font-size: 14px;
  margin: 0;
  padding: 4px 0 8px;
}

.history-link a { color: var(--accent); text-decoration: none; }
.history-link a:hover { text-decoration: underline; }

/* ── History page ────────────────────────────────────────────────────────── */

.history-bar {
  margin-bottom: 12px;
}

.history-copy-link {
  width: 100%;
  text-align: center;
}

.history-card {
  margin-bottom: 12px;
}

.hcard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.hcard-title-col { flex: 1; min-width: 0; }

.hcard-title {
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hcard-date {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.delete-btn {
  flex-shrink: 0;
  margin-top: 2px;
}

.delete-btn:hover { border-color: var(--danger); color: var(--danger); }

.hcard-summary {
  margin-bottom: 10px;
}

.hcard-meta {
  font-size: 13px;
  color: var(--muted);
}

.hcard-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.amount-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
  flex: 1;
  min-width: 140px;
}

.chip-label {
  font-size: 13px;
  color: var(--muted);
  flex: 1;
}

.chip-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hcard-notes-label > span {
  font-size: 13px;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.hcard-notes {
  font-size: 14px;
}

@media (prefers-color-scheme: dark) {
  textarea, .hcard-notes { background: #1f232b; }
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #2a2e36;
    --accent: #4a90d9;
  }
  input[type="text"], input[type="number"], select { background: #1f232b; }
  .badge.paid { background: #1a2638; color: #8ab8e6; }
  .badge.gold { background: #2a2113; color: #d6b35a; }
  .tip-buttons button { background: #1f232b; }
}
