:root {
    --primary-color: #2c5aa0;
    --primary-dark: #1e3a7a;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --text-secondary: #475569;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* Dashboard Layout */
.dashboard {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 20px;
    color: var(--primary-color);
}

.sidebar-menu {
    list-style: none;
    padding: 20px 0;
}

.sidebar-menu li {
    margin-bottom: 4px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.3s;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: var(--bg-color);
    color: var(--primary-color);
}

.sidebar-menu a i {
    margin-right: 12px;
    width: 20px;
}

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 0;
}

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    /* 2000: acima dos controles do Leaflet (z-index 1000). Sem isso o
       dropdown do menu do usuario fica por baixo do mapa. */
    z-index: 2000;
}

.topbar h1 {
    font-size: 24px;
    color: var(--text-color);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    text-align: right;
}

.user-name {
    font-weight: 500;
    color: var(--text-color);
    font-size: 14px;
}

.user-role {
    font-size: 12px;
    color: var(--text-muted);
}

/* Content Area */
.content {
    padding: 30px;
}

/* Submenu Styles */
.menu-item-has-children {
    position: relative;
}

.menu-toggle {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    cursor: pointer;
}

.menu-toggle .arrow {
    font-size: 10px;
    transition: transform 0.3s ease;
    margin-left: auto;
}

.menu-item-has-children.active .arrow {
    transform: rotate(180deg);
}

.submenu {
    display: none;
    background: var(--bg-color);
    margin: 0;
    padding: 0;
    list-style: none;
    border-left: 2px solid var(--primary-color);
    margin-left: 10px;
}

.menu-item-has-children.active .submenu {
    display: block;
}

.category-header {
    padding: 8px 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid var(--border-color);
}

.category-items {
    list-style: none;
    margin: 0;
    padding: 0;
}

.category-items li a {
    padding: 8px 20px 8px 40px !important;
    font-size: 13px;
    display: block;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.3s ease;
}

.category-items li a:hover {
    background: var(--bg-color);
    color: var(--primary-color);
    padding-left: 45px !important;
}

.category-items li a.active {
    background: var(--bg-color);
    color: var(--primary-color);
    font-weight: 500;
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 20px;
    list-style: none;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary-color);
}

.stat-card.success {
    border-left-color: var(--success-color);
}

.stat-card.warning {
    border-left-color: var(--warning-color);
}

.stat-card.danger {
    border-left-color: var(--danger-color);
}

.stat-label {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-color);
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.card-header .btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
}

.card-body {
    padding: 20px;
}

/* Table */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table thead {
    background: var(--bg-color);
}

table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-color);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

table td {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
}

table tbody tr:hover {
    background: var(--bg-color);
}

table th.text-right,
table td.text-right {
    text-align: right;
}

table th.text-center,
table td.text-center {
    text-align: center;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.3s;
}

.btn-icon:hover {
    background: var(--bg-color);
}

.btn-edit:hover {
    background: rgba(44, 90, 160, 0.1);
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 20px;
}

.close {
    color: var(--text-muted);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover {
    color: var(--danger-color);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-color);
    font-weight: 500;
    font-size: 14px;
}

.form-control,
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s;
}

.form-control:focus,
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Search Bar */
.search-bar {
    margin-bottom: 20px;
}

.search-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

/* Alert */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-error {
    background: #fee;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
}

.alert-success {
    background: #efe;
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

/* Utilities */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-20 {
    margin-top: 20px;
}

/* Context Selector */
.context-selector {
    background: var(--card-bg);
    border-bottom: 2px solid var(--primary-color);
    padding: 12px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.context-selector-content {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.context-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-field label {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
    white-space: nowrap;
}

.context-field select {
    min-width: 200px;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.context-field select:hover {
    border-color: var(--primary-color);
}

.context-field select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1);
}

/* Operation Filter */
.operation-filter {
    display: flex;
    align-items: flex-end;
    gap: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 200px;
}

.filter-field label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0;
}

.filter-field select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 14px;
    transition: all 0.2s;
}

.filter-field select:hover {
    border-color: var(--primary-color);
}

.filter-field select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1);
}

.operation-filter .btn-sm {
    padding: 8px 16px;
    font-size: 14px;
    margin-top: auto;
}

/* ===========================================================
   Telas operacionais (matriz / cards) - padrão ICEP 2025
   =========================================================== */

/* Tabela matriz (Quantidade × Segmento, Carga × Formação) - padrão 2025 */
.matriz-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.matriz-table thead th {
    background: #f5f5f5;
    padding: 12px 16px;
    text-align: left;
    font-weight: bold;
    font-size: 14px;
    color: #333;
    border-bottom: 1px solid #ddd;
}

.matriz-table th.col-numero {
    width: 180px;
    text-align: center;
}

.matriz-table tbody tr {
    border-bottom: 1px solid #f0f0f0;
}

.matriz-table tbody tr:last-child {
    border-bottom: none;
}

.matriz-table td {
    padding: 10px 16px;
    vertical-align: middle;
    color: #333;
}

.matriz-table td.col-numero {
    text-align: center;
}

.matriz-table input[type="number"] {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    text-align: right;
}

.matriz-table input[type="number"]:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

.matriz-item-meta {
    color: #666;
    font-size: 12px;
    font-weight: normal;
    margin-left: 6px;
}

/* Cards de categoria (avaliação de indicadores + comentário) - padrão 2025 */
.categoria-card {
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.categoria-header {
    background-color: #f5f5f5;
    padding: 12px 16px;
    font-weight: bold;
    border-bottom: 1px solid #ddd;
}

.categoria-body {
    padding: 16px;
}

.indicador-row {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

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

.indicador-descricao {
    flex: 1;
    padding-right: 20px;
}

.indicador-valor {
    width: 250px;
    flex-shrink: 0;
}

/* O select herda .form-control para padding/border;
   .avaliacao-valor adiciona apenas o peso e cursor de pointer. */
.avaliacao-valor {
    font-weight: 500;
    cursor: pointer;
}

/* Cores por valor de avaliação - 0=Não se Aplica, 1=Não Realizado, 2=Realizado Parcial, 3=Realizado Total */
.avaliacao-valor.valor-0 {
    background-color: #d1ecf1;
    color: #0c5460;
    border-color: #bee5eb;
}
.avaliacao-valor.valor-1 {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}
.avaliacao-valor.valor-2 {
    background-color: #fff3cd;
    color: #856404;
    border-color: #ffeaa7;
}
.avaliacao-valor.valor-3 {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

.comentario-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.comentario-label {
    font-weight: 500;
    margin-bottom: 8px;
    color: #333;
}

.comentario-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

.comentario-textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 95%;
        margin: 10% auto;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .search-input {
        max-width: 100%;
    }
}

/* ============================================================
   IDEB - tabela pivot e cards de resumo
   ============================================================ */
.ideb-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.ideb-summary .summary-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.ideb-summary .summary-label {
    font-size: 0.78em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 6px;
}
.ideb-summary .summary-value {
    font-size: 1.6em;
    font-weight: 600;
    color: var(--text-color);
    line-height: 1.1;
}
.ideb-summary .summary-meta {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-top: 4px;
}
.ideb-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85em;
}
.ideb-cell {
    text-align: center;
    cursor: pointer;
    padding: 6px 4px !important;
    position: relative;
}
.ideb-cell.empty {
    color: #cbd5e1;
}
.ideb-cell:hover {
    background: #f1f5f9;
}
.ideb-cell .ideb-valor {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-weight: 600;
}
.ideb-cell .ideb-delta {
    display: block;
    font-size: 0.72em;
    margin-top: 2px;
    color: var(--text-muted);
}
.ideb-cell .ideb-delta.up { color: #16a34a; }
.ideb-cell .ideb-delta.down { color: #dc2626; }
.ideb-row-empty td { background: #fafafa; color: var(--text-muted); }

/* ============================================================
   Banner de contexto (municipio/escola) — padrao em todas as telas
   Renderizado por /js/banner-municipio.js
   ============================================================ */
.ctx-banner {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    color: #fff;
    padding: 32px;
    border-radius: 14px;
    margin-bottom: 28px;
    position: relative;
    overflow: hidden;
}
.ctx-banner::before {
    content: ''; position: absolute; top: -50px; right: -50px;
    width: 200px; height: 200px; background: rgba(255,255,255,.08);
    border-radius: 50%; pointer-events: none;
}
.ctx-banner::after {
    content: ''; position: absolute; bottom: -80px; left: -30px;
    width: 250px; height: 250px; background: rgba(255,255,255,.05);
    border-radius: 50%; pointer-events: none;
}
/* mantem titulo/selects/meta acima dos circulos decorativos */
.ctx-banner > * { position: relative; z-index: 1; }
.ctx-banner h2 { margin: 0 0 6px 0; font-size: 22px; font-weight: 600; }
.ctx-banner .ctx-meta { opacity: 0.92; font-size: 14px; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.ctx-banner .ctx-meta span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ctx-banner .ctx-meta i { opacity: 0.85; }

/* Toggle switch reutilizavel (envolve um <input type="checkbox"> real, para
   manter o data binding nos forms). Mesmas medidas/cores do .toggle de
   administracao/parametros.html. Uso:
       <label class="toggle-switch">
           <input type="checkbox" id="...">
           <span class="slider"></span>
       </label>
*/
.toggle-switch {
    position: relative; display: inline-block;
    width: 50px; height: 28px;
    vertical-align: middle; flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; margin: 0; }
.toggle-switch .slider {
    position: absolute; inset: 0; cursor: pointer;
    background: #d1d5db; border-radius: 14px; transition: background .2s;
}
.toggle-switch .slider::before {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px;
    background: #fff; border-radius: 50%;
    transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .slider { background: #10b981; }
.toggle-switch input:checked + .slider::before { transform: translateX(22px); }
.toggle-switch input:disabled + .slider { opacity: .6; cursor: not-allowed; }
/* Linha "toggle + label" pra usar no lugar de checkbox+texto em formularios */
.toggle-row { display: flex; align-items: center; gap: 10px; }
.toggle-row .toggle-label { font-weight: 500; color: #334155; }



/* ============================================================
   Marcacao de AMBIENTE DE HOMOLOGACAO (icep-hml.rforti.com)
   ============================================================
   Quando body recebe a classe .env-hml (aplicada pelo
   js/env-marker.js apos consultar /api/status), todo o app fica
   visualmente identificado como nao-producao:
   - Barra fixa no topo (22px) com listras laranja/ambar
   - Topbar e sidebar deslocados pra acomodar a barra
   - Badge "HML" no menu do usuario (topbar.js)
   - Title da aba prefixado com [HML]
   Em producao a classe nunca eh adicionada, entao zero impacto. */
body.env-hml::before {
    content: '⚠ AMBIENTE DE HOMOLOGAÇÃO — dados de teste, alteracoes nao afetam a producao';
    position: fixed; top: 0; left: 0; right: 0;
    background: repeating-linear-gradient(45deg, #d97706, #d97706 14px, #f59e0b 14px, #f59e0b 28px);
    color: #fff; text-align: center;
    padding: 4px 12px;
    font-size: 11px; font-weight: 700; letter-spacing: 1px;
    text-transform: uppercase;
    z-index: 3000; /* acima do topbar (z-index 2000) */
    line-height: 1.4;
    box-shadow: 0 2px 4px rgba(0,0,0,.18);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.env-hml .sidebar { top: 22px; height: calc(100vh - 22px); }
body.env-hml .topbar { top: 22px; }
body.env-hml .main-content { padding-top: 22px; }

/* Badge "HML" no menu do usuario (topbar.js insere o span) */
.hml-badge {
    display: inline-block;
    background: #d97706;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
}
