/* Dashboard 2.0 — tokens + shell + componentes.
   Fonte: ../spec-design-system.md. Não duplicar valores fora daqui —
   páginas novas só consomem estas variáveis/classes. */

:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --text-1:      #0b0b0b;
  --text-2:      #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11,11,11,.10);
  --shadow-sm:   0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 8px 28px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.05);

  /* paleta categórica genérica — só páginas neutras (Home/Ajustes/Calculadora) */
  --c1: #2a78d6; --c2: #008300; --c3: #e87ba4; --c4: #eda100;
  --c5: #1baf7a; --c6: #eb6834; --c7: #4a3aa7; --c8: #e34948;

  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;

  /* cor de marca só p/ badge/ícone — nunca série de gráfico */
  --ig: #e1306c; --yt: #ff0000; --tt: #ff0050; --gads: #4285F4;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --radius-sm: 10px; --radius-md: 20px; --radius-lg: 24px; --radius-pill: 999px;

  --sidebar-bg: #14131f;
  --sidebar-text: #8f8da3;
  --sidebar-w: 232px;
  --topbar-h: 64px;

  /* badge de rede — mesma família da sidebar, mas sempre contrastando com --page */
  --badge-bg: var(--sidebar-bg);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:     #0d0d0d;
    --surface:  #1a1a19;
    --text-1:   #ffffff;
    --text-2:   #c3c2b7;
    --grid:     #2c2c2a;
    --baseline: #383835;
    --border:   rgba(255,255,255,.10);
    --c1: #3987e5; --c3: #d55181; --c4: #c98500; --c5: #199e70; --c6: #d95926; --c7: #9085e9; --c8: #e66767;
    --badge-bg: #2c2b3a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:     #0d0d0d;
  --surface:  #1a1a19;
  --text-1:   #ffffff;
  --text-2:   #c3c2b7;
  --grid:     #2c2c2a;
  --baseline: #383835;
  --border:   rgba(255,255,255,.10);
  --c1: #3987e5; --c3: #d55181; --c4: #c98500; --c5: #199e70; --c6: #d95926; --c7: #9085e9; --c8: #e66767;
  --badge-bg: #2c2b3a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-1);
  font-family: "SF Pro Display", -apple-system, system-ui, "Segoe UI", sans-serif;
}

/* ---------- shell layout ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--sidebar-bg);
  padding: var(--space-5) var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-6);
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 var(--space-2); }
.sidebar .brand img { width: 28px; height: 28px; border-radius: 8px; }
.sidebar .brand span { color: #fff; font-weight: 700; font-size: 16px; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group .group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--sidebar-text); padding: 0 var(--space-2); margin-bottom: 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-radius: var(--radius-pill); font-size: 13px; font-weight: 500;
  color: var(--sidebar-text); text-decoration: none; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--c1); color: #fff; }
.nav-item .ic { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-item .ic img { width: 16px; height: 16px; border-radius: 4px; object-fit: cover; }
.nav-item .ic svg { width: 18px; height: 18px; }
.nav-item .count {
  margin-left: auto; background: rgba(255,255,255,.12); color: #fff;
  font-size: 11px; border-radius: 999px; padding: 1px 7px;
}
.nav-item .soon {
  margin-left: auto; font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; color: var(--sidebar-text); background: rgba(255,255,255,.08);
  border-radius: var(--radius-pill); padding: 2px 7px; flex-shrink: 0;
}
.nav-item.disabled { cursor: default; opacity: .65; }
.nav-item.disabled:hover { background: transparent; color: var(--sidebar-text); }
.sidebar .footer { margin-top: auto; }
.sidebar .plan-btn {
  width: 100%; border: none; background: var(--c1); color: #fff; font-weight: 600;
  font-size: 13px; padding: 10px; border-radius: var(--radius-sm); cursor: pointer;
  display: block; box-sizing: border-box; text-align: center; text-decoration: none;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex-shrink: 0; display: flex; align-items: center;
  justify-content: space-between; padding: 0 var(--space-5); gap: var(--space-4);
  border-bottom: 1px solid var(--grid);
}
.topbar .search {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 13px; color: var(--text-2); width: 260px;
}
.topbar .search svg { width: 15px; height: 15px; flex-shrink: 0; }
.topbar .actions { display: flex; align-items: center; gap: var(--space-3); }

/* ---------- seletor de período (topbar) — ver period.js ---------- */
.period-picker { position: relative; }
.date-trigger-btn {
  display: flex; align-items: center; gap: 8px; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--text-1);
  cursor: pointer; text-align: left; transition: border-color .15s;
}
.date-trigger-btn:hover, .date-trigger-btn.open { border-color: var(--c1); }
.date-trigger-btn .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date-trigger-btn .chevron { font-size: 10px; color: var(--muted); transition: transform .15s; }
.date-trigger-btn.open .chevron { transform: rotate(180deg); }

.dp-overlay { display: none; position: fixed; inset: 0; z-index: 40; }
.dp-overlay.open { display: block; }
.dp-panel {
  /* position:fixed (não absolute) de propósito: o pai `.dp-overlay` é
     position:fixed (cobre a tela inteira, cortina pra fechar clicando
     fora), o que vira o containing block de qualquer descendente
     absolute — sem isso, top/left aqui contavam % da tela inteira, não
     do botão. Coordenadas reais vêm do JS em dpToggle() (period.js). */
  position: fixed; top: 0; left: 0; z-index: 41;
  width: min(680px, calc(100vw - 48px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); display: grid; grid-template-columns: 180px 1fr; overflow: hidden;
}
.dp-presets { padding: var(--space-3) var(--space-2); border-right: 1px solid var(--border); overflow-y: auto; max-height: 420px; }
.dp-preset-section { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 8px 8px 4px; }
.dp-preset-btn {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-1);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; text-align: left; transition: background .12s;
}
.dp-preset-btn:hover { background: var(--page); }
.dp-preset-btn.active { background: var(--c1); color: #fff; }
.dp-preset-dot { width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; flex-shrink: 0; position: relative; }
.dp-preset-btn.active .dp-preset-dot::after { content: ''; position: absolute; inset: 2px; border-radius: 50%; background: #fff; }

.dp-cal-wrap { padding: var(--space-4) var(--space-5); }
.dp-cal-months { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.dp-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dp-cal-title { font-size: 13px; font-weight: 700; color: var(--text-1); text-transform: capitalize; }
.dp-cal-nav {
  width: 26px; height: 26px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--page); color: var(--text-1); cursor: pointer; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.dp-cal-nav.hidden { visibility: hidden; }
.dp-days-head { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; margin-bottom: 4px; }
.dp-days-head span { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-2); padding: 4px 0; }
.dp-days { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; }
.dp-day {
  min-height: 30px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-1);
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: background .1s;
  display: flex; align-items: center; justify-content: center;
}
.dp-day:hover:not(.dp-day-empty) { background: var(--page); }
.dp-day-empty { visibility: hidden; pointer-events: none; }
.dp-day-in-range { background: var(--grid); border-radius: 0; }
.dp-day-start, .dp-day-end { background: var(--c1) !important; color: #fff !important; border-radius: var(--radius-sm) !important; }

.dp-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.dp-selected-label { font-size: 13px; font-weight: 700; }
.dp-selected-sub { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.dp-actions { display: flex; gap: 8px; }
.dp-btn {
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--page); color: var(--text-1); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.dp-btn-primary { border-color: transparent; background: var(--c1); color: #fff; }
@media (max-width: 900px) {
  .dp-panel { grid-template-columns: 1fr; position: fixed; left: 24px; right: 24px; top: 74px; width: auto; }
  .dp-presets { border-right: none; border-bottom: 1px solid var(--border); max-height: none; display: flex; flex-wrap: wrap; }
}
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-2);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.spinning svg { animation: icon-spin .7s linear infinite; }
.icon-btn.done { border-color: var(--good); color: var(--good); }
@keyframes icon-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-chip .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--c1); }
.user-chip .name { font-size: 13px; font-weight: 600; }
.user-chip .role { font-size: 11px; color: var(--text-2); }

.content { padding: var(--space-5); flex: 1; }
.content h1 { font-size: 24px; font-weight: 700; margin: 0 0 var(--space-5); }

/* ---------- shared components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm); padding: var(--space-4);
}
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: var(--space-4); margin-bottom: var(--space-5); }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-4); margin-bottom: var(--space-5); }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-label { font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 4px; display:flex; align-items:center; gap:6px; }
.stat-value { font-size: 32px; font-weight: 700; line-height: 1.1; }
.stat-delta { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; }
.stat-delta.up { color: var(--good); }
.stat-delta.down { color: var(--critical); }

.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 var(--space-3); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }

.legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: 12px; }
.legend .item { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ---------- tooltip compartilhado por todo gráfico SVG (charts.js) ---------- */
.chart-tooltip {
  position: fixed; z-index: 1000; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  padding: 8px 10px; font-size: 12px; color: var(--text-1);
  opacity: 0; transform: translate(-50%, calc(-100% - 10px));
  transition: opacity .1s ease; white-space: nowrap;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip-title { font-weight: 600; color: var(--text-2); margin-bottom: 4px; font-size: 11px; }
.chart-tooltip-row { display: flex; align-items: center; gap: 14px; justify-content: space-between; }
.chart-tooltip-row + .chart-tooltip-row { margin-top: 3px; }
.chart-tooltip-key { width: 8px; height: 2px; border-radius: 1px; flex-shrink: 0; }
.chart-tooltip-label { color: var(--text-2); }
.chart-tooltip-value { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- estados de hover dos gráficos ---------- */
.chart-axis-label { font-size: 10px; fill: var(--muted); }
.chart-gridline { stroke: var(--grid); stroke-width: 1; }
.chart-bar { cursor: pointer; transition: opacity .12s ease; }
.chart-bar:hover, .chart-bar.hovered { opacity: .82; }
.donut-seg { cursor: pointer; transition: opacity .12s ease; }
.donut-seg.dimmed { opacity: .35; }
.chart-hit { fill: transparent; cursor: crosshair; }
.chart-crosshair { stroke: var(--baseline); stroke-width: 1; pointer-events: none; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--grid); }
table th { color: var(--text-2); font-weight: 500; font-size: 12px; }
table th.num, table td.num { text-align: right; }
table td.num { font-variant-numeric: tabular-nums; }
table tr:last-child td { border-bottom: none; }
.net-cell { display: flex; align-items: center; gap: 10px; }
.net-icon {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: var(--badge-bg); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.net-icon svg { display: block; }

.rate-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.rate-cell .bar-track { width: 56px; height: 6px; border-radius: var(--radius-pill); background: var(--grid); overflow: hidden; }
.rate-cell .bar-fill { height: 100%; border-radius: var(--radius-pill); }

.donut-wrap { display: flex; align-items: center; gap: var(--space-5); }

.fol-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: var(--space-4); }
.fol-card { display: flex; flex-direction: column; gap: 4px; }
.fol-platform { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.fol-platform .net-icon { width: 22px; height: 22px; }
.fol-video-label { font-size: 11px; color: var(--text-2); margin-top: 2px; }
