:root {
  --red: #d9372b;
  --red-d: #b52a20;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7f9;
  --blue: #2563eb;
  --sb-w: 372px;
  --shadow: 0 6px 22px rgba(15, 23, 42, .18), 0 1px 3px rgba(15, 23, 42, .12);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--ink); font-size: 14px; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.grow { flex: 1; }
.muted { color: var(--muted); }
kbd { font: 600 10.5px/1 ui-monospace, Consolas, monospace; padding: 2px 5px; border-radius: 4px; background: #eef0f3; border: 1px solid #d5d9df; color: #4b5563; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Barra lateral ---------- */
#sidebar { width: var(--sb-w); flex: none; display: flex; flex-direction: column; background: #fff; border-right: 1px solid var(--line); z-index: 5; transition: margin-left .25s ease; }
body.sb-closed #sidebar { margin-left: calc(var(--sb-w) * -1); }
.sb-head { background: linear-gradient(150deg, var(--red) 0%, var(--red-d) 100%); color: #fff; padding: 14px 16px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.2px; }
.logo { width: 28px; height: 28px; }
.map-name { width: 100%; margin-top: 12px; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .25); color: #fff; font-weight: 600; font-size: 15px; padding: 8px 10px; border-radius: 8px; outline: none; }
.map-name::placeholder { color: rgba(255, 255, 255, .7); }
.map-name:focus { background: rgba(255, 255, 255, .22); border-color: #fff; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.stats div { background: rgba(0, 0, 0, .18); border-radius: 8px; padding: 6px 4px; text-align: center; }
.stats b { display: block; font-size: 16px; font-weight: 800; }
.stats small { font-size: 10.5px; opacity: .85; text-transform: uppercase; letter-spacing: .4px; }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 34px; width: 250px; background: #fff; color: var(--ink); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 50; font-weight: 500; font-size: 14px; letter-spacing: 0; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 6px; }
.menu button:hover { background: #f3f4f6; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

.icon-btn { border: 0; background: transparent; width: 30px; height: 30px; border-radius: 50%; font-size: 17px; line-height: 1; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(0, 0, 0, .07); }
.icon-btn.light { color: #fff; font-size: 22px; }
.icon-btn.light:hover { background: rgba(255, 255, 255, .2); }

.search-box { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); position: relative; }
.search { display: flex; align-items: center; gap: 8px; background: #f3f4f6; border: 1px solid transparent; border-radius: 9px; padding: 0 10px; color: var(--muted); }
.search:focus-within { background: #fff; border-color: var(--red); box-shadow: 0 0 0 3px rgba(217, 55, 43, .15); }
.search input { flex: 1; border: 0; background: transparent; outline: none; padding: 9px 0; color: var(--ink); }
.results { position: absolute; left: 14px; right: 14px; top: 52px; background: #fff; border-radius: 10px; box-shadow: var(--shadow); z-index: 30; max-height: 260px; overflow: auto; padding: 4px; }
.res { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; font-size: 13px; }
button.res:hover { background: #f3f4f6; }
div.res { cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; color: #4b5563; }
.chip:hover { border-color: var(--red); color: var(--red); }

.layers { flex: 1; overflow-y: auto; padding: 6px 0 12px; }
.sys { border-bottom: 1px solid var(--line); position: relative; transition: background .12s; }
.sys-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px 10px; }
.sys-title { flex: 1; display: flex; align-items: center; gap: 8px; border: 0; background: none; text-align: left; padding: 0; }
.sys-title b { display: block; font-size: 15px; }
.sys-title small { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }
.chev { color: var(--muted); font-size: 13px; transition: transform .15s; }
.sys.collapsed .chev { transform: rotate(-90deg); }
.sys.collapsed .sys-body { display: none; }
.sys-body { padding: 0 8px 10px 10px; }

.drag-handle { cursor: grab; color: #9ca3af; font-size: 14px; line-height: 1; padding: 4px 2px; user-select: none; flex: none; opacity: .65; transition: opacity .15s, color .15s; }
.li:hover .drag-handle, .sys-head:hover .drag-handle { opacity: 1; color: #4b5563; }
.drag-handle:active { cursor: grabbing; }

.chk { display: inline-flex; align-items: center; cursor: pointer; flex: none; }
.chk input { position: absolute; opacity: 0; width: 0; height: 0; }
.chk .box { width: 18px; height: 18px; border-radius: 5px; border: 2px solid #b8bec7; background: #fff; display: inline-block; position: relative; }
.chk input:checked + .box { background: var(--c, var(--red)); border-color: var(--c, var(--red)); }
.chk input:checked + .box::after { content: ''; position: absolute; left: 4px; top: 0; width: 4px; height: 9px; border: solid #fff; border-width: 0 2.2px 2.2px 0; transform: rotate(45deg); }
.chk input:focus-visible + .box { outline: 2px solid var(--blue); outline-offset: 2px; }

.li { display: flex; align-items: center; gap: 6px; border-radius: 9px; padding: 3px 4px; margin: 1px 0; position: relative; transition: background .12s; }
.li:hover { background: #f5f6f8; }
.li.sel { background: #fdecea; box-shadow: inset 3px 0 0 var(--red); }
.li.dragging, .sys.dragging { opacity: .45; background: #eff6ff; }
.li.drop-before::before, .sys.drop-before::before { content: ''; position: absolute; left: 4px; right: 4px; top: -2px; height: 3px; background: var(--blue); border-radius: 2px; pointer-events: none; z-index: 5; }
.li.drop-after::after, .sys.drop-after::after { content: ''; position: absolute; left: 4px; right: 4px; bottom: -2px; height: 3px; background: var(--blue); border-radius: 2px; pointer-events: none; z-index: 5; }
.sys.drop-inside { background: #eff6ff; outline: 2px dashed #93c5fd; outline-offset: -2px; }
.li-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; border: 0; background: none; text-align: left; padding: 5px 2px; }
.code { flex: none; min-width: 26px; height: 24px; padding: 0 6px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12.5px; }
.li-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-meta { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.tag { font-style: normal; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; background: #fff3cd; color: #8a6100; border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.empty { color: var(--muted); font-size: 12.5px; padding: 6px 4px; }
.fld .empty { text-transform: none; letter-spacing: 0; font-weight: 500; }
.add-line { margin-top: 4px; width: 100%; border: 1.5px dashed #cfd4db; background: none; border-radius: 9px; padding: 8px; color: #4b5563; font-weight: 600; font-size: 13px; }
.add-line:hover { border-color: var(--red); color: var(--red); background: #fff7f6; }
.sb-foot { padding: 10px 14px; border-top: 1px solid var(--line); }

.btn { border: 1px solid #d5d9df; background: #fff; border-radius: 8px; padding: 7px 12px; font-weight: 600; font-size: 13px; color: #374151; }
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); }
.btn.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.danger-o { color: #b91c1c; border-color: #f3c0bc; }
.btn.danger-o:hover { background: #fef2f2; }
.btn.wide { width: 100%; }
.btn.sm { padding: 4px 8px; font-size: 12px; }

/* ---------- Palco / mapa ---------- */
#stage { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; z-index: 0; background: #e5e3df; }
.leaflet-container { font-family: inherit; }
.sb-toggle { position: absolute; top: 12px; left: 12px; z-index: 500; width: 40px; height: 40px; border: 0; border-radius: 10px; background: #fff; box-shadow: var(--shadow); font-size: 18px; color: #374151; }
.sb-toggle:hover { color: var(--red); }

.toolbar { position: absolute; top: 12px; left: 62px; z-index: 500; display: flex; align-items: center; gap: 3px; background: #fff; padding: 5px; border-radius: 13px; box-shadow: var(--shadow); white-space: nowrap; }
.tb { display: flex; align-items: center; gap: 7px; border: 0; background: transparent; padding: 7px 11px; border-radius: 9px; font-weight: 600; font-size: 13px; color: #374151; white-space: nowrap; }
.tb svg { width: 18px; height: 18px; flex: none; }
.tb:hover:not(:disabled) { background: #f1f3f5; }
.tb.on { background: var(--red); color: #fff; }
.tb:disabled { opacity: .35; cursor: default; }
.tb kbd { display: none; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 4px 4px; }

.map-opts { position: absolute; top: 12px; right: 12px; z-index: 500; display: flex; align-items: center; gap: 8px; background: #fff; padding: 4px; border-radius: 12px; box-shadow: var(--shadow); }
.seg { display: flex; background: #f1f3f5; border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: #4b5563; }
.seg button.on { background: #fff; color: var(--red); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.opt { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: #4b5563; white-space: nowrap; cursor: pointer; }
.opt input { accent-color: var(--red); }

.hint { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 500; width: min(780px, calc(100% - 150px)); background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.hint-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hint-row label { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 12.5px; }
.hint select { border: 1px solid #d5d9df; border-radius: 7px; padding: 4px 6px; background: #fff; }
.hint input[type=range] { width: 130px; accent-color: var(--red); }
.hint-row > b:first-child { color: var(--red); }

.inspector { position: absolute; top: 68px; right: 12px; z-index: 500; width: 322px; max-height: calc(100% - 160px); overflow-y: auto; background: #fff; border-radius: 14px; box-shadow: var(--shadow); }
.insp-head { display: flex; align-items: center; gap: 10px; padding: 12px 10px 8px 16px; position: sticky; top: 0; background: #fff; z-index: 2; border-bottom: 1px solid var(--line); }
.insp-head h3 { margin: 0; font-size: 15px; flex: 1; }
.insp-body { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.fld > span b { color: var(--ink); text-transform: none; letter-spacing: 0; margin-left: 4px; }
.fld input:not([type=range]):not([type=color]):not([type=checkbox]), .fld select, .modal select { width: 100%; border: 1px solid #d5d9df; border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); font-weight: 500; font-size: 14px; text-transform: none; letter-spacing: 0; outline: none; }
.fld input:focus, .fld select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(217, 55, 43, .13); }
.fld input[type=range], .vtx-row input[type=range] { width: 100%; accent-color: var(--red); }
.row2 { display: grid; grid-template-columns: 90px 1fr; gap: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .2); padding: 0; }
.sw.on { box-shadow: 0 0 0 2.5px var(--ink); }
.swatches input[type=color] { width: 28px; height: 28px; border: 0; padding: 0; background: none; border-radius: 50%; cursor: pointer; }
.vtx { background: #eff6ff; border-radius: 10px; padding: 10px; }
.vtx-row { display: flex; align-items: center; gap: 6px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tip { margin: 0; color: var(--muted); font-size: 12px; }
.insp-sub { font-size: 13px; color: var(--muted); }
.insp-sub b { color: var(--ink); font-size: 15px; }
.stn-list { display: flex; flex-direction: column; border-left: 3px solid #e5e7eb; margin-left: 6px; }
.stn { display: flex; align-items: center; gap: 8px; border: 0; background: none; text-align: left; padding: 5px 6px; border-radius: 6px; width: 100%; }
.stn:hover { background: #f3f4f6; }
.stn .dot { width: 11px; height: 11px; border-radius: 50%; border: 3px solid #333; background: #fff; margin-left: -13px; flex: none; }
.stn-name { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stn small { color: var(--muted); font-size: 11.5px; }
.mini { font-size: 10.5px; font-weight: 800; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; }
.lrows { display: flex; flex-direction: column; gap: 2px; max-height: 190px; overflow: auto; }
.lrow { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 7px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 500; font-size: 13.5px; cursor: pointer; }
.lrow:hover { background: #f3f4f6; }
.lrow.on { background: #f0fdf4; }
.lrow input { accent-color: var(--red); }
.lname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lrow small { color: var(--muted); font-size: 11px; }
.krow { display: flex; align-items: center; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 500; }
.st-badge { width: 22px; height: 22px; border-radius: 50%; border: 5px solid #222; background: #fff; flex: none; }
.st-badge.ix { border-width: 5px; background: conic-gradient(#0455a1 0 50%, #ee1c25 50% 100%); border: 0; position: relative; }
.st-badge.ix::after { content: ''; position: absolute; inset: 5px; background: #fff; border-radius: 50%; }
.st-badge.link { border-style: dotted; border-color: var(--blue); }

/* ---------- Elementos no mapa ---------- */
.st-icon, .badge-icon, .vh-icon { background: none !important; border: 0 !important; overflow: visible; }
.st-dot { position: absolute; left: 0; top: 0; width: 15px; height: 15px; transform: translate(-50%, -50%); border-radius: 50%; background: #fff; border: 3.5px solid var(--c, #222); box-shadow: 0 1px 3px rgba(0, 0, 0, .4); pointer-events: auto; cursor: pointer; transition: box-shadow .12s; }
.st-dot.ix { width: 23px; height: 23px; border: 0; background: var(--ring, #222); box-shadow: 0 0 0 2px #fff, 0 1px 5px rgba(0, 0, 0, .5); }
.st-dot.ix::after { content: ''; position: absolute; inset: 4.5px; border-radius: 50%; background: #fff; }
.st-dot.free { border: 3px dashed #6b7280; background: #f3f4f6; }
.st-icon:hover .st-dot { box-shadow: 0 0 0 4px rgba(37, 99, 235, .3), 0 1px 3px rgba(0, 0, 0, .4); }
.st-icon.sel .st-dot { box-shadow: 0 0 0 4px rgba(37, 99, 235, .65), 0 1px 3px rgba(0, 0, 0, .4); }
.st-icon.pending .st-dot { box-shadow: 0 0 0 5px rgba(245, 158, 11, .8); }
.st-label { position: absolute; left: 14px; top: 0; transform: translateY(-50%); white-space: nowrap; display: none; font: 700 12px/1.1 Inter, "Segoe UI", sans-serif; color: #111; pointer-events: none; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff, 0 0 5px #fff; }
.labels-on .st-label, .st-icon.sel .st-label, .st-icon:hover .st-label { display: block; }
.st-icon:hover { z-index: 9999 !important; }
.z-lo .st-dot { width: 8px; height: 8px; border-width: 2px; }
.z-lo .st-dot.ix { width: 12px; height: 12px; border: 0; }
.z-lo .st-dot.ix::after { inset: 2.5px; }
.z-mid .st-dot { width: 12px; height: 12px; border-width: 3px; }
.z-mid .st-dot.ix { width: 18px; height: 18px; border: 0; }
.z-mid .st-dot.ix::after { inset: 3.5px; }
body[data-base=dark] .st-label, body[data-base=sat] .st-label { color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 4px #000, 0 0 6px #000; }

.end-badge { position: absolute; left: 0; top: 0; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font: 800 12.5px/1 Inter, "Segoe UI", sans-serif; box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0, 0, 0, .45); white-space: nowrap; }
.z-lo .end-badge { display: none; }

.vh { position: absolute; left: 0; top: 0; width: 15px; height: 15px; transform: translate(-50%, -50%); background: #fff; border: 2.5px solid #111; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); cursor: grab; pointer-events: auto; display: flex; align-items: center; justify-content: center; }
.vh.t0 { border-color: #0284c7; background: #f0f9ff; }
.vh.t1 { border-color: #ea580c; background: #fff7ed; }
.vh.t0:hover { background: #bae6fd; }
.vh.t1:hover { background: #fed7aa; }
.vh.sel { background: var(--blue) !important; border-color: #fff !important; box-shadow: 0 0 0 3px #1d4ed8 !important; }
.vh.sharp { transform: translate(-50%, -50%) rotate(45deg); border-radius: 1px; }
.vh .vh-num { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 8.5px; font-weight: 800; line-height: 1; color: #1e293b; pointer-events: none; user-select: none; font-family: Inter, -apple-system, sans-serif; }
.vh.sel .vh-num { color: #fff; }
.vh.sharp .vh-num { transform: translate(-50%, -50%) rotate(-45deg); }
.vh.mid { width: 10px; height: 10px; border-width: 2px; border-radius: 50%; opacity: .82; background: #fff; }
.vh.mid.t0 { border-color: #0284c7; background: #e0f2fe; }
.vh.mid.t1 { border-color: #ea580c; background: #ffedd5; }
.vh.mid:hover { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }

.track-box { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px; margin-top: 4px; }
.track-box-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.track-box-head span { font-weight: 600; font-size: 12px; color: #334155; }
.seg-btn-group { display: flex; gap: 4px; }
.seg-btn-group .btn { flex: 1; padding: 5px 4px; font-size: 11px; text-align: center; border-radius: 6px; }
.seg-btn-group .btn.on { background: #2563eb; color: #fff; border-color: #2563eb; font-weight: 600; }

.leaflet-container.tool-draw, .leaflet-container.tool-station, .leaflet-container.tool-link { cursor: crosshair; }
.leaflet-container.tool-select.hovering { cursor: pointer; }
.leaflet-container.tool-draw .leaflet-interactive, .leaflet-container.tool-station .leaflet-interactive { cursor: crosshair; }
.leaflet-container.tool-draw .st-dot { cursor: crosshair; }

/* ---------- Modais e avisos ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 3000; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 16px; padding: 20px; width: min(420px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-body p { margin: 0; line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-actions .left { order: -1; margin-right: auto; }

#toasts { position: fixed; top: 74px; left: calc(50% + var(--sb-w) / 2); transform: translateX(-50%); z-index: 4000; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
body.sb-closed #toasts { left: 50%; }
.toast { pointer-events: auto; background: #1f2937; color: #fff; border-radius: 10px; padding: 10px 14px; font-size: 13px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); max-width: 520px; animation: pop .2s ease; transition: opacity .4s; }
.toast.out { opacity: 0; }
.toast button { border: 0; background: none; color: #fca5a5; font-weight: 700; padding: 0; }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } }

@media (max-width: 900px) {
  :root { --sb-w: 310px; }
  .toolbar .tb span, .toolbar .tb kbd { display: none; }
  .map-opts .opt { display: none; }
  .inspector { top: auto; bottom: 12px; right: 12px; max-height: 50%; }
  .hint { width: calc(100% - 24px); bottom: 12px; }
}

/* ---------- Custos, polígonos e acessos ---------- */
.cost-bar { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-top: 8px; background: rgba(255, 255, 255, .96); color: var(--ink); border: 0; border-radius: 8px; padding: 8px 11px; font-weight: 600; font-size: 12.5px; }
.cost-bar b { color: var(--red); font-size: 14px; }
.cost-bar:hover { background: #fff; }
.li-meta { text-align: right; line-height: 1.25; }
.li-meta b { color: #374151; font-weight: 700; }

.mixbar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: #e5e7eb; }
.mixbar i { display: block; height: 100%; }
.mixrow { display: flex; align-items: center; gap: 10px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 600; font-size: 13px; }
.mixrow label { width: 128px; flex: none; }
.mixrow b { color: var(--muted); margin-left: 4px; }
.mixrow input[type=range] { flex: 1; accent-color: var(--red); }
.cost { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; }
.cost-total { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.cost-total b { font-size: 19px; color: var(--red); }
.cost-total small { color: var(--muted); font-size: 12px; }
.cost-row { position: relative; display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; padding: 3px 0 5px; }
.cost-row span { color: #4b5563; }
.cost-row i { position: absolute; left: 0; bottom: 0; height: 2.5px; background: #f59e0b; border-radius: 2px; }

.modal.wide { width: min(1040px, calc(100% - 32px)); max-height: 92vh; display: flex; flex-direction: column; }
.modal.wide .modal-body { overflow: auto; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { background: #f8fafc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
.tbl th small { display: block; text-transform: none; font-weight: 500; letter-spacing: 0; }
.tbl td.n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { background: #fdecea; border-bottom: 0; }
.tbl.params input { width: 84px; border: 1px solid #d5d9df; border-radius: 6px; padding: 5px 6px; }
.tbl.params .rowh { background: #f8fafc; color: var(--ink); font-size: 13px; text-transform: none; }
.row2b { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2b .fld input { width: 100%; border: 1px solid #d5d9df; border-radius: 8px; padding: 8px 10px; }
.modal-actions .grp { display: flex; gap: 8px; }

.ac-icon { display: none; }
.z-ac .ac-icon, .ac-icon.sel { display: block; }
.ac { position: absolute; left: 0; top: 0; width: 19px; height: 19px; transform: translate(-50%, -50%); border-radius: 5px; background: #1d4ed8; color: #fff; font: 800 11px/19px Inter, "Segoe UI Symbol", sans-serif; text-align: center; box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0, 0, 0, .5); pointer-events: auto; cursor: pointer; }
.ac.k-elevador { background: #0e7490; }
.ac.k-escada { background: #7c3aed; }
.ac.k-emergencia { background: #dc2626; }
.ac-icon.sel .ac { box-shadow: 0 0 0 2px #fff, 0 0 0 5px rgba(37, 99, 235, .7); }
.ac.mini-ac { position: static; transform: none; flex: none; width: 20px; height: 20px; line-height: 20px; box-shadow: none; cursor: inherit; }
.insp-head .ac.mini-ac { box-shadow: none; }
.vh.poly { background: #2563eb; border-color: #fff; border-radius: 50%; width: 11px; height: 11px; }
.leaflet-container.tool-poly, .leaflet-container.tool-access { cursor: crosshair; }
.leaflet-container.tool-poly .st-dot, .leaflet-container.tool-access .st-dot { cursor: crosshair; }

/* ---------- Badges de Via e Trechos ---------- */
.tag-track-hdr { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 2px 7px; border-radius: 5px; margin-left: 6px; }
.tag-track-hdr.double { background: #dbeafe; color: #1e40af; }
.tag-track-hdr.single { background: #fef3c7; color: #92400e; }

.tag-track { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; padding: 2px 6px; border-radius: 4px; }
.tag-track.single { background: #fef3c7; color: #92400e; }
.tag-track.double { background: #dbeafe; color: #1e40af; }

.cost-track-tag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }
.cost-track-tag.single { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.cost-track-tag.double { background: #f1f5f9; color: #475569; }

.sched-info { display: flex; justify-content: space-between; align-items: center; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; padding: 5px 8px; font-size: 12px; margin: 3px 0; }
.sched-info span { color: #475569; font-weight: 500; }
.sched-info b { color: #0f172a; font-size: 12.5px; }

.cost-dist-summary { display: flex; gap: 6px; justify-content: space-between; font-size: 11px; color: #64748b; font-weight: 600; background: #f1f5f9; border-radius: 5px; padding: 4px 6px; margin-bottom: 2px; }

.btn-compare-methods { background: #e0f2fe; color: #0284c7; border: 1px solid #bae6fd; font-weight: 700; margin-top: 6px; transition: background .15s; }
.btn-compare-methods:hover { background: #bae6fd; color: #0369a1; }

.mix-legend { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 600; margin-top: 3px; }

.vtx-seg-box { display: flex; flex-direction: column; gap: 4px; }

/* Comparativo de Métodos Construtivos (Modal) */
.method-comp-intro { font-size: 13.5px; color: #334155; margin-bottom: 8px; line-height: 1.4; }
.method-comp-tbl tbody tr.highlight-row { background: #eff6ff; font-weight: 600; }
.method-comp-tbl td { vertical-align: middle; }
.badge-cur { display: inline-block; background: #3b82f6; color: #fff; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 4px; }
.tag-impact { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 4px; display: inline-block; }
.tag-impact.low { background: #dcfce7; color: #166534; }
.tag-impact.mid { background: #fef3c7; color: #92400e; }
.tag-impact.high { background: #fee2e2; color: #991b1b; }

.verdict-box { margin-top: 14px; background: #f8fafc; border-left: 4px solid var(--blue); border-radius: 0 8px 8px 0; padding: 12px 14px; }
.verdict-box h4 { margin: 0 0 6px; font-size: 14px; color: #1e293b; display: flex; align-items: center; gap: 6px; }
.verdict-box p { margin: 0; font-size: 13px; line-height: 1.5; color: #334155; }

/* ---------- Simulação de Trens e Frota ---------- */
.train-canvas { pointer-events: none; position: absolute; top: 0; left: 0; }
.sim-bar { position: absolute; top: 64px; left: 12px; z-index: 500; display: flex; align-items: center; gap: 6px; background: #fff; padding: 5px 8px; border-radius: 12px; box-shadow: var(--shadow); white-space: nowrap; }
.sim-ctrl { display: flex; align-items: center; gap: 4px; }
.sim-play { border: 1px solid #d1d5db; background: #f9fafb; border-radius: 8px; padding: 5px 11px; font-size: 12.5px; font-weight: 700; color: #374151; transition: all .15s; cursor: pointer; }
.sim-play.on { background: #10b981; border-color: #059669; color: #fff; box-shadow: 0 1px 3px rgba(16, 185, 129, .3); }
.sim-play.zoom-muted { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }
.sim-play:hover { filter: brightness(0.95); }
.sim-speed button { padding: 4px 8px; font-size: 12px; cursor: pointer; }
.opt-sep { width: 1px; height: 22px; background: var(--line); display: inline-block; }

.inspector { width: 348px; }
.fleet-box { background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 11px; padding: 11px 12px; display: flex; flex-direction: column; gap: 9px; }
.fleet-box-head { display: flex; justify-content: space-between; align-items: center; }
.fleet-box-head > span { font-size: 12px; font-weight: 800; color: #0f172a; text-transform: uppercase; letter-spacing: .3px; }
.fleet-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; color: #334155; text-transform: none; letter-spacing: 0; cursor: pointer; }
.fleet-toggle input { accent-color: #10b981; cursor: pointer; }
.fld-sub { display: flex; flex-direction: column; gap: 3px; text-transform: none; letter-spacing: 0; font-size: 11.5px; color: #475569; font-weight: 600; }
.fld-sub select { padding: 6px 8px !important; font-size: 12.5px !important; }

.train-schematic { background: #0f172a; border-radius: 8px; padding: 9px 10px 7px; color: #f8fafc; display: flex; flex-direction: column; gap: 6px; }
.sch-consist { display: flex; align-items: center; justify-content: center; gap: 2px; min-height: 20px; overflow-x: auto; padding: 2px 0; }
.sch-car { flex: 1; min-width: 14px; max-width: 38px; height: 15px; background: #fff; border: 1.5px solid #cbd5e1; border-radius: 3px; position: relative; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.sch-car.lead { border-top-left-radius: 8px; border-bottom-left-radius: 5px; }
.sch-car.tail { border-top-right-radius: 8px; border-bottom-right-radius: 5px; }
.sch-stripe { display: block; width: calc(100% - 4px); height: 5px; border-radius: 2px; background: var(--lc, #2563eb); }
.sch-coupler { width: 3px; height: 7px; background: #64748b; flex: none; border-radius: 1px; }
.sch-dims { display: flex; justify-content: space-between; font-size: 11px; color: #cbd5e1; font-weight: 500; text-transform: none; letter-spacing: 0; }
.sch-dims b { color: #fff; font-weight: 700; }

.ops-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; text-transform: none; letter-spacing: 0; }
.ops-kpi { background: #fff; border: 1px solid #e2e8f0; border-radius: 7px; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.ops-kpi small { font-size: 10.5px; color: #64748b; font-weight: 600; text-transform: uppercase; letter-spacing: .2px; }
.ops-kpi b { font-size: 13.5px; color: #0f172a; font-weight: 800; }
.ops-kpi .unit { font-size: 11px; font-weight: 600; color: #475569; }

.fleet-cost-chip { display: flex; justify-content: space-between; align-items: center; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 7px; padding: 6px 9px; margin-top: 6px; font-size: 11.5px; color: #065f46; text-transform: none; letter-spacing: 0; font-weight: 500; }
.fleet-cost-chip b { color: #047857; font-weight: 800; font-size: 12.5px; }

.ops-warn { margin-top: 5px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 6px; padding: 5px 8px; font-size: 11px; line-height: 1.35; text-transform: none; letter-spacing: 0; font-weight: 600; }
.ops-note { margin-top: 5px; background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; border-radius: 6px; padding: 5px 8px; font-size: 11px; line-height: 1.35; text-transform: none; letter-spacing: 0; font-weight: 500; }

.fleet-sliders { display: flex; flex-direction: column; gap: 7px; border-top: 1px solid #e2e8f0; padding-top: 8px; text-transform: none; letter-spacing: 0; }
.fl-row { display: flex; flex-direction: column; gap: 2px; }
.fl-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fl-lbl { display: flex; justify-content: space-between; align-items: baseline; font-size: 11.5px; color: #334155; font-weight: 600; }
.fl-lbl b { color: #0f172a; font-weight: 800; font-size: 12px; }

.btn-follow-train { background: #0284c7; color: #fff; border-color: #0284c7; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 12px; margin-top: 2px; }
.btn-follow-train:hover { background: #0369a1; }

/* ---------- HUD de Telemetria e Acompanhamento de Trem ---------- */
.train-hud { position: absolute; bottom: 22px; left: 16px; z-index: 520; width: 330px; max-width: calc(100% - 32px); background: rgba(15, 23, 42, 0.94); backdrop-filter: blur(10px); color: #f8fafc; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; font-family: Inter, -apple-system, sans-serif; pointer-events: auto; transition: opacity .2s, transform .2s; }
.train-hud.hidden { display: none !important; }
.hud-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.12); padding-bottom: 9px; }
.hud-line-btn { display: flex; align-items: center; gap: 8px; border: 0; background: none; color: inherit; text-align: left; padding: 0; cursor: pointer; flex: 1; min-width: 0; }
.hud-line-btn:hover .hud-title b { text-decoration: underline; }
.hud-title { display: flex; flex-direction: column; min-width: 0; }
.hud-title b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.hud-title small { font-size: 11px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-nav { display: flex; align-items: center; gap: 4px; flex: none; }
.hud-btn { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.18); color: #fff; border-radius: 6px; padding: 4px 7px; font-size: 11px; cursor: pointer; transition: background .15s; }
.hud-btn:hover { background: rgba(255, 255, 255, 0.22); }
.hud-idx { font-size: 11px; font-weight: 700; color: #94a3b8; padding: 0 2px; }
.hud-close { color: #f87171; font-weight: 800; margin-left: 2px; }
.hud-close:hover { background: rgba(239, 68, 68, 0.25); color: #fff; }

.hud-body { display: flex; flex-direction: column; gap: 7px; }
.hud-row { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; }
.hud-status { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.hud-status.st-move { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.hud-status.st-dwell { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.hud-status.st-wait { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.hud-seg { font-size: 11px; color: #cbd5e1; font-weight: 600; }

.hud-speed-row { display: flex; flex-direction: column; gap: 4px; background: rgba(0, 0, 0, 0.35); padding: 7px 9px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.08); }
.hud-spd-val { font-size: 11.5px; color: #94a3b8; display: flex; align-items: baseline; gap: 3px; }
.hud-spd-val b { font-size: 18px; color: #fff; font-weight: 800; }
.hud-max { margin-left: auto; font-size: 11px; color: #64748b; }
.hud-bar { width: 100%; height: 5px; background: rgba(255, 255, 255, 0.12); border-radius: 3px; overflow: hidden; }
.hud-bar i { display: block; height: 100%; border-radius: 3px; transition: width .15s ease-out; }

.hud-next { font-size: 12px; color: #e2e8f0; line-height: 1.35; padding: 2px 0 0; }
.hud-next b { color: #fff; font-weight: 700; }
.hud-dist { color: #38bdf8; font-weight: 600; font-size: 11.5px; }

/* ---------- Backdrop para Barra Lateral em Mobile ---------- */
.sb-backdrop { display: none; }

/* ============================================================
   Interface Responsiva e Mobile-Friendly (Telas <= 768px)
   ============================================================ */

@media (max-width: 768px) {
  /* Barra lateral vira uma gaveta deslizante sobreposta */
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(340px, 86vw);
    max-width: 100vw;
    z-index: 1500;
    margin-left: 0 !important;
    transform: translateX(0);
    transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }
  body.sb-closed #sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sb-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
    backdrop-filter: blur(2px);
    z-index: 1450;
    opacity: 1;
    pointer-events: auto;
    transition: opacity .25s ease;
  }
  body.sb-closed .sb-backdrop {
    opacity: 0;
    pointer-events: none;
  }

  /* Evita auto-zoom incômodo do iOS Safari ao focar inputs */
  .fld input, .fld select, .search input, .modal input, .modal select {
    font-size: 16px !important;
  }

  /* Botão do menu lateral */
  .sb-toggle {
    top: 10px;
    left: 10px;
    width: 38px;
    height: 38px;
    font-size: 17px;
    border-radius: 9px;
  }

  /* Barra de ferramentas: foco em ícones grandes e toque fácil */
  .toolbar {
    top: 10px;
    left: 54px;
    padding: 3px;
    gap: 2px;
    border-radius: 11px;
    max-width: calc(100vw - 195px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .tb {
    padding: 7px 8px;
    min-width: 34px;
    justify-content: center;
  }
  .tb span { display: none; } /* Oculta textos longos mantendo ícones límpidos */
  .tb kbd { display: none; }
  .toolbar .sep { margin: 3px 2px; }

  /* Opções do mapa (basemap) compactas no canto superior direito */
  .map-opts {
    top: 10px;
    right: 10px;
    padding: 3px 5px;
    gap: 3px;
    border-radius: 11px;
  }
  .map-opts .opt { display: none; } /* Oculta checkboxes secundários para não estourar a tela */
  .map-opts .seg button {
    padding: 5px 6px;
    font-size: 11px;
  }

  /* Barra de simulação flutuante na segunda linha */
  .sim-bar {
    top: 54px;
    left: 10px;
    padding: 3px 6px;
    gap: 4px;
    border-radius: 10px;
    max-width: calc(100vw - 20px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sim-bar::-webkit-scrollbar { display: none; }
  .sim-play {
    padding: 4px 8px;
    font-size: 11.5px;
  }
  .sim-speed button {
    padding: 4px 6px;
    font-size: 11px;
  }

  /* Inspetor em formato "Bottom Sheet" (como Google Maps / Apple Maps) */
  .inspector {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 74vh;
    border-radius: 20px 20px 0 0;
    z-index: 1200;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35);
    animation: slideUpBottom .2s ease-out;
    -webkit-overflow-scrolling: touch;
  }
  .insp-head {
    border-radius: 20px 20px 0 0;
    padding: 12px 14px 8px;
  }
  .insp-head::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #cbd5e1;
  }

  /* Barra de traçado / dica no rodapé */
  .hint {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 12px;
    transform: none;
    width: auto;
    border-radius: 14px;
    max-height: 48vh;
    overflow-y: auto;
    padding: 10px 12px;
    z-index: 1300;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    -webkit-overflow-scrolling: touch;
  }
  .hint-row {
    gap: 8px;
  }

  /* HUD de Telemetria do Trem ajustado à largura da tela */
  .train-hud {
    position: fixed;
    bottom: 12px;
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
    z-index: 1350;
    padding: 10px 12px;
    border-radius: 14px;
  }

  /* Lista de cidades da busca com rolagem horizontal suave */
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }

  /* Modais ocupam tela inteira confortável com margem segura */
  .modal {
    width: calc(100% - 24px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 16px;
    border-radius: 16px;
  }
}

@keyframes slideUpBottom {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

