:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --danger: #dc2626;
  --warn-bg: #fef3c7;
  --warn: #92400e;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --card: #1a2127;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #2d363e;
    --accent: #2dd4bf;
    --accent-soft: #134e4a;
    --danger: #f87171;
    --warn-bg: #3b2f12;
    --warn: #fcd34d;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Myanmar", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--accent);
  color: #fff;
  padding: calc(8px + env(safe-area-inset-top)) 12px 0;
}
.top h1 { margin: 0 4px 6px; font-size: 1.15rem; }
.tabs { display: flex; gap: 2px; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: rgba(255,255,255,.75);
  padding: 10px 2px; font: inherit; font-size: .9rem; font-weight: 600;
  border-bottom: 3px solid transparent; cursor: pointer;
}
.tabs button.active { color: #fff; border-bottom-color: #fff; }
@media (prefers-color-scheme: dark) { .top { background: #134e4a; } }

main { max-width: 640px; margin: 0 auto; padding: 12px 12px 96px; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .88rem; margin: 4px 0 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

button.btn, label.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 600;
  cursor: pointer; min-height: 44px;
}
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { button.btn.primary { color: #042f2e; } }
button.btn.small { padding: 6px 10px; min-height: 34px; font-size: .88rem; }
button.btn.danger { color: var(--danger); }
button.btn.block { width: 100%; }
button.icon {
  border: 0; background: transparent; color: var(--muted);
  font-size: 1.15rem; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; flex: none;
}
button.icon:active { background: var(--line); }

input, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-height: 40px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.num { text-align: right; }
.w-qty { width: 54px; flex: none; }
.w-price { width: 100px; flex: none; }
.w-cat { width: 120px; flex: none; padding: 8px 4px; }


.item-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.item-row:last-child { border-bottom: 0; }
.item-row .row + .row { margin-top: 6px; }

.totals { width: 100%; border-collapse: collapse; }
.totals td { padding: 4px 0; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: 8px; }

.warn { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 8px 10px; font-size: .9rem; margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  border-radius: 99px; padding: 6px 12px; font: inherit; font-size: .9rem; cursor: pointer;
  min-height: 36px; user-select: none;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }
.chip.on::before { content: "✓ "; }

.person { padding: 10px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .name { font-weight: 700; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: .9rem;
}

.split-item .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.split-item .title { font-weight: 700; }
.split-item .price { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.split-item .meta { color: var(--muted); font-size: .85rem; margin: 2px 0 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; font-size: .8rem; }
.badge.custom { border-color: var(--accent); color: var(--accent); }
.linkish { border: 0; background: none; color: var(--accent); font: inherit; font-size: .85rem; cursor: pointer; padding: 4px; text-decoration: underline; }

.result-person .head { display: flex; align-items: center; gap: 10px; }
.result-person .total { margin-left: auto; font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-person details { margin-top: 8px; }
.result-person summary { color: var(--muted); font-size: .88rem; cursor: pointer; }
.breakdown { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: 6px; }
.breakdown td { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.breakdown td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 8px; }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.bottom-bar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.bottom-bar .sum { font-size: .85rem; color: var(--muted); }
.bottom-bar .sum b { display: block; color: var(--text); font-size: 1.05rem; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 99px;
  font-size: .9rem; z-index: 50; max-width: 90vw; text-align: center;
}

.bill-title { margin: 8px 4px 12px; font-size: 1.15rem; overflow-wrap: anywhere; }
.bill-date { display: block; font-size: .9rem; font-weight: 500; color: var(--muted); margin-top: 2px; }
input[type="date"] { min-height: 44px; -webkit-appearance: none; appearance: none; }

/* share-as-image preview */
.img-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.72);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.img-sheet {
  background: var(--card); border-radius: 18px; padding: 12px; width: 100%; max-width: 520px;
  max-height: 100%; display: flex; flex-direction: column;
}
.img-sheet img { width: 100%; min-height: 0; flex: 1 1 auto; object-fit: contain; border-radius: 10px; background: var(--bg); }
a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-weight: 600; min-height: 44px; text-decoration: none;
}
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* header: title + History button */
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.top-row h1 { margin: 0 4px; }
.history-btn {
  border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff;
  font: inherit; font-size: .85rem; font-weight: 600; border-radius: 99px; padding: 6px 12px;
  min-height: 34px; cursor: pointer; white-space: nowrap;
}
.history-btn.active { background: #fff; color: var(--accent); border-color: #fff; }
@media (prefers-color-scheme: dark) { .history-btn.active { color: #134e4a; } }
.page-title { margin: 4px 2px 8px; font-size: 1.15rem; }
.empty-icon { font-size: 2.4rem; margin-bottom: 8px; }

/* history */
.hist-list { padding: 4px 14px; }
.hist-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 0;
  font: inherit; color: var(--text); cursor: pointer;
}
.hist-item:last-child { border-bottom: 0; }
.hist-item:active { background: var(--bg); }
.hist-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.hist-main .hint { margin: 2px 0 0; }
.hist-names { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-total { font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
