/* =====================================================================
   AZTV Family — Backoffice · Design System (app.css)
   Paleta e tratamento extraídos do dashboard atual (dashboard.php):
   fundo #050505, superfícies em white-alpha, hairlines, pesos leves,
   laranja #FF6A00 com texto preto nos botões, paleta de apoio viva e
   cor por plano (Mensal=azul, Tri=roxo, Sem=amber, Anual=laranja).
   Números em JetBrains Mono / tabular-nums. Sem sombras pesadas.
   ===================================================================== */

/* ------------------------------------------------------------------ */
/* 1. TOKENS (idênticos ao sistema atual + extensões do backoffice)   */
/* ------------------------------------------------------------------ */
:root {
  --bg: #050505;
  --surface-1: rgba(255,255,255,.022);
  --surface-2: rgba(255,255,255,.035);
  --surface-3: rgba(255,255,255,.05);
  --elevated: #0d0d10;                 /* opaco: tooltips, dropdowns, toast, menus */

  --border-1: rgba(255,255,255,.055);
  --border-2: rgba(255,255,255,.085);
  --border-hover: rgba(255,255,255,.12);

  --text-1: rgba(255,255,255,.96);
  --text-2: rgba(255,255,255,.55);
  --text-3: rgba(255,255,255,.35);
  --text-4: rgba(255,255,255,.22);

  --brand: #FF6A00;
  --brand-hover: #FF7818;
  --brand-soft: rgba(255,106,0,.10);
  --brand-border: rgba(255,106,0,.25);

  --green: #4ade80;  --green-soft: rgba(74,222,128,.10);  --green-border: rgba(74,222,128,.22);
  --red: #f87171;    --red-soft: rgba(248,113,113,.10);   --red-border: rgba(248,113,113,.22);
  --blue: #60a5fa;   --blue-soft: rgba(96,165,250,.10);   --blue-border: rgba(96,165,250,.22);
  --purple: #a78bfa; --purple-soft: rgba(167,139,250,.10);--purple-border: rgba(167,139,250,.22);
  --amber: #fbbf24;  --amber-soft: rgba(251,191,36,.10);  --amber-border: rgba(251,191,36,.25);
  --whatsapp: #25D366;
  --whatsapp-soft: rgba(37,211,102,.10);

  /* --- tokens extraídos de valores fixos (DARK mantém exatamente o valor que estava inline) --- */
  --on-brand: #000;                      /* texto sobre o laranja (botão/logo) — preto nos 2 temas */
  --brand-ink: #FF6A00;                  /* laranja de TEXTO/ícone (no light escurece p/ passar AA) */
  --brand-selection: rgba(255,106,0,.3);
  --field-bg: rgba(255,255,255,.04);     /* input, badge, pill.flat, segmented, input-group, cell-input:focus */
  --shimmer: rgba(255,255,255,.05);      /* skeleton */
  --tooltip-title-bg: rgba(255,255,255,.03);
  --overlay: rgba(0,0,0,.6);             /* scrim do menu mobile */
  --overlay-2: rgba(0,0,0,.55);          /* scrim do drawer */
  --track: rgba(255,255,255,.06);        /* trilho da .bar */
  --track-alt: rgba(255,255,255,.08);    /* quadradinhos do RFM */
  --on-cohort: #fff;                     /* texto sobre a célula do cohort (fundo sempre saturado) */
  --shadow-1: rgba(0,0,0,.22);
  --shadow-2: rgba(0,0,0,.3);
  --shadow-3: rgba(0,0,0,.45);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='rgba(255,255,255,.4)' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");

  /* --- paleta das SÉRIES dos gráficos (separada do texto: séries só precisam 3:1, texto precisa 4.5:1).
         DARK = os mesmos valores de hoje -> gráficos idênticos. LIGHT = paleta validada (CVD 9.2 / normal 19.8). --- */
  --chart-brand: #FF6A00;
  --chart-blue: #60a5fa;
  --chart-purple: #a78bfa;
  --chart-amber: #fbbf24;
  --chart-green: #4ade80;
  --chart-red: #f87171;

  --radius-card: 12px;
  --radius-input: 8px;
  --radius-pill: 6px;

  --ease: cubic-bezier(0.2,0,0,1);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --sidebar-w: 248px;
  --topbar-h: 60px;

  --form-scheme: dark;   /* color-scheme dos inputs/selects nativos (calendário, spinner, dropdown) — segue o tema */
  color-scheme: dark;
}

/* ------------------------------------------------------------------ */
/* 1b. TEMA LIGHT — paleta PRÓPRIA (não é o dark invertido).           */
/*   · fundo #FAFAFA (não branco puro, cansa menos) + cards brancos    */
/*   · tons de estado ESCURECIDOS: os pastéis do dark lavam no claro   */
/*   · laranja puro só como PREENCHIMENTO (botão, texto preto 7.3:1);  */
/*     como texto usa --brand-ink #C2410C (4.96:1 = AA)                */
/*   Contrastes conferidos: text-1 16.9 · text-2 7.4 · text-3 5.0 ·    */
/*   green 5.2 · red 4.6 · blue 5.7 · purple 5.5 · amber 4.8 (todos AA)*/
/*   Séries dos gráficos: paleta validada (CVD 9.2 · normal 19.8)      */
/* ------------------------------------------------------------------ */
[data-theme="light"] {
  --bg: #FAFAFA;
  --surface-1: #FFFFFF;
  --surface-2: #F4F4F5;
  --surface-3: #ECECEF;
  --elevated: #FFFFFF;

  --border-1: #E7E7EA;
  --border-2: #D8D8DD;
  --border-hover: #B4B4BC;

  --text-1: #18181B;
  --text-2: #52525B;
  --text-3: #6B6B76;
  --text-4: #82828B;

  --brand: #FF6A00;
  --brand-hover: #E85F00;
  --brand-ink: #C2410C;
  --brand-soft: rgba(255,106,0,.10);
  --brand-border: rgba(255,106,0,.32);
  --brand-selection: rgba(255,106,0,.22);

  --green:  #047857; --green-soft:  rgba(4,120,87,.09);   --green-border:  rgba(4,120,87,.22);
  --red:    #dc2626; --red-soft:    rgba(220,38,38,.09);  --red-border:    rgba(220,38,38,.22);
  --blue:   #0369a1; --blue-soft:   rgba(3,105,161,.09);  --blue-border:   rgba(3,105,161,.22);
  --purple: #7c3aed; --purple-soft: rgba(124,58,237,.09); --purple-border: rgba(124,58,237,.22);
  --amber:  #b45309; --amber-soft:  rgba(180,83,9,.09);   --amber-border:  rgba(180,83,9,.24);
  --whatsapp: #0F766E; --whatsapp-soft: rgba(15,118,110,.10);

  --on-brand: #000;
  --field-bg: #F4F4F5;
  --shimmer: rgba(0,0,0,.05);
  --tooltip-title-bg: rgba(0,0,0,.03);
  --overlay: rgba(24,24,27,.45);
  --overlay-2: rgba(24,24,27,.38);
  --track: rgba(0,0,0,.08);
  --track-alt: rgba(0,0,0,.11);
  --on-cohort: #fff;                     /* célula do cohort segue saturada -> texto branco */
  --shadow-1: rgba(24,24,27,.06);
  --shadow-2: rgba(24,24,27,.10);
  --shadow-3: rgba(24,24,27,.14);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='rgba(0,0,0,.45)' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");

  --chart-brand: #EA580C;
  --chart-blue: #0284c7;
  --chart-purple: #7c3aed;
  --chart-amber: #b45309;
  --chart-green: #059669;
  --chart-red: #dc2626;

  --form-scheme: light;
  color-scheme: light;
}

/* ------------------------------------------------------------------ */
/* 2. BASE                                                            */
/* ------------------------------------------------------------------ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  background: var(--bg); color: var(--text-1);
  font-family: var(--font-sans); font-size: 14px; line-height: 1.5; font-weight: 400;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--brand-selection); }
h1,h2,h3,h4 { font-weight: 600; letter-spacing: -.2px; text-wrap: balance; line-height: 1.2; }
p { text-wrap: pretty; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
img { display: block; }
.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* scrollbar + focus */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }
:focus-visible { outline: none; border-color: var(--brand-border); box-shadow: 0 0 0 3px var(--brand-soft); }

.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.eyebrow { font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-3); font-weight: 500; }
.row { display: flex; align-items: center; }
.gap-1{gap:.5rem}.gap-2{gap:.75rem}.gap-3{gap:1rem}.gap-4{gap:1.5rem}

/* ------------------------------------------------------------------ */
/* 3. APP SHELL                                                       */
/* ------------------------------------------------------------------ */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: 100vh; overflow: hidden; transition: grid-template-columns .22s var(--ease); }

.sidebar { background: var(--bg); border-right: 1px solid var(--border-1); display: flex; flex-direction: column; overflow-y: auto; }
.sidebar__brand { display: flex; align-items: center; gap: 10px; height: var(--topbar-h); padding: 0 18px; border-bottom: 1px solid var(--border-1); flex-shrink: 0; }
.sidebar__logo { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 15px; flex-shrink: 0; }
.sidebar__logoimg { height: 22px; width: auto; display: block; flex-shrink: 0; }
.sidebar__brand b { font-weight: 600; font-size: 14px; letter-spacing: -.2px; }
.sidebar__brand small { display: block; font-size: 11px; color: var(--text-3); font-weight: 500; }

.sidebar__nav { padding: 8px 10px 24px; }
.nav-group { margin-top: 16px; }
.nav-group__title { padding: 0 10px 6px; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-4); font-weight: 500; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius-input);
  color: var(--text-2); font-size: 13px; font-weight: 500; text-align: left; border: 0; background: transparent;
  transition-property: background, color; transition-duration: 180ms; transition-timing-function: var(--ease);
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-3); transition: color 180ms var(--ease); }
.nav-item:hover { background: var(--surface-1); color: var(--text-1); }
.nav-item:hover svg { color: var(--text-2); }
.nav-item.is-active { background: var(--surface-2); color: var(--text-1); }
.nav-item.is-active svg { color: var(--brand-ink); }
.nav-item.is-active::before { content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%); width: 2px; height: 16px; border-radius: 99px; background: var(--brand); }
.nav-item__badge { margin-left: auto; font-size: 10px; color: var(--text-4); }

.main { display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar { height: var(--topbar-h); flex-shrink: 0; display: flex; align-items: center; gap: 14px; padding: 0 24px; border-bottom: 1px solid var(--border-1); }
.topbar__title { font-size: 14px; font-weight: 600; letter-spacing: -.2px; }
.topbar__title small { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; letter-spacing: 0; }
.topbar__spacer { flex: 1; }
.status-dot { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.status-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); animation: pulse 2s ease infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.hamburger { display: inline-flex; }   /* visível nos 2 contextos: mobile abre o overlay, desktop recolhe a sidebar */

/* DESKTOP: sidebar recolhida em faixa de ícones (toggle no #hb; persiste em aztv_sidebar).
   Só no desktop — no mobile o #hb controla o overlay (.app.nav-open), não isto. */
@media (min-width: 1024.02px) {   /* casa exatamente com o teste do JS (min-width:1024.02) — sem fresta entre 1024/1025 */
  :root.sidebar-collapsed .app { grid-template-columns: 64px 1fr; }
  :root.sidebar-collapsed .nav-item span,
  :root.sidebar-collapsed .nav-group__title,
  :root.sidebar-collapsed .sidebar__brand b,
  :root.sidebar-collapsed .sidebar__brand small { display: none; }
  :root.sidebar-collapsed .nav-item { justify-content: center; padding: 8px 0; }
  :root.sidebar-collapsed .nav-item.is-active::before { display: none; }
  :root.sidebar-collapsed .sidebar__brand { justify-content: center; padding: 0; overflow: hidden; }
  :root.sidebar-collapsed .sidebar__logoimg { height: auto; max-width: 42px; }   /* wordmark escala p/ caber na faixa, sem cortar */
  :root.sidebar-collapsed .sidebar__nav { padding: 8px 8px 24px; }
}

.content { flex: 1; overflow-y: auto; padding: 24px; }
.content__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.content__head h1 { font-size: 20px; }
.content__head p { color: var(--text-3); font-size: 13px; margin-top: 3px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 12px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* Projeção de fechamento (Visão Geral) — card com barra de progresso + células */
.projhead { align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.projprog { min-width: 200px; flex: 0 0 auto; }
.projprog__txt { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-3); text-align: right; margin-bottom: 6px; }
.projprog__txt b { color: var(--text-1); font-weight: 600; }
.projbar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.projbar__fill { height: 100%; border-radius: 999px; background: var(--brand); transition: width .4s ease; }
.projgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.projcell { background: var(--surface-1); border: 1px solid var(--border-1); border-radius: 10px; padding: 12px 14px; }
.projcell__label { display: block; font-size: 12px; color: var(--text-3); }
.projcell__value { display: block; font-family: 'JetBrains Mono', monospace; font-size: 20px; font-weight: 500; color: var(--text-1); margin-top: 4px; letter-spacing: -.01em; }
.projcell__sub { display: block; font-size: 11px; color: var(--text-3); margin-top: 3px; }
.projcell--hero { background: var(--brand-soft); border-color: var(--brand-border); }
.projcell--hero .projcell__value { color: var(--brand-ink); }
.projcell--hero.projcell--neg { background: var(--red-soft); border-color: var(--red-border); }
.projcell--hero.projcell--neg .projcell__value { color: var(--red); }

/* Estoque de códigos + Burn Rate (Fase 5) */
.stockgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .stockgrid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stockgrid { grid-template-columns: 1fr; } }
.stockcard { background: var(--surface-1); border: 1px solid var(--border-1); border-radius: 14px; padding: 16px 18px; }
.stockcard__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stockcard__name { font-size: 11px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: .8px; }
.stockcard__badge { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; padding: 3px 7px; border-radius: 5px; color: var(--green); background: var(--green-soft); border: 1px solid var(--green-border); }
.stockcard__value { font-family: 'JetBrains Mono', monospace; font-size: 30px; font-weight: 500; color: var(--text-1); line-height: 1; letter-spacing: -.02em; }
.stockcard__sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.stockbar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin: 12px 0 8px; }
.stockbar__fill { height: 100%; border-radius: 999px; background: var(--green); }
.stockcard__foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); }
.stockcard--baixo .stockcard__badge { color: var(--amber); background: var(--amber-soft); border-color: var(--amber-border); }
.stockcard--baixo .stockbar__fill { background: var(--amber); }
.stockcard--baixo .stockcard__value { color: var(--amber); }
.stockcard--critico { border-color: var(--red-border); background: var(--red-soft); }
.stockcard--critico .stockcard__badge { color: var(--red); background: var(--red-soft); border-color: var(--red-border); }
.stockcard--critico .stockbar__fill { background: var(--red); }
.stockcard--critico .stockcard__value { color: var(--red); }
.alertbar { display: flex; align-items: center; gap: 10px; background: var(--red-soft); border: 1px solid var(--red-border); color: var(--text-1); border-radius: 12px; padding: 12px 16px; margin-bottom: 12px; font-size: 13px; }
.alertbar svg { color: var(--red); flex: none; }

/* ponto de alerta crítico no item da sidebar (Estoque de Códigos) */
.nav-alert { margin-left: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--red); flex: none; box-shadow: 0 0 0 3px var(--red-soft); animation: pulse 2s ease infinite; }
/* pop-up de estoque crítico (canto inferior direito, junto dos toasts) */
.alert-toast { min-width: 300px; max-width: 360px; padding: 14px 16px; background: var(--elevated); border: 1px solid var(--red-border); border-left: 3px solid var(--red); border-radius: var(--radius-card); animation: toast-in .28s var(--ease) both; display: flex; flex-direction: column; gap: 12px; }
.alert-toast.is-out { animation: toast-out .2s var(--ease) both; }
.alert-toast__body { display: flex; gap: 10px; align-items: flex-start; }
.alert-toast__body svg { color: var(--red); flex: none; margin-top: 1px; }
.alert-toast__body b { font-size: 13px; font-weight: 600; }
.alert-toast__body p { font-size: 12px; color: var(--text-2); margin: 4px 0 0; line-height: 1.4; }
.alert-toast__actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.alert-toast__close { background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 6px; border-radius: 6px; display: inline-flex; }
.alert-toast__close:hover { background: var(--surface-2); color: var(--text-1); }

/* Insights (cards de regra determinística) */
.insight-list { display: grid; gap: 10px; }
.insight { display: flex; gap: 12px; align-items: flex-start; background: var(--surface-1); border: 1px solid var(--border-1); border-left: 3px solid var(--text-3); border-radius: 12px; padding: 14px 16px; transition: background 180ms var(--ease); }
.insight:hover { background: var(--surface-2); }
.insight[data-goto] { cursor: pointer; }
.insight__icon { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); }
.insight__icon svg { color: var(--text-2); }
.insight__body { flex: 1; min-width: 0; }
.insight__sev { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); }
.insight__body p { font-size: 13.5px; color: var(--text-1); margin: 2px 0 0; line-height: 1.45; }
.insight__link { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--brand-ink); margin-top: 6px; }
.insight--critico { border-left-color: var(--red); }   .insight--critico .insight__icon { background: var(--red-soft); }   .insight--critico .insight__icon svg { color: var(--red); }   .insight--critico .insight__sev { color: var(--red); }
.insight--atencao { border-left-color: var(--amber); } .insight--atencao .insight__icon { background: var(--amber-soft); } .insight--atencao .insight__icon svg { color: var(--amber); } .insight--atencao .insight__sev { color: var(--amber); }
.insight--info { border-left-color: var(--blue); }     .insight--info .insight__icon { background: var(--blue-soft); }     .insight--info .insight__icon svg { color: var(--blue); }     .insight--info .insight__sev { color: var(--blue); }
.insight--positivo { border-left-color: var(--green); }.insight--positivo .insight__icon { background: var(--green-soft); }.insight--positivo .insight__icon svg { color: var(--green); }.insight--positivo .insight__sev { color: var(--green); }
/* Insights embutidos na Visão Geral: o container (#ovInsights) usa .card__body--flush
   (padding 0), então sem isto os cards ficam full-bleed e desalinhados do header. Recompõe
   o recuo (20px horizontais = .card__head), o respiro vertical e um padding interno mais
   folgado. Escopado ao #ovInsights p/ NÃO alterar a tela de Insights (renderiza no .content). */
#ovInsights { padding: 16px 20px; }
#ovInsights .insight-list { gap: 12px; }
#ovInsights .insight { padding: 14px 18px; }

/* Vendas ao Vivo — indicador + destaque de venda nova (sutil, one-shot ~2s) */
.live-ind { display: flex; align-items: center; gap: 12px; }
tr.is-new { animation: rowNew 2.2s var(--ease); }
@keyframes rowNew {
  0%   { background: var(--green-soft); box-shadow: inset 3px 0 0 var(--green); }
  60%  { background: var(--green-soft); box-shadow: inset 3px 0 0 var(--green); }
  100% { background: transparent;       box-shadow: inset 3px 0 0 transparent; }
}
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 900px) { .grid-3 { grid-template-columns: 1fr; } }

/* barra de filtros global (espelha o dashboard atual: período + custom + plano) */
.filterbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border-1); flex-wrap: nowrap; overflow-x: auto; }
.filterbar__label { font-size: 11px; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: .8px; white-space: nowrap; flex-shrink: 0; }
.filterbar .select, .filterbar .input { height: 36px; font-size: 13px; }
.filterbar .select { width: 168px; flex-shrink: 0; }
.filterbar .segmented, .filterbar .btn, .filterbar__dates { flex-shrink: 0; }
.filterbar__dates { display: flex; align-items: center; gap: 8px; }
.filterbar__dates[hidden] { display: none; }
.filterbar__dates span { color: var(--text-4); font-size: 12px; }
.filterbar__sep { width: 1px; height: 20px; background: var(--border-1); }
.filterbar__spacer { flex: 1; }

/* custo por código: 4 campos compactos numa linha só */
.cpc-grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 200px)); gap: 14px; }
.cpc-grid .input-group { max-width: 200px; }
@media (max-width: 720px) { .cpc-grid { grid-template-columns: repeat(2, 1fr); } }

/* toggle de plano (segmented reaproveitado, cor por plano) */
.plan-toggle button[data-plan="mensal"].is-active { color: var(--blue); }
.plan-toggle button[data-plan="tri"].is-active { color: var(--purple); }
.plan-toggle button[data-plan="sem"].is-active { color: var(--amber); }
.plan-toggle button[data-plan="anual"].is-active { color: var(--brand-ink); }

/* ------------------------------------------------------------------ */
/* 4. CARD                                                            */
/* ------------------------------------------------------------------ */
.card { background: var(--surface-1); border: 1px solid var(--border-1); border-radius: var(--radius-card); transition-property: background, border-color; transition-duration: 200ms; transition-timing-function: var(--ease); }
.card:hover { border-color: var(--border-2); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-1); }
.card__head h3 { font-size: 13px; font-weight: 500; color: var(--text-2); }
.card__head .muted { font-size: 12px; color: var(--text-3); }
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }

/* ------------------------------------------------------------------ */
/* 5. KPI                                                             */
/* ------------------------------------------------------------------ */
.card { min-width: 0; }
.kpi { padding: 18px 18px 16px; display: flex; flex-direction: column; min-height: 138px; min-width: 0; }
.kpi__label { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.kpi__label svg { width: 14px; height: 14px; color: var(--text-3); }
.kpi__value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 21px; font-weight: 500; color: var(--text-1); letter-spacing: -.4px; line-height: 1.15; margin-bottom: 8px; overflow-wrap: break-word; }
.kpi__label { min-width: 0; }
.kpi__label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi__value small { font-size: 13px; color: var(--text-3); }
.kpi__foot { margin-top: auto; padding-top: 4px; display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-3); }

/* pills de variação (idênticas ao sistema atual) */
.pill { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 500; padding: 2px 7px; border-radius: var(--radius-pill); line-height: 1.4; font-family: var(--font-mono); font-variant-numeric: tabular-nums; border: 1px solid transparent; }
.pill svg { width: 11px; height: 11px; }
.pill.up { color: var(--green); background: var(--green-soft); border-color: var(--green-border); }
.pill.dn { color: var(--red); background: var(--red-soft); border-color: var(--red-border); }
.pill.flat { color: var(--text-3); background: var(--field-bg); border-color: var(--border-1); }

/* KPI colorido por natureza do valor */
.kpi--pos .kpi__value, .kpi--pos .kpi__label svg { color: var(--green); }
.kpi--neg .kpi__value, .kpi--neg .kpi__label svg { color: var(--red); }
.kpi--brand .kpi__value { color: var(--brand-ink); }

/* ------------------------------------------------------------------ */
/* 6. BOTÕES                                                          */
/* ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px; padding: 0 16px; border-radius: var(--radius-input);
  font-size: 13px; font-weight: 500; border: 1px solid transparent; white-space: nowrap;
  transition-property: background, border-color, transform, color; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--brand); color: var(--on-brand); }
.btn--primary:hover { background: var(--brand-hover); }
.btn--outline { background: transparent; border-color: var(--border-1); color: var(--text-2); }
.btn--outline:hover { background: var(--surface-1); border-color: var(--border-2); color: var(--text-1); }
.btn--ghost { background: transparent; color: var(--text-3); }
.btn--ghost:hover { background: var(--surface-1); color: var(--text-1); }
.btn--sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn--icon { width: 34px; height: 34px; padding: 0; }
.btn--danger-ghost { background: transparent; color: var(--text-3); }
.btn--danger-ghost:hover { background: var(--red-soft); color: var(--red); }
.btn--wa { background: transparent; border-color: var(--border-1); color: var(--whatsapp); }
.btn--wa:hover { background: var(--whatsapp-soft); border-color: var(--whatsapp); }
.btn--wa svg { color: var(--whatsapp); }

/* ------------------------------------------------------------------ */
/* 7. INPUTS                                                          */
/* ------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11px; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: .8px; }
.input, .select {
  height: 40px; width: 100%; padding: 0 12px;
  background: var(--field-bg); border: 1px solid var(--border-1); border-radius: var(--radius-input);
  color: var(--text-1); font-family: inherit; font-size: 13px; outline: none; color-scheme: var(--form-scheme);
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
.input:hover, .select:hover { border-color: var(--border-hover); }
.input:focus, .select:focus { border-color: var(--brand-border); box-shadow: 0 0 0 3px var(--brand-soft); }
.input::placeholder { color: var(--text-4); }
.input.num { text-align: right; font-family: var(--font-mono); }
.select { appearance: none; padding-right: 30px; background-image: var(--select-arrow); background-repeat: no-repeat; background-position: right 12px center; }
.select option { background: var(--elevated); color: var(--text-1); }
.input-group { display: flex; align-items: center; background: var(--field-bg); border: 1px solid var(--border-1); border-radius: var(--radius-input); overflow: hidden; transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease); }
.input-group:hover { border-color: var(--border-hover); }
.input-group:focus-within { border-color: var(--brand-border); box-shadow: 0 0 0 3px var(--brand-soft); }
.input-group__prefix { padding: 0 10px; align-self: stretch; display: flex; align-items: center; color: var(--text-3); font-family: var(--font-mono); font-size: 13px; border-right: 1px solid var(--border-1); }
.input-group .input { border: 0; background: transparent; }
.input-group .input:focus { box-shadow: none; }

/* ------------------------------------------------------------------ */
/* 8. TABELA (densa, estilo do sistema)                               */
/* ------------------------------------------------------------------ */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--elevated);
  text-align: left; font-weight: 500; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-3);
  padding: 10px 16px; border-bottom: 1px solid var(--border-1); white-space: nowrap;
}
.table tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border-1); vertical-align: middle; color: var(--text-1); }
.table tbody tr { transition: background 150ms var(--ease); }
.table tbody tr:hover { background: var(--surface-1); }
.table tbody tr:last-child td { border-bottom: 0; }
.table th.num, .table td.num { text-align: right; }
.cell-strong { font-weight: 500; }
.cell-sub { display: block; font-size: 11px; color: var(--text-3); margin-top: 1px; }
.cell-time { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); }

/* tabela editável (Custos & Lançamentos) */
.cell-input { width: 100%; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; color: var(--text-1); font-family: inherit; font-size: 13px; outline: none; color-scheme: var(--form-scheme); transition: border-color 150ms var(--ease), background 150ms var(--ease); }
.cell-input:hover { border-color: var(--border-1); }
.cell-input:focus { border-color: var(--brand-border); background: var(--field-bg); box-shadow: 0 0 0 3px var(--brand-soft); }
.cell-input.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
select.cell-input { appearance: none; color-scheme: var(--form-scheme); }
select.cell-input option, .select option { background: var(--elevated); color: var(--text-1); }
.table__addrow td { padding: 10px 16px; border-bottom: 0; }
input[type=checkbox] { accent-color: var(--brand-ink); width: 15px; height: 15px; cursor: pointer; }

/* ------------------------------------------------------------------ */
/* 9. BADGES (soft + colored border, como as pills do sistema)        */
/* ------------------------------------------------------------------ */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius-pill); font-size: 11px; font-weight: 500; line-height: 1.5; background: var(--field-bg); color: var(--text-2); border: 1px solid var(--border-1); }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge--plain::before { display: none; }
.badge--green { color: var(--green); background: var(--green-soft); border-color: var(--green-border); }
.badge--red { color: var(--red); background: var(--red-soft); border-color: var(--red-border); }
.badge--brand { color: var(--brand-ink); background: var(--brand-soft); border-color: var(--brand-border); }
.badge--blue { color: var(--blue); background: var(--blue-soft); border-color: var(--blue-border); }
.badge--purple { color: var(--purple); background: var(--purple-soft); border-color: var(--purple-border); }
.badge--amber { color: var(--amber); background: var(--amber-soft); border-color: var(--amber-border); }

/* ------------------------------------------------------------------ */
/* 10. SEGMENTED / TABS                                               */
/* ------------------------------------------------------------------ */
.segmented { display: inline-flex; align-items: center; gap: 4px; background: var(--field-bg); border: 1px solid var(--border-1); border-radius: var(--radius-input); padding: 3px; }
.segmented button { background: transparent; border: 0; color: var(--text-3); padding: 6px 12px; border-radius: 5px; font-size: 12px; font-weight: 500; transition: background 150ms var(--ease), color 150ms var(--ease); }
.segmented button:hover { color: var(--text-1); }
.segmented button.is-active { background: var(--surface-3); color: var(--text-1); }

.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--border-1); margin-bottom: 18px; }
.tabs button { padding: 10px 1px; border: 0; background: none; color: var(--text-3); font-size: 13px; font-weight: 500; position: relative; transition: color 150ms var(--ease); }
.tabs button:hover { color: var(--text-1); }
.tabs button.is-active { color: var(--text-1); }
.tabs button.is-active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--brand); border-radius: 99px; }

/* ------------------------------------------------------------------ */
/* 11. TOAST                                                          */
/* ------------------------------------------------------------------ */
.toast-wrap { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast { display: flex; align-items: center; gap: 12px; min-width: 240px; padding: 12px 14px; background: var(--elevated); border: 1px solid var(--border-2); border-left: 2px solid var(--green); border-radius: var(--radius-card); animation: toast-in .28s var(--ease) both; }
.toast.is-out { animation: toast-out .2s var(--ease) both; }
.toast b { font-size: 13px; font-weight: 500; }
.toast span { font-size: 11px; color: var(--text-3); }
@keyframes toast-in { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:none} }
@keyframes toast-out { to{opacity:0;transform:translateY(6px)} }

/* ------------------------------------------------------------------ */
/* 12. SKELETON / EMPTY                                               */
/* ------------------------------------------------------------------ */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--radius-input); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, var(--shimmer), transparent); animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 24px; color: var(--text-3); }
.state svg { width: 30px; height: 30px; color: var(--text-4); }
.state b { color: var(--text-1); font-size: 14px; font-weight: 500; }
.state p { font-size: 12px; max-width: 340px; line-height: 1.6; }

/* ------------------------------------------------------------------ */
/* 13. ENTER STAGGER                                                  */
/* ------------------------------------------------------------------ */
.stagger > * { animation: fade-up .42s var(--ease) both; }
.stagger > *:nth-child(1){animation-delay:.02s}
.stagger > *:nth-child(2){animation-delay:.08s}
.stagger > *:nth-child(3){animation-delay:.14s}
.stagger > *:nth-child(4){animation-delay:.20s}
.stagger > *:nth-child(5){animation-delay:.26s}
.stagger > *:nth-child(6){animation-delay:.32s}
@keyframes fade-up { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

/* ------------------------------------------------------------------ */
/* 14. APEXCHARTS — overrides                                         */
/* ------------------------------------------------------------------ */
.apexcharts-text, .apexcharts-legend-text { fill: var(--text-3) !important; color: var(--text-3) !important; font-family: var(--font-sans) !important; }
.apexcharts-gridline { stroke: var(--border-1); }
.apexcharts-tooltip { background: var(--elevated) !important; border: 1px solid var(--border-2) !important; box-shadow: none !important; color: var(--text-1) !important; border-radius: var(--radius-input) !important; }
.apexcharts-tooltip-title { background: var(--tooltip-title-bg) !important; border-bottom: 1px solid var(--border-1) !important; font-family: var(--font-sans) !important; font-weight: 500; }
.apexcharts-xaxistooltip, .apexcharts-yaxistooltip { background: var(--elevated) !important; border-color: var(--border-2) !important; color: var(--text-1) !important; }
.apexcharts-xaxistooltip::after { border-bottom-color: var(--elevated) !important; }
.apexcharts-xaxistooltip::before { border-bottom-color: var(--border-2) !important; }

/* ------------------------------------------------------------------ */
/* 15. RESPONSIVO                                                     */
/* ------------------------------------------------------------------ */
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 50; transform: translateX(-100%); transition: transform .25s var(--ease); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: var(--overlay); z-index: 40; }
  .hamburger { display: inline-flex; }
}
@media (max-width: 860px) {
  .status-dot { display: none; }
  .topbar { padding: 0 14px; gap: 10px; }
  .filterbar { padding: 10px 14px; gap: 10px; }
  .filterbar__sep { display: none; }
  .content__head { gap: 12px; }
}
@media (max-width: 560px) {
  .content { padding: 16px; }
  .filterbar .select { min-width: 0; flex: 1; }
  .filterbar__dates { width: 100%; }
  .filterbar__dates .input { flex: 1; min-width: 0; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

/* ------------------------------------------------------------------ */
/* 16. FAIXAS / RFM / MINI-BARRAS (Fase 3)                            */
/* ------------------------------------------------------------------ */
/* barra de força (score, taxa) dentro de célula de tabela */
.bar { position: relative; height: 5px; border-radius: 99px; background: var(--track); overflow: hidden; min-width: 60px; }
.bar__fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--brand); }
.bar__fill.g { background: var(--green); } .bar__fill.a { background: var(--amber); } .bar__fill.r { background: var(--red); }
.scorecell { display: flex; align-items: center; gap: 8px; }
.scorecell .num { min-width: 26px; }

/* quadradinhos R/F/M (1..5) */
.rfm { display: inline-flex; gap: 3px; }
.rfm span { width: 8px; height: 14px; border-radius: 2px; background: var(--track-alt); }
.rfm span.on { background: var(--brand); }

/* linha de tabela clicável (abre o drawer) */
.table tbody tr.clickable { cursor: pointer; }

/* ------------------------------------------------------------------ */
/* 17. DRAWER (detalhe do cliente)                                    */
/* ------------------------------------------------------------------ */
.drawer-backdrop {
  position: fixed; inset: 0; background: var(--overlay-2); z-index: 70;
  opacity: 0; pointer-events: none; transition: opacity .2s var(--ease);
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 92vw); z-index: 71;
  background: var(--elevated); border-left: 1px solid var(--border-2);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(100%); transition: transform .26s var(--ease);
}
.drawer.is-open { transform: none; }
.drawer__head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 22px; border-bottom: 1px solid var(--border-1); }
.drawer__head .grow { flex: 1; min-width: 0; }
.drawer__name { font-size: 16px; font-weight: 600; letter-spacing: -.2px; }
.drawer__sub { font-size: 12px; color: var(--text-3); margin-top: 3px; word-break: break-all; }
.drawer__close { flex-shrink: 0; }
.drawer__body { flex: 1; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 20px; }

.metricrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metricrow .m { background: var(--surface-1); border: 1px solid var(--border-1); border-radius: var(--radius-input); padding: 12px; }
.metricrow .m .l { font-size: 10px; letter-spacing: .8px; text-transform: uppercase; color: var(--text-3); }
.metricrow .m .v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 16px; font-weight: 500; margin-top: 4px; }

.drawer__section-title { font-size: 11px; letter-spacing: .8px; text-transform: uppercase; color: var(--text-3); font-weight: 500; margin-bottom: 12px; }

/* timeline de compras */
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 1px; background: var(--border-1); }
.timeline__item { position: relative; padding-bottom: 16px; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot { position: absolute; left: -18px; top: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); box-shadow: 0 0 0 3px var(--elevated); }
.timeline__dot.mensal { background: var(--blue); } .timeline__dot.trimestral { background: var(--purple); }
.timeline__dot.semestral { background: var(--amber); } .timeline__dot.anual { background: var(--brand); }
.timeline__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.timeline__plan { font-size: 13px; font-weight: 500; }
.timeline__val { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 13px; }
.timeline__meta { font-size: 11px; color: var(--text-3); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------------ */
/* 18. PAGINADOR (Base de Clientes)                                   */
/* ------------------------------------------------------------------ */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border-1); flex-wrap: wrap; }
.pager:empty { display: none; }
.pager__info { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.btn[disabled] { opacity: .4; pointer-events: none; }

/* ------------------------------------------------------------------ */
/* 19. COHORT RETENTION (mapa de calor de safras)                     */
/* ------------------------------------------------------------------ */
.cohort-table { min-width: max-content; }
.cohort-table th, .cohort-table td { white-space: nowrap; text-align: center; padding: 9px 13px; }
.cohort-table th.num, .cohort-table td.num { text-align: right; }
.cohort-sticky { position: sticky; left: 0; z-index: 2; background: var(--elevated); text-align: left; }
.cohort-table thead .cohort-sticky { z-index: 3; }
.cohort-cell { color: var(--on-cohort); font-variant-numeric: tabular-nums; font-weight: 500; }
.cohort-cell--empty { background: var(--surface-1); color: var(--text-3); font-weight: 400; }
.cohort-table tbody tr:hover { background: transparent; }

/* ---------- modal de confirmação (ação sensível / gasto de créditos) ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--overlay); animation: toast-in .18s var(--ease) both; }
.modal__card { background: var(--elevated); border: 1px solid var(--border-2); border-radius: var(--radius-card); padding: 22px; max-width: 440px; width: 100%; box-shadow: 0 8px 28px rgba(0,0,0,.22); }
.modal__card h3 { font-size: 16px; margin-bottom: 10px; }
.modal__body { font-size: 13px; color: var(--text-2); line-height: 1.55; margin-bottom: 20px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; }

/* prévia da mensagem (Renovação SMS) */
.sms-preview { font-size: 13px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border-1); border-radius: var(--radius-input); padding: 12px 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
