:root{
  --bg:#0b0b0c; --card:#141416; --muted:#8b8d93; --text:#f3f4f6;
  --primary:#635bff; --danger:#ef4444; --line:#23252a;
  --tabbar:rgba(20,20,22,0.72); --blur:12px;
  --ok:#16a34a; --err:#ef4444; --amber:#f59e0b
}
body.light{
  --bg:#f6f7fb; --card:#ffffff; --muted:#667085; --text:#0f172a;
  --primary:#4f46e5; --danger:#ef4444; --line:#e5e7eb;
  --tabbar:rgba(255,255,255,0.86); --blur:16px
}

*{box-sizing:border-box}
html,body{width:100%; min-width:320px; -webkit-text-size-adjust:100%}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial;
  padding-bottom:calc(80px + env(safe-area-inset-bottom,0));
  overflow-x:hidden;
}
.wrap{width:100%; max-width:430px; margin:0 auto; padding:12px;}

.topbar{
  position:sticky; top:0; z-index:5; display:flex; justify-content:space-between; align-items:center;
  padding:10px 12px; background:var(--bg)
}
.headline{font-weight:800; font-size:16px; opacity:.95; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; animation:fadeIn .6s ease}
.theme-btn{width:36px;height:36px;border-radius:10px;border:1px solid var(--line); background:var(--card); color:var(--text); display:flex; align-items:center; justify-content:center}

/* Splash */
.splash-overlay{ position:fixed; inset:0; z-index:99999; background:var(--bg);
  animation:splashFade 1.2s ease 1s forwards;
}
.splash-scene{ position:absolute; inset:0; display:grid; place-items:center; overflow:hidden }
.splash-glow{
  position:absolute; inset:-20%;
  background:
    radial-gradient(800px 500px at 50% 120%, rgba(99,91,255,.25), transparent 60%),
    radial-gradient(700px 420px at 60% 20%, rgba(6,182,212,.18), transparent 60%),
    linear-gradient(180deg, #0b0b0c, #0e1220);
  filter: blur(40px);
  animation:glowSpin 3s ease-in-out infinite alternate;
}
.splash-card{
  width:min(86vw, 360px);
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.08);
  border-radius:20px;
  padding:24px 20px 18px;
  text-align:center;
  box-shadow:0 20px 60px rgba(0,0,0,.35);
  transform:translateY(6px) scale(.98);
  animation:rise .9s ease forwards;
}
.hello{font-size:13px; color:var(--muted); margin-bottom:6px}
.appname{font-size:24px; font-weight:900; letter-spacing:.2px}
.mini{font-size:12px; color:var(--muted); margin-top:8px}
.splash-card .loader-line{
  width:120px; height:8px; margin:12px auto 0; border-radius:999px;
}
/* Scoped loading (per card) */
.card{ position:relative; background:var(--card); border:1px solid var(--line); border-radius:16px; padding:16px; margin-top:12px }
/* Scoped loading (per card) – floating chip, non-blocking */
/* Scoped loading – chip gọn, không chặn tương tác */
.section-loading{
  position:absolute; top:0; left:0; right:0; height:3px;
  overflow:hidden; pointer-events:none; z-index:3;
  border-top-left-radius:16px; border-top-right-radius:16px;
}
.section-loading .loading-text{
  font-size:12px; letter-spacing:.2px;
  color:var(--text); opacity:.85; line-height:1;
}

.loader-line{
  position:relative; display:block;
  width:100%; height:16px; border-radius:999px;
  background:rgba(255,255,255,.08); overflow:hidden;
}
.loader-line::before{
  content:""; position:absolute; inset:0;
  width:40%;
  background:linear-gradient(90deg, transparent, var(--primary), transparent);
  transform:translateX(-100%);
  animation:loaderSlide 1.1s cubic-bezier(.4,0,.2,1) infinite;
  will-change:transform;
}

/* Splash bản to hơn một chút */
.splash-card .loader-line{ width:120px; height:8px; margin:12px auto 0; border-radius:999px; }
.splash-card .loader-line::before{
  content:""; position:absolute; inset:0;
  width:40%;
  background:linear-gradient(90deg, transparent, var(--primary), transparent);
  transform:translateX(-100%);
  animation:loaderSlide 1.1s cubic-bezier(.4,0,.2,1) infinite;
}
/* Loading chip canh text đẹp hơn */
.section-loading{ gap:10px }
.section-loading .loading-text{
  font-size:12px; letter-spacing:.2px; color:var(--text); opacity:.85; line-height:1;
}
/* Loader line khi nằm trong section-loading: full-width, mỏng */
.section-loading .loader-line{
  height:100%; border-radius:0; background:transparent;
}
.section-loading .loader-line::before{
  content:""; position:absolute; inset:0;
  width:35%;
  background:linear-gradient(90deg, transparent, var(--primary), transparent);
  transform:translateX(-100%);
  animation:loaderSlide 1s cubic-bezier(.4,0,.2,1) infinite;
}

@keyframes loaderSlide{ to{ transform:translateX(250%) } }

/* Respect người dùng giảm animation */
@media (prefers-reduced-motion: reduce){
  .loader-line::before{ animation-duration:2s }
}
/* Typography */
h2{margin:0 0 12px}
label{display:block; font-size:13px; color:var(--muted); margin-bottom:8px}

/* Inputs */
.c-input,.c-textarea,select,input,textarea,button{
  width:100%; border-radius:14px; border:1px solid var(--line); background:transparent; color:var(--text); font-size:17px;
}
.c-input{ height:52px; padding:12px 14px; line-height:28px }
.c-textarea{ padding:12px 14px; min-height:64px; resize:vertical }
.amount-wrap{ margin-bottom:8px }
.amount-input{ height:58px; font-size:22px; font-weight:800; letter-spacing:.3px }
.amount-wrap .hint{ margin-top:6px; font-size:12px; color:var(--muted) }

button{cursor:pointer; font-weight:700}
.btn{background:var(--card)}
.btn-primary{background:var(--primary); color:#fff; border:none}
.btn-lg{ height:52px; border-radius:14px }
.btn-sm{ height:44px; border-radius:12px; font-size:15px }
.btn-row{ gap:12px }

/* btn loading (không block app) */
button.is-loading{ position:relative; pointer-events:none; opacity:.9 }
/* Save button – text -> spinner centered */
#btnSave{ position:relative; }
#btnSave.loading{ color:transparent; }               /* ẩn chữ, vẫn giữ kích thước */
#btnSave.loading::after{
  content:""; position:absolute; left:50%; top:50%;
  width:18px; height:18px; margin:0; transform:translate(-50%,-50%);
  border:2px solid #fff; border-top-color:transparent; border-right-color:transparent;
  border-radius:50%; animation:spin .8s linear infinite;
}
@keyframes spin{ to{ transform:translate(-50%,-50%) rotate(360deg) } }


/* Manage */
.manage-wrap{display:grid; grid-template-columns:1fr; gap:14px}
@media(min-width:560px){ .manage-wrap{ grid-template-columns:1fr 1fr } }
.manage-col .add-row{ display:grid; grid-template-columns:1fr 110px; gap:10px; margin-top:10px }
.list{display:flex; flex-direction:column; gap:8px; margin-top:10px}
.item{ display:flex; align-items:center; gap:8px; border:1px solid var(--line); border-radius:12px; padding:10px 10px; background:transparent }
.item-title{ flex:1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis }
.icon-btn{ width:38px;height:38px;border-radius:10px;border:1px solid var(--line); background:transparent; color:var(--text); display:flex; align-items:center; justify-content:center; font-size:16px }

/* Grid */
.grid{display:grid; grid-template-columns:1fr; gap:12px}
@media(min-width:520px){ .grid{grid-template-columns:1fr 1fr}}

/* Filters */
.filters{display:flex; gap:8px; align-items:center; margin-bottom:10px}
.c-input.sm{ height:44px; font-size:15px; padding:8px 12px; border-radius:12px }

/* KPI */
.kpis{ display:grid; grid-template-columns:1fr; gap:12px; margin-bottom:12px }
.kpi{ border:1px solid var(--line); border-radius:16px; padding:12px; display:flex; flex-direction:column; gap:4px }
.kpi-primary{ background:linear-gradient(180deg, var(--primary) 0%, transparent 120%); border-color:transparent }
.kpi-primary .kpi-title{ color:#e9e9ff }
.kpi-primary .kpi-val{ color:#fff }
.kpi-title{font-size:13px; color:var(--muted)}
.kpi-val{font-weight:800; font-size:26px}

/* Charts */
.charts{display:grid; grid-template-columns:1fr; gap:12px}
.chartBox{height:300px; border:1px solid var(--line); border-radius:12px; padding:10px; background:transparent}
.chartBox canvas{width:100% !important; height:100% !important; display:block}

/* Categories */
.cat-sections{display:grid; grid-template-columns:1fr; gap:10px; margin-top:8px}
@media(min-width:640px){ .cat-sections{grid-template-columns:1fr 1fr} }
.cat-card{border:1px solid var(--line); border-radius:12px; padding:10px}
.cat-title{font-size:12px; color:var(--muted); margin-bottom:6px}
.cat-list{display:flex; flex-direction:column; gap:8px}
.cat-row{display:flex; align-items:center; gap:8px}
.cat-name{flex:0 0 44%}
.cat-amt{flex:0 0 26%; text-align:right}
.cat-bar{flex:1; height:8px; background:var(--line); border-radius:999px; overflow:hidden}
.cat-bar>span{display:block; height:100%; background:var(--primary)}

/* Toasts */
.toast-list{ position:fixed; left:0; right:0; bottom:80px; display:grid; place-items:center; gap:8px; z-index:99997; pointer-events:none }
.toast{
  pointer-events:auto; background:var(--card); border:1px solid var(--line); color:var(--text);
  padding:10px 14px; border-radius:12px; font-weight:700; font-size:14px; box-shadow:0 6px 20px rgba(0,0,0,.25);
  animation:toastIn .2s ease; display:flex; align-items:center; gap:10px
}
.toast.ok{ border-color:rgba(22,163,74,.5) }
.toast.err{ border-color:rgba(239,68,68,.5) }
.toast .dot{ width:10px; height:10px; border-radius:999px; background:var(--ok) }
.toast.err .dot{ background:var(--err) }

/* Spacer for tabbar */
.bottom-spacer{ height: calc(80px + env(safe-area-inset-bottom,0)); }

/* Tabbar */
.tabbar{
  position:fixed; left:0; right:0; bottom:0; height:68px;
  padding-bottom:env(safe-area-inset-bottom,0);
  display:flex; gap:0; justify-content:space-around; align-items:flex-end;
  background:var(--tabbar); backdrop-filter:saturate(180%) blur(var(--blur)); -webkit-backdrop-filter:saturate(180%) blur(var(--blur));
  border-top:1px solid var(--line); z-index:9999;
}
.btab{ flex:1; border:0; background:transparent; color:var(--muted);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  padding:6px 0 10px; gap:4px; font-weight:600; font-size:12px }
.btab .ico{ width:22px; height:22px; fill:currentColor; stroke:currentColor; stroke-width:1.6 }
.btab.active{ color:var(--primary) }


/* iPhone 14 Pro Max */
@media (min-width:390px) and (max-width:460px){
  html{ font-size:17px }
  .wrap{ padding:16px 16px 0 }
  .kpi-val{ font-size:28px }
  .chartBox{ height:320px }
}

/* Animations */
@keyframes fadeUp{ from{opacity:0; transform:translateY(8px)} to{opacity:1; transform:translateY(0)} }
@keyframes fadeIn{ from{opacity:0} to{opacity:1} }
@keyframes rise{ from{opacity:0; transform:translateY(14px) scale(.98)} to{opacity:1; transform:translateY(0) scale(1)} }
@keyframes splashFade{ to{ opacity:0; visibility:hidden } }
@keyframes glowSpin{ from{transform:rotate(0)} to{transform:rotate(20deg)} }
@keyframes loadSpin{ 0%{transform:rotate(0)} 100%{transform:rotate(360deg)} }
@keyframes toastIn{ from{opacity:0; transform:translateY(6px)} to{opacity:1; transform:translateY(0)} }
/* Full height cho iOS (dùng dvh chỗ nào có thể) */
html, body { height: 100%; min-height: 100dvh; }
body { min-height: 100dvh; }

/* Topbar tránh tai thỏ khi chạy standalone */
.topbar{ padding-top: calc(10px + env(safe-area-inset-top, 0)); }

/* Bottom bar đã có safe-area; giữ nguyên: */
.tabbar{ padding-bottom: env(safe-area-inset-bottom, 0); }

/* Nếu muốn main luôn tràn full chiều cao màn, trừ thanh tabbar */
#appRoot{ min-height: calc(100dvh - 80px - env(safe-area-inset-bottom,0)); }
/* ===== Bottom tab – safe for iPhone home indicator ===== */
.tabbar{
  position: fixed; left:0; right:0; bottom:0;
  height: calc(68px + env(safe-area-inset-bottom, 0));   /* <- include safe-area */
  padding-bottom: env(safe-area-inset-bottom, 0);
  display:flex; align-items:center; justify-content:space-around; gap:0;
  background: var(--tabbar);
  backdrop-filter: saturate(180%) blur(var(--blur)); -webkit-backdrop-filter: saturate(180%) blur(var(--blur));
  border-top:1px solid var(--line);
  z-index: 9999;
}
.btab{
  flex:1; border:0; background:transparent; color:var(--muted);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  height:48px;               /* icon + label nằm giữa, tránh chạm home bar */
  gap:4px; font-weight:600; font-size:12px;
}
.btab .ico{ width:22px; height:22px; fill:currentColor; stroke:currentColor; stroke-width:1.6 }
.btab.active{ color:var(--primary) }

/* Spacer để nội dung không bị che bởi tabbar */
.bottom-spacer{
  height: calc(68px + env(safe-area-inset-bottom, 0) + 8px);
}
