:root {
  --bg: #f4f6f9; --surface: #ffffff; --text: #1b2430; --muted: #66727f; --line: #dfe5ec;
  --brand: #1f4e78; --brand-ink: #ffffff; --ok: #1f8f5f; --warn: #c76a00; --bad: #c0392b; --info: #2a6fb5;
  --purple: #7a4bb0; --chip: #eaf0f6; --shadow: 0 1px 2px rgba(20, 30, 45, .08), 0 4px 14px rgba(20, 30, 45, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c; --surface: #1a212a; --text: #e8edf3; --muted: #93a0ae; --line: #2a3441;
    --brand: #4a8fd0; --brand-ink: #0b1118; --ok: #3cc08a; --warn: #f0a03c; --bad: #ef6f60; --info: #6aa8e6;
    --purple: #b48ae6; --chip: #232d39; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
.boot { text-align: center; margin-top: 40vh; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---- đăng nhập ---- */
.login { max-width: 380px; margin: 0 auto; padding: 12vh 20px 40px; }
.login img.logo-big { width: min(280px, 80%); height: auto; display: block; margin: 0 auto 10px; background: #fff; border-radius: 18px; padding: 14px 18px; box-sizing: content-box; }
.login h1 { text-align: center; font-size: 22px; margin: 0 0 22px; }

/* ---- khung ---- */
.shell { min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: #fff; color: #3a2a2a; border-bottom: 1px solid #ece6e6; }
.topbar .title { flex: 1; font-weight: 700; font-size: 17px; line-height: 0; }
.topbar .logo-top { height: 46px; width: auto; display: block; }
.topbar .who { font-size: 13px; opacity: .9; }
.topbar button { background: #f1ecec; color: inherit; border: 0; border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.banner { background: #fff4d6; color: #6b4a00; padding: 8px 16px; font-size: 14px; border-bottom: 1px solid #f0dca0; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2f10; color: #f2d58b; border-color: #5a4a1c; } }
main { max-width: 760px; margin: 0 auto; padding: 14px 14px 20px; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; background: none; border: 0; padding: 9px 4px 8px; color: var(--muted); font-size: 12px; min-height: 56px; }
.tabs button .ico { display: block; font-size: 22px; line-height: 1.1; }
.tabs button.on { color: var(--brand); font-weight: 700; }

/* ---- thành phần ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 9px; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.card .head { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.card .head .main { flex: 1; min-width: 0; }
.card .name { font-weight: 700; }
.card .sub { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.card .cod { font-weight: 700; white-space: nowrap; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--chip); color: var(--muted); }
.pill.waiting_pickup { color: var(--info); } .pill.transit { color: var(--info); }
.pill.delivered, .pill.audited, .pill.created { color: var(--ok); }
.pill.problem, .pill.need_info, .pill.error { color: var(--warn); }
.pill.returned { color: var(--purple); } .pill.cancelled, .pill.dry_run { color: var(--muted); }
.detail { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; margin-bottom: 10px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 8px 0 12px; padding: 0 0 0 4px; font-size: 14px; }
.timeline li { padding: 0 0 8px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline .t { color: var(--muted); font-size: 12px; }
.problems { background: #fff4e5; border: 1px solid #f3d2a2; border-radius: 10px; padding: 8px 12px; margin: 8px 0; font-size: 14px; color: #6b3d00; }
@media (prefers-color-scheme: dark) { .problems { background: #33260f; border-color: #5c4519; color: #f2c987; } }
.problems ul { margin: 4px 0 0; padding-left: 18px; }
label.f { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 3px; }
input[type=text], input[type=password], input[type=search], input[type=tel], input[type=date], input[type=number], textarea, select {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 14px; font-size: 14px; }
.chips button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.hero { text-align: center; padding: 18px 10px 10px; }
.hero .big { width: 100%; min-height: 64px; font-size: 18px; }
.hero p { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.kpi .v { font-size: 24px; font-weight: 800; } .kpi .l { color: var(--muted); font-size: 13px; } .kpi .s { font-size: 13px; color: var(--muted); }
h2 { font-size: 16px; margin: 18px 2px 8px; }
.toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: #222d3a; color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 90vw; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.toast.bad { background: var(--bad); }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
.err { color: var(--bad); font-size: 14px; margin: 8px 0; min-height: 20px; }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--brand-ink); }

.pill.ready { color: var(--info); } .pill.bad { color: #c0392b; background: #fdecea; }
.okbox { background: #e8f6ec; border: 1px solid #b6e0c2; border-radius: 10px; padding: 8px 12px; margin: 8px 0; font-size: 14px; color: #1b5e2f; }
@media (prefers-color-scheme: dark) { .okbox { background: #14301d; border-color: #245c37; color: #8fd6a5; } .pill.bad { background: #3a1814; color: #ff9b8f; } }

.kpi.big { grid-column: 1 / -1; background: #e8f6ec; border-color: #b6e0c2; } .kpi.big .v { color: #1b7a3a; font-size: 28px; }
@media (prefers-color-scheme: dark) { .kpi.big { background: #14301d; border-color: #245c37; } .kpi.big .v { color: #8fd6a5; } }
.card.day .head { align-items: center; } .card.day .mini { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.card.day .net { text-align: right; } .card.day .net .l { font-size: 12px; color: var(--muted); } .card.day .net .v { font-size: 19px; font-weight: 800; color: #1b7a3a; white-space: nowrap; }
.card.day .net.zero .v { color: var(--muted); font-weight: 600; }
.card.day .ord { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.card.day .ord .main { flex: 1; min-width: 0; } .card.day .ord .calc { text-align: right; white-space: nowrap; } .card.day .ord .calc .v { font-weight: 700; }
.card.day .ord.ex { opacity: .55; }

.pill.delivering { color: var(--info); } .pill.returning { color: var(--purple); }
.seg { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--chip); margin: 10px 0 8px; } .seg i { display: block; height: 100%; }
.checks { display: grid; gap: 4px; margin-top: 4px; } .chk { display: flex; gap: 8px; font-size: 14px; line-height: 1.3; padding: 5px 8px; border-radius: 8px; }
.chk.ok { background: #e8f6ec; color: #1b5e2f; } .chk.bad { background: #fff4e5; color: #7a4300; } .chk .mk { flex: none; }
.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.badge.ok { background: #e8f6ec; color: #1b7a3a; } .badge.open { background: #fff4e5; color: #9a5a00; } .badge.late { background: #fdecea; color: #c0392b; } .badge.dry { background: var(--chip); color: var(--muted); }
.card.day.overdue { border-color: #e8a39b; box-shadow: 0 0 0 1px #e8a39b; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin: 6px 0; } .legend i, .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.card.day .ord small { color: var(--muted); font-weight: 400; } .tap { text-align: center; margin-top: 6px; }
.kpi.k-ok .v { color: #1b7a3a; } .kpi.k-info .v { color: #2468a8; } .kpi.k-warn .v { color: #b97a00; } .kpi.k-ret .v { color: #7b4bb5; } .kpi .v { font-size: 20px; }
.warnbox { background: #fff4e5; border: 1px solid #f3d2a2; border-radius: 10px; padding: 8px 12px; font-size: 14px; color: #6b3d00; }
@media (prefers-color-scheme: dark) { .chk.ok { background: #14301d; color: #8fd6a5; } .chk.bad { background: #33260f; color: #f2c987; } .badge.ok { background: #14301d; } .badge.open { background: #33260f; } .badge.late { background: #3a1814; } .warnbox { background: #33260f; border-color: #5c4519; color: #f2c987; } }

.botwrap{display:flex;flex-direction:column;gap:10px}
.chips{display:flex;gap:6px;flex-wrap:wrap}
.chip{border:1px solid #c8d3df;background:#fff;border-radius:16px;padding:6px 12px;font-size:14px}
.chat{display:flex;flex-direction:column;gap:8px;min-height:40vh;max-height:56vh;overflow-y:auto;padding:4px}
.bubble{max-width:92%;padding:9px 12px;border-radius:14px;font-size:15px;line-height:1.4}
.bubble.me{align-self:flex-end;background:#1f4e78;color:#fff}
.bubble.bot{align-self:flex-start;background:#eef2f6}
.choices{display:flex;flex-direction:column;gap:6px;align-self:stretch}
.chatbar{display:flex;gap:8px}
.chatbar input{flex:1}
.livebox{margin:10px 0;padding:10px;border:1px dashed #c8d3df;border-radius:10px}

.bill-box { margin-bottom: 10px; }
.bill-thumb { width: 100%; max-height: 240px; object-fit: contain; background: #f3f4f6; border: 1px solid var(--line); border-radius: 8px; cursor: zoom-in; }
.bill-ov { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 99; display: flex; flex-direction: column; }
.bill-x { color: #fff; padding: 12px 16px; font-weight: 700; text-align: right; }
.bill-sc { flex: 1; overflow: auto; text-align: center; -webkit-overflow-scrolling: touch; }
.bill-sc img { max-width: 100%; touch-action: pinch-zoom; }
@media (min-width: 900px) { .bill-sc img { max-width: 900px; } }
