:root {
    --bg-dark: #0f1419;
    --bg-card: #1a2332;
    --bg-card-hover: #1f2a3d;
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.3);
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #2d3748;
}

* { box-sizing: border-box; }

body {
    background: var(--bg-dark);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    min-height: 100vh;
}

.cockpit-header {
    background: linear-gradient(135deg, #111827 0%, #1e293b 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.cockpit-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
}

.cockpit-header .subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}

.sync-bar {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding-bottom: 0.5rem;
}

.periodo-select {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text);
    width: 160px;
}

.filtro-cargos-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.filtro-cargos-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 0;
}
#filtroCargos {
    width: 220px;
    min-height: 38px;
    max-height: 120px;
}

.motor-ia-badge {
    font-size: 0.78rem;
    background: #111827;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.2rem 0.65rem;
    color: var(--text-muted);
}
.motor-ia-badge.motor-groq { border-color: #f97316; color: #fdba74; }
.motor-ia-badge.motor-openai { border-color: #10b981; color: #6ee7b7; }
.motor-ia-badge.motor-fallback { border-color: #f59e0b; color: #fcd34d; }

.btn-cockpit {
    background: var(--accent);
    border: none;
    color: #fff;
}
.btn-cockpit:hover { background: #2563eb; color: #fff; }

.section-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.section-title h2 {
    font-size: 1.1rem;
    margin: 0;
    font-weight: 600;
}
.section-title-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.btn-churn {
    background: linear-gradient(135deg, #b45309 0%, #f59e0b 100%);
    border: none;
    color: #111;
    font-weight: 600;
}
.btn-churn:hover { filter: brightness(1.08); color: #111; }
.btn-churn:disabled { opacity: 0.7; }

.churn-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.churn-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 0.85rem;
}
.churn-head h3 {
    font-size: 1rem;
    margin: 0;
}
.churn-resumo { color: var(--text-muted); font-size: 0.88rem; }
.churn-fluxo { color: #93c5fd; font-size: 0.75rem; margin-top: 0.25rem; }
.churn-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; max-width: 320px; }
.churn-loading, .churn-erro, .churn-vazio {
    padding: 0.75rem 0;
    color: var(--text-muted);
}
.churn-erro { color: #fca5a5; }
.churn-score-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    background: rgba(255,255,255,0.08);
}
.churn-score-badge.nivel-critico { background: rgba(239,68,68,0.3); color: #fecaca; }
.churn-score-badge.nivel-alto { background: rgba(245,158,11,0.3); color: #fde68a; }
.churn-score-badge.nivel-moderado { background: rgba(59,130,246,0.25); color: #93c5fd; }
.churn-score-badge.nivel-baixo { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.churn-table td, .churn-table th { vertical-align: top; }

/* Alertas */
.alertas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
}

.alerta-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    border-left: 4px solid var(--warning);
    transition: transform 0.15s, box-shadow 0.15s;
}
.alerta-card:has(.alerta-tickets-wrap) {
    grid-column: 1 / -1;
}
.alerta-card-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
}
.alerta-severidade-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    background: rgba(255,255,255,0.08);
}
.severidade-critica .alerta-severidade-badge { background: rgba(239,68,68,0.25); color: #fca5a5; }
.severidade-alta .alerta-severidade-badge { background: rgba(245,158,11,0.25); color: #fcd34d; }
.severidade-media .alerta-severidade-badge { background: rgba(59,130,246,0.25); color: #93c5fd; }
.alerta-tipo-label {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
}
.alerta-resumo {
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 0.75rem;
}
.alerta-relacao-meta {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: #93c5fd;
    margin: -0.35rem 0 0.75rem;
}
.btn-plano-play {
    display: inline-flex;
    align-items: center;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.btn-plano-play:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
    color: #fff;
}
.alerta-tickets-wrap {
    margin-top: 0.5rem;
    max-height: 220px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.alerta-tickets-table { margin: 0; font-size: 0.78rem; }
.alerta-tickets-table td, .alerta-tickets-table th { padding: 0.45rem 0.65rem; }

.ticket-link {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
}
.ticket-link:hover { color: #93c5fd; text-decoration: underline; }
.alerta-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.alerta-card.severidade-critica { border-left-color: var(--danger); background: linear-gradient(135deg, #1a2332 0%, #2d1515 100%); }
.alerta-card.severidade-alta { border-left-color: var(--warning); }
.alerta-card.severidade-media { border-left-color: var(--accent); }

/* legado removido — título duplicado */
.alerta-card .alerta-tipo,
.alerta-card .alerta-titulo,
.alerta-card .alerta-msg { display: none; }

.alerta-vazio {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    color: var(--success);
    background: var(--bg-card);
    border-radius: 10px;
}

.loading-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Tabs */
.cockpit-tabs {
    border-bottom-color: var(--border);
}
.cockpit-tabs .nav-link {
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    font-size: 0.9rem;
    padding: 0.75rem 1.25rem;
}
.cockpit-tabs .nav-link:hover { color: var(--text); }
.cockpit-tabs .nav-link.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: transparent;
}

/* Cards */
.cockpit-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--border);
}
.cockpit-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
}

.chart-wrap { position: relative; height: 320px; }

/* Toggle matriz / lista gargalo */
.view-toggle {
    display: inline-flex;
    gap: 2px;
    background: #111827;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}
.btn-view-toggle {
    border: none;
    background: transparent;
    color: var(--text-muted);
    width: 34px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-view-toggle:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.btn-view-toggle.active {
    color: #fff;
    background: var(--accent);
}
.gargalo-lista-wrap { max-height: 360px; overflow: auto; }
.gargalo-lista-table td { vertical-align: middle; }
.complex-badge {
    display: inline-block;
    min-width: 2.4rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    background: rgba(59,130,246,0.2);
    color: #93c5fd;
}
.complex-badge.complex-4,
.complex-badge.complex-5 { background: rgba(239,68,68,0.2); color: #fca5a5; }
.complex-badge.complex-3 { background: rgba(245,158,11,0.2); color: #fcd34d; }
.prio-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}
.prio-critica { background: rgba(239,68,68,0.25); color: #fca5a5; }
.prio-alta { background: rgba(245,158,11,0.25); color: #fcd34d; }
.prio-media { background: rgba(59,130,246,0.25); color: #93c5fd; }
.prio-baixa { background: rgba(148,163,184,0.2); color: #94a3b8; }

/* Transbordamento ring */
.transbordamento-ring {
    text-align: center;
    padding: 1.5rem;
    background: radial-gradient(circle, rgba(59,130,246,0.1) 0%, transparent 70%);
    border-radius: 50%;
    width: 160px;
    height: 160px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--accent);
}
.transbordamento-ring .pct {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent);
}
.transbordamento-ring .lbl {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* KPI cards */
.kpi-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 1.25rem;
    text-align: center;
    border: 1px solid var(--border);
}
.kpi-card .kpi-val { font-size: 2rem; font-weight: 800; }
.kpi-card .kpi-lbl { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.kpi-warning .kpi-val { color: var(--warning); }
.kpi-danger .kpi-val { color: var(--danger); }
.kpi-info .kpi-val { color: var(--accent); }

/* Tables */
.cockpit-table {
    width: 100%;
    font-size: 0.82rem;
    border-collapse: collapse;
}
.cockpit-table th {
    background: #111827;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.cockpit-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.cockpit-table tr:hover td { background: var(--bg-card-hover); }

.badge-flag {
    font-size: 0.68rem;
    padding: 0.2em 0.5em;
    border-radius: 4px;
    white-space: nowrap;
}
.badge-flag.danger { background: rgba(239,68,68,0.2); color: #fca5a5; }
.badge-flag.warning { background: rgba(245,158,11,0.2); color: #fcd34d; }

/* Semântica table */
.sem-row {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.sem-macro {
    min-width: 180px;
    font-weight: 700;
    font-size: 0.9rem;
}
.sem-subs { flex: 1; }
.sem-sub-tag {
    display: inline-block;
    background: #111827;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.15rem 0.6rem;
    font-size: 0.75rem;
    margin: 0.15rem;
    color: var(--text-muted);
}
.sem-sub-tag .qtd { color: var(--accent); font-weight: 700; margin-left: 0.25rem; }

/* Gap conhecimento */
.gap-item {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}
.gap-item .gap-cat { font-weight: 600; }
.gap-item .gap-meta { color: var(--text-muted); font-size: 0.75rem; }

.motivo-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}
.motivo-bar .bar {
    flex: 1;
    height: 8px;
    background: #111827;
    border-radius: 4px;
    overflow: hidden;
}
.motivo-bar .fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
}

.qa-table { max-height: 420px; overflow-y: auto; }

.legacy-chip {
    background: #111827;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}
.legacy-chip .qtd { color: var(--text-muted); font-size: 0.75rem; }

/* TMR bar highlight */
.tmr-mediana { color: var(--success); font-weight: 700; }
.tmr-media { color: var(--warning); }

.qa-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    white-space: nowrap;
}
.qa-ok { background: rgba(16,185,129,0.18); color: #6ee7b7; }
.qa-bad { background: rgba(239,68,68,0.2); color: #fca5a5; }
.qualidade-grid { display: flex; flex-direction: column; gap: 0.85rem; }
.qualidade-card {
    background: #111827;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
    padding: 0.9rem 1.1rem;
}
.qualidade-card.nivel-atencao { border-left-color: var(--warning); }
.qualidade-card.nivel-critico { border-left-color: var(--danger); }
.qualidade-card header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
}
.qualidade-resumo { font-size: 0.88rem; color: var(--text-muted); margin: 0 0 0.5rem; }
.qualidade-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.qualidade-bloco-titulo {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}
.qualidade-lista {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 0.82rem;
}
.qualidade-lista li { margin-bottom: 0.25rem; }

/* Modal Plano Reincidência */
.cockpit-modal {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
}
.cockpit-modal .modal-header,
.cockpit-modal .modal-footer {
    border-color: var(--border);
    background: #111827;
}
.modal-plano-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.plano-secao {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.plano-secao h4, .plano-secao h5 {
    font-size: 0.95rem;
    margin-bottom: 0.65rem;
}
.plano-ia {
    background: rgba(16, 185, 129, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 10px;
    padding: 1rem 1.25rem;
}
.plano-risco {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    margin-bottom: 0.75rem;
}
.plano-risco-critico { background: rgba(239,68,68,0.25); color: #fca5a5; }
.plano-risco-alto { background: rgba(245,158,11,0.25); color: #fcd34d; }
.plano-risco-medio { background: rgba(59,130,246,0.25); color: #93c5fd; }
.plano-resumo { font-size: 0.88rem; color: var(--text-muted); }
.plano-lista { font-size: 0.85rem; padding-left: 1.1rem; margin: 0; }
.plano-lista li { margin-bottom: 0.35rem; }
.atend-timeline { display: flex; flex-direction: column; gap: 1rem; }
.atend-timeline-item {
    background: #111827;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem 1rem;
}
.atend-head { display: flex; gap: 0.75rem; align-items: flex-start; }
.atend-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.atend-titulo { font-weight: 600; font-size: 0.9rem; }
.atend-meta, .atend-assunto, .atend-fechamento {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.hist-timeline {
    margin-top: 0.75rem;
    padding-left: 2.5rem;
    border-left: 2px solid var(--border);
    margin-left: 0.85rem;
}
.hist-item {
    margin-bottom: 0.65rem;
    padding: 0.5rem 0.65rem;
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
}
.hist-interno { border-left: 3px solid #6b7280; opacity: 0.85; }
.hist-meta { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.hist-texto { font-size: 0.82rem; line-height: 1.45; }
.hist-vazio { font-size: 0.8rem; padding: 0.5rem 0; }

/* Módulo E — Ranking Clientes */
.kpi-card { text-align: center; padding: 1.25rem; }
.kpi-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.35rem; }
.kpi-value { font-size: 2rem; font-weight: 800; color: var(--accent); line-height: 1.2; }
.kpi-value-sm { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.chart-wrap-sm { height: 420px; }
.busca-cliente { max-width: 220px; background: #111827; border-color: var(--border); color: var(--text); }
.clientes-table-wrap { max-height: 520px; overflow-y: auto; }
.rank-col { width: 48px; }
.rank-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 26px; height: 26px; border-radius: 6px;
    background: rgba(59,130,246,0.15); color: #93c5fd; font-size: 0.75rem; font-weight: 700;
}
.bar-col { width: 120px; }
.cliente-bar { height: 8px; background: #111827; border-radius: 4px; overflow: hidden; }
.cliente-bar-fill { height: 100%; background: linear-gradient(90deg, #3b82f6, #60a5fa); border-radius: 4px; }
.btn-plano-play-sm { padding: 0.2rem 0.5rem; font-size: 0.75rem; margin-bottom: 0; }

@media (max-width: 768px) {
    .alertas-grid { grid-template-columns: 1fr; }
    .cockpit-header h1 { font-size: 1.2rem; }
}
