/* ==========================================================================
   DASHBOARD CENTRAL DE SESSÕES E VENDAS DO PORTEFÓLIO (11 PROJETOS)
   100% Local, Modo Claro & Modo Escuro, Responsivo de 320px a 1280px+
   ========================================================================== */

:root {
  --bg-page: #f1f5f9;
  --bg-subtle: #e2e8f0;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;
  --primary-700: #1d4ed8;
  --primary-600: #2563eb;
  --emerald-700: #047857;
  --emerald-600: #059669;
  --amber-600: #d97706;
  --purple-600: #7c3aed;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html.dark-mode, body.dark-mode {
  --bg-page: #0b1120;
  --bg-subtle: #111827;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --text-light: #94a3b8;
  --border-color: #334155;
  --border-subtle: #1e293b;
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

/* ==========================================================================
   CABEÇALHO E COMUTADOR DE FONTE DE DADOS (DEMO 30D vs API WORKER D1)
   ========================================================================== */
.top-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 65%, #1e3a8a 100%);
  color: #ffffff;
  border-bottom: 3px solid #3b82f6;
  padding: 12px 20px;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.22);
  border: 1.5px solid #60a5fa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: #93c5fd;
  flex-shrink: 0;
}

.brand-titles h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.2px;
}

.brand-subtitle {
  font-size: 11.5px;
  color: #cbd5e1;
  display: block;
}

.source-mode-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  padding: 5px 8px;
}

.mode-btn {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.14s ease;
}

.mode-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.mode-btn.active {
  background: #2563eb;
  color: #ffffff;
  border-color: #60a5fa;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Botões Gerais */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.14s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary-600);
  color: #ffffff;
  border-color: var(--primary-700);
}
.btn-primary:hover {
  background: var(--primary-700);
}

.btn-emerald {
  background: var(--emerald-600);
  color: #ffffff;
  border-color: var(--emerald-700);
}
.btn-emerald:hover {
  background: var(--emerald-700);
}

.btn-outline {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-outline:hover {
  border-color: var(--primary-600);
}

.btn-outline-light {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
}
.btn-outline-light:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 11.5px;
}

/* ==========================================================================
   PAINEL DE LIGAÇÃO DIRETA À API WORKER D1 (VISÍVEL NO MODO API)
   ========================================================================== */
.api-connection-bar {
  background: var(--bg-card);
  border-bottom: 2px solid var(--primary-600);
  padding: 10px 20px;
  display: none;
}

.api-connection-bar.visible {
  display: block;
}

.api-conn-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.api-inputs-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.api-inputs-group input {
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 12px;
  min-width: 220px;
}

/* ==========================================================================
   BARRA DE FILTROS DE PERÍODO E SITES DO PORTEFÓLIO
   ========================================================================== */
.filters-toolbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 20px;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.filters-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.filter-pill {
  background: var(--bg-page);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: 99px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
}

.filter-pill:hover {
  border-color: var(--primary-600);
  color: var(--text-main);
}

.filter-pill.active {
  background: var(--primary-600);
  color: #ffffff;
  border-color: var(--primary-700);
}

.custom-dates-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.custom-dates-box input,
.filters-row select {
  padding: 5px 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
}

/* ==========================================================================
   CONTENTOR PRINCIPAL E 4 CARTÕES KPI GLOBAIS
   ========================================================================== */
.main-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

.kpi-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.kpi-card.kpi-revenue-highlight {
  border-color: #f59e0b;
  border-width: 1.5px;
}

.kpi-top-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 800;
}

.delta-badge {
  background: #dcfce7;
  color: #166534;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 99px;
}

.kpi-big-number {
  font-size: 25px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
  line-height: 1.15;
}

.kpi-sub-metrics {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.method-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

/* ==========================================================================
   GRELHA DOS 3 GRÁFICOS VISUAIS
   ========================================================================== */
.charts-grid-3 {
  display: grid;
  grid-template-columns: 1.15fr 1.15fr 0.9fr;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}

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

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
}

.panel-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
}

.chart-canvas-wrap {
  width: 100%;
  overflow: hidden;
}

.chart-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 240px;
}

/* Barras de Idioma (Gráfico 3) */
.lang-bars-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.lang-bar-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lang-bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
}

.lang-bar-name {
  color: var(--text-main);
}

.lang-bar-val {
  color: var(--text-muted);
}

.lang-bar-track {
  width: 100%;
  height: 7px;
  background: var(--bg-page);
  border-radius: 99px;
  overflow: hidden;
}

.lang-bar-fill {
  height: 100%;
  border-radius: 99px;
}

/* ==========================================================================
   TABELA COMPLETA DOS 11 SITES DO PORTEFÓLIO
   ========================================================================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.portfolio-table th {
  text-align: left;
  background: var(--bg-page);
  color: var(--text-muted);
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 9px 10px;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.portfolio-table th.num,
.portfolio-table td.num {
  text-align: right;
}

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

.portfolio-table tbody tr:hover td {
  background: var(--bg-page);
}

.portfolio-table tfoot td {
  background: var(--bg-page);
  font-weight: 800;
  border-top: 2px solid var(--border-color);
  padding: 10px;
}

.site-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-select-pill {
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
}

/* ==========================================================================
   SECÇÃO INFERIOR: ÚLTIMAS VENDAS + MENSAGENS DE CONTACTO + SNIPPET TRACKER
   ========================================================================== */
.bottom-split-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 16px;
  margin-top: 18px;
  align-items: start;
}

.contact-msg-item {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg-page);
  margin-bottom: 8px;
}

.contact-msg-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  margin-bottom: 4px;
}

.code-snippet-box {
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  overflow-x: auto;
  line-height: 1.5;
}

/* Toast Notification */
.toast-msg {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: #0f172a;
  color: #ffffff;
  border-left: 4px solid #3b82f6;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all 0.2s ease;
}

.toast-msg.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   RESPONSIVIDADE (320px A 1280px+)
   ========================================================================== */
@media (max-width: 1160px) {
  .kpi-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid-3 {
    grid-template-columns: 1fr;
  }
  .bottom-split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .top-header {
    padding: 10px 12px;
  }
  .filters-toolbar {
    padding: 8px 12px;
  }
  .main-container {
    padding: 12px 12px 28px;
  }
  .kpi-grid-4 {
    grid-template-columns: 1fr;
  }
  .custom-dates-box {
    width: 100%;
    flex-wrap: wrap;
  }
}

/* ==========================================================================
   SECÇÃO DO FUNIL DE CONVERSÃO DE 5 PASSOS + ANÁLISE DE MÉTRICAS
   ========================================================================== */
.funnel-split-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 16px;
  margin-bottom: 18px;
  align-items: stretch;
}

.funnel-steps-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.funnel-step-card {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.funnel-step-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.funnel-step-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 7px;
}

.funnel-step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.funnel-step-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.funnel-pass-badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.funnel-bar-track {
  width: 100%;
  height: 9px;
  background: var(--border-subtle);
  border-radius: 99px;
  overflow: hidden;
}

.funnel-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.25s ease;
}

.funnel-step-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.metrics-analysis-list {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.metrics-analysis-list li {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary-600);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  line-height: 1.42;
  color: var(--text-main);
}

.metrics-analysis-list li strong {
  display: block;
  font-size: 12.5px;
  margin-bottom: 2px;
}

.project-link-title {
  color: var(--text-main);
  text-decoration: none;
  font-weight: 800;
}
.project-link-title:hover {
  color: var(--primary-600);
  text-decoration: underline;
}

.project-link-url {
  color: var(--primary-600);
  text-decoration: none;
  font-weight: 600;
}
.project-link-url:hover {
  text-decoration: underline;
}

.btn-ignore-active {
  background: #dcfce7 !important;
  color: #166534 !important;
  border-color: #86efac !important;
}

@media (max-width: 1160px) {
  .funnel-split-grid {
    grid-template-columns: 1fr;
  }
}
