/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --secondary: #059669;
  --secondary-light: #10b981;
  --accent: #d97706;
  --accent-light: #f59e0b;
  --danger: #dc2626;
  --danger-light: #ef4444;
  --purple: #7c3aed;
  --teal: #0891b2;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --text-lighter: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 240px;
  --header-height: 60px;
}

html { font-size: 14px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-light); }

/* ─── Login Screen ──────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--teal) 100%);
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  text-align: center;
  color: var(--primary);
  margin-bottom: 8px;
  font-size: 1.5rem;
}

.login-card .login-subtitle {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 32px;
  font-size: 0.9rem;
}

.login-card .login-logo {
  text-align: center;
  font-size: 3rem;
  margin-bottom: 16px;
}

#login-error {
  display: none;
  background: #fef2f2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.85rem;
  border: 1px solid #fecaca;
}

.login-hint {
  margin-top: 20px;
  padding: 12px;
  background: #eff6ff;
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text-light);
  border: 1px solid #bfdbfe;
}

.login-hint strong { color: var(--primary); }

/* ─── App Layout ────────────────────────────────────────────── */
#app-screen {
  display: none;
  min-height: 100vh;
  width: 100%;
}

.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ─── Sidebar ───────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--primary-dark);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.sidebar-header p {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 4px;
}

#main-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
  cursor: pointer;
  font-size: 0.9rem;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

.nav-item.active {
  background: rgba(255,255,255,0.15);
  color: white;
  border-right: 3px solid var(--accent-light);
}

.nav-icon { margin-right: 12px; font-size: 1.1rem; width: 24px; text-align: center; }
.nav-label { white-space: nowrap; }

.nav-logout { margin-top: auto; border-top: 1px solid rgba(255,255,255,0.1); }

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.8rem;
}

.sidebar-user .user-name { font-weight: 600; color: white; }
.sidebar-user .user-role { opacity: 0.6; margin-top: 2px; }

/* ─── Main Content ──────────────────────────────────────────── */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

.main-header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

#menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  margin-right: 16px;
  color: var(--text);
}

.main-header .header-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-light);
}

#main-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}

#main-content.page-mapa {
  max-width: none;
}

.map-container {
  width: 100%;
}

/* ─── Page Header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.page-subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ─── Stats Grid ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid;
  transition: transform 0.2s;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-blue { border-color: var(--primary); }
.stat-green { border-color: var(--secondary); }
.stat-orange { border-color: var(--accent); }
.stat-red { border-color: var(--danger); }
.stat-purple { border-color: var(--purple); }
.stat-teal { border-color: var(--teal); }

.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.stat-blue .stat-value { color: var(--primary); }
.stat-green .stat-value { color: var(--secondary); }
.stat-orange .stat-value { color: var(--accent); }
.stat-red .stat-value { color: var(--danger); }
.stat-purple .stat-value { color: var(--purple); }
.stat-teal .stat-value { color: var(--teal); }
.stat-label { color: var(--text-light); font-size: 0.85rem; margin-top: 4px; }

/* ─── Dashboard Grid ────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 20px;
}

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.card-body { padding: 20px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.escritorio-card .card-header { border-bottom: none; }
.escritorio-card .card-body p { margin-bottom: 6px; color: var(--text-light); font-size: 0.9rem; }

.card-actions { display: flex; gap: 4px; }

/* ─── Tables ────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #f8fafc; }

.actions-cell { white-space: nowrap; }
.obs-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-agendado { background: #dbeafe; color: #1e40af; }
.badge-realizado { background: #d1fae5; color: #065f46; }
.badge-cancelado { background: #fee2e2; color: #991b1b; }
.badge-ativo { background: #d1fae5; color: #065f46; }
.badge-inativo { background: #f3f4f6; color: #6b7280; }
.badge-role-admin { background: #fce7f3; color: #9d174d; }
.badge-role-supervisor { background: #ede9fe; color: #5b21b6; }
.badge-role-atendente { background: #dbeafe; color: #1e40af; }

.badge-tipo-EM-EF { background: #dbeafe; color: #1e40af; }
.badge-tipo-EMC-EF { background: #ede9fe; color: #5b21b6; }
.badge-tipo-CMEI { background: #d1fae5; color: #065f46; }
.badge-tipo-CEB { background: #fef3c7; color: #92400e; }
.badge-tipo-SMED { background: #fee2e2; color: #991b1b; }
.badge-tipo-CEA { background: #cffafe; color: #155e75; }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-outline { background: transparent; color: var(--text-light); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); border-color: var(--text-lighter); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-light); }
.btn-success { background: var(--secondary); color: white; }
.btn-success:hover { background: var(--secondary-light); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

/* ─── Forms ─────────────────────────────────────────────────── */
.form { max-width: 500px; }

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.form-group textarea { resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ─── Filters ───────────────────────────────────────────────── */
.filters-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-select, .filter-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--bg-card);
  color: var(--text);
}

.filter-select:focus, .filter-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ─── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
  padding: 0;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { background: var(--secondary); }
.toast-error { background: var(--danger); }

/* ─── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.alert-warning {
  border-color: #fcd34d;
  background: #fffbeb;
}

/* ─── Progress Bars ─────────────────────────────────────────── */
.progress-item { margin-bottom: 16px; }
.progress-label { font-size: 0.85rem; font-weight: 500; margin-bottom: 4px; }

.progress-bar-container {
  background: var(--bg);
  border-radius: 20px;
  height: 24px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 30px;
  transition: width 0.5s ease;
}

.progress-detail { font-size: 0.75rem; color: var(--text-lighter); margin-top: 2px; }

/* ─── Chart Bars ────────────────────────────────────────────── */
.chart-bars { display: flex; flex-direction: column; gap: 12px; }

.chart-bar-item {
  display: grid;
  grid-template-columns: 120px 1fr 40px;
  align-items: center;
  gap: 12px;
}

.chart-bar-label { font-size: 0.85rem; color: var(--text-light); }

.chart-bar-track {
  height: 20px;
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.5s ease;
  min-width: 4px;
}

.tipo-rotina { background: var(--primary); }
.tipo-urgente { background: var(--danger); }
.tipo-acompanhamento { background: var(--accent); }

.chart-bar-value { font-size: 0.85rem; font-weight: 600; text-align: right; }

/* ─── Status Ring Chart ─────────────────────────────────────── */
.status-summary { display: flex; align-items: center; gap: 24px; }

.status-ring { position: relative; width: 120px; height: 120px; flex-shrink: 0; }

.status-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-bg { fill: none; stroke: var(--bg); stroke-width: 3; }
.ring-realizado { fill: none; stroke: var(--secondary); stroke-width: 3; stroke-linecap: round; }
.ring-agendado { fill: none; stroke: var(--primary); stroke-width: 3; stroke-linecap: round; }

.ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.status-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-realizado { background: var(--secondary); }
.dot-agendado { background: var(--primary); }
.dot-cancelado { background: var(--danger); }

/* ─── Route List ────────────────────────────────────────────── */
.route-list { display: flex; flex-direction: column; gap: 0; }

.route-stop {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.route-stop:last-child { border-bottom: none; }

.route-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.route-info { flex: 1; }
.route-name { font-weight: 600; font-size: 0.9rem; }
.route-detail { font-size: 0.8rem; color: var(--text-light); margin-top: 2px; }
.route-distance { font-size: 0.8rem; color: var(--text-light); font-weight: 500; white-space: nowrap; }

.route-summary {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-light);
}

.route-actions { margin-top: 16px; text-align: center; }

/* ─── Map ───────────────────────────────────────────────────── */
.map-container {
  height: 70vh;
  min-height: 520px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.map-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-left: 0;
  }

  #menu-toggle {
    display: block;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filters-bar {
    flex-direction: column;
  }

  .filter-select, .filter-input {
    width: 100%;
  }

  .data-table {
    font-size: 0.75rem;
  }

  .data-table th, .data-table td {
    padding: 6px 8px;
  }

  .map-container {
    height: 400px;
  }

  .chart-bar-item {
    grid-template-columns: 80px 1fr 30px;
  }

  .status-summary {
    flex-direction: column;
    text-align: center;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  #main-content {
    padding: 16px;
  }

  .modal {
    margin: 10px;
  }
}

/* ─── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--text-lighter); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ─── Utility ───────────────────────────────────────────────── */
.text-center { text-align: center; }
