:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e2e8f0;
  --gantt-grid: #cbd5e1;
  --gantt-grid-strong: #94a3b8;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #ca8a04;
  --danger: #dc2626;
  --sidebar-w: 260px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #1e3a5f 0%, #0f2744 100%);
  color: #fff;
  padding: 24px 0;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.logo {
  padding: 0 24px 28px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: 16px;
}

.logo h1 { font-size: 1.15rem; font-weight: 700; }
.logo p { font-size: .75rem; opacity: .65; margin-top: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  cursor: pointer;
  font-size: .9rem;
  transition: background .15s;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active {
  background: rgba(255,255,255,.12);
  border-left-color: #60a5fa;
  font-weight: 600;
}

.nav-icon { font-size: 1.1rem; width: 24px; text-align: center; }

/* Main */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: calc(100vw - var(--sidebar-w));
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.page-header > div:last-child,
.page-header .page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.telegram-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
}

.telegram-banner code {
  font-size: .85em;
}

.page-header h2 { font-size: 1.5rem; font-weight: 700; }
.page-header p { color: var(--text-muted); font-size: .9rem; margin-top: 4px; }

.analytics-filters {
  align-items: center;
  flex-shrink: 0;
}
.analytics-filters .filter-label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: #f8fafc; }

.table-actions { display: flex; gap: 4px; justify-content: center; }
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: .85rem;
  line-height: 1;
}
.btn-icon:hover { background: #f8fafc; }
.btn-icon-danger:hover { background: #fef2f2; border-color: #fecaca; }
.col-actions { width: 90px; text-align: center; white-space: nowrap; }
.cell-note {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: .85rem;
}
.required { color: #dc2626; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.stat-card .label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 2rem; font-weight: 700; margin: 6px 0 4px; }
.stat-card .sub { font-size: .8rem; color: var(--text-muted); }

.stat-card.green .value { color: var(--success); }
.stat-card.yellow .value { color: var(--warning); }
.stat-card.red .value { color: var(--danger); }
.stat-card.blue .value { color: var(--primary); }

/* Cards & panels */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 24px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h3 { font-size: 1rem; font-weight: 600; }
.panel-subtitle {
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 400;
}
.panel-body { padding: 20px; }

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.filters select, .filters input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-available { background: #dcfce7; color: #15803d; }
.badge-mission { background: #fef9c3; color: #a16207; }
.badge-maintenance { background: #fee2e2; color: #b91c1c; }
.badge-pending { background: #e0e7ff; color: #3730a3; }
.badge-approved { background: #dcfce7; color: #15803d; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }

/* Tree */
.tree { font-size: .9rem; }
.tree-node { margin-left: 0; }
.tree-node .node-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.tree-node .node-label:hover { background: #f1f5f9; }
.tree-children { margin-left: 24px; border-left: 2px solid var(--border); }
.tree-vehicle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 6px;
  margin: 4px 0;
  background: #f8fafc;
  gap: 12px;
  flex-wrap: wrap;
}

/* Calendar / Gantt */
.calendar-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-tabs { display: flex; gap: 4px; background: #f1f5f9; padding: 4px; border-radius: 8px; }
.view-tab {
  padding: 6px 14px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: .85rem;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-muted);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.view-tab.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,.06); font-weight: 600; }

.calendar-toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.calendar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.calendar-actions .btn {
  padding: 8px 14px;
  font-size: .82rem;
}

@media screen {
  .print-only {
    display: none !important;
  }
}

.calendar-print-header {
  text-align: center;
  margin-bottom: 12px;
}
.calendar-print-header h2 {
  font-size: 1.1rem;
  margin: 0 0 6px;
}
.calendar-print-header p {
  font-size: .82rem;
  color: #334155;
  margin: 2px 0;
}

.calendar-print-signatures {
  margin-top: 20px;
}
.sign-table {
  width: 100%;
  border-collapse: collapse;
}
.sign-table td {
  width: 33.33%;
  vertical-align: top;
  padding: 8px 12px;
  text-align: center;
  font-size: .82rem;
}
.sign-line {
  margin-top: 48px;
  font-size: .75rem;
  color: #64748b;
}
.sign-date {
  margin-top: 8px;
  font-size: .75rem;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }
  body.print-calendar-mode {
    background: #fff !important;
  }
  body.print-calendar-mode .sidebar,
  body.print-calendar-mode .sidebar-overlay,
  body.print-calendar-mode .mobile-topbar,
  body.print-calendar-mode .toast,
  body.print-calendar-mode .calendar-screen-only,
  body.print-calendar-mode .page-header,
  body.print-calendar-mode .modal-overlay {
    display: none !important;
  }
  body.print-calendar-mode .main {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }
  body.print-calendar-mode .page {
    display: none !important;
  }
  body.print-calendar-mode #page-calendar {
    display: block !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  body.print-calendar-mode #calendar-panel {
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
  }
  body.print-calendar-mode #calendar-panel .panel-body {
    padding: 0 !important;
  }
  body.print-calendar-mode .print-only {
    display: block !important;
  }
  body.print-calendar-mode .gantt-wrap {
    overflow: visible !important;
  }
  body.print-calendar-mode .gantt-table {
    min-width: 0 !important;
    font-size: .7rem;
  }
  body.print-calendar-mode .gantt-table th,
  body.print-calendar-mode .gantt-table td {
    padding: 4px 3px !important;
  }
  body.print-calendar-mode .gantt-table .vehicle-col {
    min-width: 120px !important;
  }
  body.print-calendar-mode .gantt-table .meta-col {
    min-width: 60px !important;
  }
  body.print-calendar-mode .cell-available,
  body.print-calendar-mode .cell-mission,
  body.print-calendar-mode .cell-maintenance {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
.gantt-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.gantt-wrap::-webkit-scrollbar {
  height: 8px;
}
.gantt-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.gantt-wrap.is-dragging {
  cursor: grabbing;
  user-select: none;
}
.gantt-wrap.is-dragging * {
  pointer-events: none;
}

.gantt-scroll-hint {
  margin: 0 0 10px;
  padding: 8px 12px;
  font-size: .78rem;
  color: var(--primary);
  background: #eff6ff;
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  text-align: center;
}

#calendar-panel {
  overflow: visible;
}

#calendar-panel .panel-body {
  overflow: visible;
}

.gantt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  border: 1px solid var(--gantt-grid-strong);
  background: #fff;
}

.gantt-table.gantt-month {
  width: max-content;
  table-layout: auto;
}

/* Tab Tuần — full khung, cột định rõ không chồng lấn */
.gantt-table:not(.gantt-month) {
  table-layout: fixed;
}

.gantt-table:not(.gantt-month) col.col-vehicle {
  width: 108px;
}

.gantt-table:not(.gantt-month) col.col-branch {
  width: 76px;
}

.gantt-table:not(.gantt-month) col.col-dept {
  width: 88px;
}

.gantt-table:not(.gantt-month) .vehicle-col {
  text-align: left;
  background: #fafbfc;
  font-weight: 500;
  white-space: normal;
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: anywhere;
  padding: 8px 10px;
}

.gantt-table:not(.gantt-month) .vehicle-col small {
  display: block;
  color: var(--text-muted);
  font-size: .75rem;
  margin-top: 2px;
}

.gantt-table:not(.gantt-month) .meta-col {
  text-align: left;
  background: #fafbfc;
  color: var(--text-muted);
  font-size: .75rem;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
  padding: 8px 6px;
}

.gantt-table:not(.gantt-month) th:not(.vehicle-col):not(.meta-col),
.gantt-table:not(.gantt-month) td:not(.vehicle-col):not(.meta-col) {
  min-width: 96px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-schedule {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  line-height: 1.25;
  padding: 2px 0;
}

.cell-time {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(133, 77, 14, 0.14);
  color: #92400e;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
}

.cell-time-compact {
  display: block;
  font-size: .58rem;
  padding: 1px 2px;
  line-height: 1.1;
  white-space: normal;
  word-break: break-word;
}

.cell-mission-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: .74rem;
  font-weight: 500;
  color: #854d0e;
  word-break: break-word;
}

.gantt-table th,
.gantt-table td {
  border: 1px solid var(--gantt-grid);
  padding: 10px 8px;
  text-align: center;
  vertical-align: middle;
}

.gantt-table thead th {
  border-bottom: 2px solid var(--gantt-grid-strong);
}

.gantt-table tbody tr + tr td {
  border-top: 1px solid var(--gantt-grid);
}

.gantt-table th { background: #f8fafc; font-weight: 600; color: var(--text-muted); font-size: .78rem; }

.gantt-table .vehicle-col { text-align: left; background: #fafbfc; font-weight: 500; }
.gantt-table .meta-col { text-align: left; background: #fafbfc; color: var(--text-muted); font-size: .78rem; }

/* Phân tách cột thông tin xe và cột lịch theo ngày */
.gantt-table th.vehicle-col,
.gantt-table td.vehicle-col {
  border-right: 2px solid var(--gantt-grid-strong);
}

.gantt-table thead th:nth-child(3),
.gantt-table tbody td:nth-child(3) {
  border-right: 2px solid var(--gantt-grid-strong);
}

.gantt-table.gantt-month th:not(.vehicle-col):not(.meta-col),
.gantt-table.gantt-month td:not(.vehicle-col):not(.meta-col) {
  min-width: 40px;
  max-width: 40px;
  padding: 8px 2px;
  font-size: .68rem;
  line-height: 1.2;
}

.gantt-table.gantt-month .vehicle-col,
.gantt-table.gantt-month th.vehicle-col,
.gantt-table.gantt-month td.vehicle-col {
  position: sticky;
  left: 0;
  z-index: 3;
  box-shadow: 2px 0 6px rgba(15, 23, 42, 0.08);
}

.cell-available { background: #f1f5f9; color: var(--text-muted); }
.cell-mission { background: #fef9c3; color: #854d0e; font-weight: 500; }
.cell-maintenance { background: #fee2e2; color: #991b1b; font-weight: 500; }

/* Search form */
.search-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  align-items: end;
}

.form-group label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
}

.form-group .flatpickr-wrapper {
  display: block;
  width: 100%;
}

.form-group .flatpickr-wrapper input {
  width: 100%;
}

.form-row-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 768px) {
  .form-row-split {
    grid-template-columns: 1fr;
  }

  .pending-passenger-row {
    grid-template-columns: 1fr;
  }
}

.search-results { margin-top: 20px; }
.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #f0fdf4;
  flex-wrap: wrap;
  gap: 12px;
}

.pending-item { background: #fff; align-items: flex-start; }
.pending-item-body { flex: 1; min-width: 0; }
.pending-meta { display: block; color: var(--text-muted); margin-top: 4px; }
.pending-passenger-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-top: 6px;
}
.pending-passenger-item {
  display: block;
  color: var(--text);
  line-height: 1.45;
  word-break: break-word;
}
.pending-passenger-item span {
  color: var(--text-muted);
  font-weight: 500;
}
.pending-reason {
  display: block;
  margin-top: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 6px;
  color: var(--text);
  line-height: 1.45;
}
.pending-reason span { color: var(--text-muted); font-weight: 500; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #f8fafc; font-weight: 600; color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.data-table tr:hover td { background: #fafbfc; }

/* Workflow timeline */
.workflow-steps {
  --timeline-track: #e2e8f0;
  --timeline-done: #22c55e;
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  padding: 28px 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.step {
  flex: 1;
  min-width: 150px;
  text-align: center;
  position: relative;
  padding: 0 12px;
}

/* Đường nối giữa các bước */
.step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 18px;
  left: calc(50% + 20px);
  width: calc(100% - 40px);
  height: 3px;
  background: var(--timeline-track);
  border-radius: 2px;
  z-index: 0;
}

.step.done:not(:last-child)::after {
  background: var(--timeline-done);
}

.step-num {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin: 0 auto 10px;
  font-size: .9rem;
  position: relative;
  z-index: 1;
  border: 3px solid var(--surface);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.step.done .step-num {
  background: var(--success);
  box-shadow: 0 2px 6px rgba(34, 197, 94, 0.3);
}

/* Bước hiện tại (ngay sau bước đã hoàn thành) */
.step.done + .step:not(.done) .step-num {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18), 0 2px 6px rgba(37, 99, 235, 0.25);
}

.step-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.step.done .step-title {
  color: #166534;
}

.step.done + .step:not(.done) .step-title {
  color: var(--primary);
}

.step-desc {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
  max-width: 160px;
  margin-left: auto;
  margin-right: auto;
}

/* Analytics */
.chart-bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label { width: 160px; font-size: .82rem; flex-shrink: 0; }
.bar-track { flex: 1; height: 28px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; display: flex; align-items: center; padding-left: 10px; font-size: .75rem; font-weight: 600; color: #fff; transition: width .6s ease; }
.bar-fill.high { background: linear-gradient(90deg, #2563eb, #3b82f6); }
.bar-fill.mid { background: linear-gradient(90deg, #ca8a04, #eab308); }
.bar-fill.low { background: linear-gradient(90deg, #94a3b8, #cbd5e1); color: #475569; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.grid-2-equal {
  align-items: stretch;
  margin-bottom: 24px;
}
.grid-2-equal > .panel {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
  height: 600px;
}
.grid-2-equal > .panel .panel-body-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.grid-2-equal > .panel .panel-body-scroll::-webkit-scrollbar {
  width: 6px;
}
.grid-2-equal > .panel .panel-body-scroll::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
.grid-2-equal > .panel .panel-body-scroll::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}
#transfer-suggestions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
@media (max-width: 900px) {
  .grid-2-equal > .panel {
    height: auto;
    max-height: 600px;
  }
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 { font-size: 1.1rem; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

.page { display: none; }
.page.active { display: block; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 14px 20px;
  border-radius: 8px;
  font-size: .875rem;
  z-index: 300;
  transform: translateY(80px);
  opacity: 0;
  transition: all .3s;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

.toast.show { transform: translateY(0); opacity: 1; }

/* Login */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f2744 0%, #1e3a5f 50%, #2563eb 100%);
  padding: 24px;
  box-sizing: border-box;
}

.login-wrap {
  width: min(100%, 420px);
  flex: 0 0 auto;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 36px;
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  width: 100%;
  box-sizing: border-box;
}

.login-card h2 { font-size: 1.35rem; margin-bottom: 6px; }
.login-card .subtitle { color: var(--text-muted); font-size: .875rem; margin-bottom: 24px; }

.login-error {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: .85rem;
  margin-bottom: 16px;
}
.login-error.show { display: block; }

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.role-admin { background: #ede9fe; color: #5b21b6; }
.role-fleet { background: #dbeafe; color: #1d4ed8; }
.role-director { background: #fef3c7; color: #b45309; }
.role-dept { background: #dcfce7; color: #15803d; }

.user-panel {
  margin-top: auto;
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.user-info { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.user-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem;
}
.user-name { font-size: .85rem; font-weight: 600; }
.user-role { font-size: .72rem; opacity: .65; margin-top: 2px; }
.btn-logout {
  display: block;
  width: 100%;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.2);
  background: transparent;
  color: #fff;
  border-radius: 6px;
  font-size: .8rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.btn-logout:hover { background: rgba(255,255,255,.1); color: #fff; }

.sidebar { display: flex; flex-direction: column; }
.sidebar nav { flex: 1; }

.scope-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: .85rem;
  color: #1e40af;
  margin-bottom: 20px;
}

.perm-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.perm-table th, .perm-table td { padding: 10px 14px; border: 1px solid var(--border); text-align: center; }
.perm-table th { background: #f8fafc; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; font-weight: 600; }
.perm-yes { color: var(--success); font-weight: 700; }
.perm-no { color: #cbd5e1; }
.perm-scope { color: var(--warning); font-weight: 600; font-size: .78rem; }

.perm-edit-hint {
  font-size: .85rem;
  color: var(--text-muted);
  margin: 0 0 12px;
  padding: 0 4px;
}

.perm-select {
  width: 100%;
  max-width: 160px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface);
  cursor: pointer;
  text-align: center;
}

.perm-select.perm-yes { color: var(--success); }
.perm-select.perm-scope { color: var(--warning); }
.perm-select.perm-no { color: #94a3b8; }

.perm-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}

.util-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
}
.util-pill.high { background: #dcfce7; color: #166534; }
.util-pill.mid { background: #fef9c3; color: #854d0e; }
.util-pill.low { background: #fee2e2; color: #991b1b; }

.rating-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 600;
}
.rating-high { background: #dcfce7; color: #166534; }
.rating-mid { background: #fef9c3; color: #854d0e; }
.rating-low { background: #ffedd5; color: #c2410c; }
.rating-idle { background: #f1f5f9; color: #64748b; }

.hidden { display: none !important; }
#app-container {
  display: flex;
  min-height: 100vh;
  flex-wrap: wrap;
}

/* Mobile topbar — desktop hidden */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.mobile-menu-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-topbar-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.mobile-topbar-title strong {
  font-size: .95rem;
  color: var(--text);
}

.mobile-topbar-title span {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 39, 68, .55);
  z-index: 99;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.show { display: block; }

body.nav-open { overflow: hidden; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.panel-body:has(.data-table),
.panel-body:has(.perm-table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== Tablet & Mobile ===== */
@media (max-width: 992px) {
  .mobile-topbar { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .28s ease;
    width: min(280px, 88vw);
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }

  .sidebar.open { transform: translateX(0); }

  .main {
    margin-left: 0;
    max-width: 100%;
    width: 100%;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .page-header h2 { font-size: 1.25rem; }
  .page-header p { font-size: .85rem; }

  .page-header .btn,
  .panel-header > .btn,
  .panel-header > .filters > .btn {
    width: 100%;
    justify-content: center;
  }

  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .filters {
    width: 100%;
  }

  .filters select,
  .filters input,
  .filters .btn {
    flex: 1 1 calc(50% - 6px);
    min-width: 140px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .stat-card { padding: 16px; }
  .stat-card .value { font-size: 1.65rem; }

  .calendar-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .view-tabs { width: 100%; justify-content: center; }

  .pending-item,
  .result-item {
    flex-direction: column;
    align-items: stretch;
  }

  .pending-item .btn,
  .result-item .btn {
    width: 100%;
    justify-content: center;
  }

  .tree-children { margin-left: 12px; }
  .tree-vehicle { flex-direction: column; align-items: flex-start; }

  .bar-label { width: 110px; font-size: .78rem; }

  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    text-align: center;
  }

  .data-table { min-width: 640px; }
  .perm-table { min-width: 560px; }

  .gantt-table.gantt-month .meta-col {
    display: none;
  }

  .gantt-table.gantt-month .vehicle-col,
  .gantt-table.gantt-month th.vehicle-col,
  .gantt-table.gantt-month td.vehicle-col {
    min-width: 88px;
    max-width: 88px;
    font-size: .72rem;
  }

  /* Tab Tuần mobile — scroll ngang, cột đủ rộng không đè chữ */
  .gantt-table:not(.gantt-month) {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
  }

  .gantt-table:not(.gantt-month) col.col-vehicle {
    width: 108px;
  }

  .gantt-table:not(.gantt-month) col.col-branch {
    width: 76px;
  }

  .gantt-table:not(.gantt-month) col.col-dept {
    width: 88px;
  }

  .gantt-table:not(.gantt-month) col.col-day {
    width: 88px;
  }

  .gantt-table:not(.gantt-month) th:not(.vehicle-col):not(.meta-col),
  .gantt-table:not(.gantt-month) td:not(.vehicle-col):not(.meta-col) {
    min-width: 88px;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 8px 4px;
    font-size: .72rem;
  }

  .gantt-table:not(.gantt-month) .vehicle-col,
  .gantt-table:not(.gantt-month) th.vehicle-col,
  .gantt-table:not(.gantt-month) td.vehicle-col {
    position: sticky;
    left: 0;
    z-index: 3;
    box-shadow: 2px 0 6px rgba(15, 23, 42, 0.08);
    min-width: 108px;
    max-width: 108px;
  }

  .gantt-wrap {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
  }

  .col-actions { width: auto; }
  .cell-note { max-width: 120px; }
}

@media (max-width: 640px) {
  .main { padding: 12px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .filters select,
  .filters input,
  .filters .btn {
    flex: 1 1 100%;
    width: 100%;
  }

  .search-form {
    grid-template-columns: 1fr !important;
  }

  .workflow-steps {
    padding: 20px 12px 18px;
  }

  .workflow-steps .step {
    min-width: 120px;
    padding: 0 8px;
  }

  .step:not(:last-child)::after {
    top: 16px;
    left: calc(50% + 18px);
    width: calc(100% - 36px);
  }

  .step-num {
    width: 36px;
    height: 36px;
    font-size: .82rem;
  }

  .step-desc {
    max-width: 130px;
  }

  .login-card { padding: 24px 20px; }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .btn { width: 100%; justify-content: center; }

  .table-actions { justify-content: flex-start; flex-wrap: wrap; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }

  .logo h1 { font-size: 1rem; }
  .nav-item { padding: 11px 20px; font-size: .88rem; }
}

@media (min-width: 993px) {
  .sidebar-overlay { display: none !important; }
}
