/* ==========================================================================
   CONFIGURAÇÃO, VARIÁVEIS E PALETA DE CORES INDUSTRIAIS MODERNAS (ESTILO SCADA/IGNITION)
   ========================================================================== */
:root {
    /* Cores Principais - Paleta Corporativa Industrial Segura */
    --primary: #1e3a8a;
    --primary-hover: #1d4ed8;
    --secondary: #475569;
    --secondary-hover: #334155;
    
    /* Estados de Sistema */
    --success: #16a34a;
    --success-hover: #15803d;
    --warning: #ea580c;
    --warning-hover: #c2410c;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --info: #0284c7;
    --info-hover: #0369a1;
    
    /* Superfícies e Textos */
    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --input-bg: #ffffff;
    --input-disabled: #e2e8f0;
    
    /* Elevação e Componentes */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.08);
    --radius: 8px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   RESET E CONFIGURAÇÃO BASE
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: 70px; /* Evita que o footer fixo cubra conteúdo */
    min-height: 100vh;
}

/* ==========================================================================
   HEADER DO SISTEMA
   ========================================================================== */
.main-header {
    background-color: var(--primary);
    color: #ffffff;
    padding: 24px 20px;
    text-align: center;
    border-bottom: 4px solid var(--secondary);
    box-shadow: var(--shadow);
}

.main-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.header-info {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    font-size: 0.95rem;
    color: #f8fafc;
}

.meta-indicators {
    margin-top: 10px;
    font-size: 0.85rem;
    opacity: 0.9;
    font-weight: 500;
}

/* ==========================================================================
   CONTAINER PRINCIPAL E ESTRUTURA DE CARDS
   ========================================================================== */
.container {
    width: 100%;
    max-width: 1440px;
    margin: 24px auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    width: 100%;
}

.card:hover {
    box-shadow: var(--shadow);
}

/* Tipografia Interna */
h2 {
    color: var(--primary);
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 10px;
    font-size: 1.35rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

h3 {
    color: var(--secondary);
    margin: 20px 0 12px 0;
    font-size: 1.1rem;
    font-weight: 600;
}

hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 24px 0;
}

/* ==========================================================================
   FORMULÁRIOS E LAYOUT DE GRIDS
   ========================================================================== */
.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

form label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--secondary);
}

/* Padronização de Altura e Aparência dos Inputs */
form input[type="text"],
form input[type="number"],
form input[type="date"],
form input[type="time"],
form select,
form textarea {
    width: 100%;
    height: 42px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    color: var(--text-main);
    background-color: var(--input-bg);
    outline: none;
    transition: var(--transition);
}

form textarea {
    height: auto;
    min-height: 100px;
    resize: vertical;
}

/* Estados de Foco */
form input:focus, 
form select:focus, 
form textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

/* Campos Apenas Leitura */
.readonly-input {
    background-color: var(--input-disabled) !important;
    font-weight: 600;
    color: #475569;
    cursor: not-allowed;
}

/* ==========================================================================
   CONTROLES DE SELEÇÃO (CHECKBOX / RADIO GRIDS)
   ========================================================================== */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    background: #f8fafc;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 16px;
    max-height: 220px;
    overflow-y: auto;
}

.vertical-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8fafc;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    max-height: 220px;
    overflow-y: auto;
}

.checkbox-grid label, 
.vertical-checkboxes label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-main);
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.checkbox-grid label:hover, 
.vertical-checkboxes label:hover {
    background-color: #f1f5f9;
}

.checkbox-grid input[type="checkbox"], 
.vertical-checkboxes input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

/* ==========================================================================
   SISTEMA DE BOTÕES E AÇÕES
   ========================================================================== */
.actions-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
    width: 100%;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 42px;
    padding: 0 20px;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    
    /* Configuração de Limites Responsivos Nativos */
    width: auto;
    min-width: 140px;
    max-width: 280px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn:active {
    transform: scale(0.98);
}

/* Estilização de Cores das Variantes de Botões */
.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-success { background: var(--success); color: #ffffff; }
.btn-success:hover { background: var(--success-hover); }

.btn-secondary { background: var(--secondary); color: #ffffff; }
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-warning { background: var(--warning); color: #ffffff; }
.btn-warning:hover { background: var(--warning-hover); }

.btn-danger { background: var(--danger); color: #ffffff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-info { background: var(--info); color: #ffffff; }
.btn-info:hover { background: var(--info-hover); }

.label-file { 
    margin: 0; 
    display: inline-flex;
}

/* ==========================================================================
   FILTROS AVANÇADOS
   ========================================================================== */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    background: #f8fafc;
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

/* ==========================================================================
   TABELAS DE DADOS
   ========================================================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    margin-top: 16px;
    border-radius: 6px;
    /* Suaviza a barra de rolagem em motores WebKit */
    -webkit-overflow-scrolling: touch; 
}

.shadow-box {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #ffffff;
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.data-table th, 
.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table th {
    background-color: #f8fafc;
    color: var(--secondary);
    font-weight: 700;
    border-bottom: 2px solid var(--border-color);
}

.data-table tbody tr {
    transition: var(--transition);
}

.data-table tbody tr:hover {
    background-color: #f1f5f9;
    cursor: pointer;
}

/* Botões Inline de Linha da Tabela */
.btn-row {
    height: 30px;
    padding: 0 12px;
    font-size: 0.8rem;
    min-width: auto;
    max-width: none;
    margin-right: 4px;
}

/* ==========================================================================
   DASHBOARD E GRÁFICOS (MÓDULO SCADA)
   ========================================================================== */
.dashboard-view {
    border: 2px solid var(--primary);
    background: #ffffff;
    border-radius: var(--radius);
    padding: 24px;
}

.dash-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px dashed var(--border-color);
    flex-wrap: wrap;
}

.dash-header {
    text-align: center;
    margin-bottom: 24px;
    background: #f8fafc;
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.dash-header h2 {
    border: none;
    margin-bottom: 8px;
    justify-content: center;
}

.dash-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    font-size: 0.9rem;
    margin-bottom: 16px;
    color: var(--text-muted);
}

.dash-highlight-box {
    background: var(--primary);
    color: #ffffff;
    padding: 14px 24px;
    border-radius: 6px;
    font-size: 1.15rem;
    font-weight: 600;
    display: inline-block;
    box-shadow: var(--shadow-sm);
}

/* Tabela de Sumário / KPIs */
.summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 32px;
}

.summary-table th, 
.summary-table td {
    border: 1px solid var(--border-color);
    padding: 12px 14px;
    font-size: 0.9rem;
}

.summary-table th {
    background: #f8fafc;
    color: var(--secondary);
    text-align: left;
    font-weight: 600;
    width: 25%;
}

.summary-table td {
    background: #ffffff;
    width: 25%;
}

/* Grid e Boxes de Gráficos Nativos */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
}

.chart-box {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.chart-box h4 {
    margin-bottom: 16px;
    color: var(--secondary);
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
}

canvas {
    max-width: 100% !important;
    height: auto !important;
    background: #ffffff;
    border-radius: 4px;
}

/* ==========================================================================
   UTILITÁRIOS
   ========================================================================== */
.hidden { 
    display: none !important; 
}

.icon { 
    font-style: normal; 
    font-weight: normal;
}

/* ==========================================================================
   RODAPÉ DO SISTEMA
   ========================================================================== */
.main-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #0f172a;
    color: #94a3b8;
    text-align: center;
    padding: 14px 20px;
    font-size: 0.85rem;
    border-top: 3px solid var(--secondary);
    z-index: 1000;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   RESPONSIVIDADE E ADAPTAÇÃO DE TELAS (MEDIA QUERIES)
   ========================================================================== */

/* Ajustes gerais para Notebooks e Desktop Médio */
@media (max-width: 1024px) {
    .container {
        padding: 0 16px;
        margin: 16px auto;
    }
}

/* Ajustes Finos para Tablets (Modo Retrato) */
@media (max-width: 768px) {
    .header-info {
        flex-direction: column;
        gap: 8px;
    }
    
    .actions-wrapper {
        justify-content: center;
        gap: 10px;
    }
    
    .btn {
        width: calc(50% - 5px); /* Divide em 2 colunas uniformes em tablets */
        max-width: none;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .summary-table th, 
    .summary-table td {
        display: block;
        width: 100% !important;
    }
    
    .summary-table tr {
        display: flex;
        flex-direction: column;
        border-bottom: 2px solid var(--border-color);
    }
    
    .summary-table tr:last-child {
        border-bottom: none;
    }
}

/* Ajustes Críticos para Smartphones */
@media (max-width: 480px) {
    .main-header {
        padding: 16px 12px;
    }
    
    .main-header h1 {
        font-size: 1.4rem;
    }
    
    .container {
        padding: 0 12px;
        gap: 16px;
    }
    
    .card {
        padding: 16px;
    }
    
    h2 {
        font-size: 1.15rem;
    }
    
    .grid-3 {
        grid-template-columns: 1fr; /* Força 1 coluna estrita em telas pequenas */
    }
    
    .btn {
        width: 100%; /* Ocupa largura controlada respeitando alinhamento do wrapper */
        max-width: none;
    }
    
    .checkbox-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   ESTILOS DE IMPRESSÃO PROFISSIONAL (NATIVO / RELATÓRIO INDUSTRIAL)
   ========================================================================== */
@media print {
    @page {
        size: A4 portrait;
        margin: 15mm;
    }
    
    body {
        background: #ffffff;
        color: #000000;
        font-size: 10pt;
        padding-bottom: 0;
    }
    
    /* Ocultação absoluta de elementos de interface interativa */
    .no-print, 
    .main-header, 
    .form-section, 
    .files-section, 
    .history-section, 
    .main-footer,
    .dash-controls,
    .btn,
    form {
        display: none !important;
    }
    
    /* Reset Estrutural para o Modo Relatório */
    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .dashboard-view {
        border: none !important;
        padding: 0 !important;
        background: #ffffff !important;
    }
    
    .card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        background: transparent !important;
    }
    
    /* Estilização Manual de Tabelas de Impressão */
    .summary-table,
    .data-table {
        width: 100% !important;
        border-collapse: collapse !important;
        page-break-inside: avoid;
    }
    
    .summary-table th,
    .data-table th {
        background: #e2e8f0 !important;
        color: #000000 !important;
        -webkit-print-color-adjust: exact; 
        print-color-adjust: exact;
        font-weight: bold !important;
    }
    
    .summary-table td,
    .data-table td {
        background: #ffffff !important;
        color: #000000 !important;
    }
    
    /* Gráficos e Blocos de KPI */
    .charts-grid {
        grid-template-columns: 1fr 1fr !important; /* Lado a lado se couber no papel */
        gap: 15px !important;
    }
    
    .chart-box {
        page-break-inside: avoid;
        border: 1px solid #cbd5e1 !important;
        background: #ffffff !important;
        margin-bottom: 15px;
        padding: 10px !important;
    }
    
    .print-container {
        display: block !important;
    }
}