/* Layout: app 1 cột cho điện thoại – thanh trên cố định, lịch kiểu iOS, thanh tab / thanh tổng tiền dưới cùng */
:root {
  --bg: #f2f4ef;
  --surface: #ffffff;
  --surface-2: #f4f6f1;
  --text: #16211a;
  --muted: #66756b;
  --border: #e2e8de;
  --primary: #166534;
  --primary-ink: #ffffff;
  --primary-soft: #dcfce7;
  --accent: #d9f750;
  --accent-ink: #2b3a00;
  --today: #e5484d;
  --today-ink: #ffffff;
  --danger: #c0352b;
  --danger-soft: #fde7e4;
  --warn: #c2410c;
  --warn-soft: #ffedd5;
  --wait: #a16207;
  --wait-soft: #fef3c7;
  --bar: #14532d;
  --bar-ink: #ffffff;
  --shadow: 0 1px 2px rgba(16, 40, 20, .05), 0 4px 14px rgba(16, 40, 20, .05);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d130f;
    --surface: #161e18;
    --surface-2: #1d2720;
    --text: #e6efe8;
    --muted: #94a69a;
    --border: #2a372d;
    --primary: #4ade80;
    --primary-ink: #052e13;
    --primary-soft: #173a23;
    --today: #ff6369;
    --danger: #f97066;
    --danger-soft: #3a1714;
    --warn: #fb923c;
    --warn-soft: #3b2412;
    --wait: #facc15;
    --wait-soft: #37300c;
    --bar: #10301c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d130f;
  --surface: #161e18;
  --surface-2: #1d2720;
  --text: #e6efe8;
  --muted: #94a69a;
  --border: #2a372d;
  --primary: #4ade80;
  --primary-ink: #052e13;
  --primary-soft: #173a23;
  --today: #ff6369;
  --danger: #f97066;
  --danger-soft: #3a1714;
  --warn: #fb923c;
  --warn-soft: #3b2412;
  --wait: #facc15;
  --wait-soft: #37300c;
  --bar: #10301c;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Kéo quá đầu trang lộ màu thanh trên, kéo quá cuối lộ màu nền */
/* Nửa dưới cùng màu thanh tab/thanh tổng tiền: nếu iPhone tính hụt chiều cao lúc mới mở app
   (lỗi của iOS khi mở từ màn hình chính) thì phần hụt vẫn liền màu với thanh dưới */
html { -webkit-text-size-adjust: 100%; background: linear-gradient(to bottom, var(--bar) 0 50%, var(--surface) 50% 100%) fixed; }
html:has(body.gated) { background: linear-gradient(to bottom, var(--bar) 0 50%, var(--bg) 50% 100%) fixed; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;   /* luôn phủ kín màn hình, kể cả khi nội dung ngắn */
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 26px; letter-spacing: -.02em; }
h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
h3 { font-size: 12.5px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }
.center { text-align: center; }
small { font-size: 12.5px; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, .chip:focus-visible, input:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Thanh trên ---------- */
/* Thanh trên tự chừa chỗ cho giờ / pin / tai thỏ (khi mở từ màn hình chính iPhone) */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  min-height: calc(56px + env(safe-area-inset-top, 0px));
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-bottom: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bar); color: var(--bar-ink);
}
.topbar button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.brand { font-weight: 800; font-size: 19px; display: flex; align-items: center; gap: 8px; letter-spacing: -.01em; }
.logo {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%; background-color: var(--accent);
  background-image: radial-gradient(circle, #14532d 1.6px, transparent 2px);
  background-size: 7px 7px; background-position: 1px 1px;
}
.logo.big { width: 64px; height: 64px; background-size: 14px 14px; background-image: radial-gradient(circle, #14532d 3px, transparent 3.6px); }
.role { font-size: 12px; font-weight: 600; background: rgba(255, 255, 255, .16); padding: 2px 10px; border-radius: 99px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.back { width: 40px; height: 40px; margin-left: -8px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.back svg { width: 24px; height: 24px; stroke-width: 2.6; }
.back:active { background: rgba(255, 255, 255, .15); }
.tb-title { min-width: 0; line-height: 1.2; }
.tb-title b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-title small { display: block; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-done {
  order: 3; flex: none; margin-left: 4px;
  font-weight: 700 !important; font-size: 16px !important; color: var(--accent) !important;
  padding: 8px 4px 8px 12px !important; min-height: 40px;
}
.push-banner {
  display: flex; align-items: center; gap: 10px; padding: 12px 10px 12px 14px; margin-bottom: 10px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.pb-ic { font-size: 22px; flex: none; }
.pb-main { flex: 1; min-width: 0; line-height: 1.35; }
.pb-main b { display: block; }
.pb-main span { font-size: 13px; color: var(--muted); }
.push-banner .btn { min-height: 40px; padding: 6px 16px; flex: none; }
.pb-x { flex: none; width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 15px; cursor: pointer; border-radius: 8px; }
.alert.bill-due { background: var(--primary-soft); }
.alert.bill-due .alert-ic { background: var(--primary); color: var(--primary-ink); }
.alert.bill-due .alert-main b, .alert.bill-due .chev { color: var(--primary); }
.sync { order: 2; margin-left: auto; flex: none; display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .85; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.sync.pending i { background: #fbbf24; }
.sync.error i { background: #f87171; }
.sync.error { opacity: 1; font-weight: 600; }
.sync.local { display: none; }
.sync.ok span, .sync.pending span { display: none; }

/* ---------- Khung nội dung ---------- */
main {
  max-width: 640px; margin: 0 auto;
  padding-top: 14px;
  padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
body.gated main { padding-bottom: 32px; }
body.gated .tabbar, body.gated .sync { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.badge { background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }

/* ---------- Form ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select { margin-top: 4px; }
input, select, textarea {
  width: 100%; min-height: 46px;
  font: inherit; font-size: 16px; /* >=16px để iPhone không tự phóng to */
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; outline: none;
}
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; text-align: left; }
input:focus, select:focus { border-color: var(--primary); }
input.invalid { border-color: var(--danger); background: var(--danger-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 > * { min-width: 0; }
.inline { display: flex; gap: 8px; margin-top: 10px; }
.inline input { flex: 1; min-width: 0; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  padding: 8px 16px; min-height: 46px; white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; margin-top: 4px; }
.btn.big { min-height: 54px; font-size: 16.5px; border-radius: 14px; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-size: 15px;
}
.icon-btn.placeholder { visibility: hidden; }
.icon-btn.qr-btn { width: auto; padding: 0 12px; font-size: 13px; font-weight: 700; color: var(--primary); border-color: var(--primary); }
.link-btn { font: inherit; font-weight: 600; color: var(--primary); background: none; border: 0; padding: 4px 6px; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions .btn { flex: 1; }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 14.5px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 7px 14px; border-radius: 999px; min-height: 40px;
}
.chip:active { transform: scale(.96); }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.chip.on::before { content: "✓ "; }
.chip.add { border-style: dashed; color: var(--muted); background: transparent; }
.chips.small .chip { font-size: 13.5px; padding: 5px 12px; min-height: 36px; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.hint.warn { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 12px; }
details { margin-top: 10px; }
summary { cursor: pointer; font-size: 13.5px; color: var(--muted); user-select: none; padding: 4px 0; }
details[open] > summary { margin-bottom: 8px; }

/* ---------- Lịch kiểu iPhone ---------- */
.cal { padding: 4px 2px 6px; }
.cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.cal-head h2 { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin: 0 auto 0 4px; }
.cal-head h2 span { color: var(--today); }
.nav-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--surface); color: var(--primary); cursor: pointer; display: grid; place-items: center; box-shadow: var(--shadow); }
.nav-btn svg { width: 20px; height: 20px; stroke-width: 2.6; }
.cal-wd, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-wd span { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding-bottom: 6px; }
.cal-wd .sun, .day.sun .dn { color: var(--today); }
.cal-grid { border-top: 1px solid var(--border); }
.day {
  font: inherit; background: none; border: 0; border-bottom: 1px solid var(--border); color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0 4px; min-height: 58px; cursor: pointer;
}
.day.empty { border-bottom: 1px solid var(--border); }
.dn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; }
.day.today .dn { color: var(--today); font-weight: 700; }
.day.sel .dn { background: var(--text); color: var(--bg); font-weight: 700; }
.day.sel.today .dn { background: var(--today); color: var(--today-ink); }
.dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.dot.due { background: var(--warn); }
.dot.done { background: var(--muted); opacity: .5; }

.day-panel { margin: 4px 0 12px; }
.day-panel h3 { font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 700; margin: 14px 2px 10px; }
.empty-day { margin: 0 2px 10px; }
.up-date { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 10px 4px 4px; }

/* Thẻ sự kiện kiểu lịch iOS */
.ev {
  width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px 14px 12px 12px; margin-bottom: 8px; position: relative; overflow: hidden;
}
.ev::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); }
.ev.due::before { background: var(--warn); }
.ev.done::before { background: var(--muted); opacity: .5; }
.ev:active { transform: scale(.99); }
.ev-time { flex: none; width: 46px; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; line-height: 1.2; padding-left: 4px; }
.ev-time small { display: block; color: var(--muted); font-weight: 500; }
.ev-main { flex: 1; min-width: 0; }
.ev-main b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-main span { font-size: 13px; color: var(--muted); }

.pill { flex: none; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.open { background: var(--primary-soft); color: var(--primary); }
.pill.ok { background: var(--primary-soft); color: var(--primary); }
.pill.due { background: var(--warn-soft); color: var(--warn); }
.pill.wait { background: var(--wait-soft); color: var(--wait); }

.alert {
  width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 10px;
  border-radius: 14px; border: 1px solid transparent; background: var(--warn-soft);
}
.alert.static { cursor: default; }
.alert-ic { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--warn); color: #fff; font-weight: 800; font-size: 18px; }
.alert-main { flex: 1; min-width: 0; }
.alert-main b { display: block; color: var(--warn); }
.alert-main span { font-size: 13px; color: var(--muted); }
.chev { font-size: 24px; color: var(--warn); }
.demo-note { font-size: 13px; background: var(--wait-soft); color: var(--text); padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; }

/* ---------- Màn chào ---------- */
.welcome { text-align: center; padding: 18px 8px 20px; display: grid; justify-items: center; gap: 8px; }
.welcome p { margin: 0; color: var(--muted); max-width: 32ch; }

/* ---------- Buổi chơi ---------- */
.info { display: flex; align-items: center; gap: 14px; }
.info-date { flex: none; width: 58px; text-align: center; border-radius: 14px; background: var(--surface-2); padding: 6px 0; line-height: 1.1; }
.info-date span { display: block; font-size: 11.5px; font-weight: 700; color: var(--today); text-transform: uppercase; }
.info-date span:last-child { color: var(--muted); }
.info-date b { display: block; font-size: 26px; }
.info-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.info-main b { font-size: 16.5px; }
.info-main span { font-size: 13.5px; }

.vote { text-align: left; }
.vote.on { border-color: var(--primary); background: var(--primary-soft); }
.vote p { margin: -4px 0 12px; }

.pay { text-align: center; border: 2px solid var(--primary); }
.pay-head { display: grid; justify-items: center; gap: 4px; margin-bottom: 12px; }
.pay-head span { color: var(--muted); font-size: 14px; }
.pay-head > b { font-size: 34px; letter-spacing: -.02em; color: var(--primary); font-variant-numeric: tabular-nums; }
.qr { display: block; width: 100%; max-width: 300px; margin: 6px auto 0; border-radius: 12px; border: 1px solid var(--border); background: #fff; }

.lines { display: grid; margin-top: 4px; text-align: left; }
.line { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14.5px; }
.line:last-child { border-bottom: 0; }
.line > span { flex: 1; min-width: 0; color: var(--muted); }
.line > b { font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.line.total { font-size: 15.5px; }
.line.total > span { color: var(--text); font-weight: 600; }
.copy { flex: none; font: inherit; font-size: 12.5px; font-weight: 700; color: var(--primary); background: var(--primary-soft); border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; }

.exp-list { display: grid; gap: 10px; margin-top: 12px; }
.exp { border: 1px solid var(--border); border-radius: 14px; padding: 10px; background: var(--surface-2); }
.exp input { background: var(--surface); }
.exp-main { display: flex; gap: 8px; }
.exp-name { flex: 1.25; min-width: 0; }
.exp-amt { flex: 1; min-width: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.exp details { margin-top: 6px; }

.result { border: 2px solid var(--primary); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { background: var(--surface-2); border-radius: 12px; padding: 10px; min-width: 0; }
.stats span { display: block; font-size: 12px; color: var(--muted); }
.stats b { font-size: 16px; font-variant-numeric: tabular-nums; }
.stats .hl { background: var(--accent); color: var(--accent-ink); }
.stats .hl span { color: inherit; opacity: .75; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-between select { width: auto; min-height: 40px; padding: 6px 10px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .25s; }

.people { display: grid; margin-top: 6px; }
.person { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.person:last-child { border-bottom: 0; }
.pname { flex: 1; min-width: 0; }
.pname b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname small { display: block; color: var(--muted); }
.pamt { text-align: right; font-variant-numeric: tabular-nums; }
.pamt b { font-size: 16px; }
.pamt small { display: block; color: var(--muted); }
.person.done .pname b, .person.done .pamt b { opacity: .55; text-decoration: line-through; }
.st-paid { color: var(--primary) !important; font-weight: 600; }
.st-claimed { color: var(--wait) !important; font-weight: 600; }
.st-todo { color: var(--warn) !important; }
.av { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text); font-weight: 700; border: 1px solid var(--border); }
.av.host { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.av.big { width: 56px; height: 56px; font-size: 22px; }
.wsel { width: auto; max-width: 128px; min-height: 40px; padding: 6px 8px; font-size: 14px; }

.check { position: relative; width: 38px; height: 38px; flex: none; margin: 0; display: grid; place-items: center; }
.check input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; min-height: 0; }
.check span { width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--border); background: var(--surface); display: grid; place-items: center; }
.check input:checked + span { background: var(--primary); border-color: var(--primary); }
.check input:checked + span::after { content: "✓"; color: var(--primary-ink); font-weight: 800; font-size: 15px; }
.check.placeholder { font-size: 16px; color: var(--muted); }

/* Tiến trình 2 giai đoạn của chủ kèo */
.stepper { display: flex; align-items: center; gap: 8px; margin: 2px 4px 14px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.step i { font-style: normal; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 13.5px; font-weight: 800; background: var(--surface-2); border: 2px solid var(--border); color: var(--muted); }
.step.on { color: var(--text); }
.step.on i { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.step.done i { background: var(--primary-soft); border-color: var(--primary-soft); color: var(--primary); }
.step-line { flex: 1; height: 2px; background: var(--border); border-radius: 2px; min-width: 20px; }
.step-line.done { background: var(--primary); }
.live { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--primary); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); animation: live 1.6s ease-in-out infinite; }
@keyframes live { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.card.wait-vote { background: var(--surface-2); border-style: dashed; }
.card.wait-vote h2 .live { margin: 0; }
.card.next { border: 2px dashed var(--primary); background: var(--primary-soft); }

/* Chi phí: 2 khoản chính to, rõ */
.exp.main { background: var(--surface); }
.exp.main .exp-main { align-items: center; }
.exp-label { flex: 1.25; font-weight: 700; font-size: 16px; padding-left: 4px; }
.exp.main .exp-amt { font-size: 18px; min-height: 50px; }

/* Bill gửi cho thành viên */
.bill { border: 2px solid var(--primary); }
.bill-head { display: grid; justify-items: center; gap: 2px; padding-bottom: 12px; margin-bottom: 4px; border-bottom: 2px dashed var(--border); text-align: center; }
.bill-tag { font-size: 11.5px; font-weight: 800; letter-spacing: .12em; color: var(--primary); background: var(--primary-soft); padding: 3px 10px; border-radius: 99px; }
.bill-head b { font-size: 17px; margin-top: 4px; }
.bill-head small { color: var(--muted); }
.bill .pay-head { margin: 14px 0 10px; padding-top: 12px; border-top: 2px dashed var(--border); }
.wait-card { text-align: center; background: var(--wait-soft); border-color: transparent; }
.wait-card h2 { justify-content: center; }

/* Ảnh QR chủ kèo */
.qr-card .qr { max-width: 260px; }
.file-btn { position: relative; cursor: pointer; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* Đăng nhập / Đăng ký */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; margin-bottom: 12px; }
.seg button { font: inherit; font-weight: 600; min-height: 42px; border: 0; border-radius: 10px; background: none; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.auth-switch { text-align: center; margin: 4px 0 16px; color: var(--muted); font-size: 15px; }
.auth-switch .link-btn { font-size: 15px; }
.mem-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.mem-main small { color: var(--muted); padding-left: 2px; }
.icon-btn.key { font-size: 16px; }
.role-sel { width: auto; min-height: 40px; padding: 6px 8px; font-size: 14px; flex: none; }
.mem-main b { font-weight: 600; padding-left: 2px; }

.profile { display: flex; align-items: center; gap: 14px; }
.profile > div { flex: 1; min-width: 0; }
.mem { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.mem:last-child { border-bottom: 0; }
.mem input { flex: 1; min-width: 0; }
.mem .stat { font-size: 12.5px; color: var(--muted); text-align: right; }

/* ---------- Thanh dưới ---------- */
.tabbar, .sumbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-top: 6px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.tabbar-in { max-width: 480px; margin: 0 auto; display: flex; align-items: center; }
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font: inherit; font-size: 11.5px; font-weight: 500; color: var(--muted);
  background: none; border: 0; padding: 4px 0; min-height: 50px; cursor: pointer;
}
.tabbar button svg { width: 24px; height: 24px; stroke-width: 2; }
.tabbar button.active { color: var(--primary); font-weight: 700; }
.tabbar .tab-add {
  flex: none; width: 58px; height: 58px; min-height: 0; margin: -26px 18px 0; padding: 0;
  border-radius: 50%; justify-content: center;
  background: var(--primary); color: var(--primary-ink);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 45%, transparent);
  border: 4px solid var(--bg);
}
.tabbar .tab-add svg { width: 26px; height: 26px; stroke-width: 2.8; }
body.in-session .tabbar { display: none; }
.sumbar { padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
.sumbar-in { max-width: 608px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.sum-info { flex: 1; min-width: 0; text-align: left; font: inherit; color: var(--text); background: none; border: 0; padding: 0; cursor: pointer; line-height: 1.2; }
.sum-info small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-info b { font-size: 19px; font-variant-numeric: tabular-nums; }
.sumbar .btn { min-height: 48px; padding: 0 18px; }

/* ---------- Hộp thoại trồi từ dưới ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); display: grid; place-items: end stretch; }
.sheet-box {
  background: var(--surface); color: var(--text);
  border-radius: 22px 22px 0 0; width: 100%; max-width: 560px; justify-self: center;
  max-height: 92vh; overflow-y: auto;
  padding: 22px max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  animation: sheet .22s ease-out;
}
.sheet-box > p { margin: 0 0 4px; font-size: 16px; }
.sheet-box .btn { min-height: 50px; }

#toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px);
  background: #14532d; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
  max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes sheet { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ===== Sổ quỹ ===== */
:root { --pos: #15803d; --neg: #c0352b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --pos: #4ade80; --neg: #f87171; } }
:root[data-theme="dark"] { --pos: #4ade80; --neg: #f87171; }
.pos { color: var(--pos); }
.neg-t { color: var(--neg); }

/* Thẻ "Quỹ còn lại" */
.fund {
  background: var(--bar); color: #fff; border-radius: 20px; padding: 18px 18px 16px; margin-bottom: 12px;
  display: grid; gap: 4px; box-shadow: var(--shadow);
}
.fund-label { font-size: 13px; font-weight: 600; opacity: .8; text-transform: uppercase; letter-spacing: .06em; }
.fund-amt { font-size: clamp(30px, 10vw, 40px); line-height: 1.1; letter-spacing: -.02em; color: var(--accent); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fund.neg .fund-amt { color: #fca5a5; }
.fund-sub { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; opacity: .9; margin-top: 2px; }
.fund-sub b { font-variant-numeric: tabular-nums; }
.fund-month { font-size: 13px; opacity: .75; }
.fund-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.fund-actions .btn { min-height: 46px; border: 0; }
.fund-in { background: var(--accent); color: var(--accent-ink); }
.fund-out { background: rgba(255, 255, 255, .14); color: #fff; }

/* Lịch: số tiền chi dưới mỗi ngày */
.day { min-height: 62px; gap: 0; }
.day-amt { font-size: 10.5px; font-weight: 700; color: var(--neg); height: 14px; line-height: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.day.sel .day-amt { color: var(--neg); }
.dot.in { background: var(--pos); }
.month-sum { margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; display: grid; gap: 8px; }
.ms-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.ms-head > span:first-child { font-weight: 700; }
.ms-cats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.ms-cats b { color: var(--text); }
.day-total { float: right; font-size: 14px; color: var(--neg); }

/* Dòng thu / chi */
.entry {
  width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.entry:active { transform: scale(.99); }
.en-ic { flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; background: var(--surface-2); }
.entry.in .en-ic { background: var(--primary-soft); }
.en-main { flex: 1; min-width: 0; }
.en-main b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.en-main small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.en-amt { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.en-amt b { display: block; }
.entry.in .en-amt b { color: var(--pos); }
.entry.out .en-amt b { color: var(--neg); }
.en-amt small { display: block; font-size: 11.5px; color: var(--muted); }
.month { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 8px; display: flex; justify-content: space-between; }
.month span { text-transform: none; letter-spacing: 0; }
.seg { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 1fr; }
.exp-note { margin-top: 8px; font-size: 15px !important; min-height: 40px; }
.day-result .lines { margin: 0; }

/* Thanh dưới 5 nút */
.tabbar-in { max-width: 520px; }
.tabbar button { font-size: 11px; }
.tabbar .tab-add { margin: -26px 6px 0; }

/* ===== Tương thích nhiều dòng máy ===== */
a, label, summary { -webkit-tap-highlight-color: transparent; }
html { overflow-x: hidden; }
/* Trình duyệt cũ (iOS < 16.2) chưa hiểu color-mix: dùng màu đặc */
@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .tabbar, .sumbar { background: var(--surface); }
}
/* iOS < 14.5 chưa hiểu "inset" */
.overlay { top: 0; right: 0; bottom: 0; left: 0; }
.sheet-box { max-height: 92vh; max-height: 92dvh; }
/* Bàn phím đang mở: ẩn thanh dưới để không che ô nhập */
body.kb .tabbar, body.kb .sumbar { display: none; }
body.kb main { padding-bottom: 24px; }
/* Số tiền lớn không tràn ô trên máy nhỏ */
.stats b { font-size: clamp(13px, 4.1vw, 17px); overflow-wrap: anywhere; }
.info-main span { line-height: 1.35; }

/* Máy nhỏ (iPhone SE, Android nhỏ) */
@media (max-width: 400px) {
  .exp:not(.main) .exp-main { flex-wrap: wrap; }
  .exp:not(.main) .exp-name { flex: 1 1 100%; }
  .exp:not(.main) .exp-amt { flex: 1 1 auto; }
  .stepper { gap: 6px; }
  .step { font-size: 13px; gap: 6px; }
  .sumbar .btn { padding: 0 14px; font-size: 15px; }
}
@media (max-width: 360px) {
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .card { padding: 14px 12px; }
  .sum-info b { font-size: 17px; }
  .exp-label { font-size: 15px; }
  .exp.main .exp-amt { font-size: 16px; }
  .person { gap: 10px; }
  .av { width: 34px; height: 34px; }
}

/* Điện thoại xoay ngang (màn hình thấp): thanh trên / dưới gọn lại */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { min-height: calc(46px + env(safe-area-inset-top, 0px)); padding-top: calc(4px + env(safe-area-inset-top, 0px)); padding-bottom: 4px; }
  .tabbar { padding-top: 2px; padding-bottom: calc(2px + env(safe-area-inset-bottom, 0px)); }
  .tabbar button { flex-direction: row; justify-content: center; gap: 8px; min-height: 42px; font-size: 13px; }
  .tabbar button svg { width: 20px; height: 20px; }
  .tabbar .tab-add { width: 40px; height: 40px; margin: 0 24px; border-width: 0; box-shadow: none; }
  .tabbar .tab-add svg { width: 22px; height: 22px; }
  .sumbar { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .sumbar .btn { min-height: 40px; }
  main { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  .welcome { padding: 6px 8px 10px; }
  .logo.big { width: 40px; height: 40px; background-size: 9px 9px; }
  .day { min-height: 48px; }
}

@media (max-width: 380px) {
  .dn { width: 32px; height: 32px; font-size: 16px; }
  .cal-head h2 { font-size: 24px; }
  .wsel { max-width: 96px; }
}
