:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e3e6eb; --border-strong: #cfd4dc;
  --text: #16181d; --text-2: #4d535e; --muted: #7a818c;
  --accent: #0f3d82; --accent-soft: #e7eef8; --accent-ink: #ffffff;
  --good: #0f7b48; --good-soft: #e3f4ea; --bad: #c0362c; --bad-soft: #fbe9e7; --warn: #a86400; --warn-soft: #fdf1dc;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --grid: #eceef1; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214; --surface: #1a1a19; --surface-2: #212224; --border: #2e3034; --border-strong: #3d4046;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f9198;
    --accent: #6c9fe6; --accent-soft: #1b2a40; --accent-ink: #0b1220;
    --good: #3fbf7f; --good-soft: #15291f; --bad: #ef6b5f; --bad-soft: #351a18; --warn: #e3a33b; --warn-soft: #33270f;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --grid: #2a2b2e; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214; --surface: #1a1a19; --surface-2: #212224; --border: #2e3034; --border-strong: #3d4046;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f9198;
  --accent: #6c9fe6; --accent-soft: #1b2a40; --accent-ink: #0b1220;
  --good: #3fbf7f; --good-soft: #15291f; --bad: #ef6b5f; --bad-soft: #351a18; --warn: #e3a33b; --warn-soft: #33270f;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --grid: #2a2b2e; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--bad); }
a { color: var(--accent); }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; color: var(--text-2); }

/* Đăng nhập */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; width: 100%; max-width: 360px; display: grid; gap: 12px; box-shadow: var(--shadow); }

.err { color: var(--bad); min-height: 1em; margin: 0; }

/* Khung */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 18px 10px; font-size: 20px; font-weight: 700; } .brand b { color: var(--accent); }
.brand small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
nav { padding: 6px 10px; display: grid; gap: 2px; }
nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; }
nav a:hover { background: var(--surface-2); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav a .ico { width: 18px; text-align: center; }
.side-foot { margin-top: auto; padding: 14px; border-top: 1px solid var(--border); display: grid; gap: 6px; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#btnMenu { display: none; }
.page { padding: 20px 24px 60px; display: grid; gap: 16px; }
#banner:empty { display: none; }
.banner { margin: 12px 24px 0; padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }

/* Thẻ & lưới */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.kpi.click { cursor: pointer; } .kpi.click:hover { border-color: var(--accent); }

/* Nút & form */
.btn { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.icon { padding: 4px 10px; font-size: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
label.chk { display: flex; align-items: center; gap: 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.filters label { min-width: 130px; }
.filters .grow { flex: 1; min-width: 180px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs button { background: none; border: none; padding: 9px 14px; cursor: pointer; color: var(--text-2); font: inherit; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* Bảng */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-2); position: sticky; top: 0; white-space: nowrap; cursor: default; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--accent); }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 700; background: var(--surface-2); }
tr.grp td { background: var(--surface-2); font-weight: 600; }
tr.total td { font-weight: 700; border-top: 2px solid var(--border-strong); }
td.desc { max-width: 420px; }
.table-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(10,12,16,.45); display: grid; place-items: start center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 680px; box-shadow: 0 20px 50px rgba(0,0,0,.25); border: 1px solid var(--border); }
.modal.wide { max-width: 1000px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px 20px; display: grid; gap: 14px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal footer .left { margin-right: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; transition: transform .2s; z-index: 100; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); color: #fff; }

/* Biểu đồ */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); }
.chart .axis { stroke: var(--border-strong); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 8px 10px; align-items: center; font-size: 13px; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.tip { position: fixed; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.15); z-index: 120; display: none; max-width: 280px; }
.tip b { display: block; margin-bottom: 4px; }

.cost-lines td { padding: 4px 6px; } .cost-lines input, .cost-lines select { padding: 5px 8px; }
.split { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sum-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; background: var(--surface-2); padding: 12px; border-radius: 8px; }
.sum-box div span { display: block; font-size: 12px; color: var(--muted); }
.sum-box div b { font-variant-numeric: tabular-nums; }
.note { background: var(--accent-soft); color: var(--text); border-radius: 8px; padding: 10px 14px; font-size: 13px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  #btnMenu { display: inline-block; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .banner { margin: 12px 16px 0; }
}
@media print {
  .sidebar, .topbar .top-actions, #btnMenu, .filters, .table-tools .btn { display: none !important; }
  .app { display: block; } .card, .table-wrap { box-shadow: none; }
}

/* Thương hiệu Network */
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 12px; }
.brand img, .login-brand img { border-radius: 9px; flex: none; }
.wordmark { font-weight: 800; letter-spacing: .12em; color: var(--accent); font-size: 17px; line-height: 1.1; }
.tagline { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand .wordmark { font-size: 26px; }
.side-link { color: var(--text-2); text-decoration: none; padding: 6px 2px; }
.side-link.active { color: var(--accent); font-weight: 600; }
.kpi.big .v { font-size: 26px; }
.kpi .op { font-size: 22px; color: var(--muted); align-self: center; text-align: center; }
.formula { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr; gap: 10px; align-items: stretch; }
.formula .sign { display: grid; place-items: center; font-size: 22px; color: var(--muted); font-weight: 300; }
.amount-thu { color: var(--good); } .amount-chi { color: var(--bad); }
@media (max-width: 900px) { .formula { grid-template-columns: 1fr 1fr; } .formula .sign { display: none; } }
.matrix td:first-child, .matrix th:first-child { min-width: 250px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.matrix tr.grp td:first-child, .matrix tr.total td:first-child { background: var(--surface-2); }
.matrix th:first-child { background: var(--surface-2); z-index: 2; }

/* ===== Bố cục dạng sheet Excel ===== */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.appbar .brand { padding: 0; }
.appbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sheet-tabs { display: flex; gap: 2px; padding: 8px 16px 0; background: var(--surface-2); border-bottom: 1px solid var(--border-strong); overflow-x: auto; position: sticky; top: 0; z-index: 6; }
.sheet-tabs a { padding: 8px 16px; border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; background: var(--bg); color: var(--text-2); text-decoration: none; white-space: nowrap; font-weight: 500; margin-bottom: -1px; }
.sheet-tabs a:hover { background: var(--surface); }
.sheet-tabs a.active { background: var(--surface); color: var(--accent); font-weight: 700; border-color: var(--border-strong); border-bottom: 1px solid var(--surface); }
.sheet-tabs a.new::after { content: 'mới'; font-size: 10px; margin-left: 6px; padding: 0 5px; border-radius: 6px; background: var(--good-soft); color: var(--good); vertical-align: 1px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.sheet-head h2 { margin: 0; font-size: 17px; letter-spacing: .02em; }
.sheet-head .split input[type=search] { width: 220px; }

/* Lưới nhập liệu kiểu bảng tính */
table.sheet { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.sheet th { background: #dfe8f5; color: #10294f; border: 1px solid var(--border-strong); text-align: center; white-space: normal; position: sticky; top: 0; z-index: 2; padding: 7px 6px; }
table.sheet td { border: 1px solid var(--border); padding: 0; vertical-align: middle; }
table.sheet td.ro { padding: 6px 8px; }
table.sheet td.stt { text-align: center; color: var(--muted); width: 44px; background: var(--surface-2); }
table.sheet input, table.sheet textarea, table.sheet select { border: none; border-radius: 0; background: transparent; padding: 6px 8px; width: 100%; font: inherit; color: inherit; }
table.sheet textarea { resize: none; overflow: hidden; display: block; line-height: 1.4; min-height: 32px; }
table.sheet input:focus, table.sheet textarea:focus, table.sheet select:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface); }
table.sheet input.num, table.sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.sheet td.num.ro { white-space: nowrap; }
table.sheet td.chk { text-align: center; }
table.sheet tr.newrow td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
table.sheet tr.newrow td.stt::after { content: '+'; }
table.sheet tfoot td, table.sheet tr.sum td { background: #fff4cc; font-weight: 700; padding: 7px 8px; border: 1px solid var(--border-strong); }
table.sheet td.del { width: 34px; text-align: center; }
table.sheet td.del button { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 4px 8px; }
table.sheet td.del button:hover { color: var(--bad); }
table.sheet tr:hover td { background-color: color-mix(in srgb, var(--accent) 3%, transparent); }
table.sheet .lbl { padding: 7px 8px; font-weight: 600; }
table.sheet a.lbl { display: block; color: var(--accent); text-decoration: none; }
table.sheet a.lbl:hover { text-decoration: underline; }
.tong td { font-size: 14px; }
.tong .big { font-size: 15px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) table.sheet th { background: #1f2c40; color: var(--text); } :root:not([data-theme="light"]) table.sheet tfoot td, :root:not([data-theme="light"]) table.sheet tr.sum td { background: #3a3215; } }
.saving { color: var(--warn); } .saved { color: var(--good); }
@media (max-width: 700px) { .appbar-right .btn { padding: 4px 8px; } .page { padding: 12px; } }
.login-logo { width: 220px; height: auto; margin: 0 auto; display: block; border-radius: 12px; }
.brand img.mark { background: #fff; border-radius: 8px; }

/* ===== Menu chính 5 mục ===== */
.main-nav { display: flex; gap: 4px; padding: 0 16px; background: var(--accent); overflow-x: auto; }
.main-nav a { color: #dbe6f7; text-decoration: none; padding: 11px 18px; font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; display: flex; gap: 8px; align-items: center; }
.main-nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.main-nav a.active { color: #fff; border-bottom-color: #fff; }
.main-nav .count { background: #f5b301; color: #1a1a1a; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.sheet-tabs:empty { display: none; }
.sheet-tabs a.add { border-style: dashed; color: var(--accent); background: transparent; }
.sheet-tabs a .x { margin-left: 8px; color: var(--muted); font-size: 12px; }
table.sheet input.est { color: var(--warn); font-style: italic; }
table.sheet td.st { white-space: nowrap; padding: 4px 6px; text-align: center; }
table.sheet tr.pending td { background: color-mix(in srgb, #f5b301 10%, transparent); }
.badge.edit { cursor: pointer; } .badge.edit.bad { cursor: pointer; }
.btn.xs { padding: 1px 8px; font-size: 12px; }
.chg { font-size: 12px; } .chg b { font-weight: 600; } .chg del { color: var(--bad); } .chg ins { color: var(--good); text-decoration: none; }
.kpis.k4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; }
.chart .zero { stroke: var(--border-strong); stroke-dasharray: 3 3; }
.perm-sel { width: auto; padding: 4px 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .main-nav { background: #12233f; } }
nav.main-nav { display: flex; padding: 0 16px; }
nav.main-nav a, nav.main-nav a:hover { border-radius: 0; }
nav.main-nav a.active { background: rgba(255,255,255,.14); color: #fff; }

/* ===== Điện thoại: giống app CTV V-Life – menu dưới đáy, tab con cuộn ngang ===== */
.show-mobile { display: none !important; }
.bottom-nav { display: none; }
.install-link { text-align: center; font-size: 13px; text-decoration: none; }
html { -webkit-text-size-adjust: 100%; }
@media (max-width: 760px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: inline-flex !important; }
  .appbar { padding: calc(8px + env(safe-area-inset-top)) 14px 8px; position: sticky; top: 0; z-index: 8; flex-wrap: nowrap; }
  .appbar .wordmark { font-size: 15px; }
  nav.main-nav { display: none; }
  .sheet-tabs { top: calc(54px + env(safe-area-inset-top)); padding: 6px 10px 0; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .sheet-tabs::-webkit-scrollbar { display: none; }
  .sheet-tabs a { padding: 7px 12px; font-size: 14px; }
  .page { padding: 12px 10px calc(84px + env(safe-area-inset-bottom)); gap: 12px; }
  .card { padding: 12px; border-radius: 12px; }
  .kpis, .kpis.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .v { font-size: 17px; }
  .kpi .s { font-size: 11px; }
  .sheet-head h2 { font-size: 15px; }
  .sheet-head .split input[type=search] { width: 100%; }
  .sheet-head > .split { width: 100%; }
  table.sheet { font-size: 13px; }
  .banner { margin: 8px 10px 0; font-size: 13px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none; color: var(--text-2); font-size: 11.5px; position: relative; padding: 2px 0; }
  .bottom-nav a svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .bottom-nav a.active { color: var(--accent); font-weight: 600; }
  .bottom-nav .count { position: absolute; top: -2px; left: 54%; background: var(--bad); color: #fff; border-radius: 10px; font-size: 10px; padding: 0 5px; font-weight: 700; }
  .modal-back { padding: 16px 8px; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) { [data-install] { display: none !important; } }

/* ===== Dòng nhập trong form ca (chia BS/NV, chi phí) ===== */
.lines { display: grid; gap: 8px; margin-top: 8px; }
.line { display: grid; grid-template-columns: 1.2fr 1.2fr 1.4fr 1.2fr; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.line-amt { display: flex; gap: 6px; align-items: center; }
.line-amt select { width: auto; }
.line-amt input.num { min-width: 70px; }
.line-amt b.num { min-width: 90px; text-align: right; }
#costBox .line { grid-template-columns: 1.4fr 2fr; }
.templ .line { grid-template-columns: 1fr 1.4fr; }
.mfilters { margin-bottom: 4px; }
.mhead { display: none; }
.fab { display: none; }

/* ===== Điện thoại: bố cục gọn giống app CTV V-Life ===== */
@media (max-width: 760px) {
  body { background: #f6f7f9; }
  .appbar { display: none; }
  .mhead { display: block; padding: calc(14px + env(safe-area-inset-top)) 18px 4px; background: #f6f7f9; }
  .mh-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
  .mhead h1 { font-family: 'Noto Serif', 'Times New Roman', Times, serif; font-size: 30px; font-weight: 700; margin: 0; letter-spacing: -.01em; color: #0f1b2d; line-height: 1.15; }
  .mhead p { margin: 6px 0 0; color: #6b7280; font-size: 15px; line-height: 1.4; }
  .mh-act { display: flex; gap: 8px; align-items: center; }
  .mh-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid #dfe3e8; background: #fff; font-size: 20px; color: #1f2937; display: grid; place-items: center; cursor: pointer; }
  /* tab con: chữ có gạch chân (như Mới / Đã liên hệ / Tất cả) */
  .sheet-tabs { position: sticky; top: 0; background: #f6f7f9; border-bottom: 1px solid #e5e7eb; padding: 0 14px; gap: 18px; z-index: 6; }
  .sheet-tabs a, .sheet-tabs a.active, .sheet-tabs a:hover { border: none; border-radius: 0; background: transparent; margin: 0; padding: 12px 2px 10px; font-size: 15.5px; color: #6b7280; border-bottom: 2.5px solid transparent; }
  .sheet-tabs a.active { color: #0f1b2d; font-weight: 700; border-bottom-color: var(--accent); }
  #banner .banner { margin: 8px 14px 0; border-radius: 12px; }
  .page { padding: 12px 14px calc(96px + env(safe-area-inset-bottom)); gap: 12px; }
  .page > .card, .card { border-radius: 14px; box-shadow: none; border-color: #e5e7eb; }
  .filters.mfilters { display: flex; gap: 8px; flex-wrap: nowrap; }
  .filters.mfilters label { min-width: 0; }
  .filters.mfilters input, .filters.mfilters select { height: 46px; border-radius: 12px; border-color: #dfe3e8; background: #fff; font-size: 15.5px; padding: 0 14px; }
  /* danh sách thẻ */
  .mlist { background: #fff; border: 1px solid #e5e7eb; border-radius: 14px; overflow: hidden; }
  .mcard { display: flex; align-items: center; gap: 14px; padding: 14px 14px; border-bottom: 1px solid #eef0f3; cursor: pointer; }
  .mcard:last-child { border-bottom: none; }
  .mcard:active { background: #f3f6fb; }
  .mcard.pending { background: #fffaf0; }
  .mc-day { flex: none; width: 50px; height: 50px; border-radius: 50%; border: 2px solid #ecd9b6; display: grid; place-content: center; text-align: center; line-height: 1; color: #9a6b1f; background: #fffdf8; }
  .mc-day b { font-family: 'Noto Serif', 'Times New Roman', serif; font-size: 18px; }
  .mc-day span { font-size: 10.5px; margin-top: 2px; }
  .mc-day.mc-empty { color: #b9bec6; border-color: #e5e7eb; }
  .mc-main { flex: 1; min-width: 0; }
  .mc-title { font-weight: 600; font-size: 16px; color: #111827; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .mc-sub { color: #6b7280; font-size: 13.5px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mc-badges { margin-top: 5px; display: flex; gap: 4px; flex-wrap: wrap; }
  .mc-right { flex: none; text-align: right; max-width: 42%; }
  .mc-right .mc-sub { white-space: nowrap; }
  .mc-amt { font-weight: 700; font-size: 15.5px; font-variant-numeric: tabular-nums; color: #111827; }
  .fab { display: grid; place-items: center; position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: none;
    background: var(--accent); color: #fff; font-size: 28px; box-shadow: 0 8px 20px rgba(15,61,130,.35); z-index: 19; cursor: pointer; }
  /* menu dưới: nền mờ trong suốt */
  .bottom-nav { background: rgba(255,255,255,.88); -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px); border-top: 1px solid rgba(0,0,0,.06); }
  .bottom-nav a, .bottom-nav a.active { background: transparent !important; border-radius: 0; padding: 4px 0; color: #6b7280; }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav a svg { width: 25px; height: 25px; stroke-width: 1.6; }
  /* cửa sổ: trượt từ dưới lên, chiếm gần hết màn hình */
  .modal-back { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { max-width: none; width: 100%; border-radius: 18px 18px 0 0; max-height: 94vh; display: flex; flex-direction: column; }
  .modal .body { overflow-y: auto; padding: 14px 16px; }
  .modal footer { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .modal footer .btn { flex: 1; padding: 11px; }
  .modal input, .modal select, .modal textarea { font-size: 16px; min-height: 42px; }  /* 16px: iPhone không tự phóng to */
  .line, #costBox .line, .templ .line { grid-template-columns: 1fr 1fr; }
  .line .line-amt { grid-column: 1 / -1; }
  .kpis, .kpis.k4 { gap: 10px; }
  .kpi { border-radius: 14px; box-shadow: none; }
  .grid.g2 { gap: 12px; }
  .sum-box { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) { .mc-day.mc-est { border-style: dashed; border-color: #d6b98a; } }
.toast:not(.show) { opacity: 0; visibility: hidden; }
.toast { transition: transform .2s, opacity .2s, visibility .2s; }
@media (max-width: 760px) {
  .line-amt { flex-wrap: wrap; }
  .line-amt select { min-width: 96px; }
  .line-amt input.num { flex: 1; }
  .line-amt .chk { white-space: nowrap; }
}
.line-amt select { min-width: 84px; }
.line-amt select[data-k="mode"], .line-amt select[data-f="mode"] { min-width: 104px; }
.line-amt .chk { white-space: nowrap; }
.line { grid-template-columns: 1.1fr 1.1fr 1.7fr 1.3fr; }
#costBox .line { grid-template-columns: 1.3fr 2fr; }
.reserve-line { grid-template-columns: auto 1fr 1.6fr !important; background: color-mix(in srgb, #f5b301 8%, var(--surface)); border-color: color-mix(in srgb, #f5b301 35%, var(--border)); margin-top: 8px; }
@media (max-width: 760px) { .reserve-line { grid-template-columns: 1fr !important; } }
@media (max-width: 760px) { #costBox .line > input { grid-column: 1 / -1; } }
.pit-row { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
.pit-row b { color: var(--text); }
.cost-line { grid-template-columns: 1.3fr 1.6fr 1.2fr !important; }
@media (max-width: 760px) { .cost-line { grid-template-columns: 1fr !important; } .pit-row { flex-direction: column; gap: 4px; } }
/* ô số trong dòng kíp / chi phí / mẫu: đủ rộng cho số tiền lớn */
.line-amt input[data-k="value"], .line-amt input[data-f="value"], .line-amt input[data-af="value"], .line-amt input[data-k="amount"] { min-width: 140px; flex: 1; text-align: right; font-variant-numeric: tabular-nums; }
.line-amt input.pct { min-width: 80px; max-width: 110px; }
.line-amt b.num { min-width: 110px; }
.line { grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(320px, 1.7fr) auto; }
.templ-line { grid-template-columns: minmax(180px, 1fr) minmax(260px, 1.2fr) !important; }
@media (max-width: 760px) { .line-amt input.pct { max-width: none; } .line { grid-template-columns: 1fr 1fr; } }
/* danh sách thẻ – dùng cả trên máy tính (điện thoại có cỡ chữ riêng ở trên) */
.mlist { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.mcard { display: flex; align-items: center; gap: 14px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.mcard:last-child { border-bottom: none; }
.mcard:hover { background: var(--surface-2); }
.mc-day { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 2px solid #ecd9b6; display: grid; place-content: center; text-align: center; line-height: 1; color: #9a6b1f; background: #fffdf8; }
.mc-day b { font-family: 'Noto Serif', 'Times New Roman', serif; font-size: 16px; }
.mc-day span { font-size: 10px; margin-top: 2px; }
.mc-main { flex: 1; min-width: 0; }
.mc-title { font-weight: 600; }
.mc-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.mc-badges { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
.mc-right { flex: none; text-align: right; }
.mc-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  .mlist { border-radius: 14px; border-color: #e5e7eb; }
  .mcard { padding: 14px; border-bottom-color: #eef0f3; }
  .mc-day { width: 50px; height: 50px; } .mc-day b { font-size: 18px; } .mc-day span { font-size: 10.5px; }
  .mc-title { font-size: 16px; color: #111827; } .mc-sub { font-size: 13.5px; color: #6b7280; margin-top: 3px; }
  .mc-amt { font-size: 15.5px; } .mc-right { max-width: 42%; }
}
.kip-cell { font-size: 12.5px; line-height: 1.5; min-width: 230px; }
.kip-cell b { font-variant-numeric: tabular-nums; }
.kip-mini { font-size: 12.5px; color: var(--text-2); margin-top: 4px; line-height: 1.45; white-space: normal; }
.kip-mini b { color: var(--text); font-weight: 600; }

/* ===== Giao diện luôn sáng (giống app CTV) – không đổi theo chế độ tối của điện thoại ===== */
:root { color-scheme: light; }

/* ===== Điện thoại: dòng kíp / chi phí / trích quỹ xếp lưới thẳng hàng ===== */
@media (max-width: 760px) {
  .line, #costBox .line, .cost-line, .templ-line, .reserve-line { grid-template-columns: 1fr !important; gap: 8px; padding: 10px; }
  .line > input, .line > b, .line > .hint { width: 100%; }
  .line .line-amt { display: grid; grid-template-columns: 108px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
  .line .line-amt select, .line .line-amt input { min-width: 0 !important; max-width: none !important; width: 100%; }
  .line .line-amt b.num { min-width: 0; text-align: right; font-size: 15px; }
  .line .line-amt .chk { justify-self: start; }
  .line .line-amt button[data-rm] { justify-self: end; }
  .templ-line .line-amt { grid-template-columns: 108px minmax(0, 1fr) auto; }
  .reserve-line .line-amt { grid-template-columns: 108px minmax(0, 1fr) auto; }
  .pit-row { padding-top: 2px; border-top: 1px dashed var(--border); }
  .kpis .kpi { display: flex; flex-direction: column; min-height: 96px; }
  .filters.mfilters label:not(.grow) { flex: 0 0 42%; }
  .filters.mfilters select { width: 100%; }
  .mcard .mc-right { align-self: flex-start; padding-top: 2px; }
  .sum-box { gap: 12px 10px; }
  .modal h3 { font-size: 15px; }
}
.cost-table td:first-child { min-width: 240px; }
.cost-card { padding: 12px 14px; }
.cc-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); font-size: 15px; }
.cc-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.cc-row:last-child { border-bottom: none; }
.cc-row .num { text-align: right; white-space: nowrap; }
table.sheet tr.grp td { padding: 8px 10px; background: var(--surface-2); font-weight: 700; color: var(--text); }
