:root {
  --primary: #1a73e8;
  --primary-dark: #1558b0;
  --bg: #f1f4f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --orange: #ea580c;
  --orange-bg: #ffedd5;
  --gray: #64748b;
  --gray-bg: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-block { width: 100%; }
.btn-mini { padding: 4px 10px; font-size: 12px; border-radius: 6px; background: #eef2ff; color: var(--primary); }
.btn-mini:hover { background: #e0e7ff; }
.btn-mini.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-mini.btn-danger:hover { background: #fecaca; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a, #1a73e8);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  text-align: center;
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.login-card form { text-align: right; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 14px;
  font-family: inherit;
}
.login-card input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* ---------- Alerts ---------- */
.alert { border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-top: 12px; text-align: right; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.brand { font-size: 18px; font-weight: 700; color: var(--primary); white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex: 1; justify-content: center; }
.nav-btn {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.nav-btn:hover { background: #f1f5f9; color: var(--text); }
.nav-btn.active { background: #eef2ff; color: var(--primary); }
.user-box { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.user-name { font-size: 14px; font-weight: 600; color: var(--muted); }

/* ---------- Main ---------- */
main { max-width: 1100px; margin: 24px auto; padding: 0 24px; }
.view-title { font-size: 20px; margin-bottom: 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.view-head .view-title { margin-bottom: 0; }
.view-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; margin-bottom: 14px; }

.filter-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.filter-head h3 { margin-bottom: 0; }
.filter-counts { display: flex; align-items: center; gap: 8px; }
.count-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #eef2ff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 6px 16px;
}
.count-box.sel { background: #fff; border-color: var(--border); }
.count-box.sel.on { background: #dcfce7; border-color: var(--green); }
.count-label { font-size: 13px; color: var(--primary); font-weight: 600; }
.count-box.sel .count-label { color: var(--muted); }
.count-box.sel.on .count-label { color: var(--green); }
.count-box b { font-size: 20px; color: var(--primary); line-height: 1; }
.count-box.sel b { color: var(--muted); }
.count-box.sel.on b { color: var(--green); }

/* ---------- Stats ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { text-align: center; padding: 24px 16px; }
.stat-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; }

.st-towed { color: var(--green); }
.st-not_towed { color: var(--gray); }
.st-rejected { color: var(--red); }
.st-on_way { color: var(--blue); }
.st-could_not { color: var(--orange); }
.st-deferred { color: var(--amber); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
#rec-table-wrap { scrollbar-width: none; }
#rec-table-wrap::-webkit-scrollbar { display: none; }
.table-scroll-top { display: none; overflow-x: auto; }
.table-scroll-top::-webkit-scrollbar { height: 10px; }
.table-scroll-top::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 5px; }
.table-scroll-top::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.table-scroll-top::-webkit-scrollbar-track { background: transparent; }
.scroll-spacer { height: 1px; }
.table-tools { display: flex; align-items: center; margin-bottom: 8px; }
.check-all-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  background: #eef2ff;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  padding: 6px 14px;
  user-select: none;
}
.check-all-label:hover { background: #e0e7ff; }
.check-all-label input { width: 18px; height: 18px; margin: 0; cursor: pointer; accent-color: var(--primary); }
.rec-check { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); }
th.th-check { width: 40px; }
td.td-check { text-align: center; }

/* ---------- Column visibility ---------- */
.cols-wrap { position: relative; display: inline-block; }
.cols-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  padding: 10px;
  min-width: 210px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cols-panel-head {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.cols-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.cols-panel label:hover { background: #f1f5f9; }
.cols-panel input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); cursor: pointer; }
#rec-table-wrap table.hide-date .col-date,
#rec-table-wrap table.hide-vehicle .col-vehicle,
#rec-table-wrap table.hide-actions .col-actions,
#rec-table-wrap table.hide-plate .col-plate,
#rec-table-wrap table.hide-claim .col-claim,
#rec-table-wrap table.hide-carrier .col-carrier,
#rec-table-wrap table.hide-area .col-area,
#rec-table-wrap table.hide-status .col-status,
#rec-table-wrap table.hide-note .col-note,
#rec-table-wrap table.hide-file .col-file { display: none; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 700; }
tbody tr:hover { background: #f8fafc; }
#rec-list tr.selected { background: #dbeafe !important; }
#rec-list tr.selected:hover { background: #cfe1fd !important; }
td.actions { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge.st-towed { background: var(--green-bg); color: var(--green); }
.badge.st-not_towed { background: var(--gray-bg); color: var(--gray); }
.badge.st-rejected { background: var(--red-bg); color: var(--red); }
.badge.st-on_way { background: var(--blue-bg); color: var(--blue); }
.badge.st-could_not { background: var(--orange-bg); color: var(--orange); }
.badge.st-deferred { background: var(--amber-bg); color: var(--amber); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; align-items: end; }
.form-wide { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.form-submit { display: flex; gap: 8px; }
.settings-note { margin-top: 14px; font-size: 13px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: var(--card);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
  max-height: 92vh;
  overflow-y: auto;
}
.modal-box h3 { margin-bottom: 16px; }
.modal-box label { margin-top: 12px; }
.modal-box input, .modal-box select { margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  z-index: 200;
  max-width: 90%;
}
.toast.error { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; justify-content: flex-start; }
  main { padding: 0 16px; }
}
