:root {
  --brand: #f26b1d;
  --brand-d: #d5560b;
  --brand-dd: #a8420a;
  --brand-l: #fff1e7;
  --brand-ll: #fff8f3;
  --ink: #1f2430;
  --ink2: #4b5262;
  --muted: #7a8190;
  --line: #ebe6e1;
  --line2: #f3efeb;
  --bg: #faf7f4;
  --card: #ffffff;
  --ok: #178a4c;
  --ok-l: #e6f6ed;
  --warn: #b7791f;
  --warn-l: #fdf3dc;
  --bad: #c53030;
  --bad-l: #fdeaea;
  --info: #2563a8;
  --info-l: #e8f1fb;
  --r: 12px;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 4px 14px rgba(60, 40, 20, 0.06);
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--brand-d); }
.hide { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -3px; }

/* ===== nút ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.btn:hover { background: var(--brand-ll); border-color: #f1c7a9; }
.btn:focus-visible, .chip:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.pri:hover { background: var(--brand-d); border-color: var(--brand-d); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { filter: brightness(0.93); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line2); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.big { height: 46px; font-size: 16px; padding: 0 20px; }

/* ===== form ===== */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > label, .lbl { font-size: 12px; font-weight: 700; color: var(--ink2); letter-spacing: 0.02em; }
.req { color: var(--bad); }
.inp, select.inp, textarea.inp {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid #ddd6cf; border-radius: 10px; background: #fff;
}
textarea.inp { height: auto; min-height: 76px; padding: 9px 12px; resize: vertical; }
.inp:focus { border-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 4px 0; }

/* ===== thẻ / bảng ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.cardhd { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line2); flex-wrap: wrap; }
.cardhd h3 { font-size: 15px; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; }
table.t th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  font-weight: 700; padding: 10px 14px; background: #fcfaf8; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.t td { padding: 11px 14px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: var(--brand-ll); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

/* ===== chip / badge ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink2);
}
.chip:hover { border-color: #f1c7a9; background: var(--brand-ll); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .n { font-size: 12px; opacity: 0.85; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.b-new { background: #eef0f3; color: #4b5262; }
.b-noans { background: var(--warn-l); color: var(--warn); }
.b-qual { background: var(--ok-l); color: var(--ok); }
.b-noneed { background: var(--bad-l); color: var(--bad); }
.b-bought { background: var(--info-l); color: var(--info); }
.b-test { background: #f1e8ff; color: #6b3fb5; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--brand-l); color: var(--brand-dd); font-size: 12px; font-weight: 600; margin: 0 4px 3px 0; }
.tag.gray { background: #eef0f3; color: #4b5262; }
.tag.blue { background: var(--info-l); color: var(--info); }

/* ===== khung ứng dụng ===== */
.top {
  position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: linear-gradient(90deg, var(--brand-d), var(--brand)); color: #fff; box-shadow: 0 2px 8px rgba(168, 66, 10, 0.25);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: 0.01em; }
.logo .mark {
  width: 32px; height: 32px; border-radius: 9px; background: #fff; color: var(--brand-d); display: grid; place-items: center;
  font-weight: 900; font-size: 18px;
}
.logo small { display: block; font-size: 11px; font-weight: 500; opacity: 0.9; letter-spacing: 0; margin-top: -2px; }
.top .sp { flex: 1; }
.me { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 8px; border-radius: 10px; border: 0; background: transparent; color: #fff; }
.me:hover { background: rgba(255, 255, 255, 0.14); }
.av { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: hsl(var(--h, 24) 70% 92%); color: hsl(var(--h, 24) 60% 30%); font-weight: 800; font-size: 13px; }
.me .who { text-align: left; line-height: 1.2; }
.me .who b { display: block; font-size: 13px; }
.me .who span { font-size: 11px; opacity: 0.9; }
.shell { display: flex; min-height: calc(100vh - 56px); }
.nav { width: 232px; flex: none; background: #fff; border-right: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 56px; align-self: flex-start; height: calc(100vh - 56px); overflow-y: auto; }
.nav h4 { margin: 14px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tab {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; margin-bottom: 2px; border: 0; background: transparent;
  border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--ink2); text-align: left;
}
.tab:hover { background: var(--brand-ll); }
.tab.on { background: var(--brand-l); color: var(--brand-dd); }
.tab[disabled] { opacity: 0.55; cursor: not-allowed; }
.tab[disabled]:hover { background: transparent; }
.tab .soon { margin-left: auto; font-size: 10px; background: #eef0f3; color: #6b7280; border-radius: 6px; padding: 1px 6px; font-weight: 700; }
.main { flex: 1; min-width: 0; padding: 20px; max-width: 1280px; }
.pagehd { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehd h1 { font-size: 21px; }
.pagehd .sub { color: var(--muted); font-size: 13px; }
.stack > * + * { margin-top: 16px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi.hl .v { color: var(--brand-d); }

/* banner */
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--r); background: var(--warn-l); border: 1px solid #f0d9a0; color: #7a5410; flex-wrap: wrap; }
.banner b { font-weight: 700; }
.banner.info { background: var(--info-l); border-color: #bcd5ef; color: #1c4a80; }

/* ===== đăng nhập ===== */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 50% -10%, #ffd9bf, transparent 70%), var(--bg); }
.loginbox { width: 100%; max-width: 400px; padding: 28px 26px 24px; }
.loginbox .logo { color: var(--brand-d); font-size: 24px; margin-bottom: 4px; }
.loginbox .logo .mark { background: var(--brand); color: #fff; width: 40px; height: 40px; font-size: 22px; }
.loginbox .logo small { color: var(--muted); font-size: 12px; }
.loginbox h2 { font-size: 16px; margin: 18px 0 14px; }

/* ===== drawer / modal ===== */
.layer { position: fixed; inset: 0; z-index: 60; display: flex; justify-content: flex-end; background: rgba(31, 36, 48, 0.45); }
.layer.mid { justify-content: center; align-items: center; padding: 16px; }
.drawer { width: min(520px, 100%); height: 100%; background: #fff; display: flex; flex-direction: column; box-shadow: -10px 0 30px rgba(0, 0, 0, 0.18); animation: slidein 0.18s ease-out; }
.modal { width: min(560px, 100%); max-height: 100%; background: #fff; border-radius: 16px; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); animation: pop 0.14s ease-out; }
.modal.wide { width: min(760px, 100%); }
.dhd { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dhd h3 { font-size: 16px; flex: 1; }
.dbody { padding: 18px; overflow-y: auto; flex: 1; }
.dft { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: #fcfaf8; border-radius: 0 0 16px 16px; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }

.callphone { font-size: 30px; font-weight: 800; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.callbox { background: var(--brand-ll); border: 1px solid #f6d6bf; border-radius: var(--r); padding: 16px; text-align: center; margin-bottom: 16px; }
.timer { font-size: 15px; color: var(--brand-dd); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.results { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.res { position: relative; }
.res input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.res span { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 46px; padding: 6px 8px; border: 2px solid var(--line); border-radius: 10px; font-weight: 700; font-size: 13px; background: #fff; }
.res input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.res input:checked + span.r-noans { border-color: var(--warn); background: var(--warn-l); color: var(--warn); }
.res input:checked + span.r-qual { border-color: var(--ok); background: var(--ok-l); color: var(--ok); }
.res input:checked + span.r-noneed { border-color: var(--bad); background: var(--bad-l); color: var(--bad); }
.res input:checked + span.r-bought { border-color: var(--info); background: var(--info-l); color: var(--info); }
.stars { display: flex; gap: 4px; }
.stars button { border: 0; background: transparent; cursor: pointer; padding: 2px; color: #d6cfc8; }
.stars button.on { color: #f5a30b; }
.stars .i { width: 26px; height: 26px; fill: currentColor; }

/* lịch */
.cal { padding: 14px; min-width: 0; }
.calhd { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.calhd b { flex: 1; text-align: center; font-size: 15px; }
.calgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calgrid .dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cd { position: relative; min-width: 0; aspect-ratio: 1.45; border: 1px solid var(--line2); border-radius: 8px; background: #fff; cursor: pointer; padding: 4px 6px; text-align: left; display: flex; flex-direction: column; justify-content: space-between; }
.cd:hover { border-color: #f1c7a9; background: var(--brand-ll); }
.cd.out { visibility: hidden; }
.cd .d { font-size: 12px; color: var(--ink2); font-weight: 600; }
.cd .c { font-size: 15px; font-weight: 800; color: var(--brand-d); align-self: flex-end; font-variant-numeric: tabular-nums; }
.cd.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cd.has { background: var(--brand-l); }
.cd.future { opacity: 0.45; cursor: default; }

.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; align-items: start; }
/* báo cáo */
table.rpt td, table.rpt th { white-space: normal; }
table.rpt tr.rs td { background: var(--brand-ll); color: var(--brand-dd); font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
table.rpt tr.rc td { background: #fffaf6; font-weight: 700; }
table.rpt td.sub1 { padding-left: 30px; color: var(--ink2); }
table.rpt tr.lockrow td { background: #fbf9f7; }
table.grid td, table.grid th { white-space: nowrap; }
.src { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: #eef0f3; color: #4b5262; white-space: nowrap; }
.src.s-auto { background: var(--info-l); color: var(--info); }
.src.s-roll { background: #f1e8ff; color: #6b3fb5; }
.src.s-acct { background: var(--warn-l); color: var(--warn); }
.src.s-manual { background: var(--ok-l); color: var(--ok); }
.src.s-calc { background: #eef0f3; color: #4b5262; }
.pc { display: flex; align-items: center; gap: 8px; min-width: 96px; }
.pc .pb { flex: 1; height: 7px; border-radius: 99px; background: #eee7e0; overflow: hidden; }
.pc .pb i { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.pc.a .pb i { background: #e2a110; }
.pc.r .pb i { background: var(--bad); }
.pc b { font-size: 12px; font-variant-numeric: tabular-nums; }
.autoc { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
.dv { color: var(--info); font-variant-numeric: tabular-nums; }
.xin { width: 74px; height: 34px; padding: 0 8px; border: 1px solid #ddd6cf; border-radius: 8px; background: #fff; text-align: right; font-variant-numeric: tabular-nums; }
.xin:focus { border-color: var(--brand); outline: 2px solid var(--brand-l); }
.seg { display: inline-flex; background: #f1ece7; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--ink2); font-size: 13px; }
.seg button.on { background: #fff; color: var(--brand-dd); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; background: #1f2430; color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); }
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line2); color: var(--muted); font-size: 13px; }
.pager .sp { flex: 1; }
.pw { font-family: Consolas, monospace; font-size: 22px; font-weight: 700; letter-spacing: 0.06em; background: #f6f2ee; border: 1px dashed #d8cfc7; border-radius: 10px; padding: 12px; text-align: center; user-select: all; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.checks label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checks input { width: 17px; height: 17px; accent-color: var(--brand); }
.sec { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--brand-dd); margin: 16px 0 8px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ===== điện thoại ===== */
/* chat nội bộ */
.chatfab { position: fixed; right: 18px; bottom: 18px; z-index: 50; width: 58px; height: 58px; border-radius: 50%; border: 0; background: #e53935; color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 6px 20px rgba(229, 57, 53, 0.45); }
.chatfab:hover { filter: brightness(0.95); }
.cbadge { position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: #1f2430; color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; border: 2px solid #fff; }
.chatpanel { position: fixed; right: 18px; bottom: 88px; z-index: 55; width: 380px; max-width: calc(100vw - 24px); height: 540px; max-height: calc(100vh - 110px); background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 16px 50px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; overflow: hidden; }
.chd { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: linear-gradient(90deg, var(--brand-d), var(--brand)); color: #fff; }
.chd .btn.ghost { color: #fff; }
.chd .btn.ghost:hover { background: rgba(255, 255, 255, 0.18); }
.chd .muted { color: rgba(255, 255, 255, 0.85); }
.clist { flex: 1; overflow-y: auto; }
.crow { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line2); background: #fff; cursor: pointer; position: relative; }
.crow:hover { background: var(--brand-ll); }
.crow .dot { position: absolute; left: 38px; top: 34px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c9c4be; border: 2px solid #fff; flex: none; }
.dot.on { background: #22c55e; }
.chd .dot { border-color: transparent; }
.cmsgs { flex: 1; overflow-y: auto; padding: 12px; background: #faf7f4; display: flex; flex-direction: column; gap: 8px; }
.cmsg { max-width: 82%; align-self: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 12px 12px 12px 3px; padding: 8px 11px; }
.cmsg.mine { align-self: flex-end; background: var(--brand-l); border-color: #f6d6bf; border-radius: 12px 12px 3px 12px; }
.csep { text-align: center; font-size: 11px; color: var(--muted); margin: 4px 0; }
.ccomp { padding: 10px 12px; border-top: 1px solid var(--line); background: #fff; }
.ccomp textarea { resize: none; }

@media (max-width: 880px) {
  .chatfab { bottom: 78px; right: 12px; width: 52px; height: 52px; }
  .chatpanel { right: 0; left: 0; bottom: 0; top: 0; width: auto; max-width: none; height: auto; max-height: none; border-radius: 0; }
  .shell { display: block; padding-bottom: 66px; }
  .nav {
    position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; top: auto; width: 100%; height: auto; display: flex; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; gap: 4px;
  }
  .nav h4 { display: none; }
  .tab { flex-direction: column; gap: 2px; width: auto; min-width: 74px; font-size: 11px; padding: 6px 8px; margin: 0; text-align: center; flex: 1; white-space: nowrap; }
  .tab .soon { display: none; }
  .main { padding: 14px 12px; }
  .me .who { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .kpi .v { font-size: 22px; }
  .pagehd h1 { font-size: 18px; }
  .logo small { display: none; }
}
@media (max-width: 880px) {
  /* bảng Kho 1 thành thẻ trên điện thoại để nút Gọi luôn nằm trong màn hình */
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line2); align-items: center; }
  table.cards td { display: block; padding: 0; border: 0; }
  table.cards td.c-name, table.cards td.c-phone { grid-column: 1; }
  table.cards td.c-act { grid-column: 2; grid-row: 1 / span 2; }
  table.cards td.c-status, table.cards td.c-need, table.cards td.c-last, table.cards td.c-last2 { grid-column: 1 / -1; }
  table.cards td.c-cnt { display: none; }
  table.cards td.c-need:empty { display: none; }
  table.cards td[colspan] { grid-column: 1 / -1; }
  .btn.sm.callbtn { height: 40px; padding: 0 16px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { .drawer, .modal { animation: none; } }
