:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #5d6673;
  --line: #e1e4e8;
  --accent: #0b5cad;
  --accent-ink: #fff;
  --danger: #c62828;
  --warn-bg: #fff4e5;
  --warn-ink: #8a4b00;
  --ok: #1b7f3b;
  --radius: 8px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; font-size: 14px; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: #10243e; color: #fff; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 24px; }
.brand small { display: block; opacity: .75; font-size: 12px; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 460px; }
.search input { width: 100%; padding: 8px 12px; border-radius: 6px; border: 0; font-size: 14px; }
.search-results { position: absolute; z-index: 2000; top: 38px; left: 0; right: 0; margin: 0; padding: 4px 0; list-style: none; background: #fff; color: var(--ink); border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.search-results li { padding: 7px 12px; cursor: pointer; font-size: 13px; }
.search-results li:hover { background: #eef4fb; }
.top-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.top-actions .chk { color: #fff; }
.top-actions .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 420px; max-width: 100%; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 11px 6px; background: none; border: 0; border-bottom: 3px solid transparent; font-weight: 600; color: var(--muted); cursor: pointer; font-size: 14px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab { padding: 12px 14px 24px; overflow-y: auto; flex: 1; }
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 8px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); padding: 6px 8px; border: 1px solid #cfd4da; border-radius: 6px; background: #fff; min-width: 0; }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.grid2 .full { grid-column: 1 / -1; }
.chk { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; color: var(--ink); font-size: 13px; cursor: pointer; }
.chk.inline { align-self: end; padding-bottom: 6px; }
.checks { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 6px 0; }

.btn { display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 6px; border: 1px solid #c7ccd3; background: #fff; color: var(--ink); cursor: pointer; font: inherit; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f1f4f8; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #094c90; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e7b3b3; }
.btn:disabled { opacity: .5; cursor: progress; }
.chip { border: 1px solid #c7ccd3; background: #f7f8fa; border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 12px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.stat { background: #f4f7fb; border-radius: var(--radius); padding: 8px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 11px; color: var(--muted); }
.new-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; font-size: 12px; color: var(--muted); font-weight: 600; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.filters input { grid-column: 1 / -1; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li { border: 1px solid var(--line); border-left: 5px solid var(--c, #888); border-radius: var(--radius); padding: 9px 11px; cursor: pointer; }
.list li:hover { background: #f8fafc; }
.list .t { font-weight: 700; }
.list .m { color: var(--muted); font-size: 12px; margin-top: 3px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #eef1f5; color: #333; font-weight: 600; margin-left: 4px; }
.badge.ativa { background: #ffe1e1; color: #a40000; }
.badge.aprovada { background: #e1f5e7; color: #1b6b35; }
.badge.planejada { background: #e5efff; color: #1d4ed8; }
.badge.encerrada, .badge.cancelada { background: #eee; color: #777; }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }

.ed-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.tag { font-family: ui-monospace, Menlo, monospace; background: #eef1f5; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tools button { padding: 7px 4px; border: 1px solid #c7ccd3; border-radius: 6px; background: #fff; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; }
.tools button.active { background: #10243e; color: #fff; border-color: #10243e; }
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 8px; padding: 8px; background: #f6f7f9; border-radius: var(--radius); }
.palette button { border: 2px solid transparent; background: #fff; border-radius: 6px; padding: 3px; cursor: pointer; display: flex; flex-direction: column; align-items: center; font-size: 9.5px; gap: 1px; }
.palette button.active { border-color: var(--accent); }
.palette .cat { grid-column: 1 / -1; font-size: 11px; font-weight: 700; color: var(--muted); margin-top: 4px; }

details { border-top: 1px solid var(--line); padding: 8px 0; }
summary { cursor: pointer; font-weight: 700; padding: 2px 0; }
.count { display: inline-block; min-width: 20px; text-align: center; background: #10243e; color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; margin-left: 4px; }
.mini { list-style: none; margin: 6px 0 0; padding: 0; font-size: 12.5px; }
.mini li { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.mini li button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; }
.mini li .s { color: var(--muted); font-size: 11.5px; }

table.qty { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12.5px; }
table.qty th { text-align: left; font-size: 11px; color: var(--muted); border-bottom: 2px solid var(--line); padding: 4px; }
table.qty td { padding: 3px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.qty td.n { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
table.qty tr.cat td { background: #f4f6f9; font-weight: 700; font-size: 11px; color: var(--muted); text-transform: uppercase; }
table.qty tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 6px; }

.alert { background: var(--warn-bg); color: var(--warn-ink); border-radius: 6px; padding: 8px 10px; font-size: 12.5px; margin: 6px 0; }
.alert.err { background: #fde8e8; color: #8b1111; }
.alert.ok { background: #e6f5ea; color: #145c2a; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; margin: 8px 0; }
.kv b { color: var(--muted); font-weight: 600; }

.mode-hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #10243e; color: #fff; padding: 7px 14px; border-radius: 999px; z-index: 900; font-size: 13px; box-shadow: 0 2px 10px rgba(0,0,0,.25); max-width: 90%; text-align: center; }
.status { position: absolute; bottom: 14px; left: 14px; z-index: 900; background: #fff; padding: 7px 12px; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.2); font-size: 12.5px; max-width: 60%; }
.status.loading::before { content: ''; display: inline-block; width: 10px; height: 10px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; margin-right: 7px; animation: spin .8s linear infinite; vertical-align: -1px; }
.status.error { background: #fde8e8; color: #8b1111; }
@keyframes spin { to { transform: rotate(360deg); } }
.legend { position: absolute; right: 10px; bottom: 24px; z-index: 800; background: rgba(255,255,255,.95); padding: 8px 10px; border-radius: 6px; font-size: 11.5px; line-height: 1.7; box-shadow: 0 1px 6px rgba(0,0,0,.2); }
.legend .ln { display: inline-block; width: 22px; height: 0; border-top: 4px solid; vertical-align: middle; margin-right: 4px; }
.ln.red { border-color: #d32f2f; } .ln.orange { border-color: #f57c00; } .ln.purple { border-color: #7b1fa2; } .ln.blue { border-color: #1565c0; } .ln.green { border-color: #2e7d32; } .ln.dashed { border-top-style: dashed; }
.arr { color: #1565c0; font-weight: 700; } .arr.gray { color: #777; }

/* Marcadores */
.dir-arrow { color: #1565c0; font-size: 14px; font-weight: 900; text-shadow: 0 0 2px #fff, 0 0 3px #fff; line-height: 14px; text-align: center; pointer-events: none; }
.dir-arrow.two { color: #888; font-size: 12px; }
.dir-arrow.ov { color: #7b1fa2; font-size: 18px; }
.sign-marker { filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.sign-marker .hd { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; }
.sign-marker .hd::after { content: ''; position: absolute; left: -4px; top: -26px; border: 4px solid transparent; border-bottom: 8px solid #10243e; }
.sign-marker.manual svg { outline: 2px dashed #10243e; outline-offset: 1px; border-radius: 4px; }
.km-label { background: #1565c0; color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; text-align: center; line-height: 20px; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.flag { font-size: 22px; line-height: 22px; text-shadow: 0 0 3px #fff; }
.leaflet-popup-content { font-size: 13px; min-width: 220px; }
.leaflet-popup-content h4 { margin: 0 0 6px; font-size: 14px; }
.pop-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.dir-opts { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }

@media (max-width: 820px) {
  .layout { flex-direction: column-reverse; }
  .sidebar { width: 100%; height: 50vh; border-right: 0; border-top: 1px solid var(--line); }
  .map-wrap { min-height: 50vh; }
  .top-actions .chk { display: none; }
  .legend { display: none; }
}

.report-overlay { position: fixed; inset: 0; z-index: 5000; background: rgba(16,36,62,.6); display: flex; flex-direction: column; padding: 16px; }
.report-bar { display: flex; gap: 8px; align-items: center; background: #fff; padding: 8px 12px; border-radius: 8px 8px 0 0; }
.report-overlay iframe { flex: 1; border: 0; background: #fff; border-radius: 0 0 8px 8px; width: 100%; }

.sign-marker svg { transition: transform .15s; }
.z-low .sign-marker svg { transform: scale(.6); }
.z-low .sign-marker .hd { display: none; }
.z-min .sign-marker svg { transform: scale(.4); }

/* Trajetos homologados */
.seg { display: flex; background: #eef1f5; border-radius: 8px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 6px; border-radius: 6px; font: inherit; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.list li.sel { background: #eef4fb; border-color: #b9d1ee; }
.badge.oficial { background: #10243e; color: #fff; }
.badge.vigente { background: #e1f5e7; color: #1b6b35; }
.badge.vencido { background: #fde8e8; color: #8b1111; }
.detail { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-top: 10px; background: #fbfcfd; }
.detail h4 { margin: 0 0 6px; font-size: 14px; }
dialog { border: 0; border-radius: 10px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(16,36,62,.5); }
.dlg { padding: 16px 18px; }
.dlg h3 { margin: 0 0 6px; color: var(--ink); font-size: 16px; text-transform: none; letter-spacing: 0; }
code { background: #eef1f5; padding: 0 4px; border-radius: 3px; font-size: 11.5px; }

.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.prova-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
table.provas { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 6px 0; }
table.provas th { text-align: left; font-size: 11px; color: var(--muted); border-bottom: 2px solid var(--line); padding: 3px 4px; }
table.provas td { padding: 4px; border-bottom: 1px solid var(--line); }
table.provas td .btn { padding: 2px 6px; font-size: 11.5px; }

/* Simulador */
.runner-canvas { position: absolute; inset: 0; z-index: 450; pointer-events: none; }
.sim-player { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-top: 10px; background: #fbfcfd; }
.sim-player input[type=range] { width: 100%; margin: 8px 0 4px; }
.sim-clock { margin-left: auto; font-variant-numeric: tabular-nums; }
.sim-clock b { font-size: 18px; }
.sim-clock span { color: var(--muted); font-size: 12px; }
.sim-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; margin-top: 4px; }
.sim-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.sim-summary { display: grid; gap: 6px; margin: 6px 0 10px; }
.sim-summary div { background: #f4f7fb; border-radius: 6px; padding: 7px 10px; display: flex; flex-direction: column; }
.sim-summary span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.sim-summary b { font-size: 15px; }
.sim-summary small { color: var(--muted); font-size: 11.5px; }
table.provas td .s, table.provas .s { color: var(--muted); font-size: 11px; }
