/* ==========================================================================
   FAZ LEAD (fazlead.com) - Design System v2.0 (Secao 13)
   Paleta Fechada + Tipografia Outfit + Mobile First -> Desktop
   ========================================================================== */

:root {
  --c-primary: #7C3AED;
  --c-primary-hover: #6D28D9;
  --c-primary-soft: #F3E8FF;
  --c-action: #EA580C;
  --c-action-hover: #C2410C;
  --c-action-soft: #FFEDD5;
  --c-wa: #25D366;
  --c-wa-hover: #1EBE5B;
  --c-text: #18181B;
  --c-muted: #52525B;
  --c-bg: #F4F4F5;
  --c-surface: #FFFFFF;
  --c-border: #E4E4E7;
  --c-success: #16A34A;
  --c-success-soft: #DCFCE7;
  --c-error: #DC2626;
  --c-error-soft: #FEE2E2;
  --c-warning: #F59E0B;
  --c-warning-soft: #FEF3C7;

  /* Termometro (Secao 5) */
  --term-0: #1E3A8A; /* Congelado */
  --term-1: #2563EB; /* Frio */
  --term-2: #CA8A04; /* Morno (contraste legivel) */
  --term-2-bg: #FEF08A;
  --term-3: #EA580C; /* Quente */
  --term-4: #DC2626; /* Super quente */

  --radius-card: 12px;
  --radius-ctrl: 10px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 3px rgba(24, 24, 27, 0.06);
  --shadow-md: 0 8px 24px rgba(24, 24, 27, 0.08);
  --shadow-lg: 0 16px 40px rgba(24, 24, 27, 0.14);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--c-text);
  background-color: var(--c-bg);
  overflow-x: hidden;
  min-height: 100dvh;
}

a {
  color: var(--c-primary);
  text-decoration: none;
  font-weight: 500;
}
a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* Boot & Skeletons (Secao 13.5) */
.boot-shell {
  max-width: 560px;
  margin: 48px auto;
  padding: 0 16px;
}
.boot-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  color: var(--c-primary);
  margin-bottom: 24px;
}
.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--c-primary);
  color: #FFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  position: relative;
  flex-shrink: 0;
}
.brand-badge::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-action);
}

@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton-card, .skeleton-line {
  background: linear-gradient(90deg, #E4E4E7 25%, #F4F4F5 50%, #E4E4E7 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--radius-card);
}
.skeleton-card {
  height: 96px;
  margin-bottom: 12px;
}
.skeleton-line {
  height: 18px;
  margin-bottom: 8px;
  border-radius: 6px;
}

/* ==========================================================================
   SHELL DO SISTEMA (Mobile Bottom Nav + Desktop Fixed Sidebar)
   ========================================================================== */
.app-layout {
  display: flex;
  min-height: 100dvh;
  width: 100%;
}

.sidebar {
  display: none;
}

.main-area {
  flex: 1;
  min-width: 0;
  padding: calc(12px + var(--safe-top)) 16px calc(92px + var(--safe-bottom)) 16px;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

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

.screen-title {
  font-size: 21px;
  font-weight: 700;
  margin: 0;
  color: var(--c-text);
  letter-spacing: -0.01em;
}
.screen-subtitle {
  font-size: 14px;
  color: var(--c-muted);
  margin: 2px 0 0 0;
}

/* Navegacao Inferior Mobile (5 itens + FAB Novo Lead - Secao 13.4) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-bottom);
  z-index: 90;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
}
.bottom-nav-btn {
  background: none;
  border: none;
  min-height: 58px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--c-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
}
.bottom-nav-btn svg {
  width: 22px;
  height: 22px;
}
.bottom-nav-btn.active {
  color: var(--c-primary);
  font-weight: 700;
}
.bottom-nav-btn.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 32px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--c-primary);
}

.fab-new-lead {
  position: fixed;
  right: 16px;
  bottom: calc(72px + var(--safe-bottom));
  height: 54px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  background: var(--c-action);
  color: #FFFFFF;
  border: none;
  font-weight: 600;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 20px rgba(234, 88, 12, 0.35);
  cursor: pointer;
  z-index: 91;
  transition: transform 0.15s ease, background 0.15s ease;
}
.fab-new-lead:hover {
  background: var(--c-action-hover);
  transform: translateY(-1px);
}
.fab-new-lead svg {
  width: 22px;
  height: 22px;
}

/* Tablet & Desktop (Secao 13.4) */
@media (min-width: 1024px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 260px;
    flex-shrink: 0;
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: 24px 16px;
    overflow-y: auto;
  }
  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    color: var(--c-text);
    padding: 0 8px 20px 8px;
    border-bottom: 1px solid var(--c-border);
    margin-bottom: 16px;
  }
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }
  .sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: var(--radius-ctrl);
    border: none;
    background: transparent;
    color: var(--c-muted);
    font-weight: 500;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
    width: 100%;
  }
  .sidebar-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }
  .sidebar-link:hover {
    background: var(--c-bg);
    color: var(--c-text);
  }
  .sidebar-link.active {
    background: var(--c-primary-soft);
    color: var(--c-primary);
    font-weight: 600;
  }
  .sidebar-section-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--c-muted);
    padding: 16px 12px 4px 12px;
  }
  .main-area {
    padding: 24px 32px 48px 32px;
  }
  .bottom-nav {
    display: none;
  }
  .fab-new-lead {
    bottom: 28px;
    right: 32px;
  }
}

/* ==========================================================================
   CARDS, GRIDS E CONTAINERS
   ========================================================================== */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-alert-overdue {
  border-left: 4px solid var(--c-error);
  background: #FFFDFD;
}
.card-alert-cooling {
  border-left: 4px solid var(--c-warning);
}
.card-ranking {
  background: linear-gradient(135deg, #7C3AED 0%, #5B21B6 100%);
  color: #FFFFFF;
  border: none;
}

.form-container {
  max-width: 560px;
  margin: 0 auto;
}

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

@media (min-width: 600px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* ==========================================================================
   CAMPOS E BOTOES (Secao 13.3: 48px campo, 52px botao, foco roxo 2px)
   ========================================================================== */
.field-group {
  margin-bottom: 16px;
}
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 6px;
}
.field-hint {
  font-size: 14px;
  color: var(--c-muted);
  font-weight: 400;
}
.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: var(--radius-ctrl);
  border: 1.5px solid #D4D4D8;
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.textarea {
  min-height: 92px;
  resize: vertical;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.22);
}
.input.has-error, .select.has-error {
  border-color: var(--c-error);
}
.field-error {
  font-size: 14px;
  color: var(--c-error);
  margin-top: 6px;
  font-weight: 500;
}
.inline-status {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-primary);
}

/* Botoes: apenas UM primario laranja por tela; estruturais em roxo/neutro; WhatsApp em verde */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border-radius: var(--radius-ctrl);
  font-size: 16px;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
  text-decoration: none;
  width: 100%;
}
@media (min-width: 600px) {
  .btn-inline {
    width: auto;
    min-height: 46px;
  }
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--c-action);
  color: #FFFFFF;
}
.btn-primary:hover:not(:disabled) {
  background: var(--c-action-hover);
  text-decoration: none;
}

.btn-purple {
  background: var(--c-primary);
  color: #FFFFFF;
}
.btn-purple:hover:not(:disabled) {
  background: var(--c-primary-hover);
}

.btn-secondary {
  background: var(--c-surface);
  color: var(--c-text);
  border-color: var(--c-border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--c-bg);
  border-color: #D4D4D8;
}

.btn-ghost {
  background: transparent;
  color: var(--c-primary);
  min-height: 44px;
  padding: 0 12px;
  width: auto;
}
.btn-ghost:hover {
  background: var(--c-primary-soft);
}

.btn-whatsapp {
  background: var(--c-wa);
  color: #FFFFFF;
}
.btn-whatsapp:hover:not(:disabled) {
  background: var(--c-wa-hover);
  text-decoration: none;
}

.btn-danger-outline {
  background: var(--c-surface);
  color: var(--c-error);
  border-color: #FECACA;
}

.btn-sm {
  min-height: 44px;
  padding: 0 14px;
  font-size: 14px;
  width: auto;
}

/* Pilulas, Badges & Termometro */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-purple { background: var(--c-primary-soft); color: var(--c-primary); }
.pill-success { background: var(--c-success-soft); color: var(--c-success); }
.pill-warning { background: var(--c-warning-soft); color: #B45309; }
.pill-error { background: var(--c-error-soft); color: var(--c-error); }
.pill-muted { background: var(--c-bg); color: var(--c-muted); }

.term-badge-0 { background: #DBEAFE; color: var(--term-0); }
.term-badge-1 { background: #EFF6FF; color: var(--term-1); }
.term-badge-2 { background: var(--term-2-bg); color: #854D0E; }
.term-badge-3 { background: var(--c-action-soft); color: var(--term-3); }
.term-badge-4 { background: var(--c-error-soft); color: var(--term-4); }

.thermometer-selector {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.therm-btn {
  min-height: 52px;
  border-radius: var(--radius-ctrl);
  border: 2px solid var(--c-border);
  background: var(--c-surface);
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--c-muted);
  transition: all 0.15s ease;
}
.therm-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.therm-btn.active[data-level="0"] { border-color: var(--term-0); background: #EFF6FF; color: var(--term-0); }
.therm-btn.active[data-level="1"] { border-color: var(--term-1); background: #EFF6FF; color: var(--term-1); }
.therm-btn.active[data-level="2"] { border-color: #EAB308; background: #FEFCE8; color: #854D0E; }
.therm-btn.active[data-level="3"] { border-color: var(--term-3); background: #FFF7ED; color: var(--term-3); }
.therm-btn.active[data-level="4"] { border-color: var(--term-4); background: #FEF2F2; color: var(--term-4); }

/* Chips de filtro horizontal sem quebrar layout */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.chip {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip.active {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

/* Barra de progresso (Metas & Cadastro em 3 etapas) */
.progress-track {
  width: 100%;
  height: 10px;
  background: var(--c-bg);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--c-primary);
  border-radius: var(--radius-pill);
  transition: width 0.35s ease;
}
.progress-fill.goal-hit {
  background: var(--c-success);
}

/* Tabelas responsivas: Tabela no desktop vira Card no celular (Secao 13.4) */
.resp-table {
  width: 100%;
  border-collapse: collapse;
}
.resp-table th {
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-muted);
  padding: 12px;
  border-bottom: 1.5px solid var(--c-border);
}
.resp-table td {
  padding: 12px;
  border-bottom: 1px solid var(--c-border);
  font-size: 15px;
  vertical-align: middle;
}
@media (max-width: 767px) {
  .resp-table thead {
    display: none;
  }
  .resp-table, .resp-table tbody, .resp-table tr, .resp-table td {
    display: block;
    width: 100%;
  }
  .resp-table tr {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-card);
    padding: 12px;
    margin-bottom: 12px;
  }
  .resp-table td {
    padding: 6px 0;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
  }
  .resp-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--c-muted);
    text-align: left;
    font-size: 14px;
  }
}

/* Modal / Bottom Sheet (respeitando teclado e safe area) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 27, 0.55);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  background: var(--c-surface);
  width: 100%;
  max-width: 580px;
  max-height: 92dvh;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom)) 16px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
  .modal-sheet {
    border-radius: 16px;
    padding: 24px;
  }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

/* Toast (3 segundos, sem modal - Secao 13.5) */
#toast-root {
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}
.toast {
  background: var(--c-text);
  color: #FFFFFF;
  padding: 14px 16px;
  border-radius: var(--radius-ctrl);
  font-size: 15px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}
.toast-success { border-left: 5px solid var(--c-success); }
.toast-error   { border-left: 5px solid var(--c-error); }
.toast-warning { border-left: 5px solid var(--c-warning); }

/* Empty state com acao (Secao 13.5) */
.empty-state {
  text-align: center;
  padding: 36px 20px;
  background: var(--c-surface);
  border: 1.5px dashed var(--c-border);
  border-radius: var(--radius-card);
}
.empty-state h3 {
  margin: 12px 0 6px 0;
  font-size: 18px;
}
.empty-state p {
  margin: 0 auto 20px auto;
  color: var(--c-muted);
  max-width: 380px;
}

/* Destaque de variavel faltando no WhatsApp (Secao 7.4) */
.wa-missing-token {
  background: var(--c-error-soft);
  color: var(--c-error);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
}

/* Landing page & Mockup visual do app (Secao 2.1) */
.landing-hero {
  background: linear-gradient(180deg, #FFFFFF 0%, #F4F4F5 100%);
  padding: 24px 16px 48px 16px;
  border-bottom: 1px solid var(--c-border);
}
.landing-container {
  max-width: 1120px;
  margin: 0 auto;
}
.landing-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 36px;
}
.hero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
  align-items: center;
}
@media (min-width: 900px) {
  .hero-grid {
    grid-template-columns: 1.15fr 0.85fr;
  }
}
.phone-mockup {
  background: #18181B;
  border-radius: 32px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  max-width: 360px;
  margin: 0 auto;
}
.phone-screen {
  background: var(--c-bg);
  border-radius: 22px;
  padding: 16px;
  overflow: hidden;
}

/* KPI Stat Box */
.stat-box {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 14px;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--c-text);
  line-height: 1.2;
}
.stat-label {
  font-size: 14px;
  color: var(--c-muted);
  margin-top: 4px;
}
.stat-sub {
  font-size: 14px;
  color: var(--c-muted);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--c-border);
}

/* Lista fechada de Bairros com busca */
.bairro-list-box {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-ctrl);
  background: var(--c-surface);
}
.bairro-option {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: none;
  border-bottom: 1px solid var(--c-bg);
  background: transparent;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: var(--c-text);
}
.bairro-option:hover, .bairro-option.selected {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 600;
}

/* Timeline Historico */
.timeline-item {
  position: relative;
  padding-left: 24px;
  padding-bottom: 16px;
  border-left: 2px solid var(--c-border);
  margin-left: 8px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--c-primary);
  border: 2px solid var(--c-surface);
}

/* Mapa container (Leaflet lazy-loaded) */
.map-box {
  width: 100%;
  height: 420px;
  border-radius: var(--radius-card);
  border: 1px solid var(--c-border);
  overflow: hidden;
  background: #E4E4E7;
}

/* Utilitarios */
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flex-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--c-muted); font-size: 14px; }
.text-bold { font-weight: 700; }
