:root {
  color-scheme: light;
  --bg: #f3f5f9;
  --card: #ffffff;
  --line: #e3e8ef;
  --line-2: #eef1f6;
  --ink: #16202e;
  --ink-2: #5b6778;
  --ink-3: #8a95a5;
  --brand: #1d6fd6;
  --brand-2: #1557ad;
  --brand-soft: #e8f1fd;
  --side: #0f1e36;
  --side-ink: #b9c6da;
  --ok: #0f7b3f;
  --ok-soft: #e3f5ea;
  --warn: #9a5b00;
  --warn-soft: #fff3d9;
  --bad: #c62828;
  --bad-soft: #fdeaea;
  --gray-soft: #eef1f5;
  --violet: #5b3fd0;
  --violet-soft: #efebff;
  --series-1: #257de0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 21px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14.5px; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.boot { padding: 40px; text-align: center; color: var(--ink-2); }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ------------------------------------------------ nút, ô nhập */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  text-decoration: none !important;
}
.btn:hover { background: #f7f9fc; border-color: #cfd7e3; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f0c4c4; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--gray-soft); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn .i { width: 16px; height: 16px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #d3dbe6; border-radius: 8px;
  padding: 7px 10px; min-height: 36px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: 17px; height: 17px; min-height: 0; padding: 0; accent-color: var(--brand); vertical-align: -3px; }
input[disabled], select[disabled] { background: #f4f6f9; color: var(--ink-2); }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 550; }
label.f > span em { font-style: normal; color: var(--ink-3); font-weight: 400; }
label.chk { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.span2 { grid-column: span 2; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.stack { display: grid; gap: 14px; }

/* ------------------------------------------------ khung trang */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink); padding: 14px 10px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 14px; color: #fff; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 14px; line-height: 1.2; }
.brand small { color: var(--side-ink); font-size: 11.5px; }
.nav a {
  display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--side-ink);
  text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav a.on { background: var(--brand); color: #fff; }
.nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6f819d; padding: 12px 10px 4px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 22px; background: rgba(243, 245, 249, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.top .menu { display: none; }
.me-chip { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font: inherit; color: var(--ink); }
.me-chip .av { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-2); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.me-chip small { display: block; color: var(--ink-2); font-size: 11.5px; line-height: 1.1; }
.me-chip b { display: block; font-size: 13px; line-height: 1.2; font-weight: 600; text-align: left; }
.pop { position: absolute; right: 22px; top: 54px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 30, 54, .15); padding: 6px; min-width: 200px; z-index: 30; }
.pop button { display: flex; width: 100%; gap: 8px; align-items: center; padding: 8px 10px; border: 0; background: none; font: inherit; color: var(--ink); border-radius: 6px; cursor: pointer; text-align: left; }
.pop button:hover { background: var(--gray-soft); }
#view { padding: 20px 22px 60px; max-width: 1280px; width: 100%; }
.head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { margin-right: auto; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-size: 13px; margin-bottom: 6px; }

/* ------------------------------------------------ thẻ, bảng */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .ch { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.card > .ch h2 { margin-right: auto; }
.card > .cb { padding: 14px 16px; }
.card + .card { margin-top: 16px; }
.cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
.cols > div > .card + .card { margin-top: 16px; }
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.go { cursor: pointer; }
table.t tr.go:hover td { background: #f7faff; }
table.t td.r, table.t th.r { text-align: right; }
table.t .sub { color: var(--ink-2); font-size: 12.5px; }
table.t tfoot td { font-weight: 600; background: #fafbfd; }
.empty { padding: 28px 16px; text-align: center; color: var(--ink-2); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.filters input[type=search] { max-width: 280px; }
.filters select { width: auto; min-width: 150px; }
.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-weight: 550; border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.chip.on { background: var(--brand-soft); border-color: #b9d3f6; color: var(--brand-2); font-weight: 600; }

/* trạng thái */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--ink-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-bao_gia, .b-cho_xep, .b-moi { background: var(--warn-soft); color: var(--warn); }
.b-da_chot, .b-da_hen, .b-dang_xu_ly { background: var(--brand-soft); color: var(--brand-2); }
.b-dang_lam { background: var(--violet-soft); color: var(--violet); }
.b-hoan_thanh, .b-xong { background: var(--ok-soft); color: var(--ok); }
.b-huy, .b-tu_choi { background: var(--gray-soft); color: var(--ink-3); }
.b-low { background: var(--bad-soft); color: var(--bad); }
.debt { color: var(--bad); font-weight: 600; }
.okc { color: var(--ok); font-weight: 600; }

/* ô số liệu */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { color: var(--ink-2); font-size: 12.5px; font-weight: 550; }
.tile .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile .s { color: var(--ink-3); font-size: 12px; }
.tile.hero { grid-column: span 2; }
.tile.hero .v { font-size: 34px; }
a.tile { color: inherit; text-decoration: none; }
a.tile:hover { border-color: #b9d3f6; }

/* danh sách gọn */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 16px; border-bottom: 1px solid var(--line-2); display: flex; gap: 10px; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; }

/* thông tin dạng lưới */
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--ink-2); font-size: 13px; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 24px; justify-content: end; padding: 12px 16px; border-top: 1px solid var(--line-2); max-width: 380px; margin-left: auto; }
.totals .big { font-size: 18px; font-weight: 700; }

/* ô chọn có gợi ý */
.pick { position: relative; }
.pick .drop {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 30px rgba(15, 30, 54, .14); max-height: 320px; overflow-y: auto; z-index: 15;
}
.pick .drop button { display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line-2); background: none; font: inherit; color: var(--ink); cursor: pointer; }
.pick .drop button:hover, .pick .drop button.hl { background: var(--brand-soft); }
.pick .drop button .grow { flex: 1; min-width: 0; }
.pick .drop .none { padding: 10px 12px; color: var(--ink-2); }
.lines input { min-height: 32px; padding: 4px 8px; }
.lines .qty { width: 72px; text-align: right; }
.lines .price { width: 130px; text-align: right; }
.sel-cust { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid #cfe0f7; background: #f6faff; border-radius: 10px; }
.sel-cust .grow { flex: 1; }

/* biểu đồ cột */
.chart { position: relative; padding: 8px 4px 0 52px; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .grid line { stroke: #e7ebf1; stroke-width: 1; shape-rendering: crispEdges; }
.chart .ax { fill: var(--ink-2); font-size: 11px; }
.chart .bar { fill: var(--series-1); pointer-events: none; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.on { fill: #1b64be; }
.chart .peak { fill: var(--ink); font-size: 11.5px; font-weight: 600; }
.tip { position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(15, 30, 54, .15); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -100%); z-index: 5; }
.tip b { display: block; }

/* phân quyền */
table.perm th.role { text-align: center; text-transform: none; letter-spacing: 0; font-size: 12.5px; min-width: 104px; vertical-align: bottom; }
table.perm td.c { text-align: center; }
table.perm tr.grp td { background: #f6f8fb; font-weight: 650; font-size: 12.5px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
table.perm td.lbl { min-width: 260px; }
table.perm td.lbl small { display: block; color: var(--ink-3); font-size: 11.5px; }
table.perm .dirty { background: #fffbe8; }

/* việc lắp đặt */
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.job { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; box-shadow: var(--shadow); }
.job .when { font-weight: 700; }
.job ul { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 13px; }
.job .acts { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line-2); padding-top: 10px; margin-top: 2px; }

/* hộp thoại */
dialog#dlg { border: 0; padding: 0; border-radius: 14px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 30px 80px rgba(15, 30, 54, .35); }
dialog#dlg.wide { width: min(900px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(15, 30, 54, .45); }
.dh { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.dh h2 { margin-right: auto; }
.db { padding: 16px 18px; display: grid; gap: 12px; }
.df { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: #fafbfd; position: sticky; bottom: 0; }
.err { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 8px 12px; font-size: 13.5px; }
.err:empty { display: none; }
.note { background: var(--brand-soft); color: #173d6e; border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
#toast div { background: #12223b; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-size: 14px; animation: tin .2s ease; }
#toast div.bad { background: var(--bad); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* đăng nhập */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0f1e36 0%, #163a6b 60%, #1d6fd6 140%); }
.login .card { width: min(400px, 100%); padding: 26px; }
.login .logo { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.login .logo img { width: 44px; height: 44px; }
.login form { display: grid; gap: 12px; }

/* ------------------------------------------------ in phiếu */
#print { display: none; }
@media print {
  body > *:not(#print) { display: none !important; }
  #print { display: block; color: #000; font-size: 12.5pt; }
  #print table { width: 100%; border-collapse: collapse; margin: 10px 0; }
  #print th, #print td { border: 1px solid #999; padding: 5px 7px; vertical-align: top; }
  #print th { background: #eee; }
  #print .r { text-align: right; }
  #print .hd { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #000; padding-bottom: 8px; }
  #print h1 { text-align: center; margin: 16px 0 4px; font-size: 18pt; }
  #print .sig { display: grid; grid-template-columns: 1fr 1fr; text-align: center; margin-top: 26px; min-height: 110px; }
  @page { margin: 14mm; }
}

/* ------------------------------------------------ điện thoại */
@media (max-width: 960px) {
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  .shell.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 30, 54, .45); }
  .top { padding: 8px 12px; }
  .top .menu { display: inline-flex; }
  .me-chip small, .me-chip b { display: none; }
  #view { padding: 14px 12px 70px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .hide-sm { display: none; }
  .tile.hero { grid-column: auto; }
  .tile.hero .v { font-size: 28px; }
  dl.kv { grid-template-columns: 110px 1fr; }
  .filters input[type=search], .filters select { max-width: none; flex: 1 1 140px; }
  .jobs { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  .pop { right: 12px; }
}
