/* ── Design Tokens ───────────────────────────────────────────────────────── */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'SF Mono', 'Fira Code', monospace;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, select, textarea {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
input[type="checkbox"] { width: auto; }

/* ── Utils ────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.text-muted { color: var(--text-muted); font-size: .875rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-600 { font-weight: 600; }

/* ── Login Screen ─────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.brand-icon { font-size: 2.5rem; }
.login-brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -.5px;
}
.login-brand p { color: var(--text-muted); font-size: .875rem; margin-top: 4px; }
.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: .875rem;
  margin-bottom: 12px;
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
}
.brand-icon-sm { font-size: 1.25rem; }
.brand-name { font-weight: 700; font-size: .95rem; letter-spacing: -.3px; flex: 1; }
.sidebar-close { display: none; color: var(--text-muted); font-size: 1rem; }
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .875rem;
  font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .875rem;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .72rem; color: var(--text-muted); text-transform: capitalize; }

/* Main wrapper */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left .25s ease;
}

/* Desktop sidebar collapsed */
.app.sidebar-collapsed .sidebar     { transform: translateX(-100%); }
.app.sidebar-collapsed .main-wrapper { margin-left: 0; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.menu-toggle { display: inline-flex; font-size: 1.2rem; color: var(--text-muted); }
#page-title { font-size: 1rem; font-weight: 600; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: .8rem; color: var(--text-muted); }

/* Main content */
.main-content {
  flex: 1;
  padding: 24px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  transition: background .12s, opacity .12s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.btn-full { width: 100%; justify-content: center; padding: 9px 14px; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-icon {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background .12s, color .12s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: .9rem; font-weight: 600; }
.card-body { padding: 18px; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: .78rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.stat-sub { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.primary .stat-value { color: var(--primary); }

/* Charts grid */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.chart-container {
  position: relative;
  height: 240px;
}

/* ── Form Styles ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted { color: var(--primary); }
thead th.sorted::after { content: ' ↓'; }
thead th.sorted.asc::after { content: ' ↑'; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tbody td { padding: 10px 12px; vertical-align: middle; }
.table-actions { display: flex; gap: 4px; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius) var(--radius) 0 0;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.filter-group label { font-size: .72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.filter-group input,
.filter-group select { padding: 5px 8px; font-size: .8rem; min-width: 120px; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text-muted);
}
.pagination button { padding: 4px 10px; }
.page-info { flex: 1; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-gray    { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge-orange  { background: #fff7ed; color: #c2410c; border: 1px solid #fb923c; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: .95rem; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-wide { max-width: 780px; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes slideIn {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Loading ──────────────────────────────────────────────────────────────── */
.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 60px;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: .875rem; }

/* ── Page sections ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h2 { font-size: 1.2rem; font-weight: 700; }

/* Vehicle detail */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.detail-item label { font-size: .72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.detail-item span { display: block; font-weight: 600; margin-top: 2px; }

/* Reports */
.report-controls {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
}

/* ── Add Entry specific ───────────────────────────────────────────────────── */
.entry-meta {
  display: flex;
  gap: 12px;
  font-size: .8rem;
  color: var(--text-muted);
}
.meta-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 10px;
}
.meta-pill strong { color: var(--text); }

/* Cost preview box */
.cost-preview {
  margin-bottom: 14px;
}
.cost-preview-inner {
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .85rem;
  padding: 3px 0;
  color: var(--text-muted);
}
.cost-total {
  border-top: 1px solid #bfdbfe;
  margin-top: 6px;
  padding-top: 8px;
  font-weight: 700;
  font-size: .95rem;
  color: var(--primary);
}

/* Entry confirmation */
.confirmation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.conf-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}
.conf-title { font-weight: 700; font-size: .95rem; }
.conf-slip { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }
.conf-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.conf-details div { display: flex; flex-direction: column; gap: 2px; }
.conf-details label { font-size: .72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.conf-details span { font-weight: 600; font-size: .875rem; }

/* Slip code style */
.slip-code {
  font-family: var(--mono);
  font-size: .78rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--primary);
  white-space: nowrap;
}

/* ── Import modal ─────────────────────────────────────────────────────────── */
.import-instructions {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: .875rem;
}
.import-instructions p { margin-bottom: 8px; }
.import-instructions p:last-child { margin-bottom: 0; }
.import-columns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.col-required {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: .78rem;
  font-weight: 600;
  font-family: var(--mono);
}
.col-optional {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: .78rem;
  font-family: var(--mono);
}
.import-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.import-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: .875rem;
  font-weight: 600;
}

/* ── Billing ──────────────────────────────────────────────────────────────── */
.bill-mode-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.bill-mode-btn {
  padding: 6px 18px;
  border-radius: 4px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background .12s, color .12s;
}
.bill-mode-btn.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.bill-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

/* Bill document */
.bill-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 36px;
  max-width: 860px;
  box-shadow: var(--shadow);
}
.bill-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--primary);
}
.bill-brand-name {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -.4px;
}
.bill-brand-sub {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 3px;
}
.bill-meta-block { text-align: right; }
.bill-title-tag {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text);
  margin-bottom: 8px;
}
.bill-meta-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 3px;
}
.bill-meta-row strong { color: var(--text); }

/* Bill table */
.bill-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  margin-bottom: 24px;
}
.bill-table thead th {
  padding: 10px 12px;
  background: var(--primary);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  border: none;
  cursor: default;
}
.bill-table thead th:first-child { border-radius: 4px 0 0 0; }
.bill-table thead th:last-child  { border-radius: 0 4px 0 0; }
.bill-group-row td {
  padding: 10px 12px;
  background: #f1f5f9;
  border-top: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.bill-ft-row td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.bill-ft-indent { padding-left: 28px !important; font-size: .83rem; }
.bill-sub { font-size: .78rem; color: var(--text-muted); font-weight: 400; }
.bill-table tfoot .bill-total-row td {
  padding: 12px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: .95rem;
}

/* Bill footer */
.bill-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.bill-sig-block { text-align: center; }
.bill-sig-line {
  width: 180px;
  border-bottom: 1px solid var(--text);
  margin-bottom: 6px;
}
.bill-sig-label { font-size: .78rem; color: var(--text-muted); }
.bill-note { font-size: .75rem; color: var(--text-muted); font-style: italic; }

/* ── Print styles ─────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .bill-actions, #toast-container,
  .sidebar-overlay, .page-header { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  .main-content { padding: 0 !important; }
  body { background: #fff; }
  .bill-wrap {
    border: none !important;
    box-shadow: none !important;
    padding: 16px !important;
    max-width: 100% !important;
  }
  .card { border: none !important; box-shadow: none !important; }
}

/* ── Vehicle limit info ───────────────────────────────────────────────────── */
.vehicle-limit-info {
  margin-top: 6px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 500;
}
.vehicle-limit-info.limit-ok       { background: var(--success-bg); color: var(--success); }
.vehicle-limit-info.limit-warning  { background: var(--warning-bg); color: var(--warning); }
.vehicle-limit-info.limit-exceeded { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #fecaca; }

/* ── Pending/Rejected row tints ───────────────────────────────────────────── */
tbody tr.row-pending   { background: var(--warning-bg); }
tbody tr.row-rejected  { background: #fef2f2; opacity: .75; }
tbody tr.row-emergency { background: #fff7ed; border-left: 3px solid #fb923c; }
tbody tr.row-pending:hover   { background: #fef3c7; }
tbody tr.row-rejected:hover  { background: #fee2e2; }
tbody tr.row-emergency:hover { background: #ffedd5; }

/* ── Pending confirmation message ─────────────────────────────────────────── */
.conf-pending-msg {
  font-size: .78rem;
  color: var(--warning);
  margin-top: 3px;
}

/* ── Role hint ────────────────────────────────────────────────────────────── */
.role-hint {
  margin-top: 5px;
  font-size: .76rem;
  color: var(--text-muted);
  line-height: 1.45;
  min-height: 1.2em;
}

/* ── Vehicle Search ───────────────────────────────────────────────────────── */
.vehicle-search-wrap {
  position: relative;
}
.vehicle-search-wrap input[type="text"] {
  padding-right: 32px;
}
.vehicle-search-wrap input.vd-error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220,38,38,.1);
}
.vehicle-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 60;
  max-height: 260px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.vd-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.vd-item:last-child { border-bottom: none; }
.vd-item:hover, .vd-item:active { background: var(--primary-light); }
.vd-no {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
  white-space: nowrap;
}
.vd-meta {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vd-empty {
  padding: 14px;
  text-align: center;
  font-size: .85rem;
  color: var(--text-muted);
}
.vd-add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 11px 14px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  border-top: 1px solid var(--border);
  transition: background .1s;
}
.vd-add-btn:hover, .vd-add-btn:active { background: var(--primary-light); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .main-wrapper { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .main-content { padding: 16px; }
  .filter-bar { gap: 6px; }
  .page-header { flex-direction: column; align-items: flex-start; }

  /* Entry form mobile */
  .entry-card { max-width: 100% !important; }
  input, select, textarea { font-size: 16px; } /* prevent iOS zoom */
  .entry-actions { flex-direction: column-reverse; gap: 10px; }
  .entry-actions .btn { width: 100%; justify-content: center; padding: 13px 14px; font-size: 1rem; }
  .entry-submit-btn { font-size: 1.05rem !important; }

  /* Bigger tap targets for inputs on entry form */
  .entry-card input,
  .entry-card select {
    padding: 12px 12px;
    min-height: 48px;
  }
  .vehicle-dropdown { max-height: 220px; }
  .vd-item { padding: 14px; }
  .vd-no { font-size: 1rem; }
  .vd-meta { font-size: .85rem; }
}

/* ── Permission Checkboxes ────────────────────────────────────────────────── */
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .75rem; margin-top: .35rem; }
.perm-check { display: flex; align-items: center; gap: .45rem; font-size: .87rem; cursor: pointer; padding: .3rem .4rem; border-radius: 4px; }
.perm-check:hover { background: var(--bg); }
.perm-check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); flex-shrink: 0; }

/* ── Danger Zone ──────────────────────────────────────────────────────────── */
.danger-zone { border: 1.5px solid var(--danger); margin-top: 2rem; }
.danger-zone-header { display: flex; align-items: flex-start; gap: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.danger-icon { font-size: 1.8rem; color: var(--danger); line-height: 1; }
.danger-zone-header h3 { margin: 0 0 .25rem; color: var(--danger); }
.danger-zone-header p { margin: 0; font-size: .85rem; color: var(--text-muted); }
.danger-actions { display: flex; flex-direction: column; gap: .75rem; }
.danger-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem; background: #fff5f5; border-radius: var(--radius); }
.danger-item > div strong { display: block; margin-bottom: .15rem; }
.danger-item > div p { margin: 0; font-size: .82rem; color: var(--text-muted); }
.reset-warning { background: #fff5f5; border: 1px solid #fecaca; border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1rem; }
.reset-desc { margin: 0 0 .4rem; font-weight: 600; color: var(--danger); }
.reset-note { margin: 0; font-size: .85rem; color: var(--text-muted); }

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; margin: 0; border-radius: var(--radius) var(--radius) 0 0; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .main-content { padding: 12px; }
  .entry-card .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .entry-meta { flex-wrap: wrap; }
}

/* ── Pool Board ───────────────────────────────────────────────────────────── */
.pool-board { display: flex; flex-direction: column; gap: 0; }
.pool-board-sub { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

.pool-refresh-btn { font-size: 1.15rem; font-weight: 400; }

.pool-stats-row {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; margin-bottom: 1.5rem;
}
.pool-stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; border-left: 4px solid var(--border);
  display: flex; flex-direction: column; gap: .15rem;
}
.pool-stat-card.pool-stat--free  { border-left-color: #22c55e; background: linear-gradient(135deg,#f0fdf4 0%,var(--surface) 65%); }
.pool-stat-card.pool-stat--duty  { border-left-color: #3b82f6; background: linear-gradient(135deg,#eff6ff 0%,var(--surface) 65%); }
.pool-stat-card.pool-stat--over  { border-left-color: #ef4444; background: linear-gradient(135deg,#fef2f2 0%,var(--surface) 65%); }
.pool-stat-dot { font-size: .65rem; margin-bottom: .1rem; }
.pool-stat-dot--gray { color: var(--border); }
.pool-stat-dot--free { color: #22c55e; }
.pool-stat-dot--duty { color: #3b82f6; }
.pool-stat-dot--over { color: #ef4444; }
.pool-stat-val { font-size: 2rem; font-weight: 700; line-height: 1; }
.pool-stat-lbl { font-size: .75rem; color: var(--text-muted); letter-spacing: .03em; }
.pool-stat--free  .pool-stat-val { color: #16a34a; }
.pool-stat--duty  .pool-stat-val { color: #2563eb; }
.pool-stat--over  .pool-stat-val { color: #dc2626; }

.pool-main-row { display: block; }
.pool-section-title { font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: .75rem; }

/* Fleet header with count badge */
.pool-fleet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.pool-fleet-header .pool-section-title { margin-bottom: 0; }
.pool-fleet-count { font-size: .75rem; color: var(--text-muted); background: var(--bg); padding: .18rem .55rem; border-radius: 20px; border: 1px solid var(--border); }

/* Filter bar */
.pool-filter-bar { display: flex; align-items: center; gap: .65rem; margin-bottom: .875rem; flex-wrap: wrap; }
.pool-search-wrap { position: relative; flex: 1; min-width: 180px; }
.pool-search-icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 1.05rem; pointer-events: none; line-height: 1; }
.pool-search { padding: .42rem .85rem .42rem 2.1rem; border: 1px solid var(--border); border-radius: 20px; font-size: .875rem; width: 100%; background: var(--surface); color: var(--text); transition: border-color .15s; }
.pool-search:focus { border-color: var(--primary); outline: none; }
.pool-pills { display: flex; gap: .3rem; flex-wrap: wrap; }
.pool-pill { padding: .28rem .65rem; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); font-size: .75rem; cursor: pointer; transition: all .15s; color: var(--text-muted); display: inline-flex; align-items: center; gap: .3rem; }
.pool-pill:hover { border-color: var(--primary); color: var(--primary); }
.pool-pill--active { background: var(--primary); color: #fff !important; border-color: var(--primary); }
.pool-pill--active:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.pool-pill--over-pill { border-color: #fca5a5; color: #dc2626; }
.pool-pill--over-pill:hover { background: #fef2f2; }
.pool-pill-count { font-weight: 700; font-size: .72rem; }

/* Cards */
.pool-fleet-section {}
.pool-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(182px, 1fr)); gap: .875rem;
}
.pool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; display: flex; flex-direction: column; gap: .22rem;
  cursor: pointer; transition: box-shadow .15s, transform .12s;
  border-top: 3px solid var(--border);
}
.pool-card:hover { box-shadow: 0 6px 20px rgba(0,0,0,.09); transform: translateY(-2px); }
.pool-card--free    { border-top-color: #22c55e; }
.pool-card--duty    { border-top-color: #3b82f6; }
.pool-card--overdue { border-top-color: #ef4444; background: #fff9f9; }

.pool-card-head { display: flex; align-items: center; gap: .4rem; margin-bottom: .1rem; }
.pool-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.pool-dot--free    { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,.55); }
.pool-dot--duty    { background: #3b82f6; box-shadow: 0 0 6px rgba(59,130,246,.55); }
.pool-dot--overdue { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.55); animation: pool-pulse 1.6s ease-in-out infinite; }
@keyframes pool-pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.pool-status-lbl { font-size: .67rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted); }
.pool-card--overdue .pool-status-lbl { color: #dc2626; }

.pool-vno { font-size: 1.15rem; font-weight: 800; color: var(--text); line-height: 1.2; margin-top: .1rem; letter-spacing: -.01em; }
.pool-vspecs { font-size: .72rem; color: var(--text-muted); line-height: 1.3; margin-top: .05rem; }
.pool-vdept { font-size: .74rem; color: var(--text-muted); }
.pool-card-spacer { flex: 1; min-height: .4rem; }

.pool-assignee-row { display: flex; align-items: flex-start; gap: .3rem; margin-top: .2rem; }
.pool-assignee { font-size: .82rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.pool-info-row { display: flex; align-items: flex-start; gap: .3rem; font-size: .74rem; color: var(--text-muted); line-height: 1.4; }
.pool-info-icon { flex-shrink: 0; font-size: .78rem; }
.pool-time-info { margin-top: .4rem; padding-top: .4rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .1rem; }
.pool-since { font-size: .72rem; color: var(--text-muted); }
.pool-until { font-size: .74rem; font-weight: 600; color: #2563eb; }
.pool-until--over { color: #dc2626; }

.pool-action-btn {
  margin-top: .5rem; padding: .42rem .75rem; border: none; border-radius: var(--radius-sm);
  font-size: .8rem; font-weight: 600; cursor: pointer; transition: background .15s; width: 100%; text-align: center;
}
.pool-deploy-btn { background: #eff6ff; color: #2563eb; }
.pool-deploy-btn:hover { background: #dbeafe; }
.pool-return-btn { background: #f0fdf4; color: #16a34a; }
.pool-return-btn:hover { background: #dcfce7; }
.pool-card--overdue .pool-return-btn { background: #fef2f2; color: #dc2626; }
.pool-card--overdue .pool-return-btn:hover { background: #fee2e2; }

.pool-sidebar {}
.pool-chart-box { padding: 1.25rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.pool-chart-box canvas { max-width: 160px; }
.pool-legend { width: 100%; display: flex; flex-direction: column; gap: .45rem; }
.pool-leg-item { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.pool-leg-item span:nth-child(2) { flex: 1; color: var(--text-muted); }
.pool-leg-item strong { color: var(--text); }
.pool-leg-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.pool-qstat { display: flex; justify-content: space-between; align-items: center; padding: .35rem 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.pool-qstat:last-child { border-bottom: none; }
.pool-qstat span { color: var(--text-muted); }

.pool-row-over td { background: #fff8f8 !important; }
.pool-over-txt { color: #dc2626; font-weight: 600; }

@media (max-width: 900px) {
  .pool-main-row { display: block; }
}
@media (max-width: 640px) {
  .pool-stats-row { grid-template-columns: repeat(2,1fr); }
  .pool-grid { grid-template-columns: repeat(2,1fr); }
  .pool-sidebar { grid-template-columns: 1fr; }
  .pool-filter-bar { flex-direction: column; align-items: stretch; }
}
