:root {
  --bg: #f6f5f3;
  --surface: #fff;
  --soft: #faf9f7;
  --line: #e2dfda;
  --line-strong: #c9c4bc;
  --ink: #1d1c1a;
  --muted: #6f6a63;
  --navy: #0b3a5b;
  --teal: #0e7c7b;
  --teal-ink: #0b5655;
  --teal-tint: #e3efee;
  --red: #b42318;
  --red-tint: #fdf1f0;
  --amber: #a15c07;
  --amber-tint: #fdf4e3;
  --green: #1a7f37;
  --green-tint: #e8f5ec;
  --violet: #5b3fa8;
  --violet-tint: #f1edfa;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal-ink); }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- khung ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: var(--navy); color: #fff;
}
.topbar .brand { font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .brand small { font-weight: 500; opacity: .7; margin-left: 8px; font-size: 12px; }
.topbar .spacer { flex: 1; }
.logo-slot { flex: 0 0 auto; height: 38px; min-width: 38px; max-width: 150px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 6px; padding: 3px 6px; }
.logo-slot img { max-height: 32px; max-width: 138px; object-fit: contain; display: block; }
.logo-slot.empty { background: transparent; border: 1.5px dashed rgba(255,255,255,.45); color: rgba(255,255,255,.7); font-size: 10.5px; font-weight: 700; letter-spacing: .06em; padding: 0 8px; }
.logo-preview { height: 56px; min-width: 120px; border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: center; justify-content: center; background: #fff; padding: 6px; }
.logo-preview img { max-height: 44px; max-width: 220px; }
.topbar .stage-chip { background: rgba(255,255,255,.12); border-radius: 999px; padding: 4px 12px; font-size: 12px; white-space: nowrap; }
.topbar .who { font-size: 12px; opacity: .9; white-space: nowrap; }
.topbar .btn { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); }
.topbar .btn:hover { background: rgba(255,255,255,.2); }
.menu-btn { display: none; }

.sidebar { background: var(--soft); border-right: 1px solid var(--line); padding: 14px 10px; overflow-y: auto; }
.nav-group { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin: 14px 10px 6px; }
.nav-group:first-child { margin-top: 0; }
.nav-btn {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px;
  cursor: pointer; font-weight: 500; color: var(--ink);
}
.nav-btn:hover { background: #f0eeea; }
.nav-btn.active { background: var(--teal-tint); color: var(--teal-ink); font-weight: 700; }
.nav-btn .badge { margin-left: 8px; }

main { overflow-y: auto; padding: 20px 24px 60px; min-width: 0; }
.topbar { min-width: 0; overflow: hidden; }
.topbar .stage-chip { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
table.t td:first-child { white-space: nowrap; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; color: var(--navy); letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- thành phần ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 6px; padding: 6px 12px; cursor: pointer;
  font-weight: 600; font-size: 12.5px; white-space: nowrap;
}
.btn:hover { background: var(--soft); border-color: var(--line-strong); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-ink); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-tint); border-color: #f1b8b2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 3px 8px; font-size: 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { font-size: 14px; margin: 0; color: var(--navy); }
.card-body { padding: 14px 16px; }
.grid { display: grid; gap: 14px; }
.grid.kpi { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 14px; }
.grid.two { grid-template-columns: 3fr 2fr; }

.kpi-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-align: left; cursor: default; }
button.kpi-card { cursor: pointer; }
button.kpi-card:hover { border-color: var(--teal); }
.kpi-card.active { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.kpi-card .k-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-card .k-value { font-size: 21px; font-weight: 700; color: var(--navy); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-card .k-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.kpi-card.warn .k-value { color: var(--amber); }
.kpi-card.bad .k-value { color: var(--red); }
.kpi-card.good .k-value { color: var(--green); }

.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; background: #eeece8; color: var(--muted); white-space: nowrap; }
.badge.teal { background: var(--teal-tint); color: var(--teal-ink); }
.badge.green { background: var(--green-tint); color: var(--green); }
.badge.amber { background: var(--amber-tint); color: var(--amber); }
.badge.red { background: var(--red-tint); color: var(--red); }
.badge.violet { background: var(--violet-tint); color: var(--violet); }
.badge.navy { background: #e6edf3; color: var(--navy); }

/* bảng */
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; }
table.t th {
  position: sticky; top: 0; z-index: 2; background: #f1efec; color: var(--navy);
  font-size: 11.5px; font-weight: 700; text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
table.t td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tbody tr:hover td { background: var(--soft); }
table.t tr.clickable { cursor: pointer; }
table.t tfoot td { font-weight: 700; background: #f7f6f3; position: sticky; bottom: 0; border-top: 1px solid var(--line-strong); }
table.t .name { min-width: 220px; }
table.t th.num, table.t td.num { text-align: right; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* form */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input {
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 9px; background: #fff; min-width: 0;
}
.input:focus { outline: 2px solid var(--teal-tint); border-color: var(--teal); }
textarea.input { resize: vertical; min-height: 56px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters .input { height: 32px; }
.search { min-width: 260px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.months-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.months-grid .field input { text-align: right; }

/* quy trình */
.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; }
.step { padding: 12px 14px; border-right: 1px solid var(--line); position: relative; }
.step:last-child { border-right: 0; }
.step .s-no { font-size: 11px; font-weight: 700; color: var(--muted); }
.step .s-title { font-weight: 700; margin: 2px 0 4px; }
.step .s-desc { font-size: 12px; color: var(--muted); line-height: 1.45; }
.step.done .s-no { color: var(--green); }
.step.current { background: var(--teal-tint); }
.step.current .s-no, .step.current .s-title { color: var(--teal-ink); }
.steps-list { margin: 0; padding-left: 20px; line-height: 1.7; }
.steps-list li.cur { font-weight: 700; color: var(--teal-ink); }

/* biểu đồ */
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar { height: 6px; background: #eeece8; border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--teal); }
.bar.over > span { background: var(--amber); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(11,58,91,.35); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 10px; width: min(760px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.sm { width: min(420px, 100%); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.modal-head h3 { margin: 0; font-size: 16px; color: var(--navy); }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--soft); border-radius: 0 0 10px 10px; }
.info-row { display: flex; flex-wrap: wrap; gap: 6px 18px; background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-bottom: 14px; }
.info-row div b { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.notice { border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; font-size: 12.5px; }
.notice.info { background: var(--teal-tint); color: var(--teal-ink); }
.notice.warn { background: var(--amber-tint); color: var(--amber); }
.notice.bad { background: var(--red-tint); color: var(--red); }

/* ô chọn vật tư */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 60; background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; max-height: 280px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.picker-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker-list button:hover, .picker-list button.on { background: var(--teal-tint); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--red); }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .page-head .toolbar, .filters { width: 100%; }
  .filters .input, .toolbar .input { flex: 1 1 140px; }
  .sidebar { position: fixed; top: 52px; bottom: 0; left: 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .menu-btn { display: inline-flex; }
  .grid.two { grid-template-columns: 1fr !important; }
  .modal-foot { flex-wrap: wrap; }
  .stepper { grid-template-columns: 1fr; }
  .step { border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 14px 16px 60px; }
  .topbar .brand small, .topbar .who { display: none; }
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .brand { font-size: 13px; }
  .form-grid { grid-template-columns: 1fr; }
  .months-grid { grid-template-columns: repeat(4, 1fr); }
  .search { min-width: 0; flex: 1; }
}

@media (max-width: 600px) {
  .topbar .stage-chip { display: none; }
}

@media print {
  .topbar, .sidebar, .toolbar, .filters, .no-print { display: none !important; }
  .app { display: block; height: auto; }
  main { overflow: visible; padding: 0; }
  .table-wrap { max-height: none; overflow: visible; }
  body { background: #fff; }
  .card { border: 0; }
}
