/* =====================================================
   styles.css — Talkdesk Service Level Dashboard
   Versão: 2.4 - Popover Explicativo (Clique) - Limpo e Estável
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

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

:root {
    --teal:    #4ECDC4;
    --orange:  #F4A261;
    --text:    #1a1a2e;
    --sub:     #6b7280;
    --border:  #e5e7eb;
    --card-bg: #ffffff;
    --bg:      #f9fafb;
    --link:    #6366f1;
}

/* ====================== GERAL ====================== */
body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ====================== SETUP, LOADING E DASHBOARD ====================== */
#setup-panel {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.setup-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem 3rem;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.07);
}

.setup-card h1 { font-size: 1.35rem; font-weight: 600; margin-bottom: .25rem; }
.setup-card p.sub { font-size: .85rem; color: var(--sub); margin-bottom: 2rem; }

.field { margin-bottom: 1.1rem; }
.field label {
    display: block;
    font-size: .78rem;
    font-weight: 500;
    color: var(--sub);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: .4rem;
}

.field input, .field select {
    width: 100%;
    padding: .6rem .85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: .9rem;
    color: var(--text);
    background: #fff;
}

.field input:focus, .field select:focus { border-color: var(--teal); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.btn-primary {
    width: 100%;
    margin-top: 1.5rem;
    padding: .75rem;
    background: var(--teal);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:hover { background: #3ab8af; }
.btn-primary:disabled { background: #a0d4d1; cursor: not-allowed; }

/* Loading */
#loading-panel {
    display: none;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1.2rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Dashboard */
#dashboard-panel { display: none; padding: 2rem 2.5rem 3rem; }

.dash-header h1 { font-size: 1.35rem; font-weight: 600; }
.dash-meta { font-size: 0.85rem; color: var(--sub); margin-top: 0.4rem; display: flex; gap: 2rem; flex-wrap: wrap; }

.btn-back {
    float: right;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.5rem 1rem;
    color: var(--sub);
}

.btn-back:hover { border-color: var(--teal); color: var(--teal); }

/* ====================== KPI CARDS ====================== */
.kpi-section { margin-bottom: 2rem; }

.section-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.8rem;
    padding-left: 0.2rem;
}

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: visible;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--card-bg);
    padding: 1.8rem 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 118px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: visible;
    z-index: 2;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(78, 205, 196, 0.15);
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 10px;
    min-height: 24px;
}

.kpi-label {
    font-size: 0.76rem;
    color: var(--sub);
    font-weight: 400;
    line-height: 1.4;
    text-align: center;
    flex: 1;
}

.kpi-value {
    font-size: 2.1rem;
    font-weight: 400;
    letter-spacing: -0.03em;
    margin-bottom: .55rem;
}

.kpi-subvalue {
    font-size: 0.82rem;
    color: var(--sub);
    margin-top: 4px;
    display: block;
}

/* ====================== INFO ICON + POPOVER (ÚNICA VERSÃO ATIVA) ====================== */
.info-icon {
    cursor: pointer;
    font-size: 17px;
    color: #9ca3af;
    padding: 2px 6px;
    border-radius: 50%;
    transition: all 0.2s ease;
    user-select: none;
    z-index: 10;
}

.info-icon:hover {
    color: #6366f1;
    background-color: #f1f5f9;
}

/* Popover Explicativo - Versão Final */
.kpi-popover {
    position: fixed;
    background: #1f2937;
    color: #f1f5f9;
    padding: 16px 20px;
    border-radius: 10px;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45);
    max-width: 340px;
    z-index: 99999;               /* Altíssimo */
    font-size: 0.83rem;
    line-height: 1.48;
    white-space: pre-line;
    display: none;
    pointer-events: auto;
}

/* Seta padrão */
.kpi-popover::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 25px;
    border: 8px solid transparent;
    border-top-color: #1f2937;
}

/* Seta quando abre para baixo */
.kpi-popover.arrow-down::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: #1f2937;
}

/* ====================== GRÁFICOS ====================== */
.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem 1.5rem;
}

.chart-title {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 1.1rem;
}

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

/* ====================== DRILL-DOWN MODAL ====================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 95%;
    max-width: 1150px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    overflow: hidden;
}

.modal-header {
    padding: 1.2rem 1.8rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to right, #f8f9fa, #f1f3f5);
}

.modal-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}

.modal-filters {
    padding: 0.85rem 1.75rem;
    background: #f8f9fa;
    border-bottom: 1px solid var(--border);
}

.filter-group {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-group label {
    font-size: 0.84rem;
    color: var(--sub);
    font-weight: 500;
    white-space: nowrap;
}

.filter-group select,
.filter-group input[type="text"] {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-family: inherit;
    font-size: 0.84rem;
    color: var(--text);
    background: white;
}

.filter-group select { min-width: 160px; }
.filter-group input[type="text"] { min-width: 220px; }

.filter-group select:focus,
.filter-group input[type="text"]:focus {
    border-color: var(--teal);
    outline: none;
}

.filter-btn {
    height: 34px;
    padding: 0 16px;
    font-size: 0.84rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--teal);
    color: white;
    border: none;
}

.filter-btn:hover { background: #3ab8af; }

.filter-btn--secondary {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
}

.filter-btn--secondary:hover { background: #f1f3f5; }

.modal-table-container {
    flex: 1;
    overflow: auto;
    padding: 0 1.75rem 1rem;
}

.drill-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.drill-table th {
    background: #f1f3f5;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 0.8rem 0.7rem;
    text-align: left;
    font-weight: 500;
    color: var(--sub);
    border-bottom: 2px solid var(--border);
    cursor: pointer;
}

.drill-table td {
    padding: 0.7rem 0.7rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.drill-table tr:hover {
    background: #f0f7ff;
}

/* ====================== MODAL CLOSE BUTTON ====================== */

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--sub);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
    line-height: 1;
    padding: 0;
}

.modal-close:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* ====================== MODAL FOOTER - LAYOUT EM DUAS LINHAS ====================== */

.modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 84px;
}

.footer-count {
    font-size: 0.85rem;
    color: var(--sub);
    white-space: nowrap;
}

.footer-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

/* Paginação */
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.pagination-controls button,
.pagination-controls select {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
}

.pagination-controls select { padding: 0 8px; }

.pagination-controls button:hover:not(:disabled) {
    background: var(--teal);
    color: white;
    border-color: var(--teal);
}

.pagination-controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Botões de ação à direita */
.footer-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.footer-btn {
    height: 38px;
    padding: 0 20px;
    font-size: 0.88rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.footer-btn--primary {
    background: var(--teal);
    color: #fff;
}

.footer-btn--primary:hover { background: #3ab8af; }

.footer-btn--secondary {
    background: #f1f3f5;
    color: var(--text);
    border: 1px solid var(--border);
}

.footer-btn--secondary:hover { background: #e5e7eb; }

/* Retrocompatibilidade com .action-buttons */
.action-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.action-buttons button {
    height: 38px;
    padding: 0 20px;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    line-height: 1;
    transition: all 0.2s ease;
    cursor: pointer;
}

.action-buttons .btn-primary { background: var(--teal); color: white; border: none; }
.action-buttons .btn-primary:hover { background: #3ab8af; }
.action-buttons .btn-secondary { background: #f1f3f5; color: var(--text); border: 1px solid var(--border); }
.action-buttons .btn-secondary:hover { background: #e5e7eb; }

#kpi-short-abandoned-sub {
    color: #f59e0b;           /* tom laranja suave, igual ao Talkdesk */
    font-weight: 500;
    display: block;
    margin-top: 6px;
    font-size: 0.81rem;
}

/* Ícone SVG de Informação */

/* Tooltip - Correção principal */
.tooltip {
    visibility: hidden;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    margin-bottom: 8px;
    background: #1f2937;
    color: #f1f5f9;
    font-size: 0.79rem;
    line-height: 1.45;
    padding: 12px 16px;
    border-radius: 8px;
    width: 290px;
    max-width: 320px;
    text-align: left;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    z-index: 9999;                    /* ← Aumentado significativamente */
    pointer-events: none;
    white-space: pre-line;
    opacity: 0;
    transition: all 0.25s ease;
}


.help-icon {
    width: 18px;
    height: 18px;
    cursor: help;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    display: inline-flex
}

.help-icon svg {
    width: 100%;
    height: 100%;
    fill: #9ca3af;
    transition: fill 0.2s ease;
}

.help-icon:hover svg {
    fill: #6366f1 !important;
}

/* Tooltip - Posicionado fora do card */
.help-icon .tooltip {
    visibility: hidden;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    margin-bottom: 8px;
    background: #1f2937;
    color: #f1f5f9;
    font-size: 0.79rem;
    line-height: 1.45;
    padding: 12px 16px;
    border-radius: 8px;
    width: 290px;
    max-width: 320px;
    text-align: left;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    z-index: 1000;
    pointer-events: none;
    white-space: pre-line;
    opacity: 0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.help-icon:hover .tooltip {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
    z-index: 10000;                   /* ← Garante que fique sempre por cima */
}

/* Seta do tooltip */
.help-icon .tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: #1f2937;
}

/* ====================== GRID DE GRÁFICOS ====================== */
/*
  Estratégia: mobile-first, 1 coluna por padrão.
  Em telas largas (≥ 1400px) ativa layout de 3 colunas com grid-template-areas.

  Ordem dos itens no HTML (e mobile): SL → Abn → Pie → Handle → Stacked
  Layout largo:
    [ SL (2 cols)    ] [ Pie (1 col)  ]
    [ Abn (3 cols, full)              ]
    [ Handle (3 cols, full)           ]
    [ Stacked (3 cols, full)          ]
*/

/* ── Mobile-first: 1 coluna, sem override de grid-column ────── */
.charts-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 2rem;
}

/* Altura padrão dos wraps em 1 coluna */
.charts-grid .chart-wrap {
    height: 300px;
}

/* Pie: layout vertical (pizza + legenda abaixo), adaptável */
.chart-col-pie {
    min-width: 0;
    overflow: hidden;
}

.chart-col-pie .chart-wrap {
    overflow: hidden;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

/* ── Telas largas (≥ 1400px): grid de 3 colunas com areas ───── */
@media (min-width: 1400px) {
    .charts-grid {
        display: grid;
        grid-template-columns: 1fr 1fr minmax(320px, 400px);
        grid-template-areas:
            "sl  sl  pie"
            "abn abn abn"
            "hdl hdl hdl"
            "stk stk stk";
        gap: 1.5rem;
    }

    /* Associa cada card à sua área */
    .chart-bar-sl   { grid-area: sl;  }
    .chart-bar-abn  { grid-area: abn; }
    .chart-col-pie  { grid-area: pie; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
    .chart-full-hdl { grid-area: hdl; }
    .chart-full-stk { grid-area: stk; }

    /* Pie: altura igual à linha do SL */
    .chart-col-pie .chart-wrap {
        flex: 1;
        height: auto;
        min-height: 260px;
    }

    /* Wraps dos gráficos de barra com altura padrão */
    .charts-grid .chart-wrap {
        height: 300px;
    }
}

/* ====================== RESPONSIVIDADE ====================== */
/* ====================== RESPONSIVIDADE ====================== */
@media (max-width: 768px) {
    .kpi-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .kpi-card { padding: 1.4rem 0.9rem 1rem; }
}

@media (max-width: 640px) {
    .kpi-row { grid-template-columns: 1fr; }
}

/* Força 3 colunas em telas grandes (melhor para 5 gráficos) */
@media (min-width: 1600px) {
    .charts-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Força no máximo 2 colunas em telas muito largas */
@media (min-width: 1400px) {
    .charts-row {
        grid-template-columns: repeat(2, 1fr);   /* força exatamente 2 por linha */
    }
}

/* Responsividade mobile e tablets */
@media (max-width: 1100px) {
    .charts-row {
        grid-template-columns: repeat(auto-fit, minmax(480px, 1fr)); /* volta para 2 */
    }
}

/* Responsividade extra para mobile */
@media (max-width: 640px) {
    .kpi-row {
        grid-template-columns: 1fr;
    }
    .charts-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .chart-wrap {
        height: 260px;
    }
}