/* ──────────────────────────────────────────────────────────────
   Paleta de cores — CWB Kids
   Primária: #48b8c9 (turquesa) | Acento: #ed4c81 (rosa)
   ────────────────────────────────────────────────────────────── */
:root {
  --color-primary:      #48b8c9;
  --color-primary-soft: #e3f6f9;
  --color-accent:       #ed4c81;
  --color-bg:           #f0f3f7;
  --color-card:         #ffffff;
  --color-text:         #1c3a40;
  --color-muted:        #7a8fa0;
  --color-border:       #e4eaef;
  --color-success:      #22c55e;
  --color-warning:      #f59e0b;
  --color-danger:       #ef4444;
  --color-sidebar:      #48b8c9;
  --radius:             14px;
  --radius-sm:          10px;
  --shadow-card:        0 1px 3px rgba(0,0,0,0.04), 0 6px 20px rgba(0,0,0,0.07);
  --shadow-sm:          0 1px 3px rgba(0,0,0,0.07);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

a { color: inherit; }

/* ── Layout: sidebar + conteúdo ── */
.layout-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  display: flex; flex-direction: column;
  width: 220px; min-width: 220px;
  background: var(--color-sidebar);
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-brand img {
  width: 100%;
  max-width: 110px;
  display: block;
}

/* ── Nav de abas dentro da sidebar ── */
#tabs {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 10px;
  flex: 1;
}

.nav-section-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.3);
  padding: 14px 12px 6px;
}

#tabs button {
  background: transparent; border: none;
  color: rgba(255,255,255,0.80);
  padding: 10px 12px; font-size: 0.86rem;
  font-weight: 500; cursor: pointer;
  border-radius: var(--radius-sm); text-align: left;
  display: flex; align-items: center; gap: 10px;
  transition: color 0.15s, background 0.15s;
  position: relative;
}
#tabs button:hover {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.07);
}
#tabs button.active {
  color: #fff;
  background: rgba(255,255,255,0.2);
  font-weight: 700;
  box-shadow: inset 3px 0 0 #fff;
}
.tab-icon { font-size: 1rem; flex-shrink: 0; line-height: 1; opacity: 0.85; }
.tab-icon-img { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; }
.tab-icon-img img { width: 18px; height: 18px; object-fit: contain; filter: brightness(0) invert(1); opacity: 0.75; }
#tabs button.active .tab-icon-img img { opacity: 1; }
#tabs button.active .tab-icon { opacity: 1; }

/* ── Área de conteúdo ── */
.content-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── Topbar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  height: 58px; flex-shrink: 0;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title {
  font-size: 1.05rem; font-weight: 700; color: var(--color-text);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-logout {
  background: transparent; border: 1px solid var(--color-border);
  color: var(--color-muted); border-radius: 8px;
  padding: 6px 14px; font-size: 0.8rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s;
}
.topbar-logout:hover {
  color: var(--color-text); border-color: var(--color-primary);
}

main { flex: 1; padding: 28px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Section titles ── */
.section-title {
  font-size: 0.95rem; font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: 32px 0 16px;
}
.section-title:first-child { margin-top: 0; }

/* ── KPI bar ── */
.kpi-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }

.kpi {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 20px;
  border: none;
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column;
}

.kpi-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  margin-bottom: 14px;
  flex-shrink: 0;
  background: var(--color-primary-soft);
}

.kpi .label {
  font-size: 0.68rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  line-height: 1.3;
}
.kpi .value {
  font-size: 1.6rem; font-weight: 800;
  margin-top: 4px; letter-spacing: -0.02em; line-height: 1.15;
}
.kpi .delta {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 0.68rem; font-weight: 700;
  margin-top: 10px; width: fit-content;
}
.kpi .delta.up   { background: #dcfce7; color: #15803d; }
.kpi .delta.down { background: #fee2e2; color: #dc2626; }

/* ── KPI bar compacta ── */
.kpi-bar--compact { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.kpi-bar--compact .kpi { padding: 16px; }
.kpi-bar--compact .kpi-icon { width: 34px; height: 34px; font-size: 0.9rem; margin-bottom: 10px; }
.kpi-bar--compact .kpi .value { font-size: 1.25rem; }

/* ── Card grid ── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }

/* ── Top Criativos ── */
.criativo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.criativo-card {
  background: var(--color-card); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-card); border: none;
}
.criativo-rank { font-size: 0.65rem; font-weight: 700; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.criativo-name { font-size: 0.83rem; font-weight: 600; margin-bottom: 14px; min-height: 2.6em; line-height: 1.35; word-break: break-word; }
.criativo-ctr { font-size: 2rem; font-weight: 800; color: var(--color-primary); line-height: 1; letter-spacing: -0.03em; }
.criativo-ctr-label { font-size: 0.65rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; margin-bottom: 14px; }
.criativo-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; border-top: 1px solid var(--color-border); padding-top: 14px; }
.criativo-metric { display: flex; flex-direction: column; gap: 2px; }
.criativo-metric .m-label { font-size: 0.64rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.criativo-metric .m-value { font-size: 0.88rem; font-weight: 600; }

.card { background: var(--color-card); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-card); border: none; }
.card .card-label { font-size: 0.7rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.card .card-value { font-size: 1.3rem; font-weight: 700; margin-top: 6px; }

/* ── Chart grid ── */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-card, .chart-full {
  background: var(--color-card); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow-card); border: none;
}
.chart-full { margin-top: 20px; }
.chart-card h3, .chart-full h3 {
  font-size: 0.8rem; color: var(--color-muted); margin-bottom: 18px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
}
.chart-card canvas { width: 100% !important; max-height: 280px; }
.chart-full canvas { width: 100% !important; }

/* ── Funil ── */
.funnel { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.funnel-step {
  display: grid; grid-template-columns: 160px 1fr 120px;
  align-items: center; gap: 14px; font-size: 0.82rem;
}
.funnel-label { color: var(--color-text); font-weight: 500; }
.funnel-bar-outer { display: flex; justify-content: center; height: 28px; }
.funnel-bar-inner {
  background: linear-gradient(90deg, var(--color-primary), #5ecfdf);
  height: 100%; border-radius: 6px; min-width: 4px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.funnel-rate { color: var(--color-text); font-weight: 700; text-align: right; font-size: 0.84rem; }
.funnel-conv { color: var(--color-muted); font-size: 0.73rem; font-weight: 400; margin-left: 4px; }

/* ── Tabela ── */
.table-wrap { overflow-x: auto; margin-top: 16px; border-radius: var(--radius); box-shadow: var(--shadow-card); }
table { width: 100%; border-collapse: collapse; background: var(--color-card); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 11px 16px; text-align: right; font-size: 0.82rem; border-bottom: 1px solid var(--color-border); }
th {
  background: #f8fafc;
  color: var(--color-muted); font-size: 0.72rem;
  font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  cursor: pointer; user-select: none; white-space: nowrap;
}
th:hover { color: var(--color-primary); }
th::after { content: ' \25B4\25BE'; font-size: 0.6rem; opacity: 0.35; }
th.asc::after  { content: ' \25B4'; opacity: 1; color: var(--color-primary); }
th.desc::after { content: ' \25BE'; opacity: 1; color: var(--color-primary); }
td:first-child, th:first-child { text-align: left; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fcfd; }
tfoot td { font-weight: 700; background: #f8fafc; }

.detail-toggle {
  background: transparent; border: 1px solid var(--color-border);
  color: var(--color-muted); border-radius: 8px;
  padding: 8px 16px; font-size: 0.82rem; cursor: pointer; margin-top: 18px;
  transition: all 0.15s;
}
.detail-toggle:hover { color: var(--color-text); border-color: var(--color-primary); }
.detail-section { display: none; margin-top: 8px; }
.detail-section.open { display: block; }

/* ── Insights ── */
.insights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-top: 16px; }
.insight-card {
  background: var(--color-card); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-card);
  border: none; border-left: 4px solid var(--color-primary);
}
.insight-card.success { border-left-color: var(--color-success); }
.insight-card.warning { border-left-color: var(--color-warning); }
.insight-card.danger  { border-left-color: var(--color-danger); }
.insight-card h4 { font-size: 0.86rem; font-weight: 700; margin-bottom: 6px; }
.insight-card p  { font-size: 0.82rem; color: var(--color-muted); line-height: 1.5; }

/* ── Botão de período na sidebar ── */
.sidebar-period {
  padding: 10px 10px 4px;
  flex-shrink: 0;
}
.period-trigger {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 8px;
  padding: 9px 12px; color: rgba(255,255,255,0.85);
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  text-align: left; gap: 6px; transition: background 0.15s;
}
.period-trigger:hover { background: rgba(255,255,255,0.17); }
.period-caret { opacity: 0.6; font-size: 0.75rem; flex-shrink: 0; }

/* ── Popup de data ── */
.dp-popup {
  position: fixed; z-index: 1000;
  display: flex;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 56px rgba(0,0,0,0.2);
  overflow: hidden;
}
.dp-left {
  width: 172px; min-width: 172px;
  background: #1a2b35;
  padding: 18px 0;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.dp-preset {
  background: none; border: none; color: rgba(255,255,255,0.65);
  text-align: left; padding: 9px 20px;
  font-size: 0.82rem; cursor: pointer; width: 100%;
  transition: all 0.12s;
}
.dp-preset:hover  { color: #fff; background: rgba(255,255,255,0.08); }
.dp-preset.active { color: #fff; background: rgba(72,184,201,0.2); }
.dp-months-header {
  color: rgba(255,255,255,0.3); font-size: 0.62rem;
  letter-spacing: 0.12em; text-transform: uppercase;
  padding: 14px 20px 6px;
}
.dp-month-item {
  background: none; border: none; color: rgba(255,255,255,0.65);
  text-align: left; padding: 7px 20px;
  font-size: 0.82rem; cursor: pointer; width: 100%;
  transition: all 0.12s;
}
.dp-month-item:hover  { color: #fff; background: rgba(255,255,255,0.08); }
.dp-month-item.active { color: #fff; background: rgba(72,184,201,0.2); }

/* ── Área de calendários ── */
.dp-right {
  flex: 1; display: flex; flex-direction: column; padding: 22px;
  min-width: 480px;
}
.dp-calendars { display: flex; gap: 24px; }
.dp-cal { flex: 1; }
.dp-cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; font-size: 0.88rem; font-weight: 700;
}
.dp-nav {
  background: none; border: 1px solid var(--color-border);
  border-radius: 6px; cursor: pointer;
  font-size: 1rem; color: var(--color-muted);
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.dp-nav:hover { color: var(--color-text); border-color: var(--color-primary); }
.dp-day-names {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: 0.7rem; color: var(--color-muted);
  margin-bottom: 6px; gap: 2px;
}
.dp-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; border-radius: 50%; cursor: pointer; user-select: none;
  transition: background 0.1s;
}
.dp-day:not(.empty):hover { background: var(--color-primary-soft); }
.dp-day.in-range { background: #d6f2f6; border-radius: 0; }
.dp-day.selected { background: var(--color-primary) !important; color: #fff; border-radius: 50%; font-weight: 700; }
.dp-day.today    { font-weight: 700; color: var(--color-primary); }
.dp-day.empty    { cursor: default; pointer-events: none; }

/* ── Rodapé do popup ── */
.dp-footer {
  margin-top: 18px; border-top: 1px solid var(--color-border);
  padding-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.dp-range-label { font-size: 0.8rem; color: var(--color-muted); flex: 1; }
.dp-actions { display: flex; gap: 8px; flex-shrink: 0; }
.dp-actions button {
  border-radius: 8px; padding: 8px 18px; font-size: 0.82rem; font-weight: 600; cursor: pointer; border: none;
}
#dp-cancel { background: #f0f2f5; color: #555; }
#dp-cancel:hover { background: #e4e7ec; }
#dp-apply { background: var(--color-primary); color: #fff; }
#dp-apply:hover { opacity: 0.88; }

/* ── Filtro de período (relatórios) ── */
.period-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.period-bar select {
  background: var(--color-card); border: 1px solid var(--color-border); color: var(--color-text);
  border-radius: 8px; padding: 8px 14px; font-size: 0.85rem; box-shadow: var(--shadow-sm);
}

/* ── Botões de seção nos relatórios ── */
.report-section-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 24px; }
.rst-btn {
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  color: var(--color-muted);
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.rst-btn:hover { border-color: var(--color-primary); color: var(--color-text); }
.rst-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.empty-state { color: var(--color-muted); font-size: 0.85rem; padding: 28px; text-align: center; }

/* ── Cabeçalho de impressão (oculto na tela) ── */
.print-header { display: none; }
.print-section-name { font-size: 1rem; font-weight: 800; color: rgba(255,255,255,0.92); }
.print-period { font-size: 0.72rem; color: rgba(255,255,255,0.55); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.1em; }

@media (max-width: 768px) {
  .layout-wrapper { flex-direction: column; }
  .sidebar { flex-direction: column; width: 100%; height: auto; position: static; }
  .sidebar-brand { padding: 16px 20px; border-bottom: none; border-right: none; }
  #tabs { flex-direction: row; flex-wrap: wrap; padding: 8px 10px;
          border-top: 1px solid rgba(255,255,255,0.1); }
  #tabs button { border-left: none; box-shadow: none; border-bottom: 3px solid transparent; padding: 8px 10px; }
  #tabs button.active { border-bottom-color: var(--color-primary); background: rgba(72,184,201,0.12); }
  main { padding: 16px; }
  .chart-grid { grid-template-columns: 1fr; }
  .funnel-step { grid-template-columns: 90px 1fr 60px; }
  .topbar { padding: 0 16px; }
}

@media print {
  /* ── Oculta interface de navegação ── */
  .sidebar, .topbar, .dp-popup, .period-bar, .detail-toggle,
  .detail-section { display: none !important; }

  /* ── Layout ── */
  @page { margin: 0; size: A4 portrait; }

  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  html, body { background: var(--color-sidebar) !important; margin: 0 !important; padding: 0 !important; }
  .layout-wrapper, .content-area, main { display: block !important; background: var(--color-sidebar) !important; padding: 0 !important; }

  .tab-panel { display: none !important; }
  .tab-panel.active { display: block !important; }

  /* ── Páginas ── */
  .print-page {
    background: var(--color-sidebar) !important;
    padding: 36px 44px;
    page-break-after: always;
    display: block !important;
    position: relative;
  }
  .print-page:last-child { page-break-after: auto; }

  /* ── Cabeçalho de impressão ── */
  .print-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 26px;
    padding-bottom: 14px;
    border-bottom: 1.5px solid rgba(255,255,255,0.25);
  }
  .print-header img {
    height: 34px; width: auto;
    filter: brightness(0) invert(1);
  }
  .print-header-info { text-align: right; }

  /* ── Texto sobre fundo turquesa ── */
  .section-title { color: rgba(255,255,255,0.65) !important; margin: 22px 0 12px !important; }
  .print-header + .section-title,
  .print-header ~ h2.section-title:first-of-type { margin-top: 0 !important; }

  /* ── Cards: brancos sem sombra ── */
  .kpi, .chart-card, .chart-full, .table-wrap, table,
  .insight-card, .criativo-card, .card {
    box-shadow: none !important;
    border: none !important;
  }
  th { background: #f8fafc !important; }
  .chart-full { margin-top: 0 !important; }

  /* ── Funil ── */
  .funnel-bar-inner { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
