:root {
  --bg: #ffffff; --panel: #f7f8fa; --ink: #1f2933; --ink-2: #52606d; --line: #e4e7eb;
  --accent: #0b5cad; --rep: #c62828; --prio: #00bcd4; --local: #9e9e9e; --admin: #546e7a; --tracker: #2e7d32;
  --sb-w: 390px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); }
#map { position: fixed; inset: 0 0 0 var(--sb-w); }
#sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sb-w); overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); z-index: 5; }
.sb-header { padding: 18px 20px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px; }
h1 { font-size: 18px; line-height: 1.3; margin: 0 0 8px; }
.lead { margin: 0; color: var(--ink-2); font-size: 13px; }
.sb-section { padding: 14px 20px; border-bottom: 1px solid var(--line); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin: 0 0 10px; }
h2 .count { font-weight: 400; color: var(--ink-2); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.card .v { font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.card .l { font-size: 11px; color: var(--ink-2); margin-top: 2px; }
.card.wide { grid-column: 1 / -1; }
.card.muted { grid-column: 1 / -1; color: var(--ink-2); font-size: 13px; }
.card.alert .v { color: #00838f; }
.layer { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
.layer small { color: var(--ink-2); }
.layer input { margin: 0; }
.sw { display: inline-block; width: 22px; flex: 0 0 22px; height: 4px; border-radius: 2px; background: #999; }
.sw.rep { background: var(--rep); height: 5px; }
.sw.prio { background: var(--prio); height: 9px; opacity: .55; border-radius: 5px; }
.sw.local { background: var(--local); height: 2px; }
.sw.admin { background: var(--admin); height: 2px; border-top: 2px dashed var(--admin); background: none; }
.sw.dot { width: 10px; flex-basis: 10px; height: 10px; border-radius: 50%; background: #37474f; margin: 0 6px; border: 2px solid #fff; box-shadow: 0 0 0 1px #37474f; }
.sw.dot.tracker { background: var(--tracker); box-shadow: 0 0 0 1px var(--tracker); }
.sublegend { list-style: none; margin: 0 0 4px 30px; padding: 0; font-size: 12px; color: var(--ink-2); }
.sublegend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.sublegend .sw { width: 16px; flex-basis: 16px; }
#route-search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; margin-bottom: 8px; background: #fff; }
.list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.list li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:last-child { border-bottom: 0; }
.list li:hover, .list li.active { background: #eef4fb; }
.list .ref { font-weight: 600; min-width: 64px; }
.list .name { flex: 1; color: var(--ink-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .km { color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.list .empty { color: var(--ink-2); cursor: default; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--ink-2); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; background: #fafbfc; }
td:nth-child(2), td:nth-child(3), th:nth-child(2), th:nth-child(3) { text-align: right; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #eef4fb; }
.sb-footer { padding: 14px 20px 20px; font-size: 11.5px; color: var(--ink-2); }
.sb-footer p { margin: 0 0 6px; }
#topbar { position: fixed; top: 10px; right: 10px; z-index: 6; display: flex; gap: 8px; }
.basemap { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: 12px; color: var(--ink-2); box-shadow: 0 1px 4px rgba(0,0,0,.08); display: flex; align-items: center; gap: 8px; }
.basemap select { font: inherit; border: 0; background: none; color: var(--ink); }
.btn-icon { display: none; position: fixed; top: 10px; left: 10px; z-index: 7; width: 38px; height: 38px; border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 18px; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.maplibregl-popup-content { font: 13px/1.4 inherit; padding: 10px 12px 10px; border-radius: 8px; max-width: 300px; }
.popup h3 { margin: 0 0 4px; font-size: 14px; }
.popup .tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; color: #fff; margin-right: 4px; }
.popup dl { margin: 6px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.popup dt { color: var(--ink-2); }
.popup dd { margin: 0; }
.maplibregl-ctrl-top-right { top: 50px; }
@media (max-width: 860px) {
  :root { --sb-w: 0px; }
  #map { inset: 0; }
  #sidebar { width: min(92vw, 390px); transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 20px rgba(0,0,0,.2); }
  body.sb-open #sidebar { transform: none; }
  .btn-icon { display: block; }
  #topbar { top: 10px; right: 10px; }
}

/* аккаунт, трекеры, оповещения */
#account input, #account select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; margin-bottom: 6px; background: #fff; }
.row { display: flex; gap: 8px; margin: 2px 0 8px; }
.btn { flex: 1; padding: 8px 10px; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; font: inherit; cursor: pointer; }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.small { flex: 0 0 auto; padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .6; cursor: default; }
.hint { font-size: 12px; color: var(--ink-2); margin: 0 0 6px; }
.msg { font-size: 12.5px; min-height: 0; }
.msg.err { color: #b71c1c; }
.msg.ok { color: #1b5e20; }
.msg code { display: block; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 4px 0; font-size: 12px; word-break: break-all; user-select: all; }
.who { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.who .role { color: var(--ink-2); font-size: 12px; }
#account h3 { font-size: 13px; margin: 10px 0 6px; }
.list.trackers { max-height: 240px; }
.list.trackers li { flex-wrap: wrap; }
.list.trackers .meta { flex-basis: 100%; font-size: 11.5px; color: var(--ink-2); padding-left: 30px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; color: #fff; background: #2e7d32; white-space: nowrap; }
.badge.alert { background: #d50000; }
.badge.off { background: #9e9e9e; }
.alert-card { background: #fff3f3; border: 1px solid #f5c6c6; border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 12.5px; }
.alert-card b { color: #b71c1c; }
.alert-card .row { margin: 6px 0 0; }
.alert-card .btn { font-size: 12px; padding: 4px 8px; }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); margin: 6px 0; }

/* v0.2: дежурная панель, ступени, загоны, рисование, история */
.card.danger .v { color: #b71c1c; }
.card.warn .v { color: #e65100; }
.duty-cards { margin-bottom: 8px; }
.filters { font-size: 12px; color: var(--ink-2); margin: 0 0 8px; }
.filters label { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.sw.dot.hazard { background: #ff1744; box-shadow: 0 0 0 1px #ff1744; }
.sw.dot.hotspot { background: #ff6f00; box-shadow: 0 0 0 1px #ff6f00; }
.sw.line.pasture { background: none; border-top: 2px dashed #2e7d32; height: 0; }
.sw.line.track { background: #1565c0; height: 3px; }
.sb-section.collapsed > *:not(h2) { display: none; }
h2[data-toggle] { cursor: pointer; }
h2[data-toggle]::after { content: ' ▾'; color: #9aa5b1; }
.sb-section.collapsed h2[data-toggle]::after { content: ' ▸'; }
.help p { margin: 0 0 8px; font-size: 12.5px; }
.help code { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 11.5px; word-break: break-all; }
.alert-card .ac-head { display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
.alert-card .when { color: var(--ink-2); font-size: 11.5px; white-space: nowrap; }
.alert-card.lvl-attention { background: #fffde7; border-color: #ffe082; } .alert-card.lvl-attention b { color: #8d6e00; }
.alert-card.lvl-warning { background: #fff3e0; border-color: #ffcc80; } .alert-card.lvl-warning b { color: #e65100; }
.alert-card.lvl-alarm, .alert-card.lvl-road { background: #fff3f3; border-color: #f5c6c6; } .alert-card.lvl-road b { color: #7f0000; }
.alert-card.lvl-speed, .alert-card.lvl-pasture { background: #f3e5f5; border-color: #ce93d8; } .alert-card.lvl-speed b, .alert-card.lvl-pasture b { color: #6a1b9a; }
.alert-card.lvl-silence, .alert-card.lvl-battery { background: #f5f5f5; border-color: #e0e0e0; } .alert-card.lvl-silence b, .alert-card.lvl-battery b { color: #455a64; }
.alert-card.resolved { opacity: .8; }
.alert-card .row { flex-wrap: wrap; }
.alert-card a.btn { text-decoration: none; text-align: center; }
.chip { display: inline-block; font-size: 11px; padding: 0 7px; border-radius: 10px; background: #eceff1; color: #37474f; }
.chip.ok { background: #e8f5e9; color: #1b5e20; } .chip.warn { background: #fff3e0; color: #e65100; }
.badge.l-attention { background: #fbc02d; color: #3e2723; } .badge.l-warning { background: #f57c00; } .badge.l-alarm { background: #d50000; } .badge.l-road { background: #7f0000; }
.badge.k-speed, .badge.k-pasture { background: #6a1b9a; } .badge.k-silence, .badge.k-battery { background: #78909c; }
.list li.group { background: #f1f3f5; color: var(--ink-2); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; cursor: default; padding: 4px 10px; }
.list .meta .link { margin-left: 8px; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; padding: 0; text-decoration: underline; }
button.link.danger { color: #b71c1c; }
.list.pastures li { flex-wrap: wrap; } .list.pastures .link { margin-left: auto; }
.list.history { max-height: 420px; } .list.history li { display: block; padding: 4px 6px; cursor: default; } .list.history .alert-card { margin: 0; }
#account .row select, #account .row input { margin-bottom: 6px; }
#acct-table td, #acct-table th { padding: 4px 6px; font-size: 12px; } #acct-table select { width: 100%; font: inherit; font-size: 12px; }
#acct-table td:nth-child(2), #acct-table td:nth-child(3), #acct-table th:nth-child(2), #acct-table th:nth-child(3) { text-align: left; }
.hours { margin: 6px 0 8px; } .hours .bars { display: flex; align-items: flex-end; gap: 2px; height: 46px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.hours .bars i { flex: 1; background: #0b5cad; min-height: 1px; border-radius: 1px 1px 0 0; opacity: .8; }
.hours .axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink-2); padding: 0 2px; }
.drawbar { display: none; position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%); z-index: 8; background: #fff; border: 1px solid #a5d6a7; border-radius: 8px; padding: 8px 12px; font-size: 12.5px; box-shadow: 0 2px 10px rgba(0,0,0,.15); gap: 8px; align-items: center; max-width: 92vw; }
.drawbar .btn { margin-left: 6px; }
body.drawing .drawbar { display: flex; }
.maplibregl-popup-content .btn { margin-top: 6px; }
.maplibregl-popup-content .hint { margin: 6px 0 0; }
