:root {
  --navy: #1c1c1e; --navy-2: #0f0f10; --teal: #d71920; --teal-2: #b3141a; --brand-red: #e3241b; --amber: #b45309; --red: #b91c1c; --green: #15803d;
  --bg: #f3f5f8; --card: #ffffff; --line: #dfe4ea; --text: #1f2937; --muted: #6b7280; --soft: #eef2f7;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --sidebar: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: #b3141a; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.hidden, [hidden] { display: none !important; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; }

/* ---------- layout ---------- */
#app { min-height: 100%; }
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 14px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand .logo-img { display: block; width: 100%; max-width: 190px; background: #fff; border-radius: 8px; padding: 6px 8px; }
.brand .app-name { font-size: 12.5px; font-weight: 600; margin-top: 8px; opacity: .9; }
.login .logo-img { width: 100%; max-width: 280px; display: block; margin: 0 auto 6px; }
.brand .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand .logo .mark { width: 34px; height: 34px; border-radius: 8px; background: var(--teal); display: grid; place-items: center; font-size: 18px; }
.brand .sub { font-size: 11px; opacity: .7; margin-top: 4px; }
.nav { padding: 10px 10px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: rgba(255,255,255,.85); font-size: 13.5px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: var(--brand-red); color: #fff; font-weight: 600; }
.nav a .ic { width: 18px; text-align: center; opacity: .9; }
.nav .badge { margin-left: auto; }
.nav .section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; opacity: .55; padding: 12px 12px 4px; }
.userbox { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.12); font-size: 12.5px; }
.userbox .name { font-weight: 600; }
.userbox .role { opacity: .7; font-size: 11.5px; }
.userbox button { margin-top: 8px; width: 100%; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 22px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 18px; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.content { padding: 20px 22px 60px; }
.mobile-nav { display: none; }
.hamburger { display: none; }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-h { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card .card-h h2 { font-size: 14.5px; }
.card .card-h .actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.card .card-b { padding: 16px; }
.card .card-b.tight { padding: 0; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); cursor: default; }
.kpi .lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi .val { font-size: 24px; font-weight: 700; margin-top: 4px; color: #1c1c1e; }
.kpi .val small { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi.accent { border-left: 4px solid var(--brand-red); }
.kpi.warn { border-left: 4px solid var(--amber); }
.kpi.ok { border-left: 4px solid var(--green); }
.kpi.bad { border-left: 4px solid var(--red); }
.kpi[data-href] { cursor: pointer; }
.kpi[data-href]:hover { border-color: var(--teal); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 16px; white-space: nowrap; background: #e5e7eb; color: #374151; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.stopped { background: #fef3c7; color: #92400e; }
.badge.offline { background: #e5e7eb; color: #4b5563; }
.badge.completed { background: #dbeafe; color: #1e40af; }
.badge.awaiting_approval { background: #fef3c7; color: #92400e; }
.badge.correction_requested { background: #ffedd5; color: #9a3412; }
.badge.approved { background: #dcfce7; color: #166534; }
.badge.rejected, .badge.failed, .badge.inactive { background: #fee2e2; color: #991b1b; }
.badge.pending, .badge.queued { background: #e0f2fe; color: #075985; }
.badge.sent, .badge.ok { background: #dcfce7; color: #166534; }
.badge.skipped { background: #f3f4f6; color: #6b7280; }
.badge.role { background: #ede9fe; color: #5b21b6; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.active { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.2); animation: pulse 1.5s infinite; }
.dot.stopped { background: #d97706; } .dot.offline { background: #9ca3af; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(22,163,74,.4);} 70% { box-shadow: 0 0 0 6px rgba(22,163,74,0);} 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0);} }

button, .btn { font: inherit; font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; line-height: 1.2; }
button:hover, .btn:hover { border-color: #b8c0cc; background: #f8fafc; text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-2); border-color: var(--teal-2); }
.btn-navy { background: #1c1c1e; border-color: #1c1c1e; color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-danger { background: #7f1d1d; border-color: #7f1d1d; color: #fff; }
.btn-danger:hover { background: #641717; }
.btn-warn { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 14px 20px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }
.btn-xl { width: 100%; justify-content: center; padding: 20px; font-size: 20px; letter-spacing: .5px; border-radius: 14px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-link { background: none; border: none; color: var(--teal); padding: 0; font-weight: 600; }

label { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 4px; }
input, select, textarea { font: inherit; font-size: 14px; width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: #d71920; box-shadow: 0 0 0 3px rgba(215,25,32,.15); }
input[readonly] { background: var(--soft); color: #4b5563; }
textarea { min-height: 72px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.field { min-width: 0; }
.field .help { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.checkbox { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 13px; }
.checkbox input { width: auto; margin-top: 3px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 140px; flex: 1; max-width: 220px; }
.filters .field.wide { max-width: 320px; }
.filters label { font-size: 11px; }
.filters input, .filters select { padding: 7px 9px; font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #f9fafb; font-weight: 600; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafc; }
td .sub { display: block; font-size: 11.5px; color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.map { width: 100%; height: 420px; border-radius: var(--radius); border: 1px solid var(--line); background: #e5e7eb; z-index: 1; }
.map.tall { height: calc(100vh - 190px); min-height: 420px; }
.map.small { height: 280px; }
.leaflet-container { font: inherit; }
.truck-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); font-size: 16px; color: #fff; }
.truck-label { background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-size: 11px; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); }
.leaflet-popup-content { font-size: 12.5px; line-height: 1.5; margin: 10px 12px; }
.leaflet-popup-content b { color: var(--navy); }

.dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 22px; border-left: 2px solid var(--line); margin-left: 8px; position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 12px; width: 12px; height: 12px; border-radius: 50%; background: #cbd5e1; border: 2px solid #fff; }
.timeline li.approved::before { background: #16a34a; }
.timeline li.rejected::before, .timeline li.correction_requested::before { background: #dc2626; }
.timeline li.pending::before { background: #f59e0b; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.step { flex: 1; min-width: 140px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 12.5px; }
.step .n { font-weight: 700; color: var(--muted); font-size: 11px; }
.step.approved { border-color: #86efac; background: #f0fdf4; }
.step.pending { border-color: #fcd34d; background: #fffbeb; }
.step.rejected, .step.correction_requested { border-color: #fca5a5; background: #fef2f2; }
.step.skipped { opacity: .6; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; border: 1px solid; }
.alert.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: none; background: none; border-radius: 0; padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand-red); border-bottom-color: var(--brand-red); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 980px; }
.modal .modal-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .modal-h h2 { font-size: 15px; }
.modal .modal-h .x { margin-left: auto; border: none; background: none; font-size: 20px; padding: 0 6px; }
.modal .modal-b { padding: 18px; }
.modal .modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 360px; }
.toast.error { background: #991b1b; } .toast.ok { background: #166534; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #1c1c1e 0%, #2a2a2d 55%, #b3141a 100%); padding: 16px; }
.login { background: #fff; border-radius: 14px; width: 100%; max-width: 400px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.login .logo .mark { width: 42px; height: 42px; border-radius: 10px; background: var(--teal); display: grid; place-items: center; font-size: 22px; color: #fff; }
.login h1 { font-size: 18px; } .login .sub { color: var(--muted); font-size: 12.5px; }
.demo { margin-top: 14px; font-size: 12px; color: var(--muted); background: var(--soft); border-radius: 8px; padding: 10px; }
.demo button { font-size: 11px; padding: 3px 8px; margin: 2px; }

/* tracking (mobile-first) */
.track { max-width: 560px; margin: 0 auto; }
.track .hero { text-align: center; padding: 8px 0 14px; }
.track .hero .live { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: #166534; background: #dcfce7; padding: 6px 14px; border-radius: 999px; font-size: 14px; }
.track .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.track .stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.track .stat .l { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.track .stat .v { font-size: 18px; font-weight: 700; color: #1c1c1e; }
.track .chain { display: flex; flex-direction: column; gap: 6px; }
.track .chain .arrow { text-align: center; color: var(--muted); font-size: 16px; line-height: 1; }
.track select, .track input, .track textarea { font-size: 15px; padding: 12px; }
.info-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--soft); border-radius: 6px; padding: 4px 8px; font-size: 12px; }
.chip b { color: var(--navy); }
.gps-status { font-size: 12px; color: var(--muted); text-align: center; }

.chart-box { position: relative; height: 240px; }
.progress { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand-red); }

@media (max-width: 1100px) { .grid.cols-4, .grid.cols-5 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 150; height: 100vh; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidebar-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 140; }
  .hamburger { display: inline-flex; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 16px; }
  .content { padding: 14px 12px 90px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: 1fr; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 120px 1fr; }
  .filters .field { max-width: none; min-width: calc(50% - 8px); }
  .map { height: 320px; } .map.tall { height: calc(100vh - 220px); }
  .mobile-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 90; padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; font-size: 10.5px; color: var(--muted); }
  .mobile-nav a.active { color: var(--teal); font-weight: 700; }
  .mobile-nav a .ic { font-size: 18px; }
  .topbar .actions .hide-m { display: none; }
  .modal { max-height: 100vh; border-radius: 10px; }
}
@media print { .sidebar, .topbar, .mobile-nav, .no-print { display: none !important; } .layout { display: block; } .content { padding: 0; } }
