:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --emerald: #10b981;
  --emerald-bg: #d1fae5;
  --emerald-text: #065f46;
  --amber: #f59e0b;
  --amber-bg: #fef3c7;
  --amber-text: #92400e;
  --crimson: #ef4444;
  --crimson-bg: #fee2e2;
  --crimson-text: #991b1b;
  --slate-bg: #e2e8f0;
  --slate-text: #334155;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans Khmer", "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* ---------- Login Screen ---------- */
.login-overlay {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  flex-shrink: 0;
}

.login-brand h1 {
  margin: 0;
  font-size: 18px;
}

.login-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: #334155;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.error-text {
  color: var(--crimson);
  font-size: 13px;
  margin: 8px 0 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--emerald);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #059669;
}

.btn-danger {
  background: var(--crimson);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
  padding: 11px;
  font-size: 15px;
}

/* ---------- App Shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 245px;
  background: var(--sidebar-bg);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 14px;
}

.sidebar-logo .title {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.sidebar-logo .sub {
  font-size: 11px;
  color: #94a3b8;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.nav-badge {
  background: var(--crimson);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #94a3b8;
  padding-left: 8px;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top Header ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.pill-live {
  background: var(--emerald-bg);
  color: var(--emerald-text);
  border-color: #a7f3d0;
}

.pill-warn {
  background: var(--amber-bg);
  color: var(--amber-text);
  border-color: #fde68a;
}

.pill-off {
  background: var(--crimson-bg);
  color: var(--crimson-text);
  border-color: #fecaca;
}

.content {
  padding: 20px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Cards & KPIs ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.kpi-card.clickable {
  cursor: pointer;
  transition: border-color 0.15s, transform 0.08s;
}

.kpi-card.clickable:hover {
  border-color: var(--primary);
}

.kpi-card.active-shift {
  border: 2px solid var(--primary);
  background: #eff6ff;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.kpi-val {
  font-size: 26px;
  font-weight: 800;
  margin-top: 4px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar .grow {
  flex: 1;
  min-width: 180px;
}

.toolbar input[type="date"],
.toolbar select {
  width: auto;
  min-width: 140px;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: var(--surface-alt);
}

tr:hover td {
  background: #f8fafc;
}

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.st-PENDING_PICKUP { background: var(--amber-bg); color: var(--amber-text); }
.st-COMPLETED { background: var(--emerald-bg); color: var(--emerald-text); }
.st-PARTIAL_PICKUP { background: var(--crimson-bg); color: var(--crimson-text); }
.st-CANCELLED_BY_CLIENT { background: #ffe4e6; color: #9f1239; }
.st-NO_GOODS { background: var(--slate-bg); color: var(--slate-text); }
.st-UNANSWERED { background: #ede9fe; color: #5b21b6; }
.st-Active { background: var(--emerald-bg); color: var(--emerald-text); }
.st-Paused { background: var(--amber-bg); color: var(--amber-text); }

/* ---------- Hub Photo Cards ---------- */
.batch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.photo-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.photo-thumb-wrap {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
  background: #0f172a;
  cursor: pointer;
}

.photo-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-select {
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 2;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.thumb-select input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

.orphan-banner {
  border: 2px solid var(--amber);
  background: #fffbeb;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}

.chip button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--crimson);
  font-weight: 700;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

/* ---------- Modal & Lightbox ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.lightbox-img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1100;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.3);
  max-width: 340px;
}

.toast.ok { border-left: 4px solid var(--emerald); }
.toast.err { border-left: 4px solid var(--crimson); }

/* ---------- Driver Roster & Merchant Inline Badges ---------- */
.driver-roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.driver-roster-item {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.driver-roster-item.is-off {
  border-color: #f59e0b;
  background: #fffbeb;
}

.drv-badge-rot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #f1f5f9;
  color: #475569;
  border: 1px dashed #cbd5e1;
}

.drv-badge-fixed {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.drv-badge-off {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #fef3c7;
  color: #b45309;
}

.inline-sched-select {
  width: auto;
  min-width: 148px;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 8px;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    padding: 10px;
  }
  .sidebar-logo,
  .sidebar-footer {
    display: none;
  }
  .nav-list {
    flex-direction: row;
    overflow-x: auto;
  }
  .nav-item {
    width: auto;
    white-space: nowrap;
    padding: 8px 12px;
  }
}
