* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1565C0;
  --primary-dark: #0D47A1;
  --success: #2E7D32;
  --warning: #F57F17;
  --danger: #C62828;
  --info: #1565C0;
  --bg: #F5F7FA;
  --sidebar-w: 380px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── HEADER ── */
header {
  background: var(--primary);
  color: white;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  z-index: 10;
  flex-shrink: 0;
}

header h1 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

header .progress-info {
  font-size: 0.8rem;
  opacity: 0.9;
  white-space: nowrap;
}

.btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  transition: opacity .15s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; }

.btn-white {
  background: white;
  color: var(--primary);
}

.btn-success {
  background: #43A047;
  color: white;
}

.btn-route {
  background: #FF6F00;
  color: white;
}

.origin-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  padding: 2px 4px 2px 8px;
}

.origin-input {
  background: transparent;
  border: none;
  outline: none;
  color: white;
  font-size: 0.85rem;
  width: 200px;
  padding: 4px 0;
}
.origin-input::placeholder { color: rgba(255,255,255,.7); }

.origin-gps {
  padding: 4px 8px;
  font-size: 0.9rem;
}

/* ── MAIN LAYOUT ── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: white;
  border-right: 1px solid #ddd;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-controls {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-box {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color .2s;
}
.search-box:focus { border-color: var(--primary); }

.filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid #ccc;
  background: white;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active { color: white; border-color: transparent; }
.filter-btn[data-filter="todos"].active   { background: var(--primary); }
.filter-btn[data-filter="pendente"].active { background: #C62828; }
.filter-btn[data-filter="visitado"].active { background: #2E7D32; }
.filter-btn[data-filter="tentativa"].active { background: #F57F17; }
.filter-btn[data-filter="reagendado"].active { background: #6A1B9A; }

.stats-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #555;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: #2E7D32;
  transition: width .3s;
}

/* ── SCHOOL LIST ── */
.school-list {
  flex: 1;
  overflow-y: auto;
}

.school-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background .1s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.school-item:hover { background: #f5f8ff; }
.school-item.selected { background: #E3F2FD; }

.school-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.dot-pendente  { background: #C62828; }
.dot-visitado  { background: #2E7D32; }
.dot-tentativa { background: #F57F17; }
.dot-reagendado{ background: #6A1B9A; }

.school-info { flex: 1; min-width: 0; }
.school-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.school-bairro {
  font-size: 0.75rem;
  color: #777;
  margin-top: 1px;
}
.school-dist {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
}

.school-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.status-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 10px;
  color: white;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-pendente  { background: #C62828; }
.badge-visitado  { background: #2E7D32; }
.badge-tentativa { background: #F57F17; }
.badge-reagendado{ background: #6A1B9A; }

/* ── MAP ── */
#map {
  flex: 1;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  overflow: hidden;
}

.modal-header {
  background: var(--primary);
  color: white;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.modal-header h2 { font-size: 0.95rem; line-height: 1.3; }
.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0 0 8px;
  flex-shrink: 0;
}

.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-address {
  font-size: 0.82rem;
  color: #666;
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.form-row {
  display: flex;
  gap: 10px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #444;
}
.form-group select,
.form-group input,
.form-group textarea {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color .2s;
  font-family: inherit;
}
.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus { border-color: var(--primary); }

.form-group textarea { resize: vertical; min-height: 70px; }

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-primary { background: var(--primary); color: white; }
.btn-outline {
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
}

/* ── LOADING ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.9);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 1rem;
  color: #333;
}
.loading-overlay.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #eee;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.88rem;
  opacity: 0;
  transition: all .3s;
  z-index: 3000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── MOBILE ── */
@media (max-width: 768px) {
  :root { --sidebar-w: 100%; }
  .main { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: 50vh;
    border-right: none;
    border-bottom: 1px solid #ddd;
  }
  #map { height: 50vh; }
}
