/* ════════════════════════════════════════
   CHATWOOT ANALYTICS — Design System
   Aesthetic: Industrial minimal / data-dense
   Fonts: Syne (display) + Lato (body) + DM Mono
   (mesmo design system usado no Movidesk Analytics)
   ════════════════════════════════════════ */

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

:root {
  --bg:        #0b0e14;
  --surface:   #111620;
  --surface2:  #181e2c;
  --border:    #1f2840;
  --border2:   #2a3450;
  --text:      #dce4f5;
  --muted:     #5a6a8a;
  --accent:    #4f8ef7;
  --green:     #2ecc71;
  --yellow:    #f0b429;
  --red:       #e85d5d;
  --purple:    #a78bfa;
  --teal:      #2dd4bf;
  --font:      'Lato', sans-serif;
  --font-d:    'Syne', sans-serif;
  --mono:      'DM Mono', monospace;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; overflow-x: hidden; }

/* ─── SETUP ─────────────────────────────── */
#setup-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.setup-bg { position: absolute; inset: 0; background: radial-gradient(ellipse 60% 50% at 50% 40%, rgba(79,142,247,.07) 0%, transparent 70%); pointer-events: none; }
.setup-bg::after { content: ''; position: absolute; inset: 0; background-image: repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(79,142,247,.03) 40px), repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(79,142,247,.03) 40px); }

.setup-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 100%; max-width: 520px; position: relative; z-index: 1; }
.setup-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.brand-icon { font-size: 28px; color: var(--accent); font-family: var(--font-d); }
.brand-icon.small { font-size: 18px; }
.brand-name { font-family: var(--font-d); font-size: 17px; font-weight: 700; letter-spacing: 0.5px; color: var(--text); white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 1px; margin-top: 2px; }

.setup-section { margin-bottom: 20px; }
.setup-label { font-size: 10px; letter-spacing: 1.5px; color: var(--muted); font-weight: 700; margin-bottom: 8px; font-family: var(--font-d); }
.opt { font-weight: 400; opacity: .6; text-transform: none; }
.setup-input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text); font-family: var(--font); font-size: 13px; outline: none; transition: border-color .2s; }
.setup-input.mono { font-family: var(--mono); font-size: 12px; }
.setup-input:focus { border-color: var(--accent); }
.setup-hint { font-size: 11px; color: var(--muted); margin-top: 5px; }
.setup-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.setup-btn { width: 100%; background: var(--accent); color: #050810; border: none; border-radius: 8px; padding: 13px; font-family: var(--font-d); font-size: 13px; font-weight: 700; letter-spacing: 1.5px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; transition: opacity .2s; margin-top: 8px; }
.setup-btn:hover { opacity: .88; }
.btn-arrow { font-size: 16px; }
.setup-btn-ghost { width: 100%; background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-family: var(--font); font-size: 12px; cursor: pointer; transition: all .2s; margin-top: 8px; }
.setup-btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.setup-error { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 16px; }

/* ─── APP LAYOUT ─────────────────────────── */
#app { display: flex; min-height: 100vh; }

.sidebar { width: 200px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 20px 0; position: fixed; top: 0; bottom: 0; left: 0; z-index: 10; }
.sidebar-brand { display: flex; align-items: center; gap: 8px; padding: 0 16px 24px; border-bottom: 1px solid var(--border); margin-bottom: 12px; font-family: var(--font-d); font-size: 12px; font-weight: 700; letter-spacing: 0.3px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav { flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 20px; font-size: 13px; color: var(--muted); cursor: pointer; text-decoration: none; transition: all .15s; border-left: 2px solid transparent; }
.nav-item:hover { color: var(--text); background: var(--surface2); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(79,142,247,.06); }
.nav-icon { font-size: 12px; width: 16px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.conn-dot.demo { background: var(--yellow); }
.conn-dot.off  { background: var(--red); }

.content { margin-left: 200px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* ─── TOPBAR ─────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 9; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.page-title { font-family: var(--font-d); font-size: 16px; font-weight: 600; letter-spacing: .5px; }
.mode-tag { font-family: var(--font-d); font-size: 10px; letter-spacing: 1.5px; padding: 3px 8px; border-radius: 4px; background: rgba(46,204,113,.1); color: var(--green); border: 1px solid rgba(46,204,113,.25); }
.mode-tag.demo { background: rgba(240,180,41,.1); color: var(--yellow); border-color: rgba(240,180,41,.25); }

.topbar-right { display: flex; align-items: center; gap: 6px; }
.period-selector { display: flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-right: 8px; }
.period-btn { background: none; border: none; color: var(--muted); padding: 5px 10px; font-family: var(--mono); font-size: 11px; cursor: pointer; transition: all .15s; }
.period-btn.active, .period-btn:hover { background: var(--accent); color: #050810; }
.action-btn { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 6px 14px; font-family: var(--font); font-size: 12px; cursor: pointer; transition: all .2s; white-space: nowrap; }
.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.sync { background: rgba(46,204,113,.1); border-color: rgba(46,204,113,.3); color: var(--green); }
.action-btn.ai   { background: rgba(167,139,250,.1); border-color: rgba(167,139,250,.3); color: var(--purple); }

/* Seletor de meses: no desktop aparecem os botões; no celular, o select */
.meses-select { display: none; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: var(--font); font-size: 12px; padding: 6px 10px; outline: none; }

/* ─── CELULAR (topo compacto) ───────────────
   Só telas estreitas: meses viram dropdown, botões de ação ficam só com o
   ícone (o texto some), e a barra pode quebrar linha sem espremer nada.
   No desktop nada muda. */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; row-gap: 8px; }
  .topbar-right { flex-wrap: wrap; gap: 6px; }
  .action-btn { padding: 6px 10px; font-size: 14px; }
  .action-btn .btn-label { display: none; }
  .meses-botoes { display: none !important; }
  .meses-select { display: inline-block; }

  /* Desempenho: coluna única (histórico em cima, ranking embaixo) e
     cartão do ranking compacto — posição | nome | pontos, sem colunas
     vazias estourando a largura da tela */
  .desemp-layout { display: flex !important; flex-direction: column; height: auto !important; overflow: visible !important; }
  .desemp-layout > div { overflow-y: visible !important; }
  .rank-card { grid-template-columns: 24px 1fr auto; gap: 10px; padding: 12px 14px; }
  .rank-score-big { font-size: 18px; }
  .awards-summary { grid-template-columns: repeat(2, 1fr); }
  .awards-period-form { padding: 12px; gap: 8px; }
  .awards-period-form .form-field { flex: 1 1 45%; }
  .awards-period-form .form-input { width: 100%; }

  /* Assistente IA: coluna única com o CHAT primeiro (altura confortável)
     e as ferramentas/perguntas rápidas logo abaixo */
  .ia-layout { display: flex !important; flex-direction: column; height: auto !important; }
  .ia-chat { order: 1; height: 65vh; min-height: 380px; }
  .ia-ferramentas { order: 2; max-height: none !important; overflow-y: visible !important; }
}

/* ─── AI PANEL ────────────────────────────── */
.ai-panel { margin: 16px 24px 0; background: var(--surface); border: 1px solid rgba(167,139,250,.3); border-radius: 10px; padding: 16px 20px; }
.ai-panel-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ai-icon { color: var(--purple); font-size: 14px; }
.ai-panel-header span { font-size: 13px; font-weight: 600; color: var(--purple); }
.ai-close { margin-left: auto; background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 2px 6px; }
.ai-output { font-size: 13px; line-height: 1.8; color: var(--text); white-space: pre-wrap; }

/* ─── PAGES ──────────────────────────────── */
.page { display: none; padding: 20px 24px; flex: 1; }
.page.active { display: block; }

/* ─── KPI ROW ─────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 18px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; position: relative; overflow: hidden; transition: border-color .2s; }
.kpi-card:hover { border-color: var(--border2); }
.kpi-accent { position: absolute; top: 0; left: 0; width: 100%; height: 2px; }
.kpi-lbl { font-size: 10px; letter-spacing: 1px; color: var(--muted); font-family: var(--font-d); font-weight: 600; text-transform: uppercase; margin-bottom: 10px; }
.kpi-val { font-family: var(--mono); font-size: 26px; font-weight: 500; letter-spacing: -1px; line-height: 1; }
.kpi-delta { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; margin-top: 6px; padding: 2px 7px; border-radius: 4px; }
.delta-up   { background: rgba(46,204,113,.1);  color: var(--green); }
.delta-down { background: rgba(232,93,93,.1);   color: var(--red); }
.delta-neu  { background: rgba(90,106,138,.1);  color: var(--muted); }

/* ─── KPI GAUGE ───────────────────────────── */
.kpi-gauge-wrap { margin: 5px 0 2px; }
.kpi-gauge-track { height: 5px; background: var(--surface2); border-radius: 3px; overflow: visible; position: relative; }
.kpi-gauge-fill { height: 100%; border-radius: 3px; transition: width 1s ease; }
.kpi-gauge-meta { display: flex; justify-content: flex-end; font-size: 10px; color: var(--muted); margin-top: 2px; position: relative; }
.kpi-gauge-marker { position: absolute; top: -9px; width: 1px; height: 13px; background: var(--muted); opacity: .6; }

/* ─── CHARTS ──────────────────────────────── */
/* Grid de 2 colunas — os boxes "wide" ocupam a linha inteira, os
   demais ficam sempre em pares, sem espaços em branco sobrando. */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; min-width: 0; }
.chart-box.wide { grid-column: span 2; }
.chart-box-header { margin-bottom: 14px; }
.chart-box-title { font-family: var(--font-d); font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.chart-wrap { position: relative; height: 190px; }

.agent-bars { padding: 4px 0; }
.agent-row  { display: grid; grid-template-columns: 140px 1fr 48px; align-items: center; gap: 10px; margin-bottom: 14px; }
.agent-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-track { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.agent-fill  { height: 100%; background: var(--accent); border-radius: 3px; transition: width 1s ease; }
.agent-count { font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: right; }

/* ─── TABLE ───────────────────────────────── */
.page-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-input { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--text); font-family: var(--font); font-size: 13px; outline: none; width: 280px; }
.search-input:focus { border-color: var(--accent); }
.filter-select { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--text); font-size: 12px; outline: none; cursor: pointer; }
.count-label { font-size: 11px; color: var(--muted); margin-left: auto; font-family: var(--mono); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { font-family: var(--font-d); font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); background: var(--surface); font-weight: 600; }
.data-table td { padding: 9px 12px; font-size: 12px; border-bottom: 1px solid rgba(31,40,64,.5); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.tid { font-family: var(--mono); font-size: 11px; color: var(--accent); }
.trunc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 12px; font-size: 10px; font-weight: 600; white-space: nowrap; letter-spacing: .5px; }
.b-open      { background: rgba(240,180,41,.12);  color: #f0b429; border: 1px solid rgba(240,180,41,.25); }
.b-pending   { background: rgba(79,142,247,.12);  color: #4f8ef7; border: 1px solid rgba(79,142,247,.25); }
.b-snoozed   { background: rgba(167,139,250,.12); color: #a78bfa; border: 1px solid rgba(167,139,250,.25); }
.b-resolved  { background: rgba(46,204,113,.12);  color: #2ecc71; border: 1px solid rgba(46,204,113,.25); }

.urg-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.p1 { background: #a78bfa; } .p2 { background: #e85d5d; } .p3 { background: #f0b429; } .p4 { background: #2ecc71; }

/* ─── DESEMPENHO (pontuação — sem valores em R$) ───────── */
.awards-toolbar { margin-bottom: 18px; }
.awards-period-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 10px; letter-spacing: 1px; color: var(--muted); font-family: var(--font-d); font-weight: 600; text-transform: uppercase; }
.form-input { background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; color: var(--text); font-family: var(--font); font-size: 13px; outline: none; }
.form-input:focus { border-color: var(--accent); }
.form-input.small { width: 100px; }

.awards-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.aw-sum-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; text-align: center; }
.aw-sum-val { font-family: var(--mono); font-size: 24px; font-weight: 500; margin-bottom: 4px; }
.aw-sum-lbl { font-size: 11px; color: var(--muted); letter-spacing: .5px; }

.awards-ranking { display: flex; flex-direction: column; gap: 8px; }
.rank-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; display: grid; grid-template-columns: 28px 200px 1fr 120px 110px; align-items: center; gap: 14px; transition: border-color .2s; }
.rank-card:hover { border-color: var(--border2); }
.rank-pos { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.rank-name { font-size: 14px; font-weight: 600; }
.rank-scores { display: flex; flex-direction: column; gap: 4px; }
.score-bar { display: flex; align-items: center; gap: 6px; }
.score-lbl { font-size: 10px; color: var(--muted); width: 60px; letter-spacing: .5px; }
.score-track { flex: 1; height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 2px; transition: width 1s ease; }
.score-fill.q { background: var(--accent); }
.score-fill.t { background: var(--teal); }
.score-fill.a { background: var(--purple); }
.score-num { font-family: var(--mono); font-size: 10px; color: var(--muted); width: 30px; text-align: right; }
.rank-final { text-align: center; }
.rank-score-big { font-family: var(--mono); font-size: 22px; font-weight: 500; }
.rank-score-lbl { font-size: 10px; color: var(--muted); }
.rank-faixa { text-align: center; }
.faixa-badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: .5px; font-family: var(--font-d); }
.fb-bronze   { background: rgba(205,127,50,.15);  color: #cd7f32; border: 1px solid rgba(205,127,50,.3); }
.fb-prata    { background: rgba(192,192,192,.15); color: #bbb;    border: 1px solid rgba(192,192,192,.3); }
.fb-ouro     { background: rgba(255,215,0,.15);   color: #ffd700; border: 1px solid rgba(255,215,0,.3); }
.fb-diamante { background: rgba(167,139,250,.15); color: var(--purple); border: 1px solid rgba(167,139,250,.3); }
.fb-nao      { background: rgba(90,106,138,.1);   color: var(--muted); border: 1px solid var(--border); }

/* ─── CONFIG ──────────────────────────────── */
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.config-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.config-card.full { grid-column: span 2; }
.config-card-title { font-family: var(--font-d); font-size: 10px; font-weight: 600; letter-spacing: 1.5px; color: var(--muted); text-transform: uppercase; margin-bottom: 16px; }
.config-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.config-row label { font-size: 13px; color: var(--text); flex-shrink: 0; }
.slider-wrap { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: flex-end; }
.slider-wrap input[type=range] { width: 120px; accent-color: var(--accent); }
.slider-val { font-family: var(--mono); font-size: 13px; width: 36px; text-align: right; }
.config-sum { font-family: var(--mono); font-size: 12px; color: var(--green); margin-top: 4px; }
.config-sum.err { color: var(--red); }

.faixas-table { display: flex; flex-direction: column; gap: 6px; }
.faixa-row { display: grid; grid-template-columns: 120px 80px; gap: 8px; align-items: center; font-size: 12px; }
.faixa-row.header { font-size: 10px; color: var(--muted); font-family: var(--font-d); letter-spacing: .5px; text-transform: uppercase; }
.faixa-in { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; color: var(--text); font-family: var(--mono); font-size: 12px; width: 70px; outline: none; }

.preview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.preview-card { background: var(--surface2); border-radius: 8px; padding: 14px; text-align: center; }
.preview-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.preview-val { font-family: var(--mono); font-size: 20px; color: var(--accent); }

/* ─── LOADING ─────────────────────────────── */
.loading-overlay { position: fixed; inset: 0; background: rgba(11,14,20,.85); display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(4px); }
.loading-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.loading-spinner { width: 36px; height: 36px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { color: var(--muted); font-size: 12px; letter-spacing: .5px; }

/* ─── SCROLLBAR ───────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ─── ANOMALIAS / ALERTAS IA ─────────────────── */
.alert-card { display: flex; align-items: flex-start; gap: 10px; background: rgba(232,93,93,.06); border: 1px solid rgba(232,93,93,.25); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; font-size: 12px; }
.alert-card .alert-icon { color: var(--red); font-size: 14px; flex-shrink: 0; }
