:root {
  --brand: #ee4d2d;
  --brand-dark: #d73211;
  --brand-soft: #fff1ed;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --ok: #138a4c;
  --ok-soft: #e7f6ee;
  --warn: #b86e00;
  --warn-soft: #fff5e0;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft: #3a1c15;
    --bg: #111113;
    --card: #1c1c1f;
    --text: #f2f2f5;
    --muted: #a1a1a8;
    --line: #2e2e33;
    --ok: #4fd18b;
    --ok-soft: #12301f;
    --warn: #f0b14a;
    --warn-soft: #33260c;
    --bad: #ff6b6b;
    --bad-soft: #3a1515;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.center { text-align: center; margin: 8px 0 0; }
.small { font-size: .875rem; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: .9rem; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.loading { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- Nút và ô nhập ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn.light { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.5); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0 4px; min-height: 32px; }
.btn.block { width: 100%; margin-top: 4px; }
label { display: block; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }
input {
  display: block; width: 100%; margin-top: 4px;
  min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font: inherit;
}
input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.input-row { display: flex; gap: 8px; margin: 4px 0 12px; }
.input-row input { margin: 0; flex: 1; min-width: 0; }

.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 8px; background: none;
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.wide { background: var(--card); }
.seg.wide button.on { background: var(--brand-soft); color: var(--brand); box-shadow: none; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

/* ---------- Đăng nhập ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: 32px 16px; }
.auth-hero { text-align: center; margin-bottom: 20px; }
.auth-hero h1 { font-size: 1.5rem; }
.auth-hero p { color: var(--muted); }
.auth-logo { width: 64px; height: 64px; margin-bottom: 8px; }

/* ---------- Bố cục ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.topnav { display: none; margin-left: auto; gap: 4px; }
.topnav .nav { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.topnav .nav.active { color: var(--brand); background: var(--brand-soft); }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .nav {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; border: 0; background: none; font: inherit; font-size: .75rem;
  color: var(--muted); cursor: pointer;
}
.bottomnav .ic { font-size: 1.25rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.bottomnav .nav.active { color: var(--brand); font-weight: 600; }
.bottomnav .nav.active .ic { filter: none; opacity: 1; }

@media (min-width: 760px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  main { padding-bottom: 40px; }
}

/* ---------- Số dư ---------- */
.balance-card {
  display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: center;
  padding: 18px; margin-bottom: 14px; border-radius: var(--radius);
  background: linear-gradient(135deg, #ee4d2d, #ff7337); color: #fff;
}
.balance-card .label { opacity: .9; font-size: .9rem; }
.balance-card .big { font-size: 2rem; font-weight: 800; letter-spacing: -.5px; line-height: 1.1; }
.balance-sub { grid-column: 1 / -1; display: flex; gap: 16px; flex-wrap: wrap; font-size: .875rem; opacity: .95; }
.balance-card .btn { grid-row: 1; grid-column: 2; }

/* ---------- Kết quả ---------- */
.result { border: 2px solid var(--ok); }
.result input { margin-bottom: 10px; font-size: .85rem; color: var(--muted); }
.guide summary { list-style: none; cursor: pointer; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary h2 { display: inline; }
.guide summary::after { content: "▾"; float: right; color: var(--muted); }
.guide:not([open]) summary::after { content: "▸"; }
.guide ol { margin: 10px 0 0; padding-left: 20px; }
.guide li { margin-bottom: 6px; }

/* ---------- Danh sách ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { color: var(--muted); font-size: .8rem; }
.list .side { text-align: right; white-space: nowrap; }
.list .amount { font-weight: 700; }
.list .empty { justify-content: center; color: var(--muted); padding: 20px 0; text-align: center; }
.list .btn { min-height: 36px; padding: 0 12px; font-size: .85rem; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--brand-soft); color: var(--brand); }

.bank-summary { padding: 12px; margin-bottom: 12px; border-radius: 10px; background: var(--bg); font-size: .9rem; }
.code-box { margin-top: 12px; padding: 14px; border-radius: 10px; background: var(--brand-soft); text-align: center; }
.code { font: 700 1.6rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: 3px; margin: 6px 0 12px; color: var(--brand); user-select: all; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: #1d1d1f; color: #fff; font-size: .9rem; z-index: 20; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.bad { background: var(--bad); }
@media (min-width: 760px) { .toast { bottom: 24px; } }
