/* ==========================================================================
   FECHAMENTO PREMIUM — Conecta Media Dashboard
   ========================================================================== */

.fechamento-wrapper {
    padding: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
    color: var(--text-primary);
    animation: fadeIn 0.4s ease-out;
}

/* 1. HEADER PREMIUM */
.fechamento-header-premium {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
}

.fechamento-greeting-area h1 {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    letter-spacing: -0.02em;
}

.fechamento-greeting-area p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 500;
}

.fechamento-header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.fechamento-team-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: var(--radius-md);
}

.fechamento-team-avatars {
    display: flex;
    align-items: center;
}

.fechamento-team-avatars img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
    margin-left: -8px;
    object-fit: cover;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.fechamento-team-avatars img:first-child {
    margin-left: 0;
}

.fechamento-select-custom {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 700;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    padding-right: 4px;
}

.fechamento-period-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 700;
}

.fechamento-period-selector-wrapper span {
    font-size: 16px;
    color: var(--accent-primary);
}

/* 2. KPI CARDS PREMIUM */
.fechamento-grid-kpis-premium {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
}

.fechamento-kpi-card-premium {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.01);
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fechamento-kpi-card-premium:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.04);
    z-index: 50;
}

.fechamento-kpi-top-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.fechamento-kpi-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.fechamento-kpi-label-premium {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.fechamento-kpi-value-premium {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.1;
    white-space: nowrap;
}

.fechamento-kpi-sparkline-wrapper {
    width: 100%;
    height: 35px;
    position: relative;
    margin: 6px 0;
}

.fechamento-kpi-sparkline-wrapper canvas {
    width: 100% !important;
    height: 35px !important;
    display: block;
}

.fechamento-kpi-bottom-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.fechamento-kpi-pct-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.fechamento-kpi-pct-badge.up {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.fechamento-kpi-pct-badge.down {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.fechamento-kpi-pct-badge.neutral {
    background: rgba(128, 128, 128, 0.1);
    color: var(--text-secondary);
}

.fechamento-kpi-comparison-text {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* 3. FILTROS PREMIUM CARD */
.fechamento-filters-premium-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px 24px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.01);
}

.fechamento-filters-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.fechamento-filters-title {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.fechamento-filters-title span {
    font-size: 16px;
    color: var(--accent-primary);
}

.fechamento-filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.fechamento-filter-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fechamento-filter-field label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.fechamento-filter-field select {
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 600;
    outline: none;
    font-family: inherit;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.fechamento-filter-field select:focus {
    border-color: var(--accent-primary);
}

/* 4. MIDDLE ROW (REGRAS + EVOLUCAO + DONUT) */
.fechamento-middle-row {
    display: grid;
    grid-template-columns: 1.25fr 2fr 1fr;
    gap: 20px;
}

.fechamento-middle-row > .fechamento-card-premium {
    height: 380px;
    box-sizing: border-box;
}

.fechamento-card-premium {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.01);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

.fechamento-card-premium:hover {
    z-index: 50;
}

.fechamento-card-title-premium {
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0 0 16px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.fechamento-card-title-premium span {
    font-size: 20px;
    color: var(--accent-primary);
}

/* Regras de Cálculo inputs */
.fechamento-regras-inputs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.fechamento-regras-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.fechamento-regras-field label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.fechamento-regras-field input {
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 600;
    outline: none;
}

.fechamento-regras-field input:focus {
    border-color: var(--accent-primary);
}

.fechamento-regras-section-title {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 10px 0 6px 0;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 2px;
}

.fechamento-formula-box {
    background: rgba(244, 122, 37, 0.04);
    border: 1px solid rgba(244, 122, 37, 0.12);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 6px;
}

.fechamento-formula-title {
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--accent-primary);
    text-transform: uppercase;
}

.fechamento-formula-code {
    font-family: monospace;
    font-size: 0.66rem;
    color: var(--text-primary);
    line-height: 1.3;
    word-break: break-word;
    display: block;
    white-space: normal;
}

/* Donut Chart Meta */
.fechamento-donut-meta-stats {
    margin-top: 16px;
    display: flex;
    justify-content: space-around;
    border-top: 1px solid var(--border-color);
    padding-top: 14px;
}

.fechamento-meta-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.fechamento-meta-stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.fechamento-meta-stat-value {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-primary);
}

.fechamento-meta-stat-value.gap-negative {
    color: #ef4444;
}

.fechamento-meta-stat-value.gap-positive {
    color: #22c55e;
}

/* 5. BOTTOM ROW (RANKINGS + ACTIONS/INSIGHTS) */
.fechamento-bottom-row {
    display: grid;
    grid-template-columns: 1.5fr 1.25fr 1.25fr;
    gap: 20px;
}

.fechamento-bottom-row > .fechamento-card-premium {
    height: 290px;
    box-sizing: border-box;
    padding: 16px 20px 12px 20px;
}

.fechamento-bottom-row > .fechamento-card-premium .fechamento-card-title-premium {
    margin-bottom: 12px;
    padding-bottom: 8px;
}

/* Listas de Rankings */
.fechamento-ranking-list-premium {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
}

.fechamento-ranking-list-premium::-webkit-scrollbar {
    width: 4px;
}
.fechamento-ranking-list-premium::-webkit-scrollbar-track {
    background: transparent;
}
.fechamento-ranking-list-premium::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
.fechamento-ranking-list-premium::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.fechamento-ranking-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.02);
}

.fechamento-ranking-row:last-child {
    border-bottom: none;
}

.fechamento-ranking-pos {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--text-tertiary);
    width: 16px;
}

.fechamento-ranking-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-color);
}

.fechamento-ranking-name-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
    min-width: 0;
}

.fechamento-ranking-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fechamento-ranking-role {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fechamento-ranking-value-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    margin-left: 8px;
}

.fechamento-ranking-val-est {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-primary);
}

.fechamento-ranking-tasks-count {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.fechamento-ranking-progress-group {
    width: 100px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-left: 12px;
}

.fechamento-ranking-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.04);
    border-radius: 3px;
    overflow: hidden;
}

.fechamento-ranking-progress-fill {
    height: 100%;
    border-radius: 3px;
}

.fechamento-ranking-progress-lbl {
    font-size: 0.68rem;
    font-weight: 700;
    text-align: right;
}

.fechamento-ranking-badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 800;
    text-align: center;
    min-width: 65px;
    margin-left: 12px;
}

.fechamento-ranking-badge.excelente {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.fechamento-ranking-badge.bom {
    background: rgba(37, 99, 235, 0.1);
    color: #2563EB;
}

.fechamento-ranking-badge.atencao {
    background: rgba(249, 115, 22, 0.1);
    color: #f97316;
}

.fechamento-actions-insights-col .fechamento-card-premium {
    flex: 1;
}

.card-insights {
    border: 1.5px solid rgba(244, 122, 37, 0.45) !important;
    box-shadow: 0 8px 25px rgba(244, 122, 37, 0.08) !important;
    background: linear-gradient(180deg, var(--bg-card) 0%, rgba(244, 122, 37, 0.04) 100%) !important;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.card-insights:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(244, 122, 37, 0.12) !important;
}

/* Tooltip Customizado Premium */
.fechamento-kpi-info-icon {
    font-size: 13px !important;
    color: var(--text-tertiary);
    opacity: 0.4;
    cursor: pointer;
    transition: opacity 0.2s, color 0.2s;
    margin-left: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.fechamento-kpi-info-icon:hover {
    opacity: 1;
    color: var(--accent-primary);
}

.fechamento-kpi-info-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 140%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 500 !important;
    line-height: 1.4;
    text-transform: none !important;
    letter-spacing: normal !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    white-space: pre-wrap;
    width: 240px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    text-align: left;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    font-style: normal !important;
}

.fechamento-kpi-info-icon:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Subseção de Métricas de Detalhe de Prazos */
.fechamento-prazos-details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 14px;
    border-top: 1px dashed var(--border-color);
    padding-top: 14px;
}

.fechamento-prazo-detail-card {
    background: rgba(0, 0, 0, 0.01);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
}

.fechamento-prazo-detail-card.antecedencia {
    background: rgba(16, 185, 129, 0.02);
    border-color: rgba(16, 185, 129, 0.15);
}

.fechamento-prazo-detail-card.atraso {
    background: rgba(239, 68, 68, 0.02);
    border-color: rgba(239, 68, 68, 0.15);
}

.fechamento-prazo-detail-label {
    font-size: 0.62rem;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.fechamento-prazo-detail-value {
    font-size: 0.88rem;
    font-weight: 800;
}

.fechamento-prazo-detail-card.antecedencia .fechamento-prazo-detail-value {
    color: #10B981;
}

.fechamento-prazo-detail-card.atraso .fechamento-prazo-detail-value {
    color: #ef4444;
}

.fechamento-action-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.01);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.fechamento-action-item:last-child {
    margin-bottom: 0;
}

.fechamento-action-item:hover {
    background: rgba(244, 122, 37, 0.05);
    border-color: rgba(244, 122, 37, 0.3);
    transform: translateX(2px);
}

.fechamento-action-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.fechamento-action-left span {
    font-size: 18px;
    color: var(--accent-primary);
}

.fechamento-action-text-group {
    display: flex;
    flex-direction: column;
}

.fechamento-action-title {
    font-size: 0.78rem;
    font-weight: 700;
}

.fechamento-action-desc {
    font-size: 0.68rem;
    color: var(--text-secondary);
}

.fechamento-action-item .arrow-icon {
    font-size: 16px;
    color: var(--text-tertiary);
}

/* Insights list */
.fechamento-insights-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fechamento-insight-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    background: rgba(0, 0, 0, 0.01);
    font-size: 0.75rem;
    line-height: 1.4;
}

.fechamento-insight-item span {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 2px;
}

.fechamento-insight-item.info span { color: #f97316; }
.fechamento-insight-item.success span { color: #22c55e; }
.fechamento-insight-item.error span { color: #ef4444; }

/* 6. RESPONSIVIDADE */
@media (max-width: 1200px) {
    .fechamento-grid-kpis-premium {
        grid-template-columns: repeat(3, 1fr);
    }
    .fechamento-middle-row {
        grid-template-columns: 1fr 1fr;
    }
    .fechamento-middle-row .card-donut {
        grid-column: span 2;
    }
    .fechamento-bottom-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .fechamento-grid-kpis-premium {
        grid-template-columns: 1fr;
    }
    .fechamento-middle-row {
        grid-template-columns: 1fr;
    }
    .fechamento-middle-row .card-donut {
        grid-column: span 1;
    }
    .fechamento-header-premium {
        padding: 16px 20px;
        flex-direction: column;
        align-items: flex-start;
    }
}
