/* ============================================================
   Módulo Rotas Escolares — painel admin + monitor
============================================================ */
#rePanel {
  position: fixed;
  top: 70px;
  /* Ancorado pela ESQUERDA (mesmo aparecendo a direita): com 'resize', a alca
     fica no canto inferior-direito e SEGUE o cursor naturalmente. Se ancorasse
     por 'right', o resize horizontal nao acompanhava o mouse. */
  left: max(16px, calc(100vw - 476px));
  right: auto;
  width: 460px;
  max-width: calc(100vw - 32px);
  height: 78vh;
  max-height: calc(100vh - 90px);
  min-width: 320px;
  min-height: 240px;
  /* Resize por QUALQUER borda/canto e' feito via JS (_enablePanelInteract em
     rotas-escolares.js), ancorando por left/top. O 'resize: both' do CSS so'
     dava o canto inferior-direito — por isso foi removido. */
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
  display: flex;
  flex-direction: column;
  z-index: 1200;
  overflow: hidden;
  font-size: 13px;
  color: #1a2533;
}
#rePanel.hidden { display: none; }
/* Alca de resize bem visivel (dica). pointer-events:none p/ o resizer nativo atuar. */
#rePanel::after {
  content: "";
  position: absolute;
  right: 3px; bottom: 3px;
  width: 15px; height: 15px;
  pointer-events: none;
  opacity: .85;
  background:
    linear-gradient(135deg, transparent 0 48%, #7d93a8 48% 60%, transparent 60% 72%, #7d93a8 72% 84%, transparent 84%);
}

.re-header {
  background: #003b73;
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: move;
}
.re-header h2 { margin: 0; font-size: 15px; font-weight: 700; flex: 1; }
.re-header .re-close {
  background: transparent; border: none; color: #fff; font-size: 20px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
.re-header .re-min {
  background: none; border: none; color: #fff; font-size: 15px;
  line-height: 1; cursor: pointer; padding: 2px 6px 0;
}
.re-header .re-estoque {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.35);
  color: #fff; font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 4px 10px; border-radius: 5px; line-height: 1; white-space: nowrap;
}
.re-header .re-estoque:hover { background: rgba(255,255,255,.28); }

.re-tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 8px 0; background: #eef3f8; border-bottom: 1px solid #d1dce8; }
.re-tab {
  border: none; background: transparent; padding: 6px 10px; font-size: 12px; cursor: pointer;
  border-radius: 6px 6px 0 0; color: #34516b; font-weight: 600;
}
.re-tab.active { background: #fff; color: #003b73; box-shadow: 0 -2px 0 #003b73 inset; }

.re-body { flex: 1; overflow-y: auto; padding: 12px 14px; }

.re-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.re-btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 7px;
  font-size: 12px; font-weight: 600; cursor: pointer; border: none; background: #003b73; color: #fff;
}
.re-btn:hover { background: #002b54; }
.re-btn.outline { background: #fff; color: #003b73; border: 1.5px solid #003b73; }
.re-btn.danger { background: #c0392b; }
.re-btn.sm { padding: 3px 8px; font-size: 11px; }
.re-btn:disabled { opacity: .5; cursor: not-allowed; }

.re-list { display: flex; flex-direction: column; gap: 6px; }
.re-card {
  border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px 10px; background: #fbfdff;
  display: flex; align-items: center; gap: 8px;
}
.re-card .re-card-main { flex: 1; min-width: 0; }
.re-card .re-card-title { font-weight: 700; }
.re-card .re-card-sub { font-size: 11px; color: #667; }
.re-card .re-card-actions { display: flex; gap: 4px; }

.re-form { display: flex; flex-direction: column; gap: 8px; }
.re-form label { font-size: 11px; color: #556; text-transform: uppercase; letter-spacing: .03em; display: block; margin-bottom: 2px; }
.re-form input, .re-form select, .re-form textarea {
  width: 100%; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; box-sizing: border-box;
}
.re-form .re-row { display: flex; gap: 8px; }
.re-form .re-row > div { flex: 1; }
.re-form-actions { display: flex; gap: 8px; margin-top: 6px; }

.re-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.re-stat { flex: 1; min-width: 90px; text-align: center; border-radius: 8px; padding: 9px 8px; background: #f1f6fb; border: 1px solid #d8e3ef; }
.re-stat .n { font-size: 20px; font-weight: 700; color: #003b73; }
.re-stat .l { font-size: 10px; color: #667; text-transform: uppercase; }

.re-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.re-table th { text-align: left; font-size: 10px; color: #5a7a99; text-transform: uppercase; padding: 4px 6px; border-bottom: 1px solid #d1dce8; }
.re-table td { padding: 5px 6px; border-bottom: 1px solid #f0f4f8; }

.re-empty { padding: 18px; text-align: center; color: #94a3b8; font-style: italic; }
.re-hint { font-size: 11px; color: #667; margin: 4px 0 8px; }
.re-draw-banner {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  background: #003b73; color: #fff; padding: 8px 16px; border-radius: 20px;
  z-index: 1300; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.re-draw-banner.hidden { display: none; }

.re-badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.re-badge.green { background: #dcfce7; color: #15803d; }
.re-badge.red { background: #fee2e2; color: #b91c1c; }
.re-badge.gray { background: #f1f5f9; color: #475569; }
.re-badge.orange { background: #ffedd5; color: #c2410c; }

/* ── Caixa de seleção (paradas / escolas atendidas) do form de rota ── */
.re-sel-box {
  overflow-y: auto; overflow-x: hidden;
  border: 1px solid #e2e8f0; border-radius: 8px; padding: 4px; background: #fbfdff;
}
/* Linhas de parada (arrastáveis, ordem de embarque) e de escola compartilham o
   layout em flex: checkbox alinhado + nome com reticências. */
.re-par-row, .re-esc-row {
  display: flex; gap: 8px; align-items: center;
  font-size: 13.5px; text-transform: none; margin-bottom: 2px;
  padding: 6px 8px; border-radius: 6px; background: #fff;
}
.re-par-row:hover, .re-esc-row:hover { background: #eef5fc; }
.re-par-row.dragging { opacity: .45; background: #dbeafe; }
.re-par-grip { cursor: grab; color: #94a3b8; font-size: 15px; user-select: none; }
/* o checkbox herda width:100% do .re-form input e colapsa o nome (flex-basis 0) —
   reset + tamanho maior (18px) p/ toque e alinhamento vertical */
.re-par-row input[type="checkbox"], .re-esc-row input[type="checkbox"] {
  width: 18px; height: 18px; flex: none; margin: 0; accent-color: #003b73; cursor: pointer;
}
.re-par-row .re-par-nome, .re-esc-row .re-esc-nome {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.re-par-row input[type="number"] {
  width: 44px; text-align: center; border: 1px solid #e2e8f0; border-radius: 6px;
  background: #f8fafc; color: #475569; font-weight: 600; pointer-events: none;
}

@media (max-width: 520px) {
  #rePanel { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-width: 100%; height: 86vh; border-radius: 12px 12px 0 0; }
}

/* ── Modal de OS (Rotas Escolares) ───────────────────────────── */
.re-os-ov {
  position: fixed; inset: 0; z-index: 100000;
  background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px;
}
.re-os-modal {
  background: #fff; width: 460px; max-width: 100%; max-height: 90vh; overflow: auto;
  border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.3); display: flex; flex-direction: column;
}
.re-os-head {
  background: #003b73; color: #fff; padding: 10px 14px; border-radius: 10px 10px 0 0;
  display: flex; align-items: center; justify-content: space-between; font-size: 15px;
}
.re-os-x { background: transparent; border: none; color: #fff; font-size: 20px; cursor: pointer; line-height: 1; }
.re-os-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.re-os-body label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: #334155; }
.re-os-body input, .re-os-body select, .re-os-body textarea {
  font-size: 13px; padding: 7px 8px; border: 1px solid #cbd5e1; border-radius: 6px; box-sizing: border-box; font-weight: 400;
}
.re-os-row { display: flex; gap: 10px; }
.re-os-row label { flex: 1; }
.re-os-foot { padding: 10px 14px; border-top: 1px solid #e2e8f0; display: flex; justify-content: flex-end; gap: 8px; }

/* ── Popup "Editar/Nova Rota" (design 2 colunas; arrastável + resize nativo) ── */
#reRotaPopup {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  width: 740px; max-width: 94vw; max-height: calc(100vh - 84px);
  min-width: 540px; min-height: 400px;
  background: #fff; border-radius: 10px; box-shadow: 0 14px 44px rgba(0, 0, 0, .38);
  z-index: 10600; display: flex; flex-direction: column;
  resize: both; overflow: hidden;
}
#reRotaPopup .re-pop-hd {
  background: #003b73; color: #fff; padding: 9px 14px; font-weight: 700; font-size: 14.5px;
  display: flex; align-items: center; gap: 8px; cursor: move; user-select: none; flex: 0 0 auto;
}
#reRotaPopup .re-pop-x {
  margin-left: auto; background: none; border: none; color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px;
}
#reRotaPopup .re-pop-min {
  margin-left: auto; background: none; border: none; color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer; padding: 2px 4px 0;
}
#reRotaPopup .re-pop-min + .re-pop-x { margin-left: 0; }
/* estado minimizado: só a barra de título (JS esconde as partes com esta classe) */
.re-minimized-hide { display: none !important; }
#reRotaPopup .re-pop-body { flex: 1 1 auto; overflow: auto; padding: 12px 14px; }
.re-pop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; align-items: start; }
@media (max-width: 780px) { .re-pop-grid { grid-template-columns: 1fr; } #reRotaPopup { min-width: 0; } }
.re-pop-col { min-width: 0; }
.re-pop-sec {
  font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: #0b5cab; border-bottom: 1px solid #e2e8f0; padding-bottom: 4px; margin-bottom: 8px;
}
.re-pop-foot {
  flex: 0 0 auto; border-top: 1px solid #e2e8f0; background: #f8fafc;
  padding: 8px 14px 10px; display: flex; flex-direction: column; gap: 6px;
}
.re-pop-frow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.re-pop-flab {
  flex: 0 0 74px; font-size: 11px; font-weight: 800; letter-spacing: .05em;
  text-transform: uppercase; color: #52606d;
}
.re-pop-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
