/* QN ERP - giao diện */
:root {
  color-scheme: light;
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8fafc; --surface-3: #eef2f7;
  --border: #e2e8f0; --border-strong: #cbd5e1;
  --text: #0f172a; --text-2: #475569; --text-3: #64748b;
  --primary: #1d4ed8; --primary-hover: #1e40af; --primary-soft: #e8efff; --on-primary: #fff;
  --brand: #b7791f; --brand-soft: #fdf3e1;
  --side-bg: #0f1d2b; --side-text: #c4cfdc; --side-muted: #7d8da0; --side-active: #1e3348; --side-hover: #172839;
  --good: #15803d; --good-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf2e2; --bad: #b91c1c; --bad-soft: #fdecec; --info: #1d4ed8; --info-soft: #e8efff;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --grid: #e7ebf0;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --radius: 10px; --radius-sm: 7px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d141c; --surface: #141d27; --surface-2: #18222e; --surface-3: #1e2a37;
    --border: #263342; --border-strong: #34445a;
    --text: #e6edf5; --text-2: #b4c1d0; --text-3: #8797aa;
    --primary: #4f8cf7; --primary-hover: #6b9ff8; --primary-soft: #1a2a45; --on-primary: #08111f;
    --brand: #e0a54a; --brand-soft: #2c2312;
    --side-bg: #0a1118; --side-active: #182635; --side-hover: #121d29;
    --good: #4ade80; --good-soft: #10291a; --warn: #f2b44c; --warn-soft: #2d2210; --bad: #f87171; --bad-soft: #321616; --info: #6b9ff8; --info-soft: #1a2a45;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #223040;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 10px 30px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d141c; --surface: #141d27; --surface-2: #18222e; --surface-3: #1e2a37;
  --border: #263342; --border-strong: #34445a;
  --text: #e6edf5; --text-2: #b4c1d0; --text-3: #8797aa;
  --primary: #4f8cf7; --primary-hover: #6b9ff8; --primary-soft: #1a2a45; --on-primary: #08111f;
  --brand: #e0a54a; --brand-soft: #2c2312;
  --side-bg: #0a1118; --side-active: #182635; --side-hover: #121d29;
  --good: #4ade80; --good-soft: #10291a; --warn: #f2b44c; --warn-soft: #2d2210; --bad: #f87171; --bad-soft: #321616; --info: #6b9ff8; --info-soft: #1a2a45;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #223040;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 10px 30px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }

/* ---------- Đăng nhập ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 600px at 10% -10%, rgba(183, 121, 31, .18), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(29, 78, 216, .16), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px 28px; }
.login-card h1 { margin: 14px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--text-3); }
.logo { width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, #d89b3a, #8a5a14); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 20px; letter-spacing: .5px; box-shadow: 0 6px 16px rgba(138, 90, 20, .35); }
.logo.sm { width: 34px; height: 34px; border-radius: 9px; font-size: 14px; box-shadow: none; }

/* ---------- Thanh mất kết nối ---------- */
.offline-bar { position: fixed; left: 0; right: 0; top: 0; z-index: 1500; display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
  background: var(--warn); color: #fff; padding: 8px 12px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg); }
.offline-bar .btn { height: 28px; background: rgba(255, 255, 255, .15); color: #fff; border-color: rgba(255, 255, 255, .5); }
@media (max-width: 720px) { .offline-bar { top: auto; bottom: 64px; font-size: 12.5px; } }

/* ---------- Trang cài app ---------- */
.install-card { max-width: 460px; }
.ins-title { font-size: 17px; margin: 18px 0 12px; }
.qr { width: 240px; max-width: 100%; margin: 0 auto 16px; padding: 10px; background: #fff; border-radius: 12px; border: 1px solid var(--border); }
.qr svg { display: block; width: 100%; height: auto; }
.link-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.link-box .inp { font-family: Consolas, monospace; font-size: 13px; }
.steps h3 { font-size: 14px; margin: 16px 0 6px; }
.steps ol { margin: 0; padding-left: 20px; color: var(--text-2); }
.steps li { margin: 4px 0; }
.menu-hint { position: fixed; top: 8px; right: 8px; z-index: 50; background: var(--brand); color: #fff; padding: 8px 12px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow-lg); animation: nudge 1.2s ease-in-out infinite alternate; }
@keyframes nudge { to { transform: translate(-4px, 4px); } }
.ios-share { display: inline-block; border: 1px solid var(--border-strong); border-radius: 5px; padding: 0 5px; font-size: 12px; }

/* ---------- Khung ứng dụng ---------- */
.app { display: grid; grid-template-columns: 252px 1fr; min-height: 100%; }
.side { background: var(--side-bg); color: var(--side-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; z-index: 40; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.side-head b { color: #fff; font-size: 15px; display: block; }
.side-head span { font-size: 11px; color: var(--side-muted); }
.nav { padding: 8px 8px 24px; flex: 1; }
.nav-group > button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; background: none; color: var(--side-text); border-radius: 8px; cursor: pointer; text-align: left; font-weight: 600; font-size: 13.5px; }
.nav-group > button:hover { background: var(--side-hover); color: #fff; }
.nav-group > button .chev { margin-left: auto; transition: transform .15s; width: 14px; height: 14px; opacity: .6; }
.nav-group.open > button .chev { transform: rotate(90deg); }
.nav-group.active > button { color: #fff; }
.nav-group.active > button svg:first-child { color: var(--brand); }
.nav-sub { display: none; padding: 2px 0 6px 28px; }
.nav-group.open .nav-sub { display: block; }
.nav-sub a { display: block; padding: 7px 10px; color: var(--side-text); border-radius: 7px; font-size: 13px; text-decoration: none; }
.nav-sub a:hover { background: var(--side-hover); color: #fff; }
.nav-sub a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.nav-sub .sub-h { padding: 8px 10px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--side-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 58px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 30; }
.top h2 { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .crumb { font-size: 12px; color: var(--text-3); }
.top-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 1px solid transparent; background: none; border-radius: 9px; cursor: pointer; color: var(--text-2); position: relative; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.user-chip .u-name { font-size: 13px; font-weight: 600; line-height: 1.1; }
.user-chip .u-role { font-size: 11px; color: var(--text-3); }
.menu-btn { display: none; }
.content { padding: 20px; max-width: 1600px; width: 100%; }
.bottom-nav { display: none; }
.backdrop { display: none; }

/* ---------- Thẻ, nút, form ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-h h3 { margin: 0; font-size: 15px; }
.card-h .sub { font-size: 12px; color: var(--text-3); }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.block { width: 100%; height: 42px; font-size: 14px; }
.btn svg.i { width: 16px; height: 16px; }

label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-2); min-width: 0; }
label.f.req > span::after { content: " *"; color: var(--bad); }
.inp, select.inp, textarea.inp { height: 38px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); width: 100%; outline: none; font-weight: 400; font-size: 14px; }
textarea.inp { height: auto; min-height: 70px; padding: 8px 11px; resize: vertical; }
.inp:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.inp[readonly] { background: var(--surface-2); color: var(--text-2); }
.inp.sm { height: 32px; font-size: 13px; padding: 0 8px; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13.5px; color: var(--text); padding-top: 22px; }
.chk input { width: 18px; height: 18px; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.search { position: relative; min-width: 220px; flex: 1; max-width: 360px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 16px; height: 16px; }
.search .inp { padding-left: 34px; }

/* ---------- Bảng ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar select.inp, .toolbar input[type=date].inp { width: auto; min-width: 140px; height: 36px; }
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-2); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 12.5px; position: sticky; top: 0; z-index: 1; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tbody tr.click { cursor: pointer; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }
.tbl .acts { white-space: nowrap; text-align: right; }
.tbl .code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.tbl td.cell-edit { padding: 4px 6px; }
.empty { padding: 40px 16px; text-align: center; color: var(--text-3); }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 16px; justify-content: space-between; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }

/* Trạng thái - luôn có biểu tượng + chữ, không chỉ dùng màu */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 7px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2); }
.tag.tc { background: var(--brand-soft); color: var(--brand); }
.tag.hu { background: var(--primary-soft); color: var(--primary); }

.progress { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; min-width: 80px; }
.progress > i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.kpi .k-l { font-size: 12.5px; color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi .k-l .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.kpi .k-v { font-size: 24px; font-weight: 700; letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.kpi .k-d { font-size: 12px; color: var(--text-3); }
.kpi .k-d b.up { color: var(--good); } .kpi .k-d b.down { color: var(--bad); }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; }
.mini-stats > div { padding: 12px 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.mini-stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.mini-stats span { font-size: 12px; color: var(--text-3); }

/* ---------- Biểu đồ ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar:hover { opacity: .85; }
.legend { display: flex; gap: 14px; 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; }
.tip { position: fixed; pointer-events: none; z-index: 1000; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-lg); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 140px; }
.tip b { display: block; margin-bottom: 4px; }
.tip .tr { display: flex; justify-content: space-between; gap: 14px; }
.tip .tr i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ---------- Tab ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; padding: 0 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: none; padding: 12px 14px; font-weight: 600; font-size: 13.5px; color: var(--text-3); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .cnt { font-size: 11px; background: var(--surface-3); border-radius: 10px; padding: 1px 6px; margin-left: 4px; }

/* ---------- Công đoạn (timeline) ---------- */
.stages { display: flex; flex-direction: column; gap: 0; }
.stage { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: start; padding: 12px 16px; border-bottom: 1px solid var(--border); position: relative; }
.stage .s-n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--surface-3); color: var(--text-2); border: 2px solid var(--border-strong); }
.stage.done .s-n { background: var(--good); color: #fff; border-color: var(--good); }
.stage.doing .s-n { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.stage.pause .s-n { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.stage .s-t { font-weight: 600; }
.stage .s-m { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.stage .s-a { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Hộp thoại ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 14, 22, .55); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; border: 1px solid var(--border); display: flex; flex-direction: column; max-height: calc(100vh - 80px); }
.modal.lg { max-width: 980px; } .modal.xl { max-width: 1200px; } .modal.sm { max-width: 440px; }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-h h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-b { padding: 18px 20px; overflow-y: auto; }
.modal-f { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 11px 14px; border-radius: 9px; box-shadow: var(--shadow-lg); font-size: 13.5px; display: flex; gap: 8px; align-items: center; animation: fade .15s; max-width: 420px; }
.toast.bad { background: var(--bad); color: #fff; } .toast.good { background: var(--good); color: #fff; }
.lines-tbl .inp { min-width: 80px; }
.lines-tbl td { padding: 5px 6px; }
.lines-tbl td.num .inp { text-align: right; }

/* Ô chọn có tìm kiếm */
.picker { position: relative; }
.picker-list { position: fixed; max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow-lg); z-index: 300; text-align: left; }
.picker-list div { padding: 8px 11px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.picker-list div:last-child { border-bottom: 0; }
.picker-list div:hover, .picker-list div.hl { background: var(--primary-soft); }
.picker-list div small { color: var(--text-3); margin-left: 6px; }

/* Lưới chấm công */
.ts td, .ts th { padding: 4px 3px; text-align: center; font-size: 12px; border: 1px solid var(--border); }
.ts th.we, .ts td.we { background: var(--surface-3); }
.ts td.cell { cursor: pointer; min-width: 30px; height: 30px; font-weight: 700; user-select: none; }
.ts td.cell:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
.ts td.k-X { color: var(--good); } .ts td.k-N { color: var(--series-1); } .ts td.k-P, .ts td.k-L { color: var(--warn); } .ts td.k-K, .ts td.k-O { color: var(--bad); }
.ts td.name { text-align: left; white-space: nowrap; position: sticky; left: 0; background: var(--surface); z-index: 1; padding: 4px 8px; }
.ts .dirty { box-shadow: inset 0 -3px 0 var(--brand); }

.perm-tbl td, .perm-tbl th { text-align: center; }
.perm-tbl td:first-child, .perm-tbl th:first-child { text-align: left; }
.perm-tbl input { width: 18px; height: 18px; accent-color: var(--primary); }
.alert { padding: 10px 14px; border-radius: 9px; font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.alert.warn { background: var(--warn-soft); color: var(--warn); } .alert.bad { background: var(--bad-soft); color: var(--bad); } .alert.info { background: var(--info-soft); color: var(--info); } .alert.good { background: var(--good-soft); color: var(--good); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 20px; }
.kv > div span { display: block; font-size: 12px; color: var(--text-3); }
.kv > div b { font-weight: 600; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Máy tính bảng ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .app.nav-open .side { transform: none; }
  .app.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 14, 22, .5); z-index: 35; }
  .menu-btn { display: inline-grid; }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* ---------- Điện thoại ---------- */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .top { padding: 0 8px 0 4px; height: 54px; }
  .top h2 { font-size: 16px; }
  .top .crumb, .user-chip .u-txt { display: none; }
  .user-chip { padding: 2px; border: 0; background: none; }
  .content { padding: 12px 12px 88px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; } .kpi .k-v { font-size: 18px; } .kpi .k-l .ic { display: none; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .card-h { padding: 12px; } .card-b { padding: 12px; }
  .toolbar { padding: 10px 12px; }
  .toolbar > * { flex: 1 1 140px; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .inp, select.inp { height: 42px; font-size: 16px; } /* tránh iOS tự phóng to */
  .btn { height: 40px; }
  .modal-bg { padding: 0; align-items: stretch; }
  .modal, .modal.lg, .modal.xl, .modal.sm { max-width: none; border-radius: 0; max-height: none; min-height: 100%; border: 0; }
  .modal-f { position: sticky; bottom: 0; background: var(--surface); }
  .modal-f .btn { flex: 1; }
  /* Bảng dạng thẻ trên điện thoại */
  table.tbl.cards thead { display: none; }
  table.tbl.cards, table.tbl.cards tbody, table.tbl.cards tr, table.tbl.cards td, table.tbl.cards tfoot { display: block; width: 100%; }
  table.tbl.cards tr { border-bottom: 8px solid var(--bg); padding: 8px 4px; }
  table.tbl.cards td { border: 0; padding: 4px 10px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.tbl.cards td::before { content: attr(data-label); color: var(--text-3); font-size: 12.5px; text-align: left; font-weight: 500; flex: none; max-width: 45%; }
  table.tbl.cards td.primary-cell { font-weight: 700; font-size: 15px; justify-content: flex-start; text-align: left; }
  table.tbl.cards td.primary-cell::before { display: none; }
  table.tbl.cards td.acts { justify-content: flex-end; padding-top: 8px; }
  table.tbl.cards td.acts::before { display: none; }
  table.tbl.cards td:empty { display: none; }
  table.tbl.cards tfoot tr { border: 0; }
  .lines-tbl.cards td.cell-edit { flex-direction: column; align-items: stretch; text-align: left; gap: 4px; }
  .lines-tbl.cards td.cell-edit::before { max-width: none; }
  .lines-tbl.cards td .inp, .lines-tbl.cards td .picker { width: 100%; }
  .lines-tbl.cards tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: var(--surface-2); }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; height: 64px; background: var(--surface); border-top: 1px solid var(--border); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--text-3); text-decoration: none; border: 0; background: none; cursor: pointer; }
  .bottom-nav .active { color: var(--primary); }
  .bottom-nav svg.i { width: 22px; height: 22px; }
  .stage { grid-template-columns: 30px 1fr; padding: 12px; }
  .stage .s-a { grid-column: 1 / -1; justify-content: flex-start; }
  .tabs { padding: 0 4px; }
  .toasts { left: 16px; bottom: 76px; }
}
@media print {
  .side, .top, .bottom-nav, .toolbar, .btn, .tabs { display: none !important; }
  .app { display: block; } .content { padding: 0; } .card { box-shadow: none; border: 0; }
}
