/* Nền tảng giao diện: màu, chữ, khung ứng dụng (sidebar + topbar), nút, ô nhập, thẻ, nhãn trạng thái.
   Các file css khác chỉ dùng biến ở đây, không tự đặt màu mới. */
:root {
  --bg: #f3f5f8; --surface: #fff; --surface-2: #f8fafc; --text: #0f1b2d; --text-2: #475467; --muted: #8a94a6;
  --line: #e4e8ee; --line-2: #d3d9e2;
  --brand: #00875a; --brand-600: #00704b; --brand-50: #e6f5ef; --brand-100: #c7eadb;
  --ink: #0d1b2a; --ink-2: #1b2b3f; --ink-text: #b8c4d4;
  --danger: #d92d20; --danger-50: #fef3f2; --danger-100: #fecdca;
  --warn: #b54708; --warn-50: #fffaeb; --warn-100: #fedf89;
  --info: #175cd3; --info-50: #eff8ff; --info-100: #b2ddff;
  --ok: #067647; --ok-50: #ecfdf3; --ok-100: #abefc6;
  --grey-50: #f2f4f7;
  --be: #c28a00; --be-50: #fff7db; --aha: #e8590c; --aha-50: #fff1e8;
  /* Màu bản đồ: xanh #141ED2 (lấy hàng, tuyến đường), đỏ #EB2D4B (giao hàng). */
  --pin-a: #141ed2; --pin-b: #eb2d4b; --map-route: #141ed2;
  --radius: 12px; --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --sidebar-w: 232px; --topbar-h: 64px;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
[hidden] { display: none !important; }

/* ---------- khung ứng dụng ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--ink); color: var(--ink-text); display: flex; flex-direction: column; padding: 18px 14px;
           position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 4px 8px 22px; text-decoration: none !important; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff;
              display: inline-flex; align-items: center; justify-content: center; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink-text);
         font-weight: 500; text-decoration: none; }
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.active { background: var(--ink-2); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.nav a:focus-visible, .brand:focus-visible { outline: 2px solid var(--brand-100); outline-offset: 2px; }
.nav svg { flex: none; }
.nav-count { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--brand);
             color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.env { margin-top: auto; display: flex; flex-direction: column; gap: 6px; font-size: 12px; padding: 0 4px; }
.env-row { display: flex; align-items: center; gap: 8px; }
.env-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.env-dot.mock { background: #fdb022; } .env-dot.staging { background: #53b1fd; } .env-dot.production { background: #32d583; }
.env-row span:last-child { margin-left: auto; color: #8796ab; }

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 28px; background: var(--surface);
          border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 500; }
.topbar h1 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; min-width: 0; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex: none; }
#view { padding: 24px 28px 40px; flex: 1; min-width: 0; }
#view.flush { padding: 0; }

/* Màn hình vừa (laptop nhỏ, máy tính bảng ngang): sidebar thu thành cột biểu tượng để nhường chỗ cho nội dung. */
@media (min-width: 861px) and (max-width: 1100px) {
  :root { --sidebar-w: 84px; }
  .sidebar { padding: 18px 10px; align-items: stretch; }
  .brand { justify-content: center; padding: 4px 0 22px; }
  .brand-name, .env { display: none; }
  .nav a { flex-direction: column; gap: 3px; padding: 10px 2px; font-size: 11px; position: relative; text-align: center; white-space: nowrap; }
  .nav a.active { box-shadow: inset 3px 0 0 var(--brand); }
  .nav-count { position: absolute; top: 4px; left: calc(50% + 6px); height: 18px; min-width: 18px; padding: 0 5px; font-size: 11px; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
             z-index: 1000; border-top: 1px solid var(--ink-2); }
  .brand, .env { display: none; }
  .nav { flex-direction: row; flex: 1; }
  .nav a { flex: 1; flex-direction: column; gap: 2px; font-size: 11px; padding: 6px; position: relative; }
  .nav a.active { box-shadow: inset 0 -3px 0 var(--brand); }
  .nav-count { position: absolute; top: 2px; left: calc(50% + 6px); height: 18px; min-width: 18px; font-size: 11px; }
  .topbar { padding: 0 16px; height: 56px; }
  .topbar h1 { font-size: 16px; }
  #view { padding: 16px 16px 96px; }
  #view.flush { padding: 0 0 72px; }
}

/* ---------- nút ---------- */
:where(button, a, summary, [tabindex]):focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 14px;
       border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
       font: 600 14px/1 var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.danger { color: var(--danger); border-color: var(--danger-100); }
.btn.danger:hover { background: var(--danger-50); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--grey-50); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 46px; padding: 0 22px; font-size: 15px; }
.btn.block { width: 100%; }
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 8px; border: 0; background: transparent; color: var(--text-2);
            display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: var(--grey-50); color: var(--text); }

/* ---------- ô nhập ---------- */
.field { display: block; margin: 0 0 12px; }
.field > span, .field-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 5px; }
input, select, textarea { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  font: 14px var(--font); color: var(--text); background: var(--surface); }
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
input:disabled, select:disabled, textarea:disabled { background: var(--grey-50); color: var(--muted); cursor: not-allowed; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--brand); flex: none; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- thẻ ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 15px; font-weight: 600; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 10px; }

/* ---------- nhãn trạng thái + đơn vị ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
         font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-FINDING { background: var(--warn-50); color: var(--warn); }
.s-ACCEPTED, .s-ARRIVED, .s-DELIVERING { background: var(--info-50); color: var(--info); }
.s-DELIVERED { background: var(--ok-50); color: var(--ok); }
.s-FAILED, .s-RETURNING, .s-RETURNED, .s-NO_DRIVER, .s-ERROR { background: var(--danger-50); color: var(--danger); }
.s-CANCELLED, .s-UNKNOWN { background: var(--grey-50); color: var(--text-2); }
.prov { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.prov-logo { width: 22px; height: 22px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
             font-size: 11px; font-weight: 700; flex: none; }
.prov-logo.be { background: var(--be-50); color: var(--be); } .prov-logo.ahamove { background: var(--aha-50); color: var(--aha); }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px;
        background: var(--grey-50); color: var(--text-2); margin: 2px 4px 2px 0; white-space: nowrap; }
.order-id { font-family: var(--mono); font-weight: 600; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.err-text { color: var(--danger); }
.spacer { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty-ic { font-size: 28px; margin-bottom: 6px; opacity: .6; }
.skeleton { background: linear-gradient(90deg, var(--grey-50), #e9edf2, var(--grey-50)); background-size: 200% 100%;
            animation: sk 1.2s infinite; border-radius: 6px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- ghim bản đồ (dùng chung cho Leaflet divIcon và danh sách điểm) ---------- */
.pin { width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700; flex: none;
       display: inline-flex; align-items: center; justify-content: center; }
.pin.a { background: var(--pin-a); } .pin.b { background: var(--pin-b); }

/* ---------- thông báo nổi ---------- */
/* Đặt ở trên, ngay dưới topbar: ở dưới thì che nút Đặt đơn / thanh điều hướng. */
.toast { position: fixed; inset: calc(var(--topbar-h) + 12px) auto auto 50%; margin: 0; border: 0; transform: translate(-50%, -8px); opacity: 0;
         background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font: 500 14px/1.45 var(--font);
         width: max-content; max-width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); z-index: 3000;
         overflow: visible; cursor: default; transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 860px) { .toast { top: calc(56px + 10px + env(safe-area-inset-top)); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
