/* Estilos do mapa. A estrutura (sidebar/topbar) vem de app.css. */
:root {
  --side-bg: var(--bg); --panel: var(--card); --text2: #334155; --muted2: #475569; --line2: var(--line);
  --btnbg: #f1f5f9; --btnline: #94a3b8; --map-bg: #e5e7eb;
  --okfg: #166534; --errfg: #991b1b; --infofg: #075985; --overbg: #eff6ff;
  --warnbox-bg: #fef3c7; --warnbox-fg: #78350f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text2: #c9d1db; --muted2: #a3adba; --btnbg: #1e242c; --btnline: #3a4350; --map-bg: #1e242c;
    --okfg: #6ee7b7; --errfg: #ff9b8f; --infofg: #93c5fd; --overbg: #13283a;
    --warnbox-bg: #3a2e12; --warnbox-fg: #fcd34d;
  }
}
:root[data-theme="dark"] {
  --text2: #c9d1db; --muted2: #a3adba; --btnbg: #1e242c; --btnline: #3a4350; --map-bg: #1e242c;
  --okfg: #6ee7b7; --errfg: #ff9b8f; --infofg: #93c5fd; --overbg: #13283a;
  --warnbox-bg: #3a2e12; --warnbox-fg: #fcd34d;
}

/* ---- tela do mapa: altura cheia, sem rolagem do documento ---- */
body.map-page, body.map-page .app-main { height: 100vh; height: 100dvh; overflow: hidden; }
.map-body { display: flex; min-height: 0; }

#mapwrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--map-bg); z-index: 0; }

#connDot { margin-right: 0; }

#warn {
  display: none; position: absolute; left: 12px; right: 12px; bottom: 16px; z-index: 700;
  max-width: 420px; margin: 0 auto; padding: 9px 12px; border-radius: 9px;
  background: var(--warnbox-bg); color: var(--warnbox-fg); font-size: 13px;
  box-shadow: var(--shadow-md, 0 8px 24px rgba(0,0,0,.18));
}

/* ---- painel lateral (frota / viagens) ---- */
#side {
  width: 344px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--side-bg); border-left: 1px solid var(--line);
}
.sheet-bar { display: none; }
.sheet-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.tab {
  flex: 1; padding: 11px 10px; font: inherit; font-size: 13px; font-weight: 600;
  border: 0; border-radius: 0; background: none; cursor: pointer;
  border-bottom: 3px solid transparent; color: var(--muted2);
}
.tab:hover:not(:disabled) { background: var(--code); color: var(--text); }
.tab.on, .tab.on:hover:not(:disabled) { color: var(--text); border-bottom-color: var(--accent); }

.pane {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 0;
}

.card {
  border: 1px solid var(--line2); border-left: 5px solid var(--line2); border-radius: 10px;
  background: var(--panel); padding: 9px 11px; cursor: pointer;
  font-size: 13px; line-height: 1.45; box-shadow: none;
}
.card.sel { border-color: var(--text); box-shadow: 0 2px 10px rgba(15,23,42,.18); }
.card .top { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; }
.card .dot { margin: 0; width: 10px; height: 10px; border-radius: 50%; background: #64748b; flex: none; }
.card .st { margin-left: auto; font-weight: 600; font-size: 12px; color: var(--muted2); }
.card .row { color: var(--text2); overflow-wrap: anywhere; }
.card .row.warn { color: var(--warn); }
.card button {
  margin-top: 7px; font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 7px;
  border: 1px solid var(--btnline); background: var(--btnbg); color: var(--text); cursor: pointer;
}
.card a { font-size: 12px; margin-left: 8px; color: var(--accent); }

.box {
  background: var(--panel); border: 1px solid var(--line2); border-radius: 10px;
  padding: 11px; font-size: 13px; display: flex; flex-direction: column; gap: 7px;
}
.drop {
  display: block; border: 2px dashed var(--btnline); border-radius: 10px; padding: 16px 8px;
  text-align: center; color: var(--muted2); cursor: pointer; background: var(--side-bg);
}
.drop.over { border-color: var(--accent); background: var(--overbg); }
.kv { display: grid; grid-template-columns: 82px 1fr; gap: 3px 8px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { font-weight: 600; word-break: break-word; }

.msg { font-size: 12px; padding: 7px 9px; border-radius: 7px; }
.msg.err { background: var(--badbg); color: var(--errfg); }
.msg.ok { background: var(--okbg); color: var(--okfg); }
.msg.info { background: var(--infobg); color: var(--infofg); }
.empty { color: var(--muted); font-size: 13px; padding: 10px; }

.bar { height: 8px; background: var(--line2); border-radius: 99px; overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; background: #16a34a; width: 0; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-size: 13px; padding: 7px 12px; }
.btn:disabled { opacity: .55; cursor: wait; }
select.sel {
  font: inherit; padding: 6px 8px; border-radius: 7px; border: 1px solid var(--btnline);
  background: var(--panel); color: var(--text); width: 100%;
}

.vlabel { background: rgba(15,23,42,.86); color: #fff; border: 0; font-weight: 600; box-shadow: none; }
.vlabel:before { display: none; }
.pin {
  width: 24px; height: 24px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.stop-pin {
  width: 18px; height: 18px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 10px;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}

/* mapa no modo escuro: escurece só os blocos (marcadores e trajetos mantêm as cores) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
  :root:not([data-theme="light"]) .leaflet-bar a,
  :root:not([data-theme="light"]) .leaflet-control-attribution { background: var(--card); color: var(--text); border-color: var(--line); }
  :root:not([data-theme="light"]) .leaflet-control-attribution a { color: var(--accent); }
}
:root[data-theme="dark"] .leaflet-tile-pane .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
:root[data-theme="dark"] .leaflet-bar a,
:root[data-theme="dark"] .leaflet-control-attribution { background: var(--card); color: var(--text); border-color: var(--line); }
:root[data-theme="dark"] .leaflet-control-attribution a { color: var(--accent); }

.tiny { font-size: 11px; }
.mt-6 { margin-top: 6px; }

/* ---- celular / tablet estreito: painel vira gaveta inferior ---- */
@media (max-width: 880px) {
  #side {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 940;
    width: 100%; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0; max-height: 76vh; max-height: 76dvh;
    box-shadow: 0 -14px 44px rgba(2, 6, 23, .28);
    transform: translateY(calc(100% - 56px));
    transition: transform .24s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #side.open { transform: none; }
  .sheet-bar {
    display: flex; align-items: center; gap: 8px; width: 100%; flex: none;
    padding: 10px 16px 12px; border: 0; border-radius: 18px 18px 0 0;
    background: var(--panel); color: var(--text); font: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; border-bottom: 1px solid var(--line);
  }
  .sheet-grip {
    position: absolute; left: 50%; top: 6px; width: 38px; height: 4px; margin-left: -19px;
    border-radius: 99px; background: var(--line);
  }
  .sheet-chevron { margin-left: auto; transition: transform .2s; font-size: 15px; color: var(--muted); }
  #side.open .sheet-chevron { transform: rotate(180deg); }
  #warn { bottom: calc(72px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  #side { transition: none; }
}
