/* KPI TPC — giao diện */
:root {
  --bg: #f3f6fb; --card: #ffffff; --ink: #0f1b2d; --ink-2: #334155; --muted: #64748b; --line: #e2e8f0; --soft: #f1f5f9; --hover: #f8fafc;
  --pri: #2563eb; --pri-2: #0891b2; --pri-ink: #fff; --pri-soft: #e8efff; --pri-line: #c7d7fe;
  --ok: #047857; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2;
  --side: #ffffff; --side-2: #f1f5f9; --side-ink: #334155; --side-muted: #94a3b8; --side-on: #1d4ed8; --side-strong: #0f1b2d; --side-border: #e2e8f0;
  --side-active: linear-gradient(90deg, #e8efff, #f0f7ff);
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 2px 8px rgba(15, 27, 45, .04);
  --shadow-lg: 0 12px 40px rgba(15, 27, 45, .18);
  --grad: linear-gradient(135deg, #2563eb 0%, #0891b2 100%);
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --side-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a111c; --card: #111a28; --ink: #e6edf7; --ink-2: #c3cede; --muted: #8b9ab0; --line: #223047; --soft: #172234; --hover: #152031;
    --pri: #5b8cff; --pri-2: #22b8cf; --pri-soft: #17264a; --pri-line: #2b4380;
    --ok: #4ade80; --ok-soft: #0d2a1b; --warn: #fbbf24; --warn-soft: #2e230a; --bad: #f87171; --bad-soft: #351416;
    --side: #070d17; --side-2: #0e1726; --side-ink: #c4cfe0; --side-muted: #7184a0; --side-on: #ffffff; --side-strong: #ffffff; --side-border: rgba(255, 255, 255, .07);
    --side-active: linear-gradient(90deg, rgba(37, 99, 235, .28), rgba(8, 145, 178, .12));
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a111c; --card: #111a28; --ink: #e6edf7; --ink-2: #c3cede; --muted: #8b9ab0; --line: #223047; --soft: #172234; --hover: #152031;
  --pri: #5b8cff; --pri-2: #22b8cf; --pri-soft: #17264a; --pri-line: #2b4380;
  --ok: #4ade80; --ok-soft: #0d2a1b; --warn: #fbbf24; --warn-soft: #2e230a; --bad: #f87171; --bad-soft: #351416;
  --side: #070d17; --side-2: #0e1726; --side-ink: #c4cfe0; --side-muted: #7184a0; --side-on: #ffffff; --side-strong: #ffffff; --side-border: rgba(255, 255, 255, .07);
  --side-active: linear-gradient(90deg, rgba(37, 99, 235, .28), rgba(8, 145, 178, .12));
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--pri); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; line-height: 1.3; margin: 0 0 12px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 13px; margin: 18px 0 8px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
p { margin: 0 0 10px; }
code { background: var(--soft); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; padding: 48px 16px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }

/* ---------- khung: thanh bên + nội dung ---------- */
.layout { display: flex; min-height: 100vh; }
.side { width: var(--side-w); flex: none; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30; border-right: 1px solid var(--side-border); }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: var(--side-strong); font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.side-brand:hover { text-decoration: none; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 4px 14px rgba(37, 99, 235, .45); flex: none; }
.logo svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.side-brand small { display: block; font-size: 11px; font-weight: 500; color: var(--side-muted); letter-spacing: .02em; }
.side nav { flex: 1; overflow-y: auto; padding: 6px 10px 12px; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--side-muted); padding: 14px 10px 6px; font-weight: 600; }
.side nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; color: var(--side-ink); font-weight: 500; margin-bottom: 1px; position: relative; }
.side nav a:hover { background: var(--side-2); color: var(--side-strong); text-decoration: none; }
.side nav a.on { background: var(--side-active); color: var(--side-on); font-weight: 600; }
.side nav a.on::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #38bdf8; }
.side nav a .badge { margin-left: auto; background: #f59e0b; color: #1f1300; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 7px; line-height: 18px; }
.side-foot { border-top: 1px solid var(--side-border); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.side-foot .who-n { color: var(--side-strong); font-weight: 600; font-size: 13px; line-height: 1.2; }
.side-foot .who-r { color: var(--side-muted); font-size: 11.5px; }
.side-foot button { margin-left: auto; background: transparent; border-color: var(--side-border); color: var(--side-ink); padding: 6px 8px; }
.side-foot button:hover { background: var(--side-2); color: var(--side-strong); }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 24px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .crumb { font-size: 12px; color: var(--muted); line-height: 1.2; }
.topbar .ttl { font-size: 16px; font-weight: 650; line-height: 1.2; }
.topbar .spacer { flex: 1; }
.per-pick { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 0 4px 0 10px; color: var(--muted); }
.per-pick select { border: none; background: transparent; font-weight: 600; color: var(--ink); padding: 7px 4px; width: auto; }
.per-pick select:focus { outline: none; }
.icon-btn { background: transparent; border: 1px solid transparent; padding: 7px; border-radius: 9px; color: var(--ink-2); }
.icon-btn:hover { background: var(--soft); }
#menu-btn { display: none; }
main { width: 100%; max-width: 1320px; margin: 0 auto; padding: 22px 24px 40px; }
.scrim { display: none; }

/* ---------- thẻ, lưới ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card > h1:first-child, .card > .row:first-child h1 { font-size: 18px; }
.card.soft { background: var(--soft); box-shadow: none; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 2px 0 18px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

/* ô chỉ số */
.stat { display: flex; flex-direction: column; gap: 3px; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.stat > span:first-child { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat b { font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
.kpi-big { font-size: 36px; font-weight: 750; line-height: 1.05; letter-spacing: -.02em; }
.tile { position: relative; overflow: hidden; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.tile .t-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--pri-soft); color: var(--pri); }
.tile .t-ico.ok { background: var(--ok-soft); color: var(--ok); } .tile .t-ico.warn { background: var(--warn-soft); color: var(--warn); } .tile .t-ico.bad { background: var(--bad-soft); color: var(--bad); }
.tile .t-lbl { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.tile .t-val { font-size: 28px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.tile .t-sub { font-size: 12.5px; color: var(--muted); }
.tile .t-act { margin-top: auto; padding-top: 6px; }
.tile.hero { background: var(--grad); color: #fff; border: none; }
.tile.hero .t-lbl, .tile.hero .t-sub { color: rgba(255, 255, 255, .82); }
.tile.hero .t-ico { background: rgba(255, 255, 255, .18); color: #fff; }
.tile.hero .btn { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .3); color: #fff; }
.tile.hero .btn:hover { background: rgba(255, 255, 255, .26); }
.tile.hero .tag { background: rgba(255, 255, 255, .22); color: #fff; }
.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 16px; }

/* tiến độ */
.bar { height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; min-width: 60px; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: var(--grad); border-radius: 99px; }
.steps { display: flex; gap: 0; margin: 4px 0 2px; }
.steps .st { flex: 1; position: relative; padding-top: 22px; font-size: 12px; color: var(--muted); text-align: center; }
.steps .st::before { content: ""; position: absolute; top: 6px; left: 0; right: 0; height: 2px; background: var(--line); }
.steps .st::after { content: ""; position: absolute; top: 1px; left: calc(50% - 6px); width: 12px; height: 12px; border-radius: 50%; background: var(--card); border: 2px solid var(--line); }
.steps .st.done::before, .steps .st.done::after { background: var(--pri); border-color: var(--pri); }
.steps .st.now::after { border-color: var(--pri); box-shadow: 0 0 0 4px var(--pri-soft); }
.steps .st b { display: block; color: var(--ink); font-size: 12.5px; }
.steps .st:first-child::before { left: 50%; } .steps .st:last-child::before { right: 50%; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.check:last-child { border-bottom: none; }
.check .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; margin-top: 1px; }
.check.done .dot { background: var(--ok); border-color: var(--ok); }
.check.done .dot::after { content: ""; width: 8px; height: 4px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(-45deg) translate(1px, -1px); }

/* ---------- điều khiển ---------- */
button, .btn { font: inherit; font-weight: 550; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 7px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; line-height: 1.4; transition: background .12s, border-color .12s, box-shadow .12s; }
button:hover, .btn:hover { background: var(--hover); border-color: var(--pri-line); text-decoration: none; }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--pri-soft); border-color: var(--pri); }
button.pri, .btn.pri { background: var(--grad); border-color: transparent; color: var(--pri-ink); box-shadow: 0 2px 8px rgba(37, 99, 235, .25); }
button.pri:hover, .btn.pri:hover { filter: brightness(1.07); border-color: transparent; }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); background: var(--bad-soft); }
button.sm, .btn.sm { padding: 3px 10px; font-size: 12.5px; border-radius: 7px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; width: 100%; transition: border-color .12s, box-shadow .12s; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--pri); margin: 0; }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pri); box-shadow: 0 0 0 3px var(--pri-soft); }
input:disabled, textarea:disabled, select:disabled { background: var(--soft); color: var(--muted); }
label.f { display: flex; flex-direction: column; gap: 5px; font-weight: 550; }
label.f > span { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.inline-num { width: 76px; text-align: right; }
select.inline { width: auto; }

/* ---------- bảng ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
th { background: var(--soft); font-weight: 600; font-size: 11.5px; color: var(--muted); white-space: nowrap; text-transform: uppercase; letter-spacing: .03em; }
tr.click { cursor: pointer; }
tbody tr:hover td { background: var(--hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: var(--soft); border-top: 1px solid var(--line); border-bottom: none; }
table.edit td { padding: 4px; }
table.edit input, table.edit select { padding: 5px 7px; border-radius: 7px; }
.card table:not(.edit) { font-size: 13.5px; }

/* ---------- nhãn, thông báo ---------- */
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; border: 1px solid transparent; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.pri { background: var(--pri-soft); color: var(--pri); }
.note, .info { border-radius: 10px; padding: 10px 14px; margin: 10px 0; border: 1px solid; display: block; }
.note { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.info { background: var(--pri-soft); color: var(--ink-2); border-color: var(--pri-line); }
.minus { color: var(--bad); font-weight: 600; }
.plus { color: var(--ok); font-weight: 600; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--pri); border-color: var(--pri); }
.stars button { border: none; background: none; font-size: 26px; padding: 0 2px; color: var(--line); box-shadow: none; }
.stars button.on { color: #f5a623; }
details summary { cursor: pointer; font-weight: 600; }

/* ---------- modal, toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(8, 15, 28, .55); backdrop-filter: blur(3px); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; width: 100%; max-width: 780px; box-shadow: var(--shadow-lg); animation: pop .16s ease-out; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast div { background: #0f1b2d; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); max-width: 90vw; font-weight: 500; animation: pop .16s ease-out; }
#toast div.err { background: #b91c1c; }

/* ---------- đăng nhập ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: radial-gradient(1200px 600px at 10% 10%, #1e3a8a 0%, transparent 60%), radial-gradient(800px 500px at 90% 90%, #0e7490 0%, transparent 60%), #0b1424; color: #fff; padding: 48px; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.login-art h2 { font-size: 34px; line-height: 1.2; margin: auto 0 12px; font-weight: 750; letter-spacing: -.02em; max-width: 460px; }
.login-art p { color: #b9c6dc; max-width: 440px; font-size: 15px; }
.login-art .feat { display: flex; gap: 22px; margin-top: 26px; flex-wrap: wrap; color: #dbe5f5; font-size: 13px; }
.login-art .feat span { display: flex; align-items: center; gap: 8px; }
.login-art svg.deco { position: absolute; right: -40px; top: 60px; width: 520px; opacity: .55; }
.login-form { display: grid; place-items: center; padding: 32px 20px; }
.login-form form { width: 100%; max-width: 360px; }
.login-form h1 { font-size: 24px; margin-bottom: 4px; }
.login-form .f { margin-bottom: 14px; }
.login-form button.pri { width: 100%; justify-content: center; padding: 10px; font-size: 15px; margin-top: 6px; }

.print-only { display: none; }

/* ---------- điện thoại ---------- */
@media (max-width: 900px) {
  .side { position: fixed; left: 0; top: 0; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(8, 15, 28, .45); z-index: 25; }
  #menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .crumb { display: none; }
  main { padding: 16px 12px 32px; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { padding: 28px 24px; min-height: 0; }
  .login-art h2 { font-size: 24px; margin-top: 18px; }
  .login-art svg.deco, .login-art .feat { display: none; }
}
@media (max-width: 560px) {
  .card { padding: 14px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 18px; }
  .kpi-big { font-size: 30px; }
  .tile .t-val { font-size: 24px; }
  .per-pick { padding-left: 6px; }
  .per-pick svg { display: none; }
  .modal { padding: 16px 8px; }
  .modal-box { padding: 16px; }
}
@media print {
  .side, .topbar, .no-print, button, .scrim { display: none !important; }
  .print-only { display: block; }
  body, html { background: #fff; color: #000; }
  .card, .tile { box-shadow: none; border: none; padding: 0; }
  main { max-width: none; padding: 0; }
  th { background: #eee !important; color: #000; }
  .tbl-wrap { border: none; }
}
