/* DomBeo Asset - mobile-first */
:root {
  --bg: #f4f2fb;
  --bg2: #ffffff;
  --card: #ffffff;
  --text: #1c1530;
  --muted: #6f6886;
  --line: #ebe7f5;
  --soft: #f3effc;
  --primary: #6d28d9;
  --primary-2: #db2777;
  --up: #059669;
  --down: #e11d48;
  --warn: #d97706;
  --shadow: 0 6px 24px rgba(60, 30, 120, .08);
  --radius: 20px;
  --dom: #2563eb;
  --beo: #db2777;
  --chung: #7c3aed;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --maxw: 560px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0a1f;
    --bg2: #171029;
    --card: #1a1330;
    --text: #f1edff;
    --muted: #a59dbf;
    --line: #2b2246;
    --soft: #241b3d;
    --primary: #a78bfa;
    --primary-2: #f472b6;
    --up: #34d399;
    --down: #fb7185;
    --warn: #fbbf24;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 16px; font-weight: 700; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.money { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* ---------- Splash ---------- */
.splash { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--bg); z-index: 50; transition: opacity .3s; }
.splash img { animation: pulse 1.4s ease-in-out infinite; }
.splash-text { font-weight: 800; font-size: 18px; }
.splash.fade { opacity: 0; pointer-events: none; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px calc(24px + var(--safe-b));
  background: radial-gradient(1000px 500px at 10% -10%, rgba(109, 40, 217, .25), transparent 60%),
              radial-gradient(800px 500px at 110% 110%, rgba(219, 39, 119, .22), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 28px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.login-logo { display: block; margin: 0 auto 10px; border-radius: 22px; }
.login-card h1 { font-size: 24px; font-weight: 800; }
.login-card form { text-align: left; margin-top: 20px; display: grid; gap: 14px; }
.who-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.who-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.who-btn { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 16px; border: 2px solid var(--line); background: var(--bg2); font-weight: 700; transition: .15s; }
.who-btn[aria-checked="true"] { border-color: var(--primary); background: var(--soft); box-shadow: 0 0 0 4px rgba(124, 58, 237, .12); }
.who-ava { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; }
.ava-dom { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.ava-beo { background: linear-gradient(135deg, #f472b6, #be185d); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--bg2);
  outline: none; font-size: 16px; transition: border-color .15s, box-shadow .15s; }
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(124, 58, 237, .12); }
#pin { font-size: 22px; letter-spacing: .35em; text-align: center; }
.form-error { color: var(--down); font-size: 13.5px; min-height: 1em; }
.hint { font-size: 12.5px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn { border: 0; border-radius: 14px; padding: 13px 16px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .1s, opacity .15s; text-align: center; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-block { width: 100%; }
.btn-primary { color: #fff; background: linear-gradient(135deg, #7c3aed, #db2777); box-shadow: 0 8px 20px rgba(124, 58, 237, .28); }
.btn-ghost { background: var(--soft); color: var(--primary); }
.btn-danger { background: var(--down); color: #fff; }
.btn-danger-ghost { background: rgba(225, 29, 72, .1); color: var(--down); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 11px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--soft); display: grid; place-items: center; font-size: 18px; }
.file-btn { cursor: pointer; margin-top: 10px; }

/* ---------- App layout ---------- */
.app { max-width: var(--maxw); margin: 0 auto; padding: calc(8px + var(--safe-t)) 16px calc(96px + var(--safe-b)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 12px; position: sticky; top: 0; z-index: 5; background: var(--bg); }
.topbar-left { display: flex; gap: 10px; align-items: center; }
.topbar-logo { border-radius: 10px; }
.topbar-title { font-weight: 800; font-size: 17px; }
.topbar-sub { font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; }
.view { animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
.page-title { font-size: 20px; font-weight: 800; margin: 6px 0 14px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1.5px solid var(--line); background: var(--card); padding: 7px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; white-space: nowrap; transition: .15s; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden; border-radius: 26px; padding: 20px 20px 18px; color: #fff;
  background: linear-gradient(135deg, #5b21b6 0%, #7c3aed 40%, #db2777 100%); box-shadow: 0 14px 34px rgba(109, 40, 217, .35); }
.hero-deco { position: absolute; width: 220px; height: 220px; right: -70px; top: -80px; border-radius: 50%; background: rgba(255, 255, 255, .12); pointer-events: none; }
.hero-deco::after { content: ''; position: absolute; width: 140px; height: 140px; left: -60px; top: 150px; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.hero-label { font-size: 13.5px; opacity: .9; font-weight: 600; }
.hero-value { font-size: clamp(26px, 8.4vw, 36px); font-weight: 800; margin: 2px 0 8px; position: relative; z-index: 1; cursor: pointer; word-break: break-word; }
.hero-changes { display: flex; flex-wrap: wrap; gap: 6px; position: relative; z-index: 1; }
.delta { font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, .18); color: #fff; }
.delta.up { background: rgba(16, 185, 129, .45); color: #fff; }
.delta.down { background: rgba(244, 63, 94, .5); color: #fff; }
.delta:empty { display: none; }
.hero-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .22); position: relative; z-index: 1; }
.hero-mini-label { font-size: 12px; opacity: .85; }
.hero-mini { font-weight: 700; font-size: 15.5px; }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-top: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.alert { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 16px; margin-top: 12px; background: rgba(217, 119, 6, .12); border: 1px solid rgba(217, 119, 6, .35); cursor: pointer; }
.alert.due { background: rgba(225, 29, 72, .1); border-color: rgba(225, 29, 72, .35); }
.alert-ico { font-size: 22px; }
.alert-title { font-weight: 700; font-size: 14px; }

.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 14px; align-items: center; }
.donut-box { position: relative; width: 150px; height: 150px; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center-label { font-size: 10.5px; color: var(--muted); }
.donut-center-value { font-size: 13.5px; font-weight: 800; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.legend li { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; }
.legend .pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.legend .lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 370px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } .legend { width: 100%; } }

.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 2px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 4px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }
.line-box { position: relative; height: 190px; }

/* ---------- Groups ---------- */
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 2px 4px; }
.group { background: var(--card); border-radius: var(--radius); margin-top: 10px; box-shadow: var(--shadow); overflow: hidden; }
.group-head { width: 100%; border: 0; background: transparent; display: grid; grid-template-columns: 40px 1fr auto 18px; gap: 10px; align-items: center; padding: 12px 14px; text-align: left; }
.cat-ico { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-size: 20px; }
.group-name { font-weight: 700; font-size: 14.5px; }
.group-sub { font-size: 12px; color: var(--muted); }
.group-total { font-weight: 800; font-size: 14.5px; text-align: right; }
.group-total.neg { color: var(--down); }
.chev { transition: transform .2s; color: var(--muted); font-size: 12px; }
.group.open .chev { transform: rotate(90deg); }
.group-body { display: none; border-top: 1px solid var(--line); }
.group.open .group-body { display: block; }
.group-actions { display: flex; gap: 8px; padding: 10px 14px 0; flex-wrap: wrap; }
.row { width: 100%; border: 0; background: transparent; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--soft); }
.row-name { font-weight: 600; font-size: 14.5px; overflow-wrap: anywhere; }
.row-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.row-right { text-align: right; }
.row-value { font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.pnl { font-size: 12px; font-weight: 600; white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; color: #fff; text-transform: uppercase; letter-spacing: .02em; }
.b-dom { background: var(--dom); }
.b-beo { background: var(--beo); }
.b-chung { background: var(--chung); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--soft); color: var(--muted); font-weight: 600; }
.tag.warn { background: rgba(217, 119, 6, .15); color: var(--warn); }
.tag.due { background: rgba(225, 29, 72, .12); color: var(--down); }
.empty { text-align: center; padding: 36px 10px; }
.empty-emoji { font-size: 40px; }

/* ---------- FAB + Tabbar ---------- */
.fab { position: fixed; right: max(18px, calc(50% - var(--maxw) / 2 + 18px)); bottom: calc(80px + var(--safe-b)); width: 58px; height: 58px; border-radius: 20px; border: 0; color: #fff; font-size: 32px; font-weight: 400; line-height: 1;
  background: linear-gradient(135deg, #7c3aed, #db2777); box-shadow: 0 12px 28px rgba(124, 58, 237, .45); z-index: 10; transition: transform .15s; }
.fab:active { transform: scale(.94); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; display: flex; justify-content: center; gap: 4px; padding: 6px 10px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tab { flex: 1; max-width: 180px; border: 0; background: transparent; display: grid; justify-items: center; gap: 1px; padding: 6px 0; font-size: 11.5px; font-weight: 600; color: var(--muted); border-radius: 12px; }
.tab-ico { font-size: 20px; filter: grayscale(1); opacity: .7; transition: .15s; }
.tab.active { color: var(--primary); }
.tab.active .tab-ico { filter: none; opacity: 1; transform: translateY(-1px); }

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 5, 25, .5); z-index: 20; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: var(--maxw); max-height: 92dvh; display: flex; flex-direction: column; background: var(--card); border-radius: 26px 26px 0 0; z-index: 21; box-shadow: 0 -10px 40px rgba(0, 0, 0, .2); animation: up .25s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(100%); } }
.sheet-grip { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 8px auto 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px 6px; }
.sheet-head h3 { font-size: 18px; font-weight: 800; }
.sheet-body { overflow-y: auto; padding: 6px 16px calc(20px + var(--safe-b)); display: grid; gap: 14px; -webkit-overflow-scrolling: touch; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat-opt { border: 1.5px solid var(--line); background: var(--bg2); border-radius: 12px; padding: 7px 2px; display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 600; text-align: center; line-height: 1.15; min-width: 0; }
.cat-opt .e { font-size: 19px; }
.cat-opt.active { border-color: var(--primary); background: var(--soft); box-shadow: 0 0 0 3px rgba(124, 58, 237, .12); }
.owner-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.owner-seg button { border: 1.5px solid var(--line); background: var(--bg2); border-radius: 12px; padding: 10px; font-weight: 700; }
.owner-seg button.active[data-v="dom"] { border-color: var(--dom); background: rgba(37, 99, 235, .1); color: var(--dom); }
.owner-seg button.active[data-v="beo"] { border-color: var(--beo); background: rgba(219, 39, 119, .1); color: var(--beo); }
.owner-seg button.active[data-v="chung"] { border-color: var(--chung); background: rgba(124, 58, 237, .1); color: var(--chung); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview { background: var(--soft); border-radius: 14px; padding: 12px 14px; font-size: 13.5px; display: grid; gap: 4px; }
.preview b { font-variant-numeric: tabular-nums; }
.preview-row { display: flex; justify-content: space-between; gap: 10px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 4px; }
.sheet-actions.single { grid-template-columns: 1fr; }
.confirm-text { font-size: 15px; }
.detail-list { display: grid; gap: 8px; font-size: 14px; }
.detail-list .preview-row span:first-child { color: var(--muted); }

/* ---------- History ---------- */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.h-item { background: var(--card); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); display: grid; grid-template-columns: 36px 1fr; gap: 12px; }
.h-ico { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; font-size: 17px; background: var(--soft); }
.h-title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.h-time { font-size: 12px; color: var(--muted); }
.h-diff { font-size: 12.5px; margin-top: 4px; display: grid; gap: 2px; }
.h-diff .old { color: var(--muted); text-decoration: line-through; }
.h-day { font-size: 12.5px; font-weight: 700; color: var(--muted); margin: 8px 4px -2px; list-style: none; }

/* ---------- Settings ---------- */
.settings { display: grid; gap: 4px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; font-size: 14.5px; }
.set-title { font-weight: 700; }
.switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: .2s; cursor: pointer; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch:checked { background: var(--primary); }
.switch:checked::after { left: 21px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #1c1530; color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: .25s; z-index: 40; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #be123c; }
@media (prefers-color-scheme: dark) { .toast { background: #f1edff; color: #1c1530; } .toast.err { background: #fb7185; color: #fff; } }

@media (min-width: 720px) {
  .app { padding-top: 20px; }
  .hero { padding: 26px; }
  .line-box { height: 230px; }
}
