:root {
  --bg: #F5F4EF; --card: #FFFFFF; --ink: #1F2A27; --muted: #6B7470; --line: #E4E2DA;
  --brand: #2F5D50; --brand-2: #3F7A69; --brand-soft: #E5EFEA; --gold: #C9A227; --gold-soft: #FBF3DA;
  --in: #1E7A4F; --in-soft: #E3F3EA; --out: #B3412F; --out-soft: #FBE8E4; --xfer: #5B6B8C; --xfer-soft: #E8ECF4;
  --warn: #B7791F; --warn-soft: #FDF1DC;
  --radius: 14px; --shadow: 0 1px 2px rgba(31,42,39,.06), 0 4px 14px rgba(31,42,39,.05);
  --font: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; -webkit-text-size-adjust: 100% }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)) }
button, input, select, textarea { font: inherit; color: inherit }
a { color: var(--brand) }
.boot { padding: 40vh 0; text-align: center; color: var(--muted) }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px }
.num { font-variant-numeric: tabular-nums; white-space: nowrap }
.muted { color: var(--muted) } .small { font-size: 13px } .tiny { font-size: 12px }
.in { color: var(--in) } .out { color: var(--out) } .xf { color: var(--xfer) }
.hide { display: none !important }
.row { display: flex; align-items: center; gap: 10px } .row.between { justify-content: space-between } .grow { flex: 1; min-width: 0 }
.wrapt { flex-wrap: wrap }

/* Thanh trên */
.top { position: sticky; top: 0; z-index: 5; background: rgba(245,244,239,.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top) }
.top .wrap { display: flex; align-items: center; gap: 12px; min-height: 56px }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--brand); text-decoration: none }
.brand img { width: 28px; height: 28px; border-radius: 8px }
.top h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.month { display: inline-flex; align-items: center; border: 1px solid var(--line); background: var(--card); border-radius: 999px; overflow: hidden }
.month button { border: 0; background: none; padding: 6px 10px; cursor: pointer; font-size: 16px; color: var(--brand) }
.month span { font-weight: 600; font-size: 14px; padding: 0 2px; min-width: 76px; text-align: center }

/* Thanh dưới */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom) }
.nav .wrap { display: grid; grid-template-columns: repeat(6, 1fr); align-items: end; padding: 0 2px }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500 }
.nav a svg { width: 22px; height: 22px }
.nav a.on { color: var(--brand) }
.nav .plus { display: flex; justify-content: center }
.nav .plus button { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 30px; line-height: 1; margin-top: -22px; box-shadow: 0 6px 16px rgba(47,93,80,.35); cursor: pointer }

/* Thẻ */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 14px 0 }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px }
.card h2 small { font-weight: 400; color: var(--muted); font-size: 12px }
.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff }
.hero .muted { color: rgba(255,255,255,.75) }
.hero .big { font-size: 30px; font-weight: 700; letter-spacing: -.5px }
.hero .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px }
.hero .grid3 div { background: rgba(255,255,255,.12); border-radius: 10px; padding: 8px 10px }
.hero .grid3 b { display: block; font-size: 15px }
.hero .lbl { font-size: 12px; opacity: .8 }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0 }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px }
.kpi .lbl { font-size: 12px; color: var(--muted) }
.kpi .val { font-size: 20px; font-weight: 700; margin-top: 2px }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr) } }

.list { margin: 0; padding: 0; list-style: none }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line) }
.list li:last-child { border-bottom: 0 }
.ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; background: var(--brand-soft); flex: none }
.ico.out { background: var(--out-soft) } .ico.in { background: var(--in-soft) } .ico.xf { background: var(--xfer-soft) }
.tline { cursor: pointer }
.tline .t1 { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.tline .t2 { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.tline .amt { font-weight: 600 }
.dayhead { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 14px 2px 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px }

.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none }
.chips::-webkit-scrollbar { display: none }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 600 }
.tag.warn { background: var(--warn-soft); color: var(--warn) } .tag.bad { background: var(--out-soft); color: var(--out) } .tag.good { background: var(--in-soft); color: var(--in) } .tag.gray { background: #EEE; color: #666 }

.bar { height: 8px; background: #EEECE5; border-radius: 99px; overflow: hidden; position: relative }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px }
.bar i.warn { background: var(--warn) } .bar i.bad { background: var(--out) }

.alert { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 10px 0; display: flex; gap: 8px; align-items: flex-start }
.alert.warn { background: var(--warn-soft); color: #7A4F0F } .alert.bad { background: var(--out-soft); color: #7D2A1D } .alert.info { background: var(--brand-soft); color: var(--brand) }

/* Nút & ô nhập */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px }
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff }
.btn.gold { background: var(--gold-soft); border-color: #EBD99A; color: #6F5810 }
.btn.danger { color: var(--out); border-color: #F0C7BF }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px }
.btn.block { width: 100% }
.btn:disabled { opacity: .55; cursor: default }
label.f { display: block; margin: 10px 0 }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500 }
input.i, select.i, textarea.i { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; font-size: 16px }
input.i:focus, select.i:focus, textarea.i:focus { outline: 2px solid rgba(47,93,80,.25); border-color: var(--brand) }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; font-size: 14px }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand) }
.err { color: var(--out); font-size: 14px; min-height: 18px; margin-top: 6px }

/* Bảng */
table.t { width: 100%; border-collapse: collapse; font-size: 13px }
table.t th, table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right }
table.t th:first-child, table.t td:first-child { text-align: left }
table.t th { color: var(--muted); font-weight: 600; font-size: 12px }
.scrollx { overflow-x: auto }

/* Bảng nhập (sheet) */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(20,28,25,.45); display: flex; align-items: flex-end; justify-content: center }
.sheet[hidden] { display: none }
.sheet .panel { background: var(--bg); width: 100%; max-width: 560px; max-height: 94vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .18s ease-out }
@media (min-width: 640px) { .sheet { align-items: center } .sheet .panel { border-radius: 20px } }
@keyframes up { from { transform: translateY(30px); opacity: .5 } to { transform: none; opacity: 1 } }
.sheet .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px }
.sheet .head h3 { margin: 0; font-size: 17px }
.x { border: 0; background: #E8E6DE; width: 32px; height: 32px; border-radius: 50%; font-size: 18px; cursor: pointer }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: #E8E6DE; border-radius: 12px; padding: 3px; gap: 3px }
.seg button { border: 0; background: none; border-radius: 9px; padding: 8px; font-weight: 600; cursor: pointer; color: var(--muted) }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08) }
.seg button.on.out { color: var(--out) } .seg button.on.in { color: var(--in) } .seg button.on.xf { color: var(--xfer) }
.amount { font-size: 32px; font-weight: 700; text-align: center; border: 0; background: transparent; width: 100%; padding: 14px 0 0; outline: none }
.amount-hint { text-align: center; color: var(--muted); font-size: 13px; min-height: 18px }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px }
.cats button { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 4px; font-size: 11.5px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; line-height: 1.25; min-height: 66px }
.cats button b { font-size: 20px; font-weight: 400 }
.cats button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600 }
.sec { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 14px 0 4px }

/* Đăng nhập */
.auth { max-width: 400px; margin: 0 auto; padding: 9vh 20px 40px }
.auth .logo { text-align: center }
.auth .logo img { width: 76px; height: 76px; border-radius: 18px }
.auth .logo h1 { font-family: "Playfair Display", serif; color: var(--brand); font-size: 26px; margin: 10px 0 2px }
.auth .logo p { color: var(--muted); margin: 0 0 22px; font-size: 14px }

.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 14px; max-width: 90vw; text-align: center }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px }
.tabs { display: flex; gap: 6px; margin: 12px 0 }
.chart { width: 100%; height: auto; display: block }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px }
.pill-in { background: var(--in) } .pill-out { background: var(--out) }
details.card summary { cursor: pointer; font-weight: 600; list-style: none }
details.card summary::-webkit-details-marker { display: none }
details.card summary::after { content: "›"; float: right; transform: rotate(90deg); color: var(--muted) }
details.card[open] summary::after { transform: rotate(-90deg) }
.ol { margin: 6px 0; padding-left: 20px } .ol li { margin: 6px 0 }
