:root {
  --bg: #f4f6f8; --card: #fff; --text: #1d2329; --muted: #6b7680; --line: #dde2e7;
  --primary: #0b5fa5; --primary-text: #fff; --danger: #c62828; --warn: #d98200; --ok: #1b8a3a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
code { font-size: 12px; background: #eef1f4; padding: 1px 4px; border-radius: 3px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 18px; height: 48px; padding: 0 16px; background: #102a43; color: #fff; }
.topbar a { color: #dfe7ef; }
.topbar .brand { font-weight: 700; color: #fff; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 6px 10px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; gap: 12px; align-items: center; }
.topbar .user form { margin: 0; }
.topbar button.link { color: #dfe7ef; }

/* layout */
main { min-height: calc(100% - 48px); }
.page { max-width: 1150px; margin: 0 auto; padding: 20px 16px 40px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 380px; margin: 60px auto; }
.center-page main { display: flex; align-items: flex-start; justify-content: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 800px) { .grid2, .grid4 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; font-weight: normal; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; margin-bottom: 10px; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: normal; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e6; border-color: var(--primary); }
button, .button { font: inherit; padding: 7px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); cursor: pointer; display: inline-block; }
button:hover, .button:hover { background: #f0f3f6; text-decoration: none; }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.primary:hover, .button.primary:hover { background: #094d86; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.small { padding: 3px 9px; font-size: 12px; }
button.link { border: 0; background: none; padding: 0; color: var(--primary); }
.filter label { margin-bottom: 0; }
.danger-zone { border-color: #f1c4c4; }

/* flash */
.flash { padding: 10px 16px; }
.flash.ok { background: #e3f4e8; color: #145c2a; }
.flash.err { background: #fdecea; color: #8e1c1c; }
.flash.warn { background: #fff4e0; color: #7a4a00; border-radius: 6px; }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.table.compact th, .table.compact td { padding: 5px 8px; }
.table .num { text-align: right; }
.table tr.highlight { background: #fff8e8; }
.table tr.muted td { color: var(--muted); }
.table .actions { white-space: nowrap; }
.table .actions a, .table .actions form { display: inline-block; margin-right: 8px; }
.table tfoot th { color: var(--text); font-size: 13px; text-transform: none; }
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* status labels */
.badge { display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 10px; font-size: 11px; font-weight: 700; text-align: center; }
.badge.warn { background: var(--warn); color: #fff; }
.status { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #e8ecf0; color: #46525d; }
.s-moving, .d-approved { background: #dff3e5; color: #156b2f; }
.s-parked { background: #e1ecf7; color: #234f7a; }
.s-warning, .d-pending { background: #fff0d6; color: #8a5300; }
.s-offline, .d-rejected { background: #fde3e3; color: #9b1d1d; }
.warn-text { color: #8a5300; }

.stats { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.stats > div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px; color: var(--muted); }
.stats .big { font-size: 24px; font-weight: 700; color: var(--text); margin-right: 4px; }

/* map pages */
body.full main { height: calc(100vh - 48px); }
.split { display: flex; height: 100%; }
.sidebar { width: 320px; flex: none; overflow-y: auto; background: var(--card); border-right: 1px solid var(--line); padding: 12px; }
.map { flex: 1; height: 100%; }
@media (max-width: 700px) {
  .split { flex-direction: column; }
  .sidebar { width: 100%; max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
}
.sidebar-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.sidebar-tools { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.sidebar-tools label { margin: 0 0 0 auto; }
.vlist { list-style: none; margin: 0; padding: 0; }
.vlist li { display: flex; gap: 8px; align-items: flex-start; padding: 8px 6px; border-radius: 8px; cursor: pointer; }
.vlist li:hover { background: #f0f3f6; }
.vlist li.sel { background: #eaf2fb; }
.vlist input { margin-top: 3px; }
.vlist .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.vlist .vtext { display: flex; flex-direction: column; }
.vlist .sub { font-size: 12px; color: var(--muted); }
.stops { list-style: none; padding: 0; margin: 0; }
.stops li { padding: 5px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.stops li:hover { background: #f0f3f6; }

/* leaflet markers */
.veh-icon { position: relative; }
.veh-dot { position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; }
.veh-arrow { color: #fff; font-size: 10px; line-height: 1; display: inline-block; }
.veh-label { position: absolute; left: 26px; top: 1px; background: #fff; color: #102a43; font-weight: 700; font-size: 12px; padding: 1px 5px; border-radius: 4px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.stop-icon span { display: flex; width: 22px; height: 22px; border-radius: 50%; background: #6a1b9a; color: #fff; font-size: 11px; font-weight: 700; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.popup-title { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.popup table th { text-align: left; color: var(--muted); font-weight: normal; padding-right: 10px; }
.popup-links { margin-top: 8px; display: flex; gap: 12px; }
