/* ============================================
   CMMS Industrial - Módulo Histórico
   Matriz Prioridade + Indicadores + Gantt + PERT
   OTIMIZADO: Layout responsivo + Desktop melhorado
   CORRECAO MOBILE: Tabs organizadas (3/linha) - FORCADO
   ============================================ */

.history-module {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 0;
}

/* ========== HEADER ========== */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    padding: 18px 24px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.history-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-title i {
    color: var(--accent-purple);
    font-size: 24px;
    flex-shrink: 0;
}

.history-title h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.history-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.history-actions button {
    padding: 10px 18px;
    font-size: 13px;
    transition: all var(--transition-fast);
}

.history-actions button:active {
    transform: scale(0.97);
}

/* ===== REMOVER BOTOES DO CABECALHO ===== */
.history-actions .btn-primary:first-child {
    display: none;
}

.history-actions .btn-secondary:nth-child(2) {
    display: none;
}

.history-actions .btn-secondary:nth-child(3) {
    display: none;
}

#btnNovoRegistro,
#btnMatrizPrioridade,
#btnPertCPM {
    display: none;
}

/* ========== INDICADORES PRINCIPAIS DO HISTORICO ========== */
.indicator-main-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
    width: 100%;
}

.indicator-main-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 18px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
    height: 100%;
    box-sizing: border-box;
}

.indicator-main-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.indicator-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.indicator-icon.disponibilidade { background: rgba(46,204,113,0.15); color: var(--success); }
.indicator-icon.custo { background: rgba(245,158,11,0.15); color: var(--warning); }
.indicator-icon.total { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.indicator-icon.distribuicao { background: rgba(139,92,246,0.15); color: var(--accent-purple); }

.indicator-info {
    flex: 1;
    min-width: 0;
}

.indicator-info h4 {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 6px 0;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.indicator-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    line-height: 1.2;
}

.indicator-info small {
    font-size: 10px;
    color: var(--text-dark);
    line-height: 1.3;
    display: block;
}

/* ========== FILTROS ========== */
.history-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    padding: 18px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 140px;
}

.filter-group label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.history-filters .form-control {
    width: 100%;
}

.btn-filter-wrapper {
    display: flex;
    align-items: flex-end;
}

.btn-filter-wrapper button {
    padding: 10px 24px;
    height: 42px;
    white-space: nowrap;
}

/* ========== TABS ========== */
.history-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
}

.history-tab {
    padding: 12px 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.history-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.history-tab.active {
    color: var(--accent-purple);
    border-bottom-color: var(--accent-purple);
    background: var(--bg-primary);
}

/* ========== CONTENT CONTAINER ========== */
.history-content {
    background: transparent;
}

.history-view-container {
    min-height: 400px;
    padding: 0;
}

/* ========== LOADING STATES ========== */
.history-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
    text-align: center;
}

.history-loading i {
    font-size: 48px;
    margin-bottom: 16px;
    animation: history-spin 1s linear infinite;
}

/* ========== EMPTY STATES ========== */
.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-icon-wrapper {
    width: 80px;
    height: 80px;
    background: rgba(139, 92, 246, 0.1);
    color: var(--accent-purple);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.empty-icon-wrapper i {
    font-size: 32px;
}

.history-empty h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: var(--text-primary);
}

.history-empty p {
    margin: 0;
    font-size: 13px;
}

/* ========== GANTT CHART ========== */
.gantt-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    padding: 16px;
}

.gantt-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
    padding-bottom: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.gantt-table {
    min-width: 700px;
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.gantt-table th,
.gantt-table td {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.gantt-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
    position: sticky;
    top: 0;
    font-size: 11px;
}

.gantt-day-header {
    min-width: 36px;
    font-size: 10px;
}

.gantt-bar {
    height: 20px;
    border-radius: 4px;
    display: inline-block;
    width: 100%;
    max-width: 36px;
    transition: transform var(--transition-fast);
}

.gantt-bar:hover {
    transform: translateY(-1px);
}

/* ========== LISTA DETALHADA ========== */
.os-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.os-card {
    background: var(--bg-secondary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: all var(--transition-fast);
}

.os-card:hover {
    box-shadow: var(--shadow-sm);
}

.os-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.os-title {
    font-weight: 600;
    color: var(--text-primary);
}

.os-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.os-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ========== MATRIZ PRIORIDADE ========== */
.prioridade-matrix {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.prioridade-card {
    background: var(--bg-secondary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
    padding: 18px;
    text-align: center;
    transition: all var(--transition-fast);
}

.prioridade-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.prioridade-card.p0 { border-left: 4px solid var(--danger); background: rgba(239, 68, 68, 0.05); }
.prioridade-card.p1 { border-left: 4px solid var(--warning); background: rgba(245, 158, 11, 0.05); }
.prioridade-card.p2 { border-left: 4px solid var(--accent-blue); background: rgba(59, 130, 246, 0.05); }

.prioridade-badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 13px;
}

.prioridade-badge.p0 { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.prioridade-badge.p1 { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.prioridade-badge.p2 { background: rgba(59, 130, 246, 0.2); color: var(--accent-blue); }

/* ========== PRIORITY BADGE PADRAO ========== */
.priority-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}

.priority-badge-lg {
    display: inline-block;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 15px;
    font-weight: 800;
}

/* ========== MATRIZ DE PRIORIDADE (SECUNDARIA) ========== */
.matriz-prioridade h3 { 
    margin-bottom: 20px; 
    font-size: 18px;
}

.matriz-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.matriz-card {
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition-fast);
}

.matriz-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.matriz-card.p0 { border-left: 4px solid var(--danger); }
.matriz-card.p1 { border-left: 4px solid var(--warning); }
.matriz-card.p2 { border-left: 4px solid var(--accent-blue); }

.matriz-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.matriz-header h4 { 
    font-size: 15px; 
    color: var(--text-primary);
    margin: 0;
}

.matriz-criterios { 
    margin-bottom: 16px; 
}

.matriz-criterios h5 { 
    font-size: 11px; 
    color: var(--text-muted); 
    margin-bottom: 8px; 
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.matriz-criterios ul { 
    list-style: none; 
    font-size: 12px; 
    color: var(--text-secondary);
    padding-left: 0;
    margin: 0;
}

.matriz-criterios ul li { 
    padding: 5px 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.matriz-criterios ul li::before {
    content: "•";
    color: var(--accent-blue);
}

.matriz-criterios ul li strong { 
    color: var(--text-primary); 
}

.matriz-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
    margin: 12px 0;
    padding: 10px 0;
}

.matriz-acoes {
    font-size: 12px;
    color: var(--accent-blue);
    padding: 10px;
    background: rgba(59,130,246,0.05);
    border-radius: var(--radius-md);
}

/* ========== PERT-CPM ========== */
.pert-cpm-container h3 { 
    margin-bottom: 20px; 
    font-size: 18px;
}

.pert-diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 30px 24px;
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
}

.pert-node {
    padding: 12px 24px;
    background: var(--bg-tertiary);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.pert-node:hover {
    transform: translateY(-2px);
}

.pert-node.inicio { border-left: 4px solid var(--success); color: var(--success); }
.pert-node.fim { border-left: 4px solid var(--danger); color: var(--danger); }

.pert-arrow {
    font-size: 20px;
    color: var(--text-muted);
}

.pert-info {
    padding: 18px;
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
}

/* ========== INDICADORES DETALHADOS ========== */
.indicadores-detalhados h3 { 
    margin-bottom: 20px; 
    font-size: 18px;
}

.indicator-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}

.indicator-detail-card {
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
    transition: all var(--transition-fast);
}

.indicator-detail-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.indicator-detail-card.destaque {
    box-shadow: var(--glow-blue);
}

.indicator-detail-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(139,92,246,0.15);
    color: var(--accent-purple);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin: 0 auto 14px;
}

.indicator-detail-card h4 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.indicator-detail-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
    line-height: 1.2;
}

.indicator-detail-card p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.indicator-detail-card small {
    font-size: 10px;
    color: var(--accent-blue);
}

/* ========== ANALISE AGRUPADA ========== */
.analise-agrupada h3 { 
    margin-bottom: 20px; 
    font-size: 18px;
}

.agrupado-card {
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
    padding: 18px;
    margin-bottom: 14px;
    transition: all var(--transition-fast);
}

.agrupado-card:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.agrupado-card h4 {
    font-size: 15px;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.agrupado-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.agrupado-stats strong { 
    color: var(--text-primary); 
}

.agrupado-mini-gantt {
    display: flex;
    gap: 4px;
    height: 24px;
    margin-top: 10px;
}

.mini-bar {
    flex: 1;
    border-radius: 4px;
    min-width: 15px;
    transition: all var(--transition-fast);
}

.mini-bar:hover {
    transform: translateY(-2px);
}

/* ========== VIEW ANIMATION ========== */
.view-animate {
    animation: history-fadeIn var(--transition-normal) ease;
}

/* ========== REMOVER KPIS FIXOS DO CABECALHO NO MODULO HISTORICO ========== */
.history-module .floating-kpi-wrapper,
.history-module .kpi-panel,
.history-module .kpi-card {
    display: none;
}

/* ============================================
   CORRECAO MOBILE - TABS (3 POR LINHA) - FORCADO
   ============================================ */

/* Forcar para todos os tamanhos de tela menores que 768px */
@media (max-width: 767px) {
    /* Header */
    .history-header {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
    }
    
    .history-title {
        justify-content: center;
        text-align: center;
    }
    
    .history-title h2 {
        font-size: 18px;
    }
    
    /* BOTOES SUPERIORES */
    .history-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .history-actions button {
        flex: 1 1 calc(50% - 10px);
        font-size: 11px;
        padding: 10px 8px;
        justify-content: center;
        white-space: normal;
        word-break: break-word;
    }
    
    /* TABS - FORCADO */
    .history-tabs {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        border-bottom: none;
        margin-bottom: 16px;
        overflow-x: visible;
        background: transparent;
    }
    
    .history-tab {
        flex: 1 1 calc(33.333% - 8px);
        justify-content: center;
        text-align: center;
        padding: 10px 6px;
        font-size: 11px;
        white-space: normal;
        word-break: break-word;
        min-height: 48px;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 0;
        margin: 0;
        display: flex;
        align-items: center;
        cursor: pointer;
    }
    
    .history-tab i {
        display: inline-block;
        margin-right: 5px;
        font-size: 11px;
    }
    
    .history-tab.active {
        border-bottom: 2px solid var(--accent-purple);
        background: rgba(139, 92, 246, 0.1);
        color: var(--accent-purple);
    }
    
    /* Filtros */
    .history-filters {
        flex-direction: column;
        gap: 12px;
        padding: 14px;
    }
    
    .filter-group {
        width: 100%;
        min-width: auto;
    }
    
    .btn-filter-wrapper button {
        width: 100%;
    }
    
    /* Indicadores principais */
    .indicator-main-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .indicator-main-card {
        padding: 14px;
    }
    
    .indicator-icon {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
    
    .indicator-value {
        font-size: 22px;
    }
    
    /* Matriz */
    .matriz-grid,
    .prioridade-matrix {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    /* PERT */
    .pert-diagram {
        flex-direction: column;
        gap: 8px;
        padding: 20px;
    }
    
    .pert-arrow {
        transform: rotate(90deg);
    }
    
    /* Indicadores detalhados */
    .indicator-detail-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    
    .indicator-detail-value {
        font-size: 28px;
    }
    
    /* Análise agrupada */
    .agrupado-stats {
        flex-direction: column;
        gap: 8px;
    }
    
    /* Gantt */
    .gantt-container {
        padding: 12px;
    }
    
    .gantt-table {
        min-width: 550px;
        font-size: 10px;
    }
    
    .gantt-table th,
    .gantt-table td {
        padding: 6px 8px;
    }
    
    .gantt-day-header {
        min-width: 30px;
    }
}

/* Mobile pequeno (400px - 480px) - TABS viram 2 por linha */
@media (max-width: 480px) {
    .history-tab {
        flex: 1 1 calc(50% - 8px);
        font-size: 10px;
        padding: 8px 4px;
        min-height: 44px;
    }
    
    .history-tab i {
        font-size: 10px;
    }
    
    .indicator-main-cards {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .matriz-grid,
    .prioridade-matrix {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .matriz-card {
        padding: 16px;
    }
}

/* Mobile muito pequeno (< 350px) - TABS viram 1 por linha */
@media (max-width: 350px) {
    .history-tab {
        flex: 1 1 100%;
    }
}

/* Tablet (481px - 768px) - manter 3 colunas */
@media (min-width: 481px) and (max-width: 768px) {
    .history-tab {
        flex: 1 1 calc(33.333% - 8px);
    }
    
    .indicator-main-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
    
    .matriz-grid,
    .prioridade-matrix {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .pert-diagram {
        flex-direction: column;
        gap: 8px;
    }
    
    .pert-arrow {
        transform: rotate(90deg);
    }
}

/* Desktop (> 768px) */
@media (min-width: 769px) {
    .indicator-main-card:hover {
        transform: translateY(-3px);
    }
    
    .history-tab:hover {
        background: rgba(255, 255, 255, 0.03);
    }
}

/* Large Desktop (> 1200px) */
@media (min-width: 1201px) {
    .indicator-main-cards {
        gap: 22px;
    }
    
    .matriz-grid {
        gap: 24px;
    }
}

/* ========== ANIMACOES ========== */
@keyframes history-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes history-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ========== TOUCH OTIMIZACOES ========== */
@media (hover: none) and (pointer: coarse) {
    .history-actions button:active,
    .history-tab:active,
    .matriz-card:active {
        transform: scale(0.98);
        transition: transform 0.05s ease;
    }
    
    .indicator-main-card:hover,
    .matriz-card:hover,
    .agrupado-card:hover {
        transform: none;
    }
    
    button, .history-tab {
        min-height: 44px;
    }
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms;
        transition-duration: 0.01ms;
    }
    
    .indicator-main-card:hover,
    .matriz-card:hover {
        transform: none;
    }
}

/* ========== PRINT ========== */
@media print {
    .history-actions,
    .history-filters,
    .history-tabs {
        display: none;
    }
    
    .indicator-main-cards {
        break-inside: avoid;
    }
    
    .gantt-container {
        overflow: visible;
    }
    
    .gantt-table {
        border: 1px solid #ccc;
    }
    
    .matriz-card {
        break-inside: avoid;
        border: 1px solid #ccc;
    }
}
