:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e2e6ee;
  --text: #1f2733;
  --muted: #667085;
  --primary: #2f80ed;
  --primary-dark: #1f6fd6;
  --danger: #e04f5f;
  --success: #1f9d55;
  --shadow: 0 2px 10px rgba(31, 39, 51, 0.06);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Thanh trên cùng (dùng chung qua layout.js) ---- */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-brand { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-user { color: var(--muted); font-size: 13px; white-space: nowrap; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }

/* Nút 3 gạch */
.hamburger {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger span { display: block; height: 2px; width: 100%; background: var(--text); border-radius: 2px; }
.hamburger:hover { background: #f0f3f8; }

/* Nền mờ phía sau menu */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 35, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 900;
}
.drawer-overlay.show { opacity: 1; visibility: visible; }

/* Ngăn kéo menu */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 300px;
  max-width: 82vw;
  background: var(--card);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 16px rgba(15, 23, 35, 0.12);
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-brand { font-weight: 700; font-size: 16px; }
.drawer-close {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 8px;
}
.drawer-close:hover { background: #f0f3f8; }
.drawer-list { padding: 10px; overflow-y: auto; }
.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  min-height: 44px;
}
.drawer-item:hover { background: #f0f3f8; text-decoration: none; }
.drawer-item.active { background: #eaf2fd; color: var(--primary-dark); font-weight: 600; }
.drawer-ico { font-size: 18px; flex-shrink: 0; width: 22px; text-align: center; }
.drawer-text { min-width: 0; }

/* Trên màn hình rất hẹp, giấu bớt chữ phụ */
@media (max-width: 480px) {
  .hide-xs { display: none; }
  .topbar-user { display: none; }
  .topbar-brand { font-size: 15px; }
}

/* ---- Khung chính ---- */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

/* Khung rộng hết cỡ (dùng cho trang có bảng nhiều cột) */
.container-fluid {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 20px;
}

/* ---- Thẻ ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 22px;
}

/* ---- Trang đăng nhập ---- */
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

/* ---- Biểu mẫu ---- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.15); }
.field input[type="radio"], .field input[type="checkbox"] { width: auto; min-height: 0; padding: 0; margin: 0; flex: 0 0 auto; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* ---- Nút ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: #f0f3f8; }
.btn.ok { background: #1f9d55; color: #fff; border-color: #1f9d55; }
.btn.ok:hover { background: #1b8a4b; }

/* Dòng vi phạm đã được đánh dấu xử lý — tô nhạt cho dễ phân biệt. */
tr.row-handled { background: #eafaf0; }
tr.row-handled td { color: #5b6472; }

/* Bộ lọc trạng thái xử lý — một ô chọn có nhãn phía trên (căn đáy để bằng các nút khác). */
.hfilter { display: flex; flex-direction: column; gap: 3px; }
.hfilter-label { font-size: 12px; font-weight: 600; color: #5b6472; padding-left: 2px; }
.hfilter-select { min-height: 42px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); font-size: 14px; cursor: pointer; }

/* Căn giữa tiêu đề cột + dữ liệu cho 3 trang vi phạm (khung .vio-page). */
.vio-page table th,
.vio-page table td { text-align: center; vertical-align: middle; }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: #fdecee; }

/* ---- Thông báo ---- */
.alert { border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.alert.error { background: #fdecee; color: #b3283a; border: 1px solid #f5c6cd; }
.alert.ok { background: #e7f6ec; color: #1a7a41; border: 1px solid #b8e3c6; }
.alert.info { background: #eaf2fd; color: #1a5fb0; border: 1px solid #c3dbf7; }
.hidden { display: none !important; }

/* ---- Thanh tab (dùng ở trang Cài đặt) ---- */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 8px 8px 0 0;
}
.tab-btn:hover { color: var(--text); background: #f0f3f8; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Thẻ hạng (chip) trong Cài đặt */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  background: #eaf2fd;
  color: var(--primary-dark);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.tag .tag-x {
  border: none;
  background: transparent;
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
.tag .tag-x:hover { color: var(--danger); }

/* ---- Đầu trang danh sách ---- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 { font-size: 20px; margin: 0; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.stats b { color: var(--text); font-size: 16px; }

/* ---- Bảng ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
table { width: 100%; border-collapse: collapse; min-width: 1180px; }
thead th {
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
  white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f7f9fc; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: #eaf2fd;
  color: #1a5fb0;
  font-size: 13px;
  font-weight: 600;
}
/* ---- Cửa sổ bản đồ lộ trình ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--card);
  border-radius: 12px;
  width: 100%;
  max-width: 860px;
  box-shadow: 0 12px 40px rgba(15, 23, 35, 0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-head .modal-close {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex-shrink: 0;
}
.modal-head .modal-close:hover { background: #f0f3f8; }
#routeMap { height: 70vh; max-height: 560px; width: 100%; }
.route-info { padding: 10px 16px; font-size: 13px; color: var(--muted); }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge.st-blue { background: var(--primary); color: #fff; }
.status-badge.st-gray { background: #eceff4; color: #5b6472; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* Trang báo cáo: co giãn kín màn hình, thanh phân trang luôn nằm sát đáy */
.vio-page { display: flex; flex-direction: column; min-height: calc(100vh - 64px); }
/* Vùng danh sách chiếm hết chỗ trống còn lại + cuộn riêng */
.table-scroll { flex: 1 1 auto; overflow: auto; min-height: 120px; }
/* Giữ tiêu đề cột dính trên khi cuộn danh sách */
.table-scroll thead th { position: sticky; top: 0; z-index: 2; }

/* Thanh phân trang */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.pager-left, .pager-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pager label { font-size: 13px; color: var(--muted); }
.pager select {
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
.pager #pageLabel { font-size: 14px; font-weight: 600; min-width: 90px; text-align: center; }
.pager .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Ô tìm kiếm trên báo cáo */
.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 1 1 240px;
  min-width: 260px;
  max-width: 420px;
}
.search-ico {
  position: absolute;
  left: 11px;
  font-size: 14px;
  pointer-events: none;
  line-height: 1;
}
.search-box {
  width: 100%;
  min-height: 38px;
  padding: 6px 12px 6px 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.search-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.15); }

/* ---- Nút lọc thời gian + menu xổ ---- */
.filter-wrap { position: relative; }
.filter-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 100;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 35, 0.16);
  padding: 8px;
  min-width: 250px;
}
.filter-presets { display: flex; flex-direction: column; }
.filter-presets button {
  text-align: left;
  background: transparent;
  border: none;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.filter-presets button:hover { background: #f0f3f8; }
.filter-presets button.active { background: #eaf2fd; color: var(--primary-dark); font-weight: 600; }
.filter-custom { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 10px; }
.filter-custom .row2 { display: flex; gap: 8px; }
.filter-custom .field { margin-bottom: 8px; flex: 1; min-width: 0; }
.filter-custom .field label { font-size: 12px; margin-bottom: 4px; }
.filter-custom input[type="date"] { width: 100%; min-height: 38px; padding: 6px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Icon reload quay tròn (báo đang quét) */
.spin-icon {
  display: inline-block;
  font-size: 18px;
  color: var(--primary);
  animation: spin 0.9s linear infinite;
}
