@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;500;600;700;800;900&display=swap');

:root {
  --bg: #0b0b0d;
  --panel: #141418;
  --panel2: #1b1b21;
  --panel3: #232329;
  --line: #2b2b33;
  --text: #f4f1ea;
  --muted: #97938a;
  --gold: #c9a24b;
  --gold-2: #e0bf6e;
  --gold-d: #a5813a;
  --go: #3fae6f;      /* status entregue */
  --arr: #d99a2b;     /* status cheguei  */
  --fail: #d9534f;    /* status falhou   */
  --pend: #63636f;    /* status pendente */
  --blue: #4ea1ff;    /* posicao entregador */
  --shadow: 0 10px 40px rgba(0,0,0,.5);
  --side: 244px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Archivo', system-ui, sans-serif; overscroll-behavior: none; }
button, input, textarea, select { font-family: inherit; }
button { cursor: pointer; border: none; }
.hidden { display: none !important; }
a { color: var(--gold-2); }
::selection { background: var(--gold); color: #000; }

/* ---------- BRAND ---------- */
.wordmark { font-weight: 900; letter-spacing: 2px; text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
.wordmark .mk { color: var(--gold); }
.wordmark .diamond { width: 13px; height: 13px; background: var(--gold); transform: rotate(45deg);
  box-shadow: 0 0 16px rgba(201,162,75,.55); flex: 0 0 auto; }

/* ---------- LOGIN ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(201,162,75,.10), transparent 60%), var(--bg); }
#login .box { width: 100%; max-width: 380px; text-align: center; }
#login .wordmark { font-size: 30px; justify-content: center; margin-bottom: 6px; }
#login .tag { color: var(--muted); font-size: 13px; margin-bottom: 30px; letter-spacing: .5px; }
#login .card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px; }
#login label { display: block; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--muted); font-weight: 600; margin-bottom: 10px; }
#login input { width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 15px; font-size: 18px; text-align: center; letter-spacing: 2px; }
#login .hintcodes { margin-top: 18px; font-size: 12px; color: var(--muted); line-height: 1.7; }
#login .hintcodes b { color: var(--gold-2); }

.btn-gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #17130a; font-weight: 800;
  text-transform: uppercase; letter-spacing: .8px; border-radius: 12px; padding: 15px; font-size: 15px;
  box-shadow: 0 6px 22px rgba(201,162,75,.28); width: 100%; }
.btn-gold:active { transform: translateY(1px); }
.btn-gold:disabled { opacity: .5; box-shadow: none; }

/* ---------- APP SHELL ---------- */
#app { display: none; min-height: 100%; }
#app.on { display: block; }
.shell { display: flex; min-height: 100vh; }

/* sidebar (desktop) */
.side { width: var(--side); background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px; position: fixed; inset: 0 auto 0 0; z-index: 20; }
.side .wordmark { font-size: 19px; padding: 6px 8px 22px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 11px;
  background: transparent; color: var(--muted); font-size: 14.5px; font-weight: 600; text-align: left; width: 100%; }
.nav button .ic { width: 20px; text-align: center; font-size: 16px; }
.nav button.on { background: var(--panel3); color: var(--text); }
.nav button.on .ic { color: var(--gold); }
.nav button:hover { color: var(--text); }
.side .who { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--line); }
.side .who .nm { font-weight: 700; }
.side .who .rl { font-size: 12px; color: var(--gold-2); text-transform: uppercase; letter-spacing: 1px; }
.side .who .out { margin-top: 10px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px; width: 100%; font-size: 13px; font-weight: 600; }

/* main */
.main { flex: 1; margin-left: var(--side); min-width: 0; }
.view { display: none; }
.view.on { display: block; }
.vhead { padding: 22px 26px 14px; }
.vhead h1 { font-size: 26px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; margin: 0; }
.vhead p { color: var(--muted); font-size: 13.5px; margin: 4px 0 0; }
.vbody { padding: 0 26px 90px; }

/* bottom nav (mobile) */
.botnav { display: none; }

/* ---------- CARDS / FORM ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700;
  margin-bottom: 9px; display: block; }
.seg { display: flex; gap: 8px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 12px; border-radius: 11px; background: var(--panel2); color: var(--muted);
  font-weight: 700; font-size: 14px; border: 1px solid var(--line); }
.seg button.on { background: var(--gold); color: #17130a; border-color: var(--gold); }
input, textarea, select { width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 11px; padding: 13px 14px; font-size: 16px; }
textarea { resize: vertical; min-height: 150px; line-height: 1.65; }
input::placeholder, textarea::placeholder { color: #5f5c55; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

/* ---------- turnos ---------- */
.turno-title { font-weight: 800; font-size: 17px; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px;
  display: flex; align-items: baseline; gap: 8px; }
.turno-title span { color: var(--gold-2); font-size: 12px; font-weight: 600; letter-spacing: .5px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 20px, calc(100% - 14px) 20px; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; }

/* ---------- SLOTS de endereco ---------- */
.slot { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.slot .n { flex: 0 0 26px; height: 26px; border-radius: 7px; background: var(--panel3); color: var(--gold-2);
  font-weight: 800; font-size: 13px; display: grid; place-items: center; }
.slot input { flex: 1; padding: 12px 12px; }
.slot .rm { flex: 0 0 auto; width: 38px; height: 44px; border-radius: 10px; background: var(--panel2);
  border: 1px solid var(--line); color: var(--muted); font-size: 18px; }
.addslot { width: 100%; padding: 12px; border-radius: 11px; background: var(--panel2); color: var(--gold-2);
  border: 1px dashed var(--line); font-weight: 700; font-size: 14px; margin-top: 4px; }

/* ---------- NAVEGAÇÃO por dentro ---------- */
.navov { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: none; flex-direction: column; }
.navov.on { display: flex; }
.nav-map { flex: 1; position: relative; }
.nav-map .gmap { position: absolute; inset: 0; }
.nav-top { position: absolute; top: 0; left: 0; right: 0; z-index: 5; padding: 14px 14px 26px;
  background: linear-gradient(180deg, rgba(11,11,13,.96), rgba(11,11,13,0)); display: flex; align-items: center; gap: 12px; }
.nav-man { width: 56px; height: 56px; border-radius: 15px; background: linear-gradient(180deg,var(--gold-2),var(--gold));
  color: #17130a; display: grid; place-items: center; font-size: 28px; font-weight: 800; flex: 0 0 auto; }
.nav-instr { flex: 1; min-width: 0; }
.nav-instr .big { font-weight: 800; font-size: 19px; line-height: 1.2; }
.nav-instr .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.nav-ico { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 11px; background: var(--panel2);
  border: 1px solid var(--line); color: var(--text); font-size: 16px; }
.nav-ico.off { opacity: .45; }
.nav-then { margin-top: 8px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px;
  border-top: 1px solid rgba(255,255,255,.08); padding-top: 7px; }
.nav-then .tm { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  background: var(--panel3); color: var(--gold-2); font-size: 13px; flex: 0 0 auto; }
.nav-speed { position: absolute; left: 14px; bottom: 16px; z-index: 6; background: #fff; color: #111;
  width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.4);
  border: 3px solid #d0d0d0; line-height: 1; }
.nav-speed b { font-size: 22px; font-weight: 900; }
.nav-speed span { font-size: 9px; font-weight: 700; color: #666; text-transform: uppercase; letter-spacing: .5px; }
.nav-destbar { padding: 8px 16px; font-size: 12.5px; color: var(--muted); background: var(--bg);
  border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-recenter { position: absolute; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 6;
  background: var(--panel); border: 1px solid var(--gold-d); color: var(--gold-2); font-weight: 700;
  padding: 10px 18px; border-radius: 22px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.nav-bot { position: static; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.nav-eta { flex: 1; }
.nav-eta .big { font-weight: 900; font-size: 22px; letter-spacing: -.5px; }
.nav-eta .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.nav-recalc { flex: 0 0 auto; width: 50px; height: 50px; border-radius: 13px; background: var(--panel2);
  border: 1px solid var(--line); color: var(--text); font-size: 20px; }
.nav-done { flex: 0 0 auto; padding: 0 22px; height: 50px; border-radius: 13px; background: var(--go); color: #04140c;
  font-weight: 800; font-size: 16px; }

/* ---------- KPI TILES ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--gold); opacity: .8; }
.kpi .k-lbl { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.kpi .k-val { font-size: 34px; font-weight: 900; margin-top: 8px; line-height: 1; letter-spacing: -.5px; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi.gold .k-val { color: var(--gold-2); }

/* ---------- MAPA ---------- */
.maparea { position: relative; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.maparea.tall { height: 60vh; min-height: 380px; }
.maparea.full { height: calc(100vh - 220px); min-height: 420px; }
.gmap { width: 100%; height: 100%; }

/* ---------- LISTA ENTREGADORES / ROTAS ---------- */
.drv { display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; cursor: pointer; transition: border-color .15s; }
.drv:hover { border-color: var(--gold-d); }
.drv .av { width: 44px; height: 44px; border-radius: 12px; background: var(--panel3); display: grid; place-items: center;
  font-weight: 800; font-size: 18px; color: var(--gold-2); flex: 0 0 auto; }
.drv .info { flex: 1; min-width: 0; }
.drv .info .nm { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.drv .info .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot.on { background: var(--go); box-shadow: 0 0 8px var(--go); }
.dot.off { background: var(--pend); }
.drv .prog { text-align: right; flex: 0 0 auto; }
.drv .prog .big { font-weight: 800; font-size: 18px; }
.drv .prog .small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.mini { height: 6px; border-radius: 4px; background: var(--panel3); overflow: hidden; margin-top: 6px; width: 90px; }
.mini > i { display: block; height: 100%; background: var(--gold); }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-size: 44px; margin-bottom: 10px; opacity: .5; }

/* progress bar / stop list (reaproveitado no run + drilldown) */
.progress { margin-bottom: 14px; }
.progress .bar { height: 9px; border-radius: 6px; background: var(--panel2); overflow: hidden; }
.progress .bar > i { display: block; height: 100%; background: var(--gold); width: 0; transition: width .4s; }
.progress .txt { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 8px; }
.progress .txt b { color: var(--text); font-size: 15px; }

.stop { display: flex; gap: 12px; padding: 13px; border-radius: 14px; background: var(--panel);
  border: 1px solid var(--line); margin-bottom: 10px; align-items: flex-start; }
.stop.next { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.stop .num { flex: 0 0 34px; height: 34px; border-radius: 9px; background: var(--pend); color: #fff;
  font-weight: 800; font-size: 17px; display: grid; place-items: center; }
.stop.s-entregue .num { background: var(--go); }
.stop.s-cheguei .num { background: var(--arr); }
.stop.s-falhou .num { background: var(--fail); }
.stop .body { flex: 1; min-width: 0; }
.stop .addr { font-weight: 600; font-size: 15px; line-height: 1.3; }
.stop .cust { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; padding: 3px 8px;
  border-radius: 6px; display: inline-block; margin-top: 7px; }
.tag.pendente { background: #2a2a33; color: var(--muted); }
.tag.cheguei { background: rgba(217,154,43,.16); color: var(--arr); }
.tag.entregue { background: rgba(63,174,111,.16); color: var(--go); }
.tag.falhou { background: rgba(217,83,79,.16); color: var(--fail); }
.stop .acts { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.stop .acts button { flex: 1; min-width: 88px; padding: 11px; border-radius: 10px; font-weight: 800; font-size: 13px; }
.b-nav { background: var(--gold); color: #17130a; }
.b-arr { background: var(--panel2); color: var(--arr); border: 1px solid var(--arr) !important; }
.b-done { background: var(--go); color: #04140c; }
.b-fail { background: var(--panel2); color: var(--fail); border: 1px solid #4a2a2a !important; }
.stop .thumbs { display: flex; gap: 6px; margin-top: 9px; }
.stop .thumbs img { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }

/* run view (entregador em rota) — mapa no topo, lista abaixo */
.runwrap { display: grid; grid-template-columns: 1fr; gap: 16px; }
.run-actions { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.run-actions button { flex: 1; min-width: 120px; padding: 12px; border-radius: 11px; font-weight: 700; font-size: 13.5px;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.run-actions button.primary { background: var(--gold); color: #17130a; border-color: var(--gold); }

/* ---------- MODAL ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(4,4,6,.8); display: flex; align-items: flex-end; }
.modal .box { background: var(--panel); width: 100%; max-width: 560px; margin: 0 auto; border-radius: 20px 20px 0 0;
  padding: 20px; max-height: 94vh; overflow-y: auto; }
.modal h2 { font-size: 22px; text-transform: uppercase; margin: 0 0 2px; }
.modal .maddr { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.sigwrap { position: relative; }
.sigwrap canvas { width: 100%; height: 170px; background: #fff; border-radius: 12px; touch-action: none; }
.sigwrap .clr { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px;
  padding: 5px 10px; border-radius: 8px; }
.photo-btn { width: 100%; padding: 16px; border-radius: 12px; background: var(--panel2); border: 1px dashed var(--line);
  color: var(--muted); font-weight: 600; font-size: 15px; }
.photo-prev { width: 100%; border-radius: 12px; margin-top: 8px; max-height: 240px; object-fit: cover; }
.modal .row2 { display: flex; gap: 10px; margin-top: 16px; }
.modal .row2 button { flex: 1; padding: 15px; border-radius: 12px; font-weight: 800; font-size: 16px; }
.b-cancel { background: var(--panel2); color: var(--muted); }
.b-save { background: var(--go); color: #04140c; }

/* modal centralizado (novo entregador) */
.modal.center { align-items: center; padding: 20px; }
.modal.center .box { border-radius: 18px; }

/* ---------- utils ---------- */
.toast { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); z-index: 90; background: #000;
  color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; border: 1px solid var(--line);
  opacity: 0; transition: opacity .3s; pointer-events: none; max-width: 90%; text-align: center; }
.toast.show { opacity: 1; }
.loading { position: fixed; inset: 0; z-index: 95; background: rgba(8,8,10,.9); display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.loading.show { display: flex; }
.spin { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--gold); border-radius: 50%;
  animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.livepill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); padding: 6px 12px; border-radius: 20px; }
.livepill .d { width: 8px; height: 8px; border-radius: 50%; background: var(--go); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- RESPONSIVO (mobile) ---------- */
@media (max-width: 860px) {
  .side { display: none; }
  .main { margin-left: 0; }
  .vhead { padding: 18px 16px 10px; }
  .vhead h1 { font-size: 22px; }
  .vbody { padding: 0 16px 96px; }
  .maparea.full { height: 56vh; }
  .botnav { display: flex; position: fixed; inset: auto 0 0 0; z-index: 40; background: var(--panel);
    border-top: 1px solid var(--line); padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); }
  .botnav button { flex: 1; background: transparent; color: var(--muted); display: flex; flex-direction: column;
    align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700; padding: 4px; }
  .botnav button .ic { font-size: 19px; }
  .botnav button.on { color: var(--gold); }
  .topmob { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; background: var(--bg); z-index: 15; }
  .topmob .wordmark { font-size: 16px; }
  .topmob .out { margin-left: auto; background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
    border-radius: 9px; padding: 7px 12px; font-size: 12px; font-weight: 700; }
}
@media (min-width: 861px) { .topmob { display: none; } }

/* mapa aberto (claro de dia): faixa de instruções com fundo sólido pra ler no sol */
.nav-top { background: rgba(11,11,13,.94) !important; border-bottom: 1px solid rgba(201,162,75,.35); padding-bottom: 14px !important;
  box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.maplibregl-ctrl-attrib { font-size: 10px; }
