:root {
  --green: #0E9B4B; --green-d: #0C7C3C; --red: #E11B22; --ink: #2B2A29;
  --bg: #F4F5F7; --card: #fff; --line: #E3E6EA; --muted: #6B7280; --text: #1F2937;
  --amber: #D97706; --blue: #2563EB; --purple: #7C3AED;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* o atributo hidden precisa vencer .modal-backdrop/.topbar/.sidenav (display:flex) */
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--green-d); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 700; color: var(--ink); }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* layout */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 56px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; white-space: nowrap; }
.brand img { height: 34px; }
.gsearch { flex: 1; max-width: 640px; }
.gsearch input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.gsearch input:focus { outline: 2px solid rgba(14,155,75,.25); border-color: var(--green); background: #fff; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user { font-size: 12px; color: var(--muted); cursor: pointer; }
.user:hover { color: var(--green-d); text-decoration: underline; }
.live { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #9CA3AF; display: inline-block; }
.live.on i { background: var(--green); box-shadow: 0 0 0 3px rgba(14,155,75,.2); }
.body { display: flex; flex: 1; min-height: 0; }
.sidenav { width: 210px; padding: 12px 8px; border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
.sidenav a:hover { background: var(--bg); }
.sidenav a.active { background: rgba(14,155,75,.1); color: var(--green-d); font-weight: 600; }
.sidenav .count { font-size: 11px; background: var(--line); color: var(--muted); border-radius: 10px; padding: 1px 7px; min-width: 20px; text-align: center; }
.sidenav a.active .count { background: var(--green); color: #fff; }
.sidenav-foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 8px 12px; border-top: 1px solid var(--line); }
.main { flex: 1; min-width: 0; padding: 18px 20px 60px; overflow: auto; }
.panel { width: 440px; border-left: 1px solid var(--line); background: #fff; overflow: auto; padding: 16px; position: sticky; top: 56px; height: calc(100vh - 56px); }
@media (max-width: 1100px) { .panel { position: fixed; right: 0; top: 56px; height: calc(100vh - 56px); box-shadow: -8px 0 24px rgba(0,0,0,.08); z-index: 15; } }
@media (max-width: 800px) { .sidenav { display: none; } .gsearch { display: none; } }

/* cards, toolbars */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.tight { padding: 10px 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.filters input, .filters select { font-size: 13px; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=time], input[type=email], input[type=password], input[type=datetime-local], select, textarea {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14,155,75,.25); border-color: var(--green); }
textarea { min-height: 70px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.check input { width: auto; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-d); }
.btn-danger { background: #fff; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: #FEF2F2; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-lg { padding: 10px 16px; font-size: 14px; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* tables */
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #FAFBFC; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:hover { background: #F8FAF9; }
tbody tr.clickable { cursor: pointer; }
tbody tr.selected { background: rgba(14,155,75,.08); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: 11px; color: var(--muted); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; background: var(--line); color: var(--text); }
.badge.s-PENDING, .badge.s-DRAFT { background: #EEF0F3; color: #4B5563; }
.badge.s-PLANNED { background: #E0EAFF; color: #1E40AF; }
.badge.s-RELEASED, .badge.s-LOADING, .badge.s-LOADED { background: #FEF3C7; color: #92400E; }
.badge.s-READY { background: #DBEAFE; color: #1D4ED8; }
.badge.s-IN_ROUTE, .badge.s-ARRIVED { background: #EDE9FE; color: #5B21B6; }
.badge.s-DELIVERED, .badge.s-COMPLETED, .badge.s-CHECKED, .badge.s-OK { background: #D1FAE5; color: #065F46; }
.badge.s-PARTIALLY_DELIVERED, .badge.s-RETURNING { background: #FFEDD5; color: #9A3412; }
.badge.s-DELIVERY_FAILED, .badge.s-NOT_DELIVERED, .badge.s-CANCELED, .badge.s-DEGRADED { background: #FEE2E2; color: #991B1B; }
.badge.s-RETURNED, .badge.s-REPLACED { background: #E5E7EB; color: #374151; }
.badge.doc { background: #F3F4F6; color: var(--ink); font-weight: 600; font-family: ui-monospace, Menlo, monospace; }
.badge.doc.INVOICE { border-left: 3px solid var(--green); }
.badge.doc.SALES_ORDER { border-left: 3px solid var(--blue); }
.badge.doc.MANUAL_MANIFEST { border-left: 3px solid var(--amber); }
.badge.doc.canceled { text-decoration: line-through; opacity: .7; }
.badge.op { font-weight: 700; }
.badge.op-BONIFICACAO { background: #FCE7F3; color: #9D174D; }
.badge.op-REMESSA { background: #E0F2FE; color: #075985; }
.badge.op-TRANSFERENCIA { background: #EDE9FE; color: #5B21B6; }
.badge.op-DEVOLUCAO { background: #FFEDD5; color: #9A3412; }
.badge.op-OUTRA { background: #F3F4F6; color: #374151; }
.prio-1 { color: var(--amber); font-weight: 700; } .prio-2 { color: var(--red); font-weight: 700; }

/* alerts */
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 13px; border: 1px solid; }
.alert-warn { background: #FFFBEB; border-color: #FCD34D; color: #92400E; }
.alert-danger { background: #FEF2F2; border-color: #FCA5A5; color: #991B1B; }
.alert-info { background: #EFF6FF; border-color: #BFDBFE; color: #1E3A8A; }
.alert-ok { background: #ECFDF5; border-color: #A7F3D0; color: #065F46; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.kpi b { display: block; font-size: 20px; color: var(--ink); }
.kpi span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

/* route stops */
.stops { display: flex; flex-direction: column; gap: 8px; }
.stop { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 12px; align-items: flex-start; }
.stop.dragging { opacity: .4; }
.stop.drop-before { box-shadow: 0 -3px 0 var(--green); }
.stop.drop-after { box-shadow: 0 3px 0 var(--green); }
.stop .seq { width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; cursor: grab; }
.stop.s-DONE .seq { background: var(--green); } .stop.s-ARRIVED .seq { background: var(--purple); } .stop.s-SKIPPED .seq { background: var(--muted); }
.stop .stop-body { flex: 1; min-width: 0; }
.stop .stop-title { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stop .dl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-top: 1px dashed var(--line); font-size: 12px; }
.stop .dl:first-of-type { border-top: 0; }
.cap { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.cap i { display: block; height: 100%; background: var(--green); }
.cap i.warn { background: var(--amber); } .cap i.over { background: var(--red); }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 96px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.timeline li time { color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline li b { font-weight: 600; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(31,41,55,.45); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 720px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 1000px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal .content { padding: 16px 18px; max-height: 70vh; overflow: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.group { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.group.multi { border-color: #FCD34D; background: #FFFBEB; }
.group .opts { display: flex; gap: 12px; font-size: 12px; margin-top: 6px; }

/* panel */
.panel h2 { display: flex; align-items: center; gap: 8px; }
.panel .close { margin-left: auto; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 8px; font-size: 13px; margin-bottom: 10px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.section { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.section h3 { margin-bottom: 6px; }
.doc-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; flex-wrap: wrap; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: 380px; animation: fade .2s ease-out; }
.toast.err { background: var(--red); } .toast.ok { background: var(--green-d); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* login */
.login { max-width: 380px; margin: 8vh auto; }
.login .logo { text-align: center; margin-bottom: 18px; } .login .logo img { height: 90px; }
.scan { font-size: 18px; padding: 12px; font-family: ui-monospace, Menlo, monospace; }
.progress { display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a { padding: 8px 12px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs a.active { color: var(--green-d); border-color: var(--green); }
pre.json { background: #F9FAFB; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 11px; overflow: auto; max-height: 260px; margin: 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: var(--green); } .dot.bad { background: var(--red); } .dot.warn { background: var(--amber); }

/* ---------- mapa (Leaflet) ---------- */
.map { position: relative; z-index: 0; height: 440px; border-radius: 8px; border: 1px solid var(--line); background: #EEF2F4; }
.map-tall { height: calc(100vh - 380px); min-height: 420px; }
.map-pick { height: 420px; }
.map-boxsel, .map-boxsel .leaflet-interactive, .map-boxsel .leaflet-grab { cursor: crosshair !important; }
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content { font-size: 12px; line-height: 1.4; }
.mk { box-sizing: border-box; }
.mk-stop { width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); position: relative; }
.mk-stop.mk-DONE { background: var(--green); } .mk-stop.mk-ARRIVED { background: var(--purple); } .mk-stop.mk-SKIPPED { background: #9CA3AF; }
.mk-stop.mk-approx { border: 2px dashed var(--amber); }
.mk-stop i { position: absolute; right: -9px; top: -11px; font-size: 11px; font-style: normal; }
.mk-depot { width: 32px; height: 32px; border-radius: 8px; background: var(--red); color: #fff; font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.mk-pend { width: 16px; height: 16px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.mk-pend.mk-prio1 { background: var(--amber); } .mk-pend.mk-prio2 { background: var(--red); }
.mk-pend.mk-approx { border: 2px dashed #fff; }
.mk-pend.mk-inroute { opacity: .45; }
.mk-pend.mk-sel { background: var(--green); box-shadow: 0 0 0 3px rgba(14,155,75,.35), 0 0 0 1px rgba(0,0,0,.4); }
.legend { font-size: 11px; color: var(--muted); display: inline-flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.legend .mk { display: inline-block; width: 12px; height: 12px; vertical-align: middle; margin-right: 3px; }
.seg { display: inline-flex; }
.seg .btn { border-radius: 0; } .seg .btn:first-child { border-radius: 8px 0 0 8px; } .seg .btn:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.seg .btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.stop-title .spacer { flex: 1; }
.eta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn.lock.on { color: var(--amber); }
ol li.moved { color: var(--green-d); font-weight: 600; }

.inline-select { height: 28px; padding: 2px 6px; font-size: 12px; width: auto; margin-left: 4px; }

/* SEMPRE por último: o atributo hidden vence qualquer display definido acima (backdrop do modal, topbar, sidenav, painel) */
.modal-backdrop[hidden], .topbar[hidden], .sidenav[hidden], .panel[hidden], [hidden] { display: none !important; }
