:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0f172a;
  --surface-2: #111d33;
  --surface-3: #17233a;
  --text: #e5edf8;
  --muted: #99a8bd;
  --line: rgba(148, 163, 184, .22);
  --primary: #38bdf8;
  --primary-strong: #0ea5e9;
  --success: #22c55e;
  --danger: #fb7185;
  --warning: #f59e0b;
  --shadow: 0 22px 70px rgba(0, 0, 0, .35);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, .2), transparent 34rem),
    radial-gradient(circle at 90% 10%, rgba(34, 197, 94, .12), transparent 24rem),
    linear-gradient(180deg, #081120 0%, #060b14 100%);
  padding: env(safe-area-inset-top) 0 calc(88px + env(safe-area-inset-bottom));
}

button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 16px;
  min-height: 46px;
  padding: 12px 16px;
  color: var(--text);
  background: var(--surface-3);
  cursor: pointer;
  font-weight: 750;
  touch-action: manipulation;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: linear-gradient(135deg, var(--primary), var(--primary-strong)); color: #03111d; }
.success { background: linear-gradient(135deg, #4ade80, var(--success)); color: #031408; }
.secondary { background: linear-gradient(135deg, #818cf8, #38bdf8); color: #07111f; }
.danger { background: linear-gradient(135deg, #fb7185, #f43f5e); color: #25020a; }
.ghost { background: rgba(148, 163, 184, .12); color: var(--text); border: 1px solid var(--line); }
.small { min-height: 36px; padding: 8px 12px; border-radius: 12px; font-size: .86rem; }

.app-shell { width: min(1120px, 100%); margin: 0 auto; padding: 14px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.32rem, 5vw, 2.1rem); letter-spacing: -.04em; }
h2 { font-size: clamp(1.18rem, 4vw, 1.7rem); letter-spacing: -.03em; margin-top: 6px; }
h3 { font-size: 1.03rem; letter-spacing: -.02em; }
.eyebrow { color: var(--primary); text-transform: uppercase; font-size: .72rem; font-weight: 850; letter-spacing: .12em; }
.muted { color: var(--muted); font-size: .92rem; line-height: 1.45; }

.card {
  background: linear-gradient(180deg, rgba(15, 23, 42, .94), rgba(15, 23, 42, .86));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(18px);
}
.stack { display: grid; gap: 14px; }
.hero { position: relative; overflow: hidden; }
.hero::after {
  content: "";
  position: absolute;
  inset: auto -18% -40% 42%;
  height: 170px;
  background: radial-gradient(circle, rgba(56, 189, 248, .18), transparent 70%);
  pointer-events: none;
}
.hero-main { position: relative; z-index: 1; display: grid; gap: 16px; }
.hero-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.quality-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 850;
  background: rgba(245, 158, 11, .15);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, .35);
}
.quality-pill.good { background: rgba(34, 197, 94, .14); color: #86efac; border-color: rgba(34, 197, 94, .34); }
.quality-pill.mid { background: rgba(56, 189, 248, .14); color: #7dd3fc; border-color: rgba(56, 189, 248, .34); }
.quality-pill.low { background: rgba(251, 113, 133, .14); color: #fda4af; border-color: rgba(251, 113, 133, .34); }

.progress-wrap { height: 11px; background: rgba(148, 163, 184, .16); border-radius: 999px; margin: 16px 0 14px; overflow: hidden; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--success)); transition: width .25s ease; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpis div { background: rgba(148, 163, 184, .1); border: 1px solid rgba(148, 163, 184, .14); border-radius: 18px; padding: 12px; }
.kpis strong { display: block; font-size: 1.22rem; letter-spacing: -.03em; }
.kpis span { display: block; color: var(--muted); font-size: .78rem; margin-top: 2px; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 12px 0;
  padding: 7px;
  background: rgba(7, 17, 31, .76);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(148, 163, 184, .16);
  border-radius: 18px;
}
.tab { min-height: 40px; padding: 8px 6px; border-radius: 13px; background: transparent; color: var(--muted); font-size: .78rem; }
.tab.active { background: rgba(56, 189, 248, .16); color: var(--text); }
.view { display: none; }
.view.active { display: grid; gap: 14px; }
.content { display: grid; gap: 14px; }

.grid { display: grid; gap: 14px; }
.two { grid-template-columns: 1fr; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.section-head.compact { align-items: center; }
.toolbar { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1 1 220px; }
.field { display: grid; gap: 7px; }
.field span, .switch-line span { color: var(--muted); font-size: .82rem; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(2, 6, 23, .38);
  padding: 11px 12px;
  outline: none;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: rgba(56, 189, 248, .75); box-shadow: 0 0 0 3px rgba(56, 189, 248, .12); }
.switch-line { display: flex; align-items: center; gap: 10px; }
.switch-line input { width: 22px; min-height: 22px; accent-color: var(--primary); }
.button-row, .button-grid { display: grid; gap: 10px; }
.button-grid { grid-template-columns: 1fr; }
.note { border-radius: 16px; padding: 12px; border: 1px solid var(--line); background: rgba(148, 163, 184, .1); color: var(--muted); font-size: .9rem; line-height: 1.45; }
.note.warning { background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .3); color: #fde68a; }
.log { display: grid; gap: 8px; max-height: 280px; overflow: auto; padding-right: 3px; }
.log-entry { border: 1px solid var(--line); border-radius: 14px; padding: 10px; color: var(--muted); background: rgba(148, 163, 184, .08); font-size: .86rem; line-height: 1.35; }
.log-entry strong { color: var(--text); }

.route-list, .timeline { display: grid; gap: 10px; }
.stop-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(15, 23, 42, .9);
  padding: 14px;
  display: grid;
  gap: 12px;
}
.stop-card.done { opacity: .72; background: rgba(20, 83, 45, .18); }
.stop-card.skipped { opacity: .68; background: rgba(127, 29, 29, .2); }
.stop-head { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; }
.stop-index { width: 38px; height: 38px; border-radius: 14px; display: grid; place-items: center; background: rgba(56, 189, 248, .15); color: #7dd3fc; font-weight: 900; }
.stop-title { font-weight: 900; line-height: 1.2; }
.stop-sub { color: var(--muted); font-size: .86rem; margin-top: 4px; line-height: 1.35; }
.stop-status { display: flex; align-items: center; gap: 8px; }
.stop-status input { width: 25px; min-height: 25px; accent-color: var(--success); }
.badge-row { display: flex; flex-wrap: wrap; gap: 7px; }
.badge { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: 999px; background: rgba(148, 163, 184, .12); color: var(--muted); border: 1px solid rgba(148, 163, 184, .16); font-size: .76rem; font-weight: 750; }
.badge.good { color: #86efac; background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .25); }
.badge.warn { color: #fde68a; background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .25); }
.badge.bad { color: #fda4af; background: rgba(251, 113, 133, .12); border-color: rgba(251, 113, 133, .25); }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card-actions.three { grid-template-columns: 1fr 1fr 1fr; }
.card-actions button { min-height: 42px; padding: 9px 10px; border-radius: 13px; font-size: .86rem; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.details-grid .field input { min-height: 40px; }
.inline-label { color: var(--muted); font-size: .76rem; font-weight: 800; display: block; margin-bottom: 5px; }
.next-card { border-color: rgba(56, 189, 248, .45); background: linear-gradient(180deg, rgba(14, 165, 233, .17), rgba(15, 23, 42, .9)); }
.timeline-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 11px; border-radius: 16px; border: 1px solid var(--line); background: rgba(148, 163, 184, .08); }
.timeline-num { width: 31px; height: 31px; border-radius: 12px; display: grid; place-items: center; background: rgba(56, 189, 248, .14); color: #7dd3fc; font-size: .82rem; font-weight: 900; }
.timeline-title { font-weight: 800; font-size: .92rem; }
.timeline-meta { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.timeline-time { text-align: right; font-size: .82rem; font-weight: 850; }
.map-box { position: relative; min-height: 420px; border-radius: 22px; border: 1px solid var(--line); background: rgba(2, 6, 23, .45); overflow: hidden; display: block; }
.route-map-canvas { width: 100%; height: min(70vh, 640px); min-height: 420px; }
.leaflet-container { background: #020617; color: #0f172a; font: inherit; }
.leaflet-popup-content { color: #0f172a; line-height: 1.35; }
.map-empty { color: var(--muted); text-align: center; padding: 40px 16px; line-height: 1.45; }
.diagnostics { display: grid; gap: 8px; }
.diagnostic-line { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(148, 163, 184, .12); padding: 9px 0; }
.diagnostic-line span:first-child { color: var(--muted); }
.file-pick { display: grid; place-items: center; min-height: 46px; border: 1px dashed rgba(148, 163, 184, .4); border-radius: 16px; color: var(--text); background: rgba(148, 163, 184, .08); font-weight: 800; cursor: pointer; }
.file-pick input { display: none; }
.bottom-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(7, 17, 31, .9);
  border-top: 1px solid rgba(148, 163, 184, .2);
  backdrop-filter: blur(18px);
}
.bottom-actions button { min-height: 54px; border-radius: 18px; }
.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 60;
  display: none;
  padding: 13px 14px;
  border-radius: 16px;
  background: #e5edf8;
  color: #07111f;
  box-shadow: var(--shadow);
  font-weight: 800;
  line-height: 1.35;
}
.toast.show { display: block; }

@media (min-width: 720px) {
  body { padding-bottom: 24px; }
  .app-shell { padding: 22px; }
  .hero-main { grid-template-columns: 1fr auto; align-items: center; }
  .hero-actions { grid-template-columns: repeat(3, auto); }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .button-row { grid-template-columns: 1fr 1fr; }
  .button-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .card-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .bottom-actions { display: none; }
  .tab { font-size: .9rem; }
}

@media print {
  body { background: white; color: black; padding: 0; }
  .topbar, .tabs, .hero-actions, .bottom-actions, .toolbar, #view-otimizador, #view-mapa, #view-ajustes, .toast { display: none !important; }
  .view { display: block !important; }
  .card, .stop-card { box-shadow: none; border: 1px solid #bbb; background: white; color: black; break-inside: avoid; }
  .muted, .stop-sub, .badge { color: #333; }
}
