/* Roteirizador Beep — tokens de tema (claro/escuro) e layout das duas telas. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --hairline: #e1e0d9;
  --accent: #2a78d6;
  --accent-strong: #1c5cab;
  --critical: #d03b3b;
  --warning-bg: #fdf3dc;
  --warning-border: #eda100;
  --error-bg: #fbe9e9;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --hairline: #2c2c2a;
    --accent: #3987e5;
    --accent-strong: #6da7ec;
    --critical: #e66767;
    --warning-bg: #33290f;
    --warning-border: #c98500;
    --error-bg: #391d1d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.screen {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}
/* A tela de resultados usa quase toda a largura: prioridade é o mapa. */
#screen-results { max-width: 1560px; }

/* ---------- Cabeçalho ---------- */

.page-header h1 { margin: 0 0 4px; font-size: 26px; }
.subtitle { margin: 0 0 24px; color: var(--text-secondary); }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.header-actions { display: flex; gap: 8px; }

/* ---------- Dropzone ---------- */

.dropzone {
  border: 2px dashed var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragging {
  border-color: var(--accent);
  outline: none;
}
.dropzone-icon { font-size: 34px; display: block; margin-bottom: 8px; }
.dropzone p { margin: 4px 0; }

.hint { color: var(--text-muted); font-size: 13px; }

.file-chip {
  display: inline-block;
  margin: 20px 0 4px;
  padding: 4px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---------- Stat tiles ---------- */

.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0 24px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-value { font-size: 30px; font-weight: 650; }
.stat-value-sm { font-size: 22px; padding-top: 6px; }
.stat-label { color: var(--text-secondary); font-size: 13px; }
.stat-sub { color: var(--text-muted); font-size: 12px; }
.stat-critical { color: var(--critical); }
.stat-critical::before { content: "⚠ "; font-size: 20px; }

/* Tile largo: distribuição do tempo (barra 100% empilhada). */
.tile-wide { grid-column: span 2; justify-content: center; gap: 8px; }
@media (max-width: 900px) { .tile-wide { grid-column: span 1; } }

.dist-bar {
  display: flex;
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--page);
}
.dist-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  min-width: 2px;
  cursor: default;
}
/* Segmentos claros (ocioso) precisam de tinta escura para ler o rótulo. */
.dist-seg.seg-ocioso { color: #3a3935; }
.dist-legend { margin: 0; font-size: 12px; }

/* ---------- Formulário ---------- */

.solve-form {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-secondary); }
.field select, .field input {
  padding: 9px 12px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  font: inherit;
  min-width: 220px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn-primary {
  padding: 10px 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-primary:disabled { opacity: 0.55; cursor: wait; }

.btn-secondary {
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--accent); }

/* ---------- Status de solving ---------- */

.solving-status {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 20px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.solving-status p { margin: 0; }

.spinner {
  width: 22px;
  height: 22px;
  flex: none;
  border: 3px solid var(--hairline);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Banners ---------- */

.error-banner {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--error-bg);
  border-left: 3px solid var(--critical);
  border-radius: 6px;
  color: var(--text-primary);
}

.warning-banner {
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--warning-bg);
  border-left: 3px solid var(--warning-border);
  border-radius: 6px;
}

/* ---------- Chips (filtro de depósito) ---------- */

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--page);
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.12s;
}
.chip .swatch { margin: 0; opacity: 0.35; }
.chip.active {
  color: var(--text-primary);
  border-color: var(--border);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.chip.active .swatch { opacity: 1; }
.chip:hover { border-color: var(--accent); }

/* ---------- Mapa ---------- */

.map {
  width: 100%;
  height: 74vh;
  min-height: 560px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  margin-bottom: 24px;
}
@media (max-width: 900px) {
  .map { height: 60vh; min-height: 420px; }
}

/* ---------- Cards de rota + timeline ---------- */

.section-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.section-title { font-size: 18px; margin: 0; }

.depot-title {
  font-size: 14.5px;
  margin: 18px 0 8px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.depot-group:first-child .depot-title { margin-top: 4px; }

.eye-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--page);
  color: var(--text-secondary);
  cursor: pointer;
  flex: none;
}
.eye-btn:hover { border-color: var(--accent); color: var(--accent); }
.eye-btn.off { color: var(--text-muted); background: transparent; }

.timeline-legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.timeline-legend span { display: inline-flex; align-items: center; gap: 6px; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  flex: none;
}
.dot-deslocamento { background: #2a78d6; }
.dot-atendimento { background: #1baf7a; }
.dot-ocioso { background: #b3b1a8; }
.dot-almoco { background: #eda100; }
.dot-critical { background: var(--critical); border-radius: 50%; margin-right: 6px; }

.route-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px 18px;
  margin-bottom: 12px;
}

.route-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.route-card-header .swatch { margin: 0; }

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--border);
  flex: none;
}
.route-info { display: flex; flex-direction: column; min-width: 240px; }
.route-label { font-weight: 600; font-size: 14.5px; }
.route-meta { color: var(--text-muted); font-size: 12.5px; }

.route-totals {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}
.total-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--page);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 3px 10px;
}

.btn-sm { padding: 5px 12px; font-size: 13px; }

/* Timeline: barra horizontal em escala de tempo compartilhada entre rotas. */
.timeline {
  position: relative;
  height: 40px;
  background: var(--page);
  border-radius: 6px;
  overflow: hidden;
}
.timeline .seg {
  position: absolute;
  top: 4px;
  height: 22px;
  border-radius: 3px;
}
.seg-deslocamento { background: #2a78d6; }
.seg-atendimento { background: #1baf7a; }
.seg-ocioso { background: #b3b1a8; }
.seg-almoco { background: #eda100; }

.timeline .tick {
  position: absolute;
  top: 0;
  bottom: 14px;
  width: 1px;
  background: var(--hairline);
}
.timeline .tick-label {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.2;
}

/* ---------- Tabela de paradas ---------- */

.stops-wrap { margin-top: 12px; overflow-x: auto; }

.stops-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.stops-table th, .stops-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  white-space: nowrap;
}
.stops-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
}
.stops-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.stops-table .return-row td { color: var(--text-secondary); font-style: italic; }
.stops-table tbody tr:hover { background: var(--page); }

/* ---------- Não roteirizados ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.panel-header h2 { margin: 0 0 6px; font-size: 15px; }

.dropped-panel { margin-top: 20px; border-left: 3px solid var(--critical); }

.dropped-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}
.dropped-item {
  padding: 7px 0;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
}
.dropped-item:last-child { border-bottom: none; }
.dropped-label { font-size: 14px; font-weight: 600; display: flex; align-items: center; }

.badge-critical {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  background: var(--critical);
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  padding: 1px 7px;
  margin-left: 4px;
}

/* ---------- Cache Management ---------- */

.cache-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}
.cache-table th {
  padding: 8px 12px;
  text-align: left;
  background: var(--page);
  border-bottom: 1px solid var(--hairline);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
}
.cache-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--hairline);
}
.cache-table tr:hover { background: var(--page); }
.cache-table .btn-delete {
  background: var(--critical);
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.cache-table .btn-delete:hover { opacity: 0.8; }

.btn-danger {
  background: var(--critical);
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.btn-danger:hover { opacity: 0.9; }

.success-banner {
  background: #d4edda;
  border: 1px solid #c3e6cb;
  color: #155724;
  padding: 12px 14px;
  border-radius: 6px;
  margin: 8px 0;
}

@media (prefers-color-scheme: dark) {
  .cache-table th { background: var(--page); }
  .cache-table tr:hover { background: var(--page); }
  .success-banner {
    background: #1e4620;
    border-color: #2d6b3f;
    color: #a8e6b8;
  }
}
