/* =========================================
   1. IMPORTAÇÃO DE FONTES E VARIÁVEIS
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* TEMA ESCURO (Padrão Eletromidia) */
    --bg-body: #0a0a0a;
    --bg-surface: #171717;
    --bg-surface-hover: #262626;
    --text-main: #f5f5f5;
    --text-muted: #a3a3a3;
    --border-color: #333333;
    
    /* Cor Laranja Eletromidia */
    --primary: #ff6600; 
    --primary-hover: #e65c00;

    /* Cores de Estado para as Ferramentas (Sucesso, Alerta, Erro, Info) */
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --info: #3b82f6;
}

body.light-mode {
    /* TEMA CLARO */
    --bg-body: #f4f4f5;
    --bg-surface: #ffffff;
    --bg-surface-hover: #fafafa;
    --text-main: #171717;
    --text-muted: #52525b;
    --border-color: #e4e4e7;
}

/* =========================================
   2. RESET E CONFIGURAÇÕES GERAIS
   ========================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Scrollbar Customizada */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 10px;
}

/* =========================================
   3. CABEÇALHO (TOPBAR)
   ========================================= */
.topbar {
    height: 80px;
    padding: 0 40px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.logo-img {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.logo h2 {
    font-size: 24px;
    font-weight: 300;
    color: var(--text-main);
    letter-spacing: 2px;
    border-left: 2px solid var(--border-color);
    padding-left: 12px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
}

.icon-btn:hover { color: var(--primary); }

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
}

.user-profile img:hover { border-color: var(--primary); }

/* =========================================
   4. HUB CENTRALIZADO E BENTO GRID
   ========================================= */
.hub-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.bento-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 160px;
    gap: 20px;
    width: 100%;
    max-width: 1100px;
    grid-auto-flow: dense; 
}

.bento-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.bento-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.card-header i { font-size: 32px; color: var(--primary); margin-bottom: 12px; }
.card-content h3 { font-size: 20px; margin-bottom: 8px; font-weight: 600; }
.card-content p { color: var(--text-muted); font-size: 14px; line-height: 1.4; }

.card-large { grid-column: span 2; grid-row: span 2; }
.card-large .card-header { display: flex; align-items: center; gap: 12px; }
.card-large .card-header i { margin-bottom: 0; }

.card-normal { grid-column: span 1; grid-row: span 1; }

.card-wide { grid-column: span 2; grid-row: span 1; }
.card-wide .card-header { display: flex; align-items: center; gap: 12px; }
.card-wide .card-header i { margin-bottom: 0; }

.card-full { grid-column: span 4; grid-row: span 1; justify-content: center; }

.admin-style .card-header { display: flex; align-items: center; gap: 20px; }
.admin-style .card-header i { margin-bottom: 0; font-size: 40px; }
.admin-style .card-header h3 { font-size: 20px; font-weight: 600; color: var(--text-main); margin-bottom: 4px; }
.admin-style .card-header p { font-size: 14px; color: var(--text-muted); }

.orange-glow:hover { box-shadow: 0 0 30px rgba(255, 102, 0, 0.15); }
.highlight-border { border-top: 4px solid var(--primary); }

/* =========================================
   5. COMPONENTES DAS FERRAMENTAS
   ========================================= */
.tool-container {
    padding: 30px 40px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.toolbar {
    display: flex;
    gap: 15px;
    background-color: var(--bg-surface);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    align-items: center;
    flex-wrap: wrap;
}

.dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    background-color: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.dropzone i { font-size: 48px; color: var(--primary); }
.dropzone h3 { font-size: 18px; color: var(--text-main); font-weight: 600; }
.dropzone p { font-size: 14px; }

.dropzone:hover, .dropzone.drag-active {
    border-color: var(--primary);
    background-color: rgba(255, 102, 0, 0.05); 
    color: var(--primary);
    transform: scale(1.01);
}

.dropzone input[type="file"] {
    display: none;
}

.form-control {
    background-color: var(--bg-body);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: 8px;
    outline: none;
    font-size: 14px;
    width: 100%;
}
.form-control:focus { border-color: var(--primary); }

.btn {
    padding: 10px 18px; border-radius: 8px; font-weight: 500; font-size: 14px;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; border: none;
}
.btn-primary { background-color: var(--primary); color: #fff; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-outline { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { background-color: var(--bg-surface-hover); }

.table-wrapper {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow-x: auto;
}
.noc-table { width: 100%; border-collapse: collapse; text-align: left; }
.noc-table th {
    background-color: var(--bg-surface-hover); color: var(--text-muted);
    font-weight: 600; font-size: 13px; padding: 16px;
    border-bottom: 1px solid var(--border-color); white-space: nowrap;
}
.noc-table td {
    padding: 16px; border-bottom: 1px solid var(--border-color);
    font-size: 14px; vertical-align: middle;
}
.noc-table tr:hover td { background-color: var(--bg-body); }

/* Modais de Ação Base */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; opacity: 0; visibility: hidden; transition: 0.3s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-box {
    background-color: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: 16px; width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto;
    transform: translateY(20px); transition: 0.3s;
}
.modal-overlay.active .modal-box { transform: translateY(0); }
.modal-header { padding: 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 18px; display: flex; align-items: center; }
.modal-body { padding: 20px; }
.modal-footer { padding: 20px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 10px; background-color: var(--bg-body); }


/* =========================================
   6. RESPONSIVIDADE E MOBILE-FIRST (TABELA EM CARDS)
   ========================================= */
@media (max-width: 900px) {
    .bento-grid { grid-template-columns: repeat(2, 1fr); }
    .card-large, .card-wide, .card-full { grid-column: span 2; }
    
    /* Adaptando Cabeçalho e Busca para Telas Menores */
    .topbar {
        height: auto;
        flex-direction: column;
        padding: 15px 20px;
        gap: 15px;
    }
    .topbar > div:first-child {
        flex-direction: column;
        width: 100%;
        align-items: flex-start !important;
        gap: 15px;
    }
    .topbar > div:first-child > div {
        margin-left: 0 !important;
        width: 100%;
    }
    
    /* Forçando o input de busca a usar todo o espaço no celular */
    #searchInput {
        min-width: 100% !important; 
    }
    
    /* Ajustes na Barra de Ferramentas (Filtros) */
    .toolbar {
        flex-direction: column;
        align-items: stretch !important;
    }
    .toolbar > div {
        width: 100%;
        min-width: 100% !important;
    }
    .toolbar .btn {
        width: 100%;
    }
}

@media (max-width: 768px) {
    /* TRANSFORMAÇÃO DA TABELA EM CARDS RESUMIDOS */
    .noc-table, .noc-table tbody, .noc-table tr, .noc-table td {
        display: block;
        width: 100%;
    }
    
    .noc-table thead {
        display: none; /* Oculta os títulos das colunas no topo */
    }
    
    .noc-table tr {
        margin-bottom: 15px;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 15px;
        background-color: var(--bg-surface);
        box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    }
    
    /* Impede que linhas escondidas (como a de histórico expandido) quebrem o layout */
    .noc-table tr[style*="display: none"] {
        display: none !important;
    }
    
    .noc-table td {
        border-bottom: none;
        padding: 6px 0;
        text-align: left;
    }
    
    /* OCULTAÇÕES SOLICITADAS NO CELULAR */
    .noc-table td:nth-child(1), /* Coluna do Checkbox */
    .noc-table td:nth-child(6), /* Coluna do Histórico longo */
    .noc-table td:nth-child(7)  /* Coluna de Ações (Botões Encerrar, Tratar, etc) */ {
        display: none !important;
    }

    /* Linha divisória após a informação da OS para dar um visual mais limpo ao "card" */
    .noc-table td:nth-child(2) { 
        border-bottom: 1px dashed var(--border-color); 
        padding-bottom: 12px; 
        margin-bottom: 8px; 
    }
}

@media (max-width: 600px) {
    .bento-grid { grid-template-columns: 1fr; grid-auto-rows: minmax(150px, auto); }
    .card-large, .card-normal, .card-wide, .card-full { grid-column: span 1; grid-row: span 1; }
    .admin-style .card-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    
    .form-row { flex-direction: column; }
    .form-col-qtd, .form-col-btn { width: 100%; }
    .form-col-btn .btn { width: 100%; min-height: 45px !important; }
    
    .dropzone { padding: 20px; }
    .tool-container { padding: 15px; }
}

/* =========================================
   7. ESTILOS ESPECÍFICOS DO MODAL DE MATERIAIS
   ========================================= */
.modal-box.modal-lg {
    width: 650px; 
    max-width: 95%;
}

.modal-header h3 i {
    color: var(--primary);
    margin-right: 8px;
}

.modal-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.modal-add-box {
    background-color: rgba(0,0,0,0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.light-mode .modal-add-box {
    background-color: #0e0d0b;
}

.form-row {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.form-col-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-col-qtd {
    width: 100px;
}

.form-col-btn {
    display: flex;
    align-items: center;
}

.vinculados-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.vinculado-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-surface-hover);
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
    font-size: 14px;
}

.vinculado-item:hover {
    border-color: var(--primary);
}

.vinculado-qtd {
    color: var(--primary);
    font-weight: 700;
    margin-right: 5px;
}

.btn-remover-item {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 5px;
    font-size: 18px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.btn-remover-item:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield; 
    appearance: textfield;      
    text-align: center;
}

/* =========================================
   8. ESTILOS DE AÇÕES (MOTIVOS, CRÍTICO E ENCERRAMENTO)
   ========================================= */

/* Estilo para a Tag de Motivo (Laranja) */
.tag-motivo {
    display: inline-block;
    background-color: var(--primary, #ff6600); 
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    margin-top: 5px;
    margin-right: 5px;
    font-weight: bold;
    word-wrap: break-word;
    white-space: normal;
}

/* Estilo para Linha de Chamado Crítico */
.row-critico td {
    background-color: rgba(239, 68, 68, 0.15) !important; /* Fundo vermelho suave */
}
.light-mode .row-critico td {
    background-color: rgba(239, 68, 68, 0.1) !important;
}

/* Estilo para Chamado Encerrado */
.row-encerrado td {
    opacity: 0.6;
}
.row-encerrado td strong {
    text-decoration: line-through;
}

/* =========================================
   9. TOGGLES E CASCATA DE PERMISSÕES (ADM)
   ========================================= */

/* Switch (Toggle) iOS Style */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-color);
    transition: .3s;
    border-radius: 20px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--primary);
}
input:checked + .slider:before {
    transform: translateX(16px);
}

/* Painel Cascata de Permissões */
.permissoes-panel {
    background-color: rgba(0,0,0,0.02);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}
.light-mode .permissoes-panel {
    background-color: #fafafa;
}
.permissao-group h4 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}
.permissao-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 13px;
}