/* Thiết kế ưu tiên điện thoại; màn hình lớn chỉ nới rộng ra ở cuối file */

:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #edf1f0;
  --border: #dde3e1;
  --text: #1a2422;
  --muted: #5d6b68;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d8efec;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn: #8a5208;
  --warn-soft: #fdf0d8;
  --ok: #17643a;
  --ok-soft: #dbf2e3;
  --info: #1d4f91;
  --info-soft: #e0eaf9;
  --shadow: 0 1px 2px rgb(16 24 22 / 6%), 0 2px 10px rgb(16 24 22 / 5%);
  --radius: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514;
    --surface: #18201e;
    --surface-2: #222c2a;
    --border: #2e3a37;
    --text: #e6eceb;
    --muted: #9aa8a5;
    --primary: #2fb3a6;
    --primary-ink: #04201c;
    --primary-soft: #153834;
    --danger: #f08479;
    --danger-soft: #3b1e1b;
    --warn: #f0b660;
    --warn-soft: #382a14;
    --ok: #6fd39a;
    --ok-soft: #163224;
    --info: #8db8f2;
    --info-soft: #1a2a42;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

a { color: var(--primary); }
button, a, label, summary { touch-action: manipulation; }
h1, h2 { line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.loading, .empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- Khung ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: calc(52px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 16px 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-size: 1.05rem; }
.brand img { border-radius: 8px; }
.who { display: flex; align-items: center; color: inherit; text-decoration: none; text-align: right; line-height: 1.2; min-width: 0; }
.who strong { display: block; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
.who small { display: block; font-size: .75rem; color: var(--muted); }

/* Thanh menu dưới cùng */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 4px 4px var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
}
.tabs a {
  position: relative; flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 12px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabs a.active { color: var(--primary); }
.nav-icon {
  display: grid; place-items: center; width: 52px; height: 30px; border-radius: 999px;
  font-size: 1.25rem; transition: background .15s;
}
.tabs a.active .nav-icon { background: var(--primary-soft); }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.badge {
  position: absolute; top: 2px; left: calc(50% + 8px);
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; line-height: 20px; text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

.main {
  max-width: 720px; margin: 0 auto;
  padding: 12px 16px calc(var(--nav-h) + var(--safe-b) + 28px);
}
.page-title { font-size: 1.45rem; margin: 6px 0 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-head .btn { min-height: 40px; padding: 0 14px; }

/* ---------- Thành phần ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.list { display: flex; flex-direction: column; }
.gap { margin-bottom: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 650; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn.danger-text { color: var(--danger); }
.btn.block { width: 100%; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font-size: 1rem; cursor: pointer;
}
.btn:focus-visible, .icon-btn:focus-visible, .chip input:focus-visible + span, .chip-btn:focus-visible,
.tabs a:focus-visible, .copy-btn:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 2px;
}

label { display: block; font-weight: 600; margin-bottom: 14px; }
label.check { display: flex; align-items: center; gap: 12px; font-weight: 500; min-height: 44px; margin-bottom: 4px; }
label.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
/* font-size 16px để iPhone không tự phóng to khi chạm vào ô nhập */
input:where(:not([type=checkbox], [type=radio])), select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; min-height: 48px;
  font: inherit; font-size: 16px; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  -webkit-appearance: none; appearance: none;
}
select {
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 12px; margin: 0 0 14px; }

.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.chip { margin: 0; font-weight: 500; position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 8px 14px;
  border: 1.5px solid var(--border); border-radius: 14px; cursor: pointer; background: var(--surface);
  transition: border-color .15s, background .15s;
}
.chip input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 650; }

.money-input { position: relative; display: block; }
.money-input input { padding-right: 40px; font-size: 1.5rem; font-weight: 700; letter-spacing: .01em; min-height: 58px; }
.money-input > span { position: absolute; right: 16px; top: 50%; transform: translateY(-40%); color: var(--muted); font-weight: 700; font-size: 1.1rem; }
.quick { display: flex; gap: 8px; margin: -6px 0 16px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.quick::-webkit-scrollbar { display: none; }
.chip-btn {
  flex: none; min-height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.chip-btn:active { background: var(--primary-soft); }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.filters label:last-child:nth-child(odd) { grid-column: 1 / -1; }
.filters label { font-size: .85rem; margin-bottom: 12px; }
.filters input, .filters select { min-height: 44px; padding-top: 9px; padding-bottom: 9px; }

/* Thẻ yêu cầu */
.req { padding: 14px 14px 12px; }
.req-head { display: flex; align-items: center; gap: 12px; }
.cat-icon {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px;
  border-radius: 14px; background: var(--surface-2); font-size: 1.35rem;
}
.req-title { flex: 1; min-width: 0; line-height: 1.3; }
.req-title strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.req-title .sub { display: block; font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.req-amount { flex: none; text-align: right; line-height: 1.2; }
.amount { display: block; font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.req-amount s { font-size: .78rem; color: var(--muted); }
.reason { margin: 10px 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.req-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.needed { font-size: .8rem; color: var(--muted); }
.status { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; line-height: 1.4; }
.status.pending { background: var(--warn-soft); color: var(--warn); }
.status.approved { background: var(--info-soft); color: var(--info); }
.status.transferred { background: var(--ok-soft); color: var(--ok); }
.status.rejected { background: var(--danger-soft); color: var(--danger); }
.status.cancelled { background: var(--surface-2); color: var(--muted); }
.timeline { list-style: none; margin: 10px 0 0; padding: 10px 0 0; border-top: 1px solid var(--border); font-size: .84rem; color: var(--muted); }
.timeline li { padding-left: 18px; position: relative; margin-bottom: 4px; overflow-wrap: anywhere; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: .55em; width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.timeline li.pos::before { background: var(--ok); }
.timeline li.neg::before { background: var(--danger); }
.timeline b { color: var(--text); font-weight: 600; }
.timeline q { display: block; font-style: italic; color: var(--text); }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1 1 0; }

/* Thống kê */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stats.compact { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat-label { display: block; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat strong { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat small { display: block; font-size: .75rem; color: var(--muted); }
.stats.compact .stat { padding: 10px; }
.stats.compact .stat strong { font-size: .98rem; }

/* Bảng báo cáo: trên điện thoại mỗi dòng thành một khối */
.table-card { padding: 16px 0 4px; }
.table-card h2 { padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead { display: none; }
tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
td { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; font-variant-numeric: tabular-nums; }
td.name { grid-column: 1 / -1; font-weight: 650; padding-bottom: 4px; }
td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }

.user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.user-row.inactive { opacity: .6; }
.help { margin-top: 8px; }
.profile { display: flex; align-items: center; gap: 14px; }
.avatar {
  display: grid; place-items: center; width: 52px; height: 52px; flex: none; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary); font-size: 1.4rem; font-weight: 750;
}
.steps { margin: 0 0 4px; padding-left: 22px; }
.steps li { margin-bottom: 6px; }

/* Nhắc bật thông báo */
.push-banner {
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
  background: var(--warn-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
}
.push-banner.off { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.push-banner p:last-child, .push-banner ol:last-child { margin-bottom: 0; }

/* Đăng nhập */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 400px; padding: 24px 20px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.logo-img { border-radius: 18px; }
.login-brand h1 { margin: 8px 0 0; }
.login-brand p { margin: 4px 0 0; }

/* ---------- Hộp thoại: trượt lên từ dưới trên điện thoại ---------- */
dialog {
  width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh;
  margin: auto 0 0; padding: 0; border: 0; border-radius: 22px 22px 0 0;
  background: var(--surface); color: var(--text); overflow: hidden;
}
dialog[open] { animation: sheet-up .22s ease-out; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
#dlg-form { display: flex; flex-direction: column; max-height: inherit; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { font-size: 1.1rem; margin: 0; }
.dlg-scroll { overflow-y: auto; padding: 14px 16px 4px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.dlg-actions {
  display: flex; gap: 8px; padding: 10px 16px calc(10px + var(--safe-b));
  border-top: 1px solid var(--border); background: var(--surface);
}
.dlg-actions .btn { flex: 1 1 0; }
.dlg-actions .btn.primary, .dlg-actions .btn.danger { flex-grow: 2; }
.big-amount { font-size: 2rem; font-weight: 800; margin: 0 0 2px; color: var(--primary); font-variant-numeric: tabular-nums; }

/* Chuyển tiền */
.pay-box { background: var(--surface-2); border-radius: 14px; padding: 2px 12px; margin: 12px 0; }
.pay-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.pay-row:last-child { border-bottom: 0; }
.pay-row > span { grid-column: 1 / -1; font-size: .75rem; color: var(--muted); }
.pay-row > b { min-width: 0; overflow-wrap: anywhere; font-size: 1.02rem; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .03em; }
.copy-btn {
  min-height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--primary); font: inherit; font-size: .82rem; font-weight: 650; cursor: pointer;
}
.pay-app { margin-bottom: 8px; }
.pay-app .btn { margin-bottom: 6px; min-height: 54px; font-size: 1.05rem; }
.pay-qr { margin-bottom: 14px; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.pay-qr summary { cursor: pointer; font-weight: 600; }
.pay-qr img { display: block; width: 240px; max-width: 100%; height: auto; margin: 12px auto; background: #fff; border-radius: 10px; }
.notice { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 12px; }
.bank-fields { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }

/* Thông báo nhanh, nằm trên thanh menu */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); z-index: 100;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 600; text-align: center;
  transition: opacity .2s, transform .2s; box-shadow: 0 6px 24px rgb(0 0 0 / 20%);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }

/* ---------- Màn hình lớn (máy tính / máy tính bảng) ---------- */
@media (min-width: 760px) {
  .tabs {
    position: sticky; top: calc(52px + env(safe-area-inset-top, 0px)); bottom: auto;
    height: auto; max-width: 720px; margin: 0 auto; padding: 8px 16px;
    justify-content: flex-start; gap: 4px; background: transparent; border: 0;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tabs a { flex: none; flex-direction: row; gap: 6px; padding: 6px 14px 6px 6px; font-size: .9rem; border-radius: 999px; }
  .tabs a.active { background: var(--primary-soft); }
  .nav-icon { width: 30px; height: 30px; font-size: 1.1rem; }
  .tabs a.active .nav-icon { background: transparent; }
  .badge { position: static; box-shadow: none; }
  .main { padding-bottom: 40px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stats.compact { grid-template-columns: repeat(3, 1fr); }
  .chips { grid-template-columns: repeat(3, 1fr); }
  #toast { bottom: 24px; }
  dialog { width: min(480px, calc(100vw - 32px)); margin: auto; border-radius: 20px; }
  .dlg-actions { padding-bottom: 12px; }
  thead { display: table-header-group; }
  tbody tr { display: table-row; padding: 0; }
  td, th { display: table-cell; padding: 10px 16px; border-top: 1px solid var(--border); text-align: left; white-space: nowrap; }
  td[data-label]::before { content: none; }
  th { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
  .num { text-align: right; }
  td.name { padding-bottom: 10px; }
}

/* ---------- Quỹ gia đình ---------- */
.fund-hero {
  border-radius: 20px; padding: 18px 18px 16px; margin-bottom: 14px; color: #fff;
  background: linear-gradient(135deg, #0f766e, #115e59);
  box-shadow: 0 6px 20px rgb(15 118 110 / 25%);
}
.fund-hero.neg { background: linear-gradient(135deg, #b42318, #912018); box-shadow: 0 6px 20px rgb(180 35 24 / 25%); }
.fund-label { display: block; font-size: .85rem; opacity: .85; }
.fund-balance { display: block; font-size: 2.2rem; font-weight: 800; line-height: 1.2; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.fund-hero p { margin: 0 0 6px; font-size: .88rem; opacity: .95; }
.fund-warn { background: rgb(255 255 255 / 16%); border-radius: 10px; padding: 6px 10px; font-weight: 600; }
.fund-actions { display: flex; gap: 8px; margin-top: 12px; }
.fund-actions .btn { flex: 1 1 0; background: rgb(255 255 255 / 16%); color: #fff; border-color: rgb(255 255 255 / 35%); }

.fund-flow { margin: 0; }
.fund-flow > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.fund-flow dt { color: var(--muted); }
.fund-flow dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.fund-flow .in dd { color: var(--ok); }
.fund-flow .out dd { color: var(--danger); }
.fund-flow .total { border-bottom: 0; padding-top: 10px; }
.fund-flow .total dt { color: var(--text); font-weight: 700; }
.fund-flow .total dd { font-size: 1.15rem; font-weight: 800; color: var(--primary); }
.fund-flow .total.neg dd { color: var(--danger); }

.ledger { padding-bottom: 4px; }
.ledger ul { list-style: none; margin: 0 -16px; padding: 0; }
.fund-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--border); }
.fund-row .cat-icon { width: 40px; height: 40px; font-size: 1.2rem; }
.fund-row .req-title strong { font-size: .95rem; }
.fund-amt { flex: none; text-align: right; }
.fund-amt b { display: block; font-variant-numeric: tabular-nums; }
.fund-row.deposit .fund-amt b { color: var(--ok); }
.fund-row.expense .fund-amt b, .fund-row.transfer .fund-amt b { color: var(--danger); }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--muted); font: inherit; font-size: .78rem; text-decoration: underline; cursor: pointer; }
.fund-line { margin-top: -4px; }
.notice a { color: inherit; font-weight: 700; }
