:root {
    --bg: #f3f4fb;
    --surface: #ffffff;
    --surface-2: #f6f7fd;
    --text: #1d2140;
    --muted: #6b7194;
    --line: #e6e8f4;
    --brand: #5b5bf0;
    --brand-2: #8b5cf6;
    --brand-soft: #ecebff;
    --pos: #12a150;
    --pos-soft: #e3f7ec;
    --neg: #e5484d;
    --neg-soft: #fde8e9;
    --shadow: 0 6px 24px rgba(40, 44, 110, .08);
    --radius: 18px;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1120; --surface: #181b33; --surface-2: #1f2340; --text: #eceefb; --muted: #9aa0c9;
        --line: #2a2f55; --brand-soft: #262a5c; --pos-soft: #12301f; --neg-soft: #3a1c20;
        --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    }
}
* { box-sizing: border-box; }
/* Nút/ô nhập mặc định không kế thừa font của trang nên chữ tiếng Việt bị lỗi font */
button, input, select, textarea { font-family: inherit; font-size: inherit; line-height: inherit; }
.fab { font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 1rem; letter-spacing: 0; }
.fab i { font-family: "Font Awesome 6 Free"; font-weight: 900; }
body { background: var(--bg); color: var(--text); font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
.app-wrap { max-width: 760px; padding: 0 16px 110px; }
a { color: var(--brand); }

/* ---------- Hero ---------- */
.hero-card {
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    color: #fff; border-radius: 0 0 28px 28px; padding: 26px 22px 22px;
    margin: 0 -16px 18px; box-shadow: var(--shadow);
}
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hero-title { font-size: 1.55rem; font-weight: 700; margin: 0; line-height: 1.25; word-break: break-word; }
.hero-sub { opacity: .85; font-size: .9rem; margin-top: 4px; }
.hero-stats { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.stat { background: rgba(255, 255, 255, .16); border-radius: 14px; padding: 10px 14px; flex: 1; min-width: 96px; }
.stat b { display: block; font-size: 1.1rem; }
.stat span { font-size: .75rem; opacity: .85; }
.invite { display: flex; gap: 8px; margin-top: 16px; }
.invite input { flex: 1; min-width: 0; border: 0; border-radius: 12px; padding: 10px 12px; background: rgba(255, 255, 255, .95); color: #333; font-size: .85rem; }
.btn-glass { border: 0; border-radius: 12px; padding: 10px 14px; background: rgba(255, 255, 255, .22); color: #fff; font-weight: 600; white-space: nowrap; }
.btn-glass:hover { background: rgba(255, 255, 255, .32); color: #fff; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; background: rgba(255, 255, 255, .18); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.live-dot i { width: 8px; height: 8px; border-radius: 50%; background: #9aa; display: inline-block; }
.live-dot.on i { background: #4ade80; box-shadow: 0 0 0 4px rgba(74, 222, 128, .25); }
.live-dot.off i { background: #fbbf24; }
.icon-btn { border: 0; background: rgba(255, 255, 255, .18); color: #fff; width: 38px; height: 38px; border-radius: 12px; }
.icon-btn:hover { background: rgba(255, 255, 255, .3); }
.icon-btn.active { background: #fff; color: var(--brand); }

/* ---------- Tabs ---------- */
.tabs { position: sticky; top: 0; z-index: 20; background: var(--bg); padding: 8px 0 12px; display: flex; gap: 6px; overflow-x: auto; }
.tab-btn {
    flex: 1; border: 0; background: var(--surface); color: var(--muted); font-weight: 600; font-size: .88rem;
    padding: 10px 12px; border-radius: 14px; white-space: nowrap; box-shadow: var(--shadow); position: relative;
}
.tab-btn.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.tab-btn .pill { background: var(--neg); color: #fff; border-radius: 99px; font-size: .68rem; padding: 1px 7px; margin-left: 4px; }
.tab-panel { display: none; animation: fade .25s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card-x { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card-x.mine { border: 2px solid var(--brand); }
.card-x.recv { border: 2px solid var(--pos); }
.muted { color: var(--muted); }
.small-muted { color: var(--muted); font-size: .82rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.avatar {
    width: 40px; height: 40px; border-radius: 50%; color: #fff; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; flex: none; font-size: .95rem;
}
.avatar.sm { width: 28px; height: 28px; font-size: .75rem; }
.avatar.lg { width: 56px; height: 56px; font-size: 1.3rem; }

.transfer-flow { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.transfer-flow .who { display: flex; flex-direction: column; align-items: center; min-width: 0; max-width: 90px; text-align: center; font-size: .82rem; font-weight: 600; }
.transfer-flow .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px; }
.arrow { flex: 1; text-align: center; color: var(--muted); position: relative; }
.arrow .amt { display: block; font-weight: 700; color: var(--text); font-size: 1.02rem; }
.arrow i { font-size: .8rem; }
.arrow:after { content: ""; display: block; height: 2px; background: repeating-linear-gradient(90deg, var(--line) 0 6px, transparent 6px 10px); margin-top: 4px; }

.balance-chip { padding: 4px 10px; border-radius: 99px; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.balance-chip.pos { background: var(--pos-soft); color: var(--pos); }
.balance-chip.neg { background: var(--neg-soft); color: var(--neg); }
.balance-chip.zero { background: var(--surface-2); color: var(--muted); }

.badge-x { font-size: .68rem; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 700; }

.btn-brand { border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 600; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.btn-brand:hover { color: #fff; filter: brightness(1.06); }
.btn-brand:disabled { opacity: .6; }
.btn-soft { border: 0; border-radius: 12px; padding: 8px 14px; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.btn-soft:hover { filter: brightness(.96); color: var(--brand); }
.btn-danger-soft { border: 0; border-radius: 12px; padding: 8px 14px; font-weight: 600; background: var(--neg-soft); color: var(--neg); }
.link-btn { border: 0; background: none; color: var(--muted); padding: 4px 6px; }
.link-btn:hover { color: var(--brand); }
.link-btn.del:hover { color: var(--neg); }

.field label { font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; display: block; }
.field .form-control, .field .form-select, .form-control {
    background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 12px; padding: 10px 12px;
}
.field .form-control:focus, .form-control:focus { background: var(--surface); color: var(--text); border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: .85rem; }
.chip input:checked + span { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

.empty { text-align: center; padding: 34px 10px; color: var(--muted); }
.empty i { font-size: 2.2rem; margin-bottom: 8px; display: block; opacity: .6; }

.qr-preview { width: 100%; max-width: 280px; border-radius: 16px; border: 1px solid var(--line); background: #fff; display: block; margin: 0 auto; }
.qr-drop { border: 2px dashed var(--line); border-radius: 16px; padding: 22px; text-align: center; color: var(--muted); cursor: pointer; background: var(--surface-2); }
.qr-drop:hover { border-color: var(--brand); color: var(--brand); }

.fab {
    position: fixed; right: 20px; bottom: 22px; z-index: 30; border: 0; color: #fff; font-weight: 700;
    padding: 14px 22px; border-radius: 99px; background: linear-gradient(135deg, var(--brand), var(--brand-2));
    box-shadow: 0 10px 28px rgba(91, 91, 240, .45);
}
.fab:hover { filter: brightness(1.06); }

/* ---------- Toasts ---------- */
#toasts { position: fixed; top: 14px; right: 14px; left: 14px; z-index: 2000; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast-x {
    pointer-events: auto; background: var(--surface); color: var(--text); border-radius: 14px; padding: 12px 14px;
    box-shadow: 0 10px 30px rgba(20, 24, 70, .25); display: flex; gap: 10px; align-items: center; max-width: 380px;
    border-left: 5px solid var(--brand); animation: slideIn .3s ease;
}
.toast-x.expense { border-color: #f59e0b; } .toast-x.join { border-color: var(--pos); }
.toast-x.qr { border-color: var(--brand-2); } .toast-x.closed { border-color: var(--neg); }
.toast-x.out { opacity: 0; transform: translateX(30px); transition: all .3s; }
@keyframes slideIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* ---------- Home ---------- */
.home-hero { text-align: center; padding: 56px 0 26px; }
.home-hero .logo { width: 72px; height: 72px; border-radius: 22px; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 2rem; background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 12px 30px rgba(91, 91, 240, .4); }
.home-hero h1 { font-weight: 800; }
.feature-list { display: grid; gap: 10px; margin-top: 22px; }
.feature { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: .92rem; }
.feature i { width: 34px; height: 34px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; flex: none; }

.modal-content { background: var(--surface); color: var(--text); border-radius: 20px; border: 0; }
.modal-header, .modal-footer { border-color: var(--line); }
.btn-close { filter: var(--close-filter, none); }
@media (prefers-color-scheme: dark) { :root { --close-filter: invert(1); } }

/* ---------- Bổ sung: form, nút nổi, thanh toán ---------- */
html { -webkit-text-size-adjust: 100%; }
.text-brand { color: var(--brand); }
.hero-card.home-top { padding: 30px 22px 56px; margin-bottom: -34px; }
.home-top .logo {
    width: 68px; height: 68px; border-radius: 22px; margin: 0 auto 14px; display: flex; align-items: center; justify-content: center;
    font-size: 1.9rem; color: #fff; background: rgba(255, 255, 255, .2); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}
.form-card { position: relative; max-width: 480px; margin-left: auto; margin-right: auto; padding: 20px; }
.feature-card { max-width: 480px; margin: 14px auto 0; }
.feature-list { display: grid; gap: 12px; }
.input-icon { position: relative; }
.input-icon > i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .form-control { padding-left: 40px; }
.option-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.btn-lg-x { padding: 13px 18px; font-size: 1rem; }
.btn-sm-x { padding: 7px 12px; font-size: .85rem; border-radius: 10px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.section-h { font-weight: 700; margin: 18px 2px 10px; font-size: .95rem; }
.section-h i { color: var(--brand); margin-right: 4px; }
.done-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: .9rem; }
.done-row i { color: var(--pos); }
.done-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

.fab { bottom: calc(22px + env(safe-area-inset-bottom)); right: 20px; }
.fab-leave {
    position: fixed; left: 20px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 30; border: 0; font-weight: 700;
    padding: 14px 20px; border-radius: 99px; background: var(--surface); color: var(--neg); box-shadow: 0 10px 28px rgba(20, 24, 70, .22);
}
.fab-leave:hover { background: var(--neg-soft); }
.fab-leave.d-none { display: none !important; }
.toast-x.paid { border-color: #0ea5e9; } .toast-x.confirmed { border-color: var(--pos); }
.toast-x.rejected, .toast-x.kicked { border-color: var(--neg); } .toast-x.leave, .toast-x.password { border-color: var(--muted); }

/* ---------- Responsive điện thoại ---------- */
@media (max-width: 575.98px) {
    .app-wrap { padding-left: 12px; padding-right: 12px; padding-bottom: 120px; }
    .hero-card { margin-left: -12px; margin-right: -12px; padding: 20px 16px 18px; border-radius: 0 0 22px 22px; }
    .hero-card.home-top { padding: 24px 16px 50px; }
    .hero-title { font-size: 1.3rem; }
    .stat { min-width: 0; flex: 1 1 28%; padding: 8px 10px; }
    .stat b { font-size: .95rem; word-break: break-word; }
    .invite { flex-direction: column; }
    .btn-glass { width: 100%; }
    .tabs { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab-btn { flex: 1 0 auto; font-size: .8rem; padding: 9px 12px; }
    .card-x { padding: 14px; border-radius: 16px; }
    .transfer-flow { flex: 1 1 100%; }
    .row-between > .actions { width: 100%; justify-content: stretch; }
    .row-between > .actions > button { flex: 1; }
    .transfer-flow .who, .transfer-flow .who span { max-width: 78px; }
    .fab { right: 14px; padding: 13px 18px; font-size: .95rem; }
    .fab-leave { left: 14px; width: 48px; height: 48px; padding: 0; display: flex; align-items: center; justify-content: center; }
    .fab-leave span { display: none; }
    .form-control, .form-select { font-size: 16px; } /* tránh iOS tự phóng to khi nhập */
    #toasts { top: 8px; left: 8px; right: 8px; }
    .toast-x { max-width: 100%; width: 100%; }
    .modal-body, .modal-header, .modal-footer { padding-left: 16px; padding-right: 16px; }
}

/* QR sinh ra có sẵn số tiền */
.qr-gen { display: inline-block; padding: 12px; background: #fff; border-radius: 16px; border: 1px solid var(--line); }
.qr-gen img, .qr-gen canvas { display: block; max-width: 100%; height: auto; }
.modal-body img.qr-preview { max-height: 70vh; object-fit: contain; }
