/* ==========================================
   VARIÁVEIS E REGRAS GERAIS DO PAINEL ADMIN
   IDENTIDADE VISUAL PREFEITURA DE FAZENDA RIO GRANDE
   ========================================== */
:root {
    --primary: #0b396a;
    --primary-hover: #082b52;
    --primary-light: #eaf1f8;
    --sidebar-bg: #ffffff;
    --sidebar-width: 210px;
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --success: #1b7a3e;
    --danger: #d32f2f;
    --warning: #f57c00;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
}

.hidden {
    display: none !important;
}

/* ==========================================
   MENU LATERAL (SIDEBAR FIXA BRANCA)
   ========================================== */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: #ffffff;
    color: #1e293b;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    box-shadow: 2px 0 12px rgba(11, 57, 106, 0.08);
    border-right: 1px solid #e2e8f0;
    z-index: 1000;
}

/* CABEÇALHO DA SIDEBAR COM LOGO MAIOR PERFEITAMENTE ENCAIXADA */
.sidebar-header {
    padding: 8px 4px 4px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #ffffff;
    border-bottom: 1.5px solid #e2e8f0;
    text-align: center;
}

.sidebar-logo-container {
    background: transparent;
    padding: 0;
    border-radius: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.sidebar-logo {
    width: 100%;
    max-width: 205px;
    height: auto;
    max-height: 115px;
    object-fit: contain;
    display: block;
}

.sidebar-title-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.sidebar-title-group h2 {
    font-size: 19px;
    font-weight: 800;
    margin: 0;
    color: #0b396a;
    letter-spacing: 0.3px;
    line-height: 1.2;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar-title-group h2 span {
    color: #ffffff;
    background-color: #0b396a;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 4px;
}

/* CARD DE PERFIL DO ADMINISTRADOR / USUÁRIO LOGADO */
.user-profile-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background-color: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: #0b396a;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
    border: 2px solid #e2e8f0;
    text-transform: uppercase;
}

.user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.user-name {
    font-weight: 700;
    font-size: 13px;
    line-height: 1.35;
    color: #1e293b;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
}

.user-email {
    font-size: 12px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.user-badge {
    display: inline-block;
    align-self: flex-start;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    background-color: var(--success);
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

/* NAVEGAÇÃO INTERNA */
.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: #0b396a;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active,
.sidebar-nav a.ativo {
    background-color: #f1f5f9;
    color: #082b52;
    border-left-color: #0b396a;
}

.sidebar-nav a svg {
    stroke-width: 2;
    flex-shrink: 0;
}

/* RODAPÉ DA SIDEBAR E BOTÃO DE DESCONECTAR */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid #e2e8f0;
    background-color: #ffffff;
}

.btn-logout-sidebar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 11px;
    background-color: var(--danger);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-logout-sidebar:hover {
    background-color: #b71c1c;
}

/* ==========================================
   ÁREA DE CONTEÚDO PRINCIPAL (RECUADA)
   ========================================== */
.admin-main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    padding: 30px;
    box-sizing: border-box;
    min-height: 100vh;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.admin-header h1 {
    font-size: 22px;
    color: var(--primary);
    margin: 0;
}

.system-tag {
    font-size: 12px;
    background-color: var(--primary-light);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
}

.admin-container {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.admin-section h2 {
    font-size: 20px;
    color: var(--primary);
    margin-bottom: 20px;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 8px;
}

/* ==========================================
   CARDS DE ESTATÍSTICA (DASHBOARD)
   ========================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    border-top: 4px solid var(--primary);
}

.stat-card h3 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .number {
    font-size: 30px;
    font-weight: 700;
    color: var(--primary);
}

/* ==========================================
   TABELAS DE GESTÃO DO PAINEL
   ========================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    margin-top: 15px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.admin-table th {
    background-color: #f1f3f8;
    color: var(--primary);
    padding: 12px 15px;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.admin-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

.admin-table tbody tr:hover {
    background-color: #f8f9fa;
}

/* ==========================================
   BOTÕES DE AÇÃO ADMINISTRATIVOS
   ========================================== */
.btn-admin {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-admin-primary {
    background-color: var(--primary);
    color: #ffffff;
}

.btn-admin-primary:hover {
    background-color: var(--primary-hover);
}

.btn-admin-danger,
.btn-excluir {
    background-color: var(--danger);
    color: #ffffff;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-admin-danger:hover,
.btn-excluir:hover {
    background-color: #b71c1c;
}

.btn-admin-secondary {
    background-color: #e0e0e0;
    color: #333333;
}

.btn-admin-secondary:hover {
    background-color: #d6d6d6;
}

/* ==========================================
   FORMULÁRIOS DE GESTÃO
   ========================================== */
.admin-form-group {
    margin-bottom: 18px;
}

.admin-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-color);
}

.admin-form-group input,
.admin-form-group select,
.admin-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.admin-form-group input:focus,
.admin-form-group select:focus,
.admin-form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 35, 126, 0.1);
}

/* ==========================================
   NAVEGAÇÃO POR ABAS (OCULTAR / EXIBIR)
   ========================================== */
.aba-conteudo {
    display: none !important;
}

.aba-conteudo.ativa {
    display: block !important;
    animation: fadeIn 0.25s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================
   MODAL DE DETALHES (SOBREPOSIÇÃO E COMPACTO)
   ========================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    padding: 15px;
    box-sizing: border-box;
}

.modal-content.modal-lg {
    max-width: 580px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background-color: var(--primary);
    color: #ffffff;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.btn-close-modal {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.btn-close-modal:hover {
    opacity: 1;
}

.modal-body {
    padding: 18px 20px;
    overflow-y: auto;
    flex: 1;
}

/* RESUMO DA AVALIAÇÃO NO MODAL */
.eval-info-header {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.eval-info-item label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 2px;
}

.eval-info-item span {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
}

/* LISTAGEM E CARDS DE RESPOSTA COMPACTOS */
.responses-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.response-card {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: #ffffff;
}

.response-question {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-color);
    margin-bottom: 4px;
}

.response-answer-score {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 12px;
}

.response-answer-score.high {
    background-color: #e8f5e9;
    color: var(--success);
}

.response-answer-score.low {
    background-color: #ffebee;
    color: var(--danger);
}

.response-answer-text {
    background-color: #f5f5f5;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    color: #444444;
    white-space: pre-wrap;
    border-left: 3px solid var(--primary);
    margin-top: 4px;
}

/* ==========================================
   TOPBAR MOBILE E GAVETA (SIDEBAR OFF-CANVAS)
   ========================================== */
.mobile-topbar {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

.btn-close-sidebar {
    display: none;
}

/* Responsividade geral de tabelas e gráficos */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
}

.graficos-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 24px;
}


/* ==========================================
   RESPONSIVIDADE (TELAS MENORES / CELULARES)
   ========================================== */
@media (max-width: 768px) {
    /* Barra Superior no Mobile */
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 56px;
        background-color: #ffffff;
        border-bottom: 1px solid #e2e8f0;
        padding: 0 16px;
        z-index: 1050;
        box-shadow: 0 2px 8px rgba(11, 57, 106, 0.08);
    }

    body.admin-body {
        flex-direction: column;
    }

    .btn-mobile-toggle,
    .btn-mobile-theme {
        background: transparent;
        border: none;
        color: var(--primary);
        cursor: pointer;
        padding: 8px;
        border-radius: 6px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 40px;
        min-height: 40px;
    }

    .btn-mobile-toggle:hover,
    .btn-mobile-theme:hover {
        background-color: var(--primary-light);
    }

    .mobile-topbar-brand {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .mobile-topbar-title {
        font-size: 17px;
        font-weight: 800;
        color: var(--primary);
        letter-spacing: -0.2px;
    }

    .mobile-topbar-badge {
        font-size: 10px;
        font-weight: 700;
        background-color: #0b396a;
        color: #ffffff;
        padding: 2px 6px;
        border-radius: 4px;
        letter-spacing: 0.5px;
    }

    /* Sidebar Gaveta (Off-Canvas Drawer) */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        z-index: 1200;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-header {
        position: relative;
        padding: 14px 16px;
    }

    .btn-close-sidebar {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 10px;
        right: 10px;
        background: transparent;
        border: none;
        font-size: 26px;
        line-height: 1;
        color: #64748b;
        cursor: pointer;
        width: 36px;
        height: 36px;
        border-radius: 6px;
    }

    .btn-close-sidebar:hover {
        background-color: #f1f5f9;
        color: #0b396a;
    }

    /* Backdrop escurecido */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 1150;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Conteúdo Principal Ocupa 100% no Mobile */
    .admin-main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 16px 12px;
        min-height: calc(100vh - 56px);
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 18px;
    }

    .admin-header h1 {
        font-size: 20px;
    }

    .admin-container {
        padding: 16px 12px;
    }

    /* Ajuste de Gráficos e Cartões no Mobile */
    .graficos-grid-container {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card .number {
        font-size: 26px;
    }

    /* Formulários e botões no mobile */
    .admin-table th,
    .admin-table td {
        padding: 10px 8px;
        font-size: 13px;
        white-space: nowrap;
    }

    /* Evita zoom automático no iOS em inputs e botões confortáveis */
    input, select, textarea {
        font-size: 16px !important;
    }

    .btn-admin {
        padding: 10px 14px;
        min-height: 42px;
    }
}

.grafico-vazio {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-color);
}

/* ==========================================
   ESTILOS DE IMPRESSÃO E EXPORTAÇÃO PDF (PAISAGEM - MARGENS PADRÃO DO NAVEGADOR)
   ========================================== */
@media print {
    @page {
        size: A4 landscape;
        /* Sem margin aqui: o navegador usa as margens padrão selecionadas no diálogo */
    }

    /* Oculta menus, sidebars, filtros e botões de ação (elimina blocos em branco) */
    .no-print,
    .sidebar,
    .mobile-topbar,
    .sidebar-backdrop,
    #btn-toggle-sidebar,
    #secao-filtro-graficos,
    #btn-atualizar-dashboard,
    #btn-atualizar-graficos,
    #btn-exportar-dashboard-graficos,
    #btn-executar-download,
    .admin-container[style*="border-left: 4px solid"],
    #sec-dashboard > div:first-child,
    .btn-admin,
    #filtro-escola,
    #filtro-ano,
    #filtro-data-inicio,
    #filtro-data-fim,
    #btn-limpar-filtros-data,
    .admin-form-group,
    header.admin-header .system-tag {
        display: none !important;
    }

    html, body {
        background-color: #ffffff !important;
        color: #000000 !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    /* Remove o recuo da sidebar na impressão */
    .admin-main-content,
    .main-content,
    main {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    #conteudo-principal {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .admin-header {
        margin-bottom: 10px !important;
        padding-bottom: 6px !important;
        border-bottom: 2px solid #0b396a !important;
    }

    .admin-header h1 {
        font-size: 18px !important;
        color: #0b396a !important;
        margin: 0 0 3px 0 !important;
    }

    .admin-header p {
        font-size: 11px !important;
        color: #475569 !important;
        margin: 0 !important;
    }

    /* Cards de estatística em linha compacta */
    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px !important;
        margin-bottom: 12px !important;
        width: 100% !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .stat-card {
        background: #ffffff !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 6px !important;
        padding: 8px 12px !important;
        box-shadow: none !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .stat-card h3 {
        font-size: 10px !important;
        margin-bottom: 3px !important;
        color: #64748b !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
    }

    .stat-card .number {
        font-size: 20px !important;
        font-weight: 700 !important;
        color: #0b396a !important;
        line-height: 1 !important;
    }

    /* Gráficos lado a lado — limitados para não esticar na folha inteira */
    .graficos-grid-container {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 16px !important;
        margin: 0 auto !important;
        max-width: 220mm !important;  /* Limita a ~74% da largura A4 paisagem */
        width: 100% !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .grafico-card {
        background: #ffffff !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 6px !important;
        padding: 8px 10px !important;
        box-shadow: none !important;
        width: 100% !important;
        overflow: hidden !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .grafico-card-header {
        margin-bottom: 6px !important;
        padding-bottom: 4px !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }

    .grafico-card-titulo {
        font-size: 12px !important;
        color: #0b396a !important;
        margin: 0 !important;
    }

    .grafico-card-escala {
        font-size: 9.5px !important;
        color: #64748b !important;
    }

    /* Altura dos gráficos para impressão */
    .grafico-card div[style*="height: 320px"] {
        height: 200px !important;
        max-height: 200px !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    .grafico-card canvas {
        max-height: 200px !important;
        max-width: 100% !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* Sem quebras de página forçadas */
    .admin-container,
    .grafico-card,
    .stat-card,
    .stats-grid,
    .graficos-grid-container {
        page-break-before: avoid !important;
        page-break-after: avoid !important;
        break-before: avoid !important;
        break-after: avoid !important;
    }
}