:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --border: #e4e9f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #27ae60;
  --primary-dark: #1e8b4c;
  --warning: #f59e0b;
  --danger: #ef4444;
  --accent: #2563eb;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-meta {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 13px;
}

.filters-card,
.panel,
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters-card {
  padding: 16px;
  margin-bottom: 18px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-item label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.filter-item select,
.filter-item input {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  background: #fff;
  font-size: 14px;
}

.filter-item.actions {
  justify-content: flex-end;
  gap: 8px;
  flex-direction: row;
  align-items: end;
}

.btn-primary,
.btn-secondary {
  height: 42px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 700;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef2f7; color: var(--text); }

.kpis-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.kpis-grid-6 { grid-template-columns: repeat(6, 1fr); }

.kpi-card { padding: 18px; }
.kpi-card.warning { border-left: 5px solid var(--warning); }
.kpi-card.danger { border-left: 5px solid var(--danger); }
.kpi-card.accent { border-left: 5px solid var(--accent); }

.kpi-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
  font-weight: 600;
}

.kpi-card strong {
  font-size: 28px;
  line-height: 1.1;
}

.executive-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 0.8fr);
  gap: 16px;
  margin-bottom: 18px;
}

.panel {
  padding: 16px;
}

.panel-large { grid-column: span 1; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}

.panel-header h3 {
  margin: 0;
  font-size: 18px;
}

.panel-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chart {
  width: 100%;
  min-height: 320px;
}

.chart-large {
  min-height: 430px;
}

.week-summary {
  display: grid;
  gap: 12px;
}

.week-summary div {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fbfdff;
  padding: 16px;
}

.week-summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.week-summary strong {
  font-size: 30px;
}

.alerts-panel { margin-bottom: 18px; }

.alerts-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.alert-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fafcff;
}

.alert-card.warning { border-left: 5px solid var(--warning); }
.alert-card.danger { border-left: 5px solid var(--danger); }

.alert-card strong {
  display: block;
  margin-bottom: 6px;
}

.alert-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.alert-type {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

.charts-grid .panel-large {
  grid-column: span 2;
}

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

.table-header input {
  width: 320px;
  max-width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
}

.table-wrap {
  overflow-x: auto;
  max-height: 540px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}

thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 1;
  text-align: left;
  font-size: 13px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid #eef2f7;
  font-size: 13px;
  vertical-align: top;
}

tbody tr:hover { background: #fafcff; }

.col-description {
  max-width: 520px;
  min-width: 280px;
  line-height: 1.35;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.temp-hot { background: #fee2e2; color: #991b1b; }
.temp-warm { background: #fef3c7; color: #92400e; }
.temp-cold { background: #dbeafe; color: #1d4ed8; }
.temp-win { background: #dcfce7; color: #166534; }
.temp-intent { background: #ede9fe; color: #5b21b6; }
.temp-disqualified { background: #e5e7eb; color: #374151; }
.temp-neutral { background: #e5e7eb; color: #374151; }
.status-ok { background: #dcfce7; color: #166534; }
.status-warn { background: #fef3c7; color: #92400e; }
.status-danger { background: #fee2e2; color: #991b1b; }

.empty-cell,
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.25);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-box {
  width: 260px;
  background: #fff;
  border-radius: 18px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.15);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1400px) {
  .kpis-grid-6 { grid-template-columns: repeat(4, 1fr); }
  .alerts-list { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1200px) {
  .filters-grid { grid-template-columns: repeat(3, 1fr); }
  .kpis-grid-6 { grid-template-columns: repeat(3, 1fr); }
  .executive-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .charts-grid .panel-large { grid-column: span 1; }
  .kpis-grid-6 { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; }
  .alerts-list { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .filters-grid,
  .kpis-grid-6 { grid-template-columns: 1fr; }
  .filter-item.actions { flex-direction: column; align-items: stretch; }
  .table-header { flex-direction: column; align-items: stretch; }
  .table-header input { width: 100%; }
}

.filters-grid-wide {
  grid-template-columns: repeat(9, minmax(135px, 1fr));
}

.map-visits-panel {
  margin-bottom: 18px;
}

.map-header {
  align-items: flex-start;
}

.map-chart {
  width: 100%;
  min-height: 460px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fbfdff;
  overflow: hidden;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 12px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-flex;
  margin-right: 5px;
  border: 1px solid rgba(15, 23, 42, 0.12);
}

.temp-cold-dot { background: #2563eb; }
.temp-warm-dot { background: #f59e0b; }
.temp-hot-dot { background: #ef4444; }
.temp-intent-dot { background: #8b5cf6; }
.temp-win-dot { background: #16a34a; }
.temp-neutral-dot { background: #64748b; }

@media (max-width: 1500px) {
  .filters-grid-wide {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 900px) {
  .filters-grid-wide {
    grid-template-columns: 1fr;
  }
}

.map-wrapper {
  position: relative;
}

.map-chart {
  height: 520px;
  min-height: 520px;
}

.map-message {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--muted);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.leaflet-container {
  font-family: Arial, Helvetica, sans-serif;
}

/* Ajustes v3.1.3 */
.map-message {
  max-width: 720px;
}

.leaflet-container {
  font-family: Arial, Helvetica, sans-serif;
}

/* =========================
   V3.1.4 - Ordenação, funil e detalhamento
========================= */
.clickable-card {
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.clickable-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.10);
}

.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.sortable-th::after {
  content: " ⇅";
  color: var(--muted);
  font-size: 11px;
}

.sortable-th.sort-asc::after {
  content: " ↑";
  color: var(--primary);
  font-weight: 800;
}

.sortable-th.sort-desc::after {
  content: " ↓";
  color: var(--primary);
  font-weight: 800;
}

.detail-panel {
  margin-bottom: 18px;
  border-left: 5px solid var(--accent);
}

.detail-wrap {
  max-height: 560px;
}

#detalhamentoTable {
  min-width: 1050px;
}

.funnel-chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  min-height: 300px;
  justify-content: center;
}

.funnel-step {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  min-width: 210px;
  box-shadow: 0 8px 18px rgba(39, 174, 96, 0.18);
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.funnel-step:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}

.funnel-step strong {
  font-size: 18px;
}

.data-mode-note {
  margin: -6px 0 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fbfdff;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.kpi-label small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.mini-filters { display: flex; align-items: center; gap: 8px; }
.mini-filters label { font-size: 13px; color: var(--muted); font-weight: 700; }
.mini-filters select { height: 36px; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 0 10px; font-size: 13px; }


.hidden { display: none !important; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(22, 101, 52, 0.94), rgba(15, 23, 42, 0.92));
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: #ffffff;
  border-radius: 22px;
  padding: 28px;
  border: 1px solid rgba(255,255,255,0.4);
  box-shadow: 0 22px 70px rgba(0,0,0,0.28);
}

.login-brand {
  color: var(--primary);
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
  margin-bottom: 12px;
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
  color: var(--text);
}

.login-message {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.login-message.error { color: var(--danger); font-weight: 700; }
.login-message.success { color: var(--primary); font-weight: 700; }

.login-form { display: grid; gap: 14px; }
.login-field { display: grid; gap: 6px; }
.login-field span { font-size: 13px; font-weight: 700; color: var(--muted); }
.login-field input {
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 15px;
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.login-actions button {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.topbar-meta-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#loggedUser {
  color: var(--text);
  font-weight: 700;
}

.btn-logout {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
}


.vendedores-hoje-panel {
  margin-top: 0;
}

.vendedores-hoje-wrap {
  max-height: 420px;
}

.vendedores-hoje-wrap table {
  min-width: 1200px;
}

/* V33.3 */
.onde-vendedores-full { grid-column: 1 / -1; }
.vendedores-hoje-wrap { max-height: 420px; }

/* V33.4 - Linha executiva com Meta + Funil + Temperatura */
.executive-grid-three {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
}
.executive-panel { min-width: 0; }
.chart-executive { min-height: 360px; }
.vendedores-hoje-panel { margin-bottom: 18px; }
@media (max-width: 1300px) {
  .executive-grid-three { grid-template-columns: 1fr; }
  .chart-executive { min-height: 320px; }
}

/* ===== Carregamento progressivo por bloco ===== */
.block-loading {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(248,250,252,0.9), rgba(241,245,249,0.9), rgba(248,250,252,0.9));
  background-size: 200% 100%;
  animation: loadingShimmer 1.4s ease-in-out infinite;
}

.inline-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.mini-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.mini-spinner-inline {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

@keyframes loadingShimmer {
  0% { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}
