/* ========================================
   Raiz Dashboard — Painel de Conversão
   Tema: editorial verde escuro
======================================== */

:root {
  /* Paleta da marca (compartilhada) */
  --raiz-green-900: #0A2918;
  --raiz-green-800: #0F3D24;
  --raiz-green-700: #14532D;
  --raiz-green-500: #22C55E;
  --raiz-green-100: #DCFCE7;

  /* Tema CLARO (default) — fundo mais escuro pra dar contraste com cards brancos */
  --bg: #E7EBE2;
  --card: #FFFFFF;
  --card-hover: #F3F6EF;

  --text-strong: #0F172A;
  --text: #334155;
  --text-muted: #64748B;
  --text-light: #94A3B8;

  --border: #D7DDD0;
  --border-soft: #E0E5DA;

  --red: #DC2626;
  --amber: #D97706;

  /* Header */
  --header-from: #0F3D24;
  --header-to: #0A2918;

  /* Variáveis de chart (lidas pelo JS) */
  --chart-text: #334155;
  --chart-grid: #E0E5DA;
  --chart-border: #FFFFFF;
  --chart-tooltip-bg: #0F3D24;

  /* Espaçamentos */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Tipografia */
  --font-sans: 'Geist', system-ui, sans-serif;
  --font-mono: 'Geist Mono', 'SF Mono', Menlo, monospace;

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.08);
}

/* Tema ESCURO */
[data-theme="dark"] {
  --raiz-green-500: #2DD46F;
  --raiz-green-100: #16382410;

  --bg: #070F0A;
  --card: #0F2117;
  --card-hover: #16301F;

  --text-strong: #ECF2EE;
  --text: #C5D2CB;
  --text-muted: #8A9A90;
  --text-light: #5E6E64;

  --border: #214031;
  --border-soft: #18301F;

  --header-from: #0B1C13;
  --header-to: #061009;

  --chart-text: #C5D2CB;
  --chart-grid: #214031;
  --chart-border: #0F2117;
  --chart-tooltip-bg: #214031;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
}

html {
  transition: background-color 0.3s ease;
}

/* ========================================
   Reset / Base
======================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Garante que [hidden] funcione mesmo em overlays com display:grid/flex */
[hidden] {
  display: none !important;
}

html, body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

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

a {
  color: inherit;
  text-decoration: none;
}

/* ========================================
   Header
======================================== */
.header {
  background: var(--header-from);
  background-image: linear-gradient(135deg, var(--header-from) 0%, var(--header-to) 100%);
  color: #FFFFFF;
  border-bottom: 1px solid var(--header-to);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-8);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.brand-ord {
  display: flex;
  align-items: center;
  transition: opacity 0.15s;
}

.brand-ord:hover {
  opacity: 0.8;
}

.brand-ord-logo {
  height: 26px;
  width: auto;
  display: block;
}

.brand-divider {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.2);
}

.brand-client-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  transition: opacity 0.15s;
}

.brand-client-wrap[href] {
  cursor: pointer;
}

.brand-client-wrap[href]:hover {
  opacity: 0.8;
}

.brand-client-logo {
  height: 34px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 500;
}

.brand-client {
  font-size: 16px;
  font-weight: 600;
  color: #FFFFFF;
}

.header-tabs {
  display: flex;
  gap: var(--space-1);
  justify-self: center;
}

.tab {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.65);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.tab:hover:not(:disabled) {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.08);
}

.tab-active {
  background: rgba(255, 255, 255, 0.14);
  color: #FFFFFF;
}

.tab-disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tab-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
}

.header-period {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  color: #FFFFFF;
  transition: all 0.15s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: block; }

[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }

.period-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 500;
}

.period-select, .period-custom input {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #FFFFFF;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  transition: border-color 0.15s;
  cursor: pointer;
}

.period-select:hover, .period-custom input:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.period-select:focus, .period-custom input:focus {
  border-color: var(--raiz-green-500);
}

.period-select option {
  background: var(--raiz-green-900);
  color: #FFFFFF;
}

.period-custom {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.period-sep {
  color: rgba(255, 255, 255, 0.4);
  font-family: var(--font-mono);
}

/* ========================================
   Main layout
======================================== */
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-12);
}

.section {
  margin-bottom: var(--space-10);
}

.section-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-5);
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.section-title-muted {
  color: var(--text-light);
}

/* ========================================
   KPIs
======================================== */
.kpi-grid {
  display: grid;
  gap: var(--space-3);
}

.kpi-grid-primary {
  grid-template-columns: repeat(4, 1fr);
}

.kpi-grid-secondary {
  grid-template-columns: repeat(4, 1fr);
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.kpi:hover {
  border-color: var(--raiz-green-500);
  box-shadow: var(--shadow);
}

.kpi-secondary {
  padding: var(--space-4);
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: var(--space-3);
}

.kpi-secondary .kpi-label {
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 26px;
  line-height: 1.1;
  color: var(--text-strong);
  letter-spacing: -0.02em;
}

.kpi-secondary .kpi-value {
  font-size: 20px;
}

.kpi-currency {
  font-family: var(--font-sans);
  font-size: 0.65em;
  font-weight: 500;
  color: var(--text-muted);
  margin-right: 2px;
}

.kpi-suffix {
  font-family: var(--font-sans);
  font-size: 0.65em;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 2px;
}

.kpi-accent::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--raiz-green-500);
}

/* ========================================
   Cards
======================================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card-head {
  padding: var(--space-5) var(--space-5) var(--space-3);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}

.card-meta {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 500;
}

/* ========================================
   Tabela
======================================== */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  text-align: right;
  padding: var(--space-3) var(--space-4);
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  background: var(--card-hover);
}

.data-table thead th.th-name {
  text-align: left;
}

.data-table thead th.th-thumb,
.data-table thead th.th-link {
  width: 1%;
}

.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  text-align: right;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-strong);
  white-space: nowrap;
}

.data-table tbody td.td-name {
  text-align: left;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-strong);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table tbody tr:hover {
  background: var(--card-hover);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Linhas de campanha clicáveis (filtro por campanha) */
.campaign-row {
  cursor: pointer;
  transition: background 0.12s ease;
}
.campaign-row:hover {
  background: var(--card-hover);
}
.campaign-row:focus-visible {
  outline: 2px solid var(--raiz-green-500);
  outline-offset: -2px;
}
.campaign-row-active,
.campaign-row-active:hover {
  background: var(--raiz-green-100);
}
.campaign-row-active td.td-name {
  box-shadow: inset 3px 0 0 var(--raiz-green-500);
  font-weight: 600;
}

/* Pílula do filtro de campanha ativo */
.filter-chip {
  margin-left: auto;
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 340px;
  padding: 5px 10px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: var(--raiz-green-700);
  background: var(--raiz-green-100);
  border: 1px solid var(--raiz-green-500);
  border-radius: 999px;
  cursor: pointer;
  transition: filter 0.12s ease;
}
.filter-chip:hover {
  filter: brightness(0.97);
}
.filter-chip .filter-chip-prefix {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  opacity: 0.7;
}
.filter-chip .filter-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filter-chip .filter-chip-x {
  font-size: 12px;
  opacity: 0.65;
}
.filter-chip:hover .filter-chip-x {
  opacity: 1;
}

.data-table tfoot td {
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-strong);
  text-align: right;
  border-top: 2px solid var(--border);
  background: var(--card-hover);
  white-space: nowrap;
}

.data-table tfoot td.td-name {
  text-align: left;
  font-family: var(--font-sans);
}

.td-muted {
  color: var(--text-light) !important;
  font-weight: 400 !important;
}

/* Thumbnail criativos */
.thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--card-hover);
  background-size: cover;
  background-position: center;
  display: block;
  border: 1px solid var(--border-soft);
}

.creative-link {
  color: var(--raiz-green-700);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.creative-link:hover {
  background: var(--raiz-green-100);
  border-color: var(--raiz-green-500);
}

/* ========================================
   Funil
======================================== */
.funnel {
  padding: var(--space-3) var(--space-5) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.funnel-row {
  position: relative;
}

.funnel-bar {
  background: linear-gradient(90deg, var(--raiz-green-800), var(--raiz-green-700));
  border-radius: var(--radius-sm);
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 60px;
}

.funnel-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.funnel-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.funnel-pct {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ========================================
   Charts row
======================================== */
.charts-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
}

.chart-wrap {
  padding: var(--space-4) var(--space-5) var(--space-5);
  height: 260px;
  position: relative;
}

.chart-wrap-timeline {
  height: 320px;
}

.chart-empty {
  position: absolute;
  inset: var(--space-4) var(--space-5);
  display: grid;
  place-items: center;
  color: var(--text-light);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  background: var(--card);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* ========================================
   Overlays (loading / error)
======================================== */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 100;
}

.overlay-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 2.5px solid var(--border);
  border-top-color: var(--raiz-green-700);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.overlay-error {
  background: rgba(247, 248, 245, 0.96);
}

.error-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--red);
}

.error-detail {
  color: var(--text-muted);
  max-width: 480px;
  font-size: 13px;
}

.error-retry {
  margin-top: var(--space-3);
  background: var(--raiz-green-800);
  color: #FFFFFF;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13px;
  transition: background 0.15s;
}

.error-retry:hover {
  background: var(--raiz-green-700);
}

/* ========================================
   Footer
======================================== */
.footer {
  padding: var(--space-8) 0;
  text-align: center;
  color: var(--text-light);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

.footer-sep {
  color: var(--border);
}

/* ========================================
   Animations
======================================== */
.fade-in {
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

.fade-in:nth-child(2) { animation-delay: 0.05s; }
.fade-in:nth-child(3) { animation-delay: 0.1s; }
.fade-in:nth-child(4) { animation-delay: 0.15s; }
.fade-in:nth-child(5) { animation-delay: 0.2s; }
.fade-in:nth-child(6) { animation-delay: 0.25s; }
.fade-in:nth-child(7) { animation-delay: 0.3s; }
.fade-in:nth-child(8) { animation-delay: 0.35s; }

/* ========================================
   Responsivo
======================================== */
@media (max-width: 1100px) {
  .section-row { grid-template-columns: 1fr; }
  .kpi-grid-primary, .kpi-grid-secondary { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .header-inner {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
  .header-tabs { justify-self: start; }
  .kpi-grid-primary, .kpi-grid-secondary { grid-template-columns: 1fr 1fr; }
  .main { padding: var(--space-5) var(--space-3); }
}
