/* RotaVisitas - Estilos Customizados */

:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* Sidebar nav item */
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s;
  color: #9ca3af;
  -webkit-user-select: none;
  user-select: none;
  min-height: 44px; /* touch target */
}
.nav-item:hover { background: #374151; color: #fff; }
.nav-item.active { background: #1d4ed8; color: #fff; font-weight: 600; }
.nav-item i { width: 1.25rem; text-align: center; flex-shrink: 0; }

/* Nav section label */
.nav-label {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #4b5563;
  padding: 0.5rem 0.875rem 0.25rem;
  margin-top: 0.5rem;
}

/* Cards */
.stat-card {
  background: white;
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: box-shadow 0.2s;
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); }

/* =========================================
   TABLE RESPONSIVA - CARD LAYOUT MOBILE
   ========================================= */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  color: #374151;
}
.data-table tr:hover td { background: #f8fafc; }
.data-table tr:last-child td { border-bottom: none; }

/* Mobile card layout para tabelas */
@media (max-width: 640px) {
  .table-responsive thead { display: none; }
  .table-responsive tbody tr {
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }
  .table-responsive tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.375rem 0.25rem;
    border-bottom: 1px solid #f8fafc;
    font-size: 0.8rem;
  }
  .table-responsive tbody td:last-child { border-bottom: none; }
  .table-responsive tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 0.5rem;
    flex-shrink: 0;
  }
  .table-responsive tbody td.td-no-label::before { display: none; }
  .table-responsive tbody td.td-no-label { justify-content: flex-end; }
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* =========================================
   MAP - RESPONSIVO
   ========================================= */
#map-container {
  height: calc(100vh - 300px);
  min-height: 350px;
  border-radius: 1rem;
  overflow: hidden;
}

@media (max-width: 640px) {
  #map-container {
    height: 55vh;
    min-height: 300px;
    border-radius: 0.75rem;
  }
}

/* Leaflet customizations */
.leaflet-popup-content-wrapper {
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  max-width: 220px;
}
.leaflet-popup-content { font-size: 0.85rem; }

/* Custom marker */
.marker-nao-visitado { background: #6b7280; }
.marker-produtiva { background: #059669; }
.marker-improdutiva { background: #dc2626; }

/* =========================================
   FORMS
   ========================================= */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.375rem;
}
.form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid #d1d5db;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: white;
  color: #111827;
  min-height: 44px; /* touch target */
}
.form-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1.25em;
  padding-right: 2.5rem;
}

/* =========================================
   BUTTONS
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  text-decoration: none;
  min-height: 40px; /* touch target */
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:active { background: #1e40af; transform: scale(0.98); }
.btn-success { background: #059669; color: white; }
.btn-success:hover { background: #047857; }
.btn-success:active { transform: scale(0.98); }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: #d97706; color: white; }
.btn-warning:hover { background: #b45309; }
.btn-outline { background: transparent; border: 1.5px solid #d1d5db; color: #374151; }
.btn-outline:hover { background: #f9fafb; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; min-height: 36px; }
.btn-lg { padding: 0.875rem 1.5rem; font-size: 1rem; min-height: 48px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* =========================================
   PROGRESS BAR
   ========================================= */
.progress { height: 0.5rem; background: #e2e8f0; border-radius: 9999px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 9999px; transition: width 0.5s; }

/* =========================================
   TOAST - MOBILE BOTTOM FULL
   ========================================= */
.toast {
  padding: 0.875rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 250px;
  max-width: 90vw;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: slideInRight 0.3s ease;
}
.toast-success { background: #ecfdf5; color: #065f46; border-left: 4px solid #10b981; }
.toast-error { background: #fef2f2; color: #991b1b; border-left: 4px solid #ef4444; }
.toast-warning { background: #fffbeb; color: #92400e; border-left: 4px solid #f59e0b; }
.toast-info { background: #eff6ff; color: #1e40af; border-left: 4px solid #3b82f6; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@media (max-width: 640px) {
  #toast-container {
    bottom: 1rem;
    right: 0.75rem;
    left: 0.75rem;
  }
  .toast {
    min-width: unset;
    width: 100%;
    max-width: 100%;
  }
}

/* =========================================
   CHECKBOX
   ========================================= */
.checkbox-custom {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: #2563eb;
  cursor: pointer;
}

/* =========================================
   IMPORT DROPZONE
   ========================================= */
#dropzone {
  border: 2px dashed #93c5fd;
  background: #eff6ff;
  border-radius: 1rem;
  padding: 2rem 1rem;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
}
#dropzone:hover, #dropzone.drag-over {
  border-color: #2563eb;
  background: #dbeafe;
}

/* =========================================
   PAGINATION
   ========================================= */
.pagination { display: flex; align-items: center; gap: 0.375rem; flex-wrap: wrap; }
.page-btn {
  width: 2.25rem; height: 2.25rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1.5px solid #e2e8f0;
  background: white;
  color: #475569;
  transition: all 0.15s;
  min-width: 2.25rem; /* evitar compressão no mobile */
}
.page-btn:hover { background: #f1f5f9; }
.page-btn.active { background: #2563eb; color: white; border-color: #2563eb; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* =========================================
   SEARCH BAR
   ========================================= */
.search-bar { position: relative; }
.search-bar input { padding-left: 2.5rem; }
.search-bar i {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  pointer-events: none;
}

/* =========================================
   ATENDIMENTO CARD
   ========================================= */
.atendimento-card {
  background: white;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.atendimento-header {
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  color: white;
  padding: 1.25rem;
}
.atendimento-body { padding: 1.25rem; }

/* =========================================
   KPI CARDS - MOBILE 2 COLUNAS
   ========================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}
@media (min-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 360px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

.kpi-card {
  background: white;
  border-radius: 0.875rem;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 0.875rem;
}
.kpi-icon {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
}
.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  color: #111827;
}
.kpi-label {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 0.15rem;
}

/* =========================================
   FILTERS ROW - SCROLL HORIZONTAL MOBILE
   ========================================= */
.filters-scroll {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
@media (max-width: 640px) {
  .filters-scroll {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.25rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .filters-scroll::-webkit-scrollbar { display: none; }
  .filters-scroll > * { flex-shrink: 0; }
  .filters-scroll .filter-full { flex: 1; min-width: 160px; }
}

/* =========================================
   MOBILE BOTTOM ACTION BAR
   ========================================= */
.mobile-actions {
  position: sticky;
  bottom: 0;
  background: white;
  border-top: 1px solid #e2e8f0;
  padding: 0.75rem 1rem;
  display: none;
  gap: 0.5rem;
  z-index: 10;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
}
@media (max-width: 640px) {
  .mobile-actions { display: flex; }
}

/* =========================================
   MODAL - FULL SCREEN MOBILE
   ========================================= */
#modal-overlay {
  align-items: flex-end;
}
@media (min-width: 641px) {
  #modal-overlay { align-items: center; }
}
#modal-content {
  border-radius: 1.25rem 1.25rem 0 0;
  max-height: 92vh;
  width: 100%;
}
@media (min-width: 641px) {
  #modal-content {
    border-radius: 1.25rem;
    max-width: 36rem;
    width: 100%;
    max-height: 90vh;
  }
}

/* =========================================
   SIDEBAR - MOBILE IMPROVEMENTS
   ========================================= */
@media (max-width: 767px) {
  #sidebar {
    width: 80vw;
    max-width: 280px;
  }
}

/* =========================================
   TOP BAR - COMPACT MOBILE
   ========================================= */
@media (max-width: 640px) {
  header#topbar h2, .page-title { font-size: 1rem; }
  header#topbar .page-subtitle { display: none; }
}

/* =========================================
   ANIMATIONS
   ========================================= */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   SPINNER
   ========================================= */
.spinner {
  border: 3px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  width: 1.5rem;
  height: 1.5rem;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   LEAFLET MARKER CUSTOM
   ========================================= */
.custom-marker {
  width: 14px !important;
  height: 14px !important;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* =========================================
   OFFLINE BANNER
   ========================================= */
.offline-banner {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  color: #92400e;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* =========================================
   OFFLINE QUEUE BADGE
   ========================================= */
.offline-queue-badge {
  background: #f59e0b;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  min-width: 1.2rem;
  text-align: center;
}

/* =========================================
   DISTRIBUIÇÃO CARDS - MOBILE STACK
   ========================================= */
@media (max-width: 640px) {
  .dist-grid {
    grid-template-columns: 1fr !important;
  }
}

/* =========================================
   DASHBOARD CHARTS - MOBILE
   ========================================= */
.chart-container {
  position: relative;
  width: 100%;
}
@media (max-width: 640px) {
  .chart-container canvas {
    max-height: 200px !important;
  }
}

/* =========================================
   RANKING TABLE - MOBILE COMPACT
   ========================================= */
@media (max-width: 640px) {
  .ranking-row {
    flex-direction: column;
    align-items: flex-start !important;
  }
  .ranking-progress {
    width: 100% !important;
  }
}

/* =========================================
   FILE TEMPLATE DOWNLOAD BUTTON
   ========================================= */
.btn-download-template {
  background: linear-gradient(135deg, #059669, #10b981);
  color: white;
  border-radius: 0.75rem;
  padding: 0.625rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  text-decoration: none;
  min-height: 40px;
}
.btn-download-template:hover {
  background: linear-gradient(135deg, #047857, #059669);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

/* ---- Leaflet MarkerCluster customizado ---- */
.map-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  color: #fff;
  border: 3px solid rgba(255,255,255,0.7);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  width: 40px;
  height: 40px;
}
.map-cluster span { font-size: 0.8rem; line-height: 1; }
.cluster-sm  { background: #3b82f6; }
.cluster-md  { background: #f59e0b; width: 46px; height: 46px; }
.cluster-lg  { background: #ef4444; width: 52px; height: 52px; font-size: 0.9rem; }
