/* CATPRO Dashboard — dark theme, mobile-first */
:root {
  --bg: #0b0f17;
  --bg-soft: #131a26;
  --bg-panel: #1a2332;
  --fg: #e6edf6;
  --fg-soft: #98a8be;
  --accent: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --line: #243349;
  --side-w: 260px;
  --kpis-h: 56px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}
body {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  grid-template-rows: 1fr var(--kpis-h);
  grid-template-areas:
    "side  map"
    "kpis  kpis";
}
body.collapsed { grid-template-columns: 0 1fr; }
body.collapsed .sidebar { transform: translateX(-100%); }
body.collapsed .show-side { display: flex; }

.sidebar {
  grid-area: side;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow-y: auto;
  z-index: 800;
  transition: transform 0.2s ease;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand strong { font-size: 14px; letter-spacing: 0.5px; }
.brand small { color: var(--fg-soft); font-size: 11px; }
.collapse-btn, .show-side {
  background: transparent; color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px;
  width: 28px; height: 28px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.show-side {
  display: none;
  position: absolute; top: 12px; left: 12px; z-index: 700;
  background: var(--bg-panel);
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--bad); display: inline-block;
}
.dot.ok { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

.panel {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel h3 {
  margin: 0 0 8px 0; font-size: 11px;
  text-transform: uppercase; color: var(--fg-soft); letter-spacing: 0.6px;
}
.panel label {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; font-size: 13px;
  cursor: pointer; user-select: none;
}
.panel input[type=checkbox] {
  accent-color: var(--accent);
  width: 14px; height: 14px;
}
.day-toggles label small { color: var(--fg-soft); font-size: 11px; margin-left: auto; }
.meta-panel small { color: var(--fg-soft); font-size: 10px; line-height: 1.4; }

.map-wrap {
  grid-area: map;
  position: relative;
  background: #0b0f17;
}
#map { width: 100%; height: 100%; }
.legend {
  position: absolute; bottom: 12px; right: 12px;
  background: rgba(19, 26, 38, 0.92);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 600;
  pointer-events: none;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 8px; height: 8px; }

.kpis {
  grid-area: kpis;
  background: var(--bg-panel);
  border-top: 1px solid var(--line);
  display: flex; align-items: center;
  padding: 0 12px;
  gap: 14px;
  overflow-x: auto;
  white-space: nowrap;
}
.kpi {
  display: flex; flex-direction: column;
  padding: 4px 10px;
  border-right: 1px solid var(--line);
  min-width: 78px;
}
.kpi:last-child { border-right: none; }
.kpi .lbl { font-size: 9px; color: var(--fg-soft); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi .val { font-size: 14px; font-weight: 600; }

/* Markers customizados */
.cat-marker svg { display: block; }

/* Operator marker ripple */
@keyframes ripple {
  0% { transform: scale(0.5); opacity: 0.9; }
  100% { transform: scale(2.5); opacity: 0; }
}
.operator-ripple {
  position: relative;
}
.operator-ripple::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.4);
  animation: ripple 1.6s infinite ease-out;
}

/* Popup styling */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel); color: var(--fg);
  border-radius: 8px; border: 1px solid var(--line);
}
.leaflet-popup-tip { background: var(--bg-panel); }
.leaflet-popup-content { margin: 12px 14px; font-size: 12px; line-height: 1.4; }
.leaflet-popup-content h4 { margin: 0 0 4px 0; font-size: 13px; }
.leaflet-popup-content .pp-meta { color: var(--fg-soft); font-size: 11px; margin-top: 4px; }
.leaflet-popup-content .pp-tag {
  display: inline-block; padding: 1px 6px; margin-right: 4px;
  border-radius: 4px; font-size: 10px; background: var(--bg-soft); border: 1px solid var(--line);
}

/* Routes panel */
.routes-list { display: flex; flex-direction: column; gap: 8px; }
.route-card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.route-card .route-head {
  display: flex; justify-content: space-between; align-items: center;
}
.route-card .route-title { font-weight: 600; font-size: 12px; }
.route-card .route-icon {
  width: 22px; height: 22px; border-radius: 4px;
  background: #7B1FA2; color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
}
.route-card .route-desc { color: var(--fg-soft); font-size: 11px; line-height: 1.3; }
.route-card .route-days {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: 4px; padding-top: 4px;
  border-top: 1px solid var(--line);
}
.route-day-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; gap: 6px;
  padding: 2px 0;
}
.route-day-row .day-label { color: var(--fg); font-weight: 500; min-width: 70px; }
.route-day-row .day-kpis { color: var(--fg-soft); font-size: 10px; }
.route-day-row .day-actions { display: flex; gap: 4px; }
.btn-mini {
  background: var(--bg-soft); color: var(--fg);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 2px 6px; font-size: 10px; cursor: pointer;
  white-space: nowrap;
}
.btn-mini:hover { background: var(--bg); border-color: #7B1FA2; }
.btn-mini.active { background: #7B1FA2; border-color: #7B1FA2; color: #fff; }
.btn-mini.activate { background: #16A34A; border-color: #16A34A; color: #fff; }
.btn-mini.activate:hover { background: #15803D; }
.btn-mini.activate.busy { background: #6B7280; border-color: #6B7280; cursor: wait; }
.route-card .route-agg {
  font-size: 11px; color: var(--fg-soft);
  padding: 2px 0;
}
.route-card .route-agg strong { color: var(--fg); font-weight: 600; }

/* Mobile */
@media (max-width: 720px) {
  :root { --side-w: 0; --kpis-h: 64px; }
  body { grid-template-columns: 0 1fr; }
  .sidebar {
    position: absolute;
    top: 0; left: 0;
    width: 280px; height: calc(100% - var(--kpis-h));
    transform: translateX(-100%);
  }
  body.show-side .sidebar { transform: translateX(0); }
  .show-side { display: flex; }
  .kpi { min-width: 68px; }
  .kpi .val { font-size: 12px; }
  .kpi .lbl { font-size: 8px; }
}
