/* Giao diện 2.0 — chuyên nghiệp, gọn */
:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #f0f1f3;
  --nav: #0f1b2d;
  --nav-2: #18273d;
  --nav-ink: #c3cddb;
  --accent: #0e7c74;
  --accent-ink: #ffffff;
  --accent-soft: #e5f3f1;
  --blue: #1d4ed8; --blue-soft: #e8efff;
  --green: #15803d; --green-soft: #e7f6ec;
  --amber: #b45309; --amber-soft: #fff4e0;
  --red: #c42b1c; --red-soft: #fdecea;
  --violet: #6d28d9; --violet-soft: #efe9fe;
  --slate: #475569; --slate-soft: #eef1f5;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05);
  --nav-w: 216px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.boot { padding: 48px; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(160deg, var(--nav) 0%, var(--nav) 38%, var(--bg) 38%); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 12px; padding: 28px 26px;
  box-shadow: 0 12px 40px rgba(15, 27, 45, .18); }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p.lead { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; margin-bottom: 14px; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 12px; min-width: 0; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.input { width: 100%; padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; min-height: 36px; }
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input:disabled { background: var(--line-2); color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 13.5px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 12px; min-height: 34px;
  border-radius: 6px; border: 1px solid #d1d5db; background: #fff; cursor: pointer; font-weight: 600; font-size: 13.5px;
  white-space: nowrap; color: var(--ink-2); }
.btn:hover { background: #f9fafb; border-color: #9ca3af; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { padding: 3px 8px; min-height: 28px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 15px; height: 15px; }
.form-error { background: var(--red-soft); color: var(--red); padding: 8px 11px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.form-error:empty { display: none; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.nav { width: var(--nav-w); flex-shrink: 0; background: var(--nav); color: var(--nav-ink); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 40; }
.nav-head { padding: 16px 16px 14px; display: flex; align-items: center; gap: 10px; }
.nav-head .mark { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center;
  font-weight: 700; flex-shrink: 0; }
.nav-head .name { font-weight: 700; color: #fff; font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; }
.nav-links { padding: 6px 8px; display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
.nav-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7d8aa0; padding: 12px 10px 4px; }
.nav-links a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; color: var(--nav-ink); font-weight: 500; }
.nav-links a:hover { background: var(--nav-2); color: #fff; text-decoration: none; }
.nav-links a.active { background: var(--accent); color: #fff; }
.nav-links svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .9; }
.nav-links .count { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 99px; line-height: 18px; }
.nav-foot { padding: 12px 16px; border-top: 1px solid var(--nav-2); font-size: 12.5px; }
.nav-foot .who { font-weight: 600; color: #fff; }
.nav-foot .link { background: none; border: 0; padding: 0; margin-top: 4px; color: #fca5a5; cursor: pointer; font-weight: 600; font-size: 12.5px; }
.main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
.topbar { display: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 6px; cursor: pointer; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel.pad { padding: 14px 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 14px; }
.panel-head .muted { font-size: 12.5px; }
.stack > * + * { margin-top: 14px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cols-side { display: grid; grid-template-columns: 320px 1fr; gap: 14px; align-items: start; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 14px; box-shadow: var(--shadow); display: block; color: inherit; }
a.kpi:hover { border-color: var(--accent); text-decoration: none; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi.alert .v { color: var(--red); }
.kpi.good .v { color: var(--accent); }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.toolbar .input { width: auto; min-height: 32px; padding: 5px 9px; }
.toolbar .search { flex: 1; min-width: 200px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 8px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap; font-size: 13.5px; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .n { background: var(--line-2); color: var(--ink-2); border-radius: 99px; padding: 0 7px; font-size: 11.5px; margin-left: 4px; }
.tabs button.on .n { background: var(--accent-soft); color: var(--accent); }
.tabs .n.red { background: var(--red); color: #fff; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
table.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover td { background: #fafcfc; }
table.tbl tr.click { cursor: pointer; }
table.tbl td.r, table.tbl th.r { text-align: right; }
table.tbl .name { font-weight: 600; color: var(--ink); }
table.tbl .sub { color: var(--muted); font-size: 12.5px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.bar { height: 8px; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar-bg { background: var(--line-2); border-radius: 4px; width: 100%; max-width: 220px; }

/* ---------- badges ---------- */
.b { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 4px; white-space: nowrap; line-height: 18px; }
.b.teal { background: var(--accent-soft); color: var(--accent); }
.b.blue { background: var(--blue-soft); color: var(--blue); }
.b.green { background: var(--green-soft); color: var(--green); }
.b.amber { background: var(--amber-soft); color: var(--amber); }
.b.red { background: var(--red-soft); color: var(--red); }
.b.violet { background: var(--violet-soft); color: var(--violet); }
.b.slate { background: var(--slate-soft); color: var(--slate); }
.tier-bac { background: #eef1f5; color: #475569; border: 1px solid #cbd5e1; }
.tier-vang { background: #fef6dc; color: #92600a; border: 1px solid #f2d27a; }
.tier-kc { background: #efe9fe; color: #5b21b6; border: 1px solid #c4b5fd; }

/* ---------- customer detail ---------- */
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.cust-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cust-title h2 { margin: 0; font-size: 20px; }
.big-money { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 86px 1fr; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border-bottom: 0; }
.timeline .d { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.timeline .k { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.timeline .c { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- day strip (lịch) ---------- */
.daystrip { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); }
.daystrip button { background: none; border: 0; border-right: 1px solid var(--line-2); padding: 8px 4px; cursor: pointer; text-align: center; }
.daystrip button:last-child { border-right: 0; }
.daystrip .dw { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.daystrip .dd { font-size: 15px; font-weight: 700; }
.daystrip .dc { font-size: 11px; color: var(--muted); }
.daystrip button.today .dd { color: var(--accent); }
.daystrip button.on { background: var(--accent-soft); box-shadow: inset 0 -2px 0 var(--accent); }
.day-group { padding: 6px 12px; background: #fafbfc; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 12.5px; color: var(--ink-2); }
.time { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- picker ---------- */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; background: #fff; border: 1px solid #d1d5db; border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12); max-height: 240px; overflow-y: auto; margin-top: 2px; }
.picker-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.picker-list button:hover { background: var(--accent-soft); }
.picker-chosen { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--accent);
  background: var(--accent-soft); border-radius: 6px; min-height: 36px; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 27, 45, .45); display: grid; place-items: center; padding: 16px; z-index: 60; }
.modal { background: var(--panel); border-radius: 10px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 680px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.warn-box { background: var(--amber-soft); color: #7c3d06; border-radius: 6px; padding: 9px 11px; font-size: 13px; margin-bottom: 12px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 6px; font-size: 13.5px; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 90; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); }
pre.preview { white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; font-size: 12.5px;
  font-family: inherit; max-height: 360px; overflow: auto; margin: 0; }

/* ---------- kho ---------- */
button.kpi { font: inherit; width: 100%; color: inherit; }
button.kpi:hover { border-color: var(--accent); }
.inv-line + .inv-line { margin-top: 6px; }
.inv-grid { display: grid; gap: 6px; align-items: center; }
.inv-grid.in { grid-template-columns: 1.9fr .7fr .9fr 1.5fr 1fr 32px; }
.inv-grid.out { grid-template-columns: 2.4fr .8fr 1.8fr 32px; }
.inv-grid .cell { display: block; min-width: 0; margin: 0; }
.inv-grid .m-cap { display: none; }
.inv-head { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin: 2px 0 4px; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .cols, .cols-side { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .nav { position: fixed; left: 0; top: 0; bottom: 0; height: 100%; transform: translateX(-100%); transition: transform .2s; width: 248px;
    box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .nav.open { transform: none; }
  .nav-shade { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 35; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--nav); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar .name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; cursor: pointer; }
  .topbar svg { width: 22px; height: 22px; }
  .main { padding: 14px 12px 60px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .inv-grid.in, .inv-grid.out { grid-template-columns: 1fr 1fr; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
  .inv-grid .cell:first-child { grid-column: 1 / -1; }
  .inv-grid .m-cap { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
  .inv-grid [data-rm] { grid-column: 1 / -1; justify-self: end; }
  .inv-head { display: none; }
  .page-head h2 { font-size: 17px; }
  table.tbl.cards thead { display: none; }
  table.tbl.cards, table.tbl.cards tbody, table.tbl.cards tr, table.tbl.cards td { display: block; width: 100%; }
  table.tbl.cards tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.tbl.cards tr:last-child { border-bottom: 0; }
  table.tbl.cards td { padding: 1px 0; border: 0; }
  table.tbl.cards td.r { text-align: left; }
  table.tbl.cards td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: 12.5px; }
  table.tbl.cards td.hide-m { display: none; }
  .row-actions { justify-content: flex-start; padding-top: 6px; }
  .daystrip .dw { font-size: 10.5px; }
  .modal-bg { padding: 0; place-items: end center; }
  .modal { max-height: 92vh; border-radius: 12px 12px 0 0; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .dl { grid-template-columns: 96px 1fr; }
}
