* { box-sizing: border-box; }
body { font-family: 'DM Sans', sans-serif; }
:root {
    --glass: rgba(255,255,255,0.45);
    --glass-border: rgba(255,255,255,0.60);
    --cyan: #06b6d4;
    --blue: #3b82f6;
    --teal: #0d9488;
    --linha-altura: 32px; /* Valor inicial — sobrescrito pelo calibrarTexto() em JS no desktop */
}
.glass {
    background: var(--glass);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 24px rgba(14,116,144,0.08);
}

/* TOP NAV */
.topnav { background: rgba(255,255,255,0.75); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); border-bottom: 1px solid rgba(255,255,255,0.85); }
.nav-pill { position: relative; padding: 8px 18px; border-radius: 99px; font-weight: 700; font-size: 13px; color: #64748b; transition: all .2s; cursor: pointer; border: none; background: transparent; white-space: nowrap; }
.nav-pill:hover { color: #0e7490; background: rgba(6,182,212,0.08); }
.nav-pill.active { color: #0e7490; background: rgba(6,182,212,0.12); }
.nav-pill.active::after { content: ''; position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%); width: 18px; height: 3px; background: var(--cyan); border-radius: 99px; }

/* ANIMATE */
.fade-in { animation: fadeUp .35s ease-out both; }
@keyframes fadeUp { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
.stagger-1 { animation-delay: .05s; }
.stagger-2 { animation-delay: .10s; }
.stagger-3 { animation-delay: .15s; }
.stagger-4 { animation-delay: .20s; }

/* STAT CARDS */
.stat-card { transition: transform .2s, box-shadow .2s; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 12px 40px rgba(14,116,144,0.14); }

/* SUGESTÃO */
.sugestao-card { cursor: pointer; transition: all .2s; border: 1.5px solid transparent; }
.sugestao-card:hover { border-color: var(--cyan); transform: translateY(-2px); }

/* ══════════════════════════════════════
   MODAL BASE
══════════════════════════════════════ */
.modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(8,24,40,.50);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.modal-box {
    background: #f0f9ff;
    border-radius: 24px;
    padding: 2rem;
    max-width: 900px; width: 100%;
    box-shadow: 0 32px 80px rgba(0,0,0,.22);
    position: relative;
    max-height: 92vh; overflow-y: auto;
}

/* ══════════════════════════════════════
   MODAL REDAÇÃO — NOVO DESIGN
══════════════════════════════════════ */
.modal-redacao-box {
    background: #f0f9ff;
    border-radius: 24px;
    width: 100%; max-width: 980px;
    max-height: 94vh; overflow-y: auto;
    box-shadow: 0 32px 80px rgba(0,0,0,.22);
    position: relative;
}

/* Cabeçalho impresso (Atualizado visual) */
.cabecalho-redacao {
    display: none;
    background: white;
    border: 1.5px solid #e5e7eb;
    margin: 1.5rem 1.5rem 0;
    border-radius: 12px;
    font-size: 13px;
}
.cabecalho-redacao.visivel { display: block; }

/* Formulário do cabeçalho */
.form-cabecalho {
    display: none;
    background: #fff;
    border: 1.5px solid #bae6fd;
    border-radius: 16px;
    padding: 1rem;
    margin: 0 1.5rem 1rem;
    gap: 10px;
    grid-template-columns: 1fr 1fr;
}
.form-cabecalho.visivel { display: grid; }
.form-cabecalho label {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; color: #0284c7;
    display: block; margin-bottom: 4px;
}
.form-cabecalho input {
    width: 100%; padding: 7px 10px;
    border: 1px solid #bae6fd; border-radius: 8px;
    font-size: 12px; outline: none;
    background: #f8fafc; color: #1e293b; transition: border .2s;
}
.form-cabecalho input:focus { border-color: #0ea5e9; background: #fff; }
.form-cabecalho-titulo {
    grid-column: 1 / -1; font-size: 12px; font-weight: 700; color: #0369a1;
    display: flex; align-items: center; gap: 6px;
    padding-bottom: 8px; border-bottom: 1px solid #e0f2fe; margin-bottom: 4px;
}
.btn-salvar-cab {
    grid-column: 1 / -1;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px; background: #0284c7; color: #fff;
    border: none; border-radius: 10px; font-weight: 700; font-size: 12px;
    cursor: pointer; transition: background .2s;
}
.btn-salvar-cab:hover { background: #0369a1; }

/* Inner do modal redação */
.modal-redacao-inner { padding: 1.5rem; }
.modal-redacao-header {
    display: flex; align-items: flex-start;
    justify-content: space-between; margin-bottom: 1rem;
}
.modal-redacao-titulo {
    font-size: 22px; font-weight: 800; color: #0c4a6e;
    line-height: 1.3; flex: 1; padding-right: 1rem;
}
.modal-redacao-data { font-size: 12px; color: #64748b; margin-top: 4px; }
.modal-redacao-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn-modal-acao {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 12px;
    font-size: 12px; font-weight: 700; border: 1.5px solid;
    cursor: pointer; transition: all .2s; white-space: nowrap;
    background: none;
}
.btn-modal-cab { background: #f0f9ff; border-color: #bae6fd; color: #0284c7; }
.btn-modal-cab:hover, .btn-modal-cab.ativo { background: #e0f2fe; border-color: #7dd3fc; }
.btn-modal-print { background: #f0fdf4; border-color: #86efac; color: #16a34a; }
.btn-modal-print:hover { background: #dcfce7; border-color: #4ade80; }
.btn-modal-fechar { background: #f8fafc; border-color: #cbd5e1; color: #64748b; padding: 8px 10px; }
.btn-modal-fechar:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* Nota final */
.nota-final-badge {
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border: 1.5px solid #6ee7b7; border-radius: 16px;
    padding: 12px 20px; display: flex;
    align-items: center; justify-content: space-between; margin-bottom: 1rem;
}
.nota-final-label { font-size: 13px; font-weight: 700; color: #065f46; }
.nota-final-num { font-size: 36px; font-weight: 900; color: #064e3b; }

/* Notas grid no modal */
.modal-notas-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 8px; margin-bottom: 1rem;
}
.modal-nota-card {
    background: rgba(255,255,255,0.8); border: 1px solid rgba(255,255,255,0.9);
    border-radius: 12px; padding: 10px 6px; text-align: center;
    box-shadow: 0 2px 8px rgba(14,116,144,0.06);
}
.modal-nota-label { font-size: 10px; font-weight: 800; color: #0891b2; text-transform: uppercase; }
.modal-nota-valor { font-size: 22px; font-weight: 900; color: #0c4a6e; }

/* 2 colunas texto+feedback */
.modal-body-cols {
    display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
@media (max-width: 640px) { .modal-body-cols { grid-template-columns: 1fr; } }
.secao-label {
    font-size: 10px; font-weight: 800; text-transform: uppercase;
    letter-spacing: .7px; color: #0891b2; margin-bottom: 8px;
}
.texto-redacao-modal {
    background: rgba(255,255,255,0.85); border: 1px solid #bae6fd;
    border-radius: 14px; padding: 16px; font-size: 13px;
    line-height: 1.8; color: #1e293b; white-space: pre-wrap;
    max-height: 320px; overflow-y: auto;
    font-family: 'Georgia', serif;
}
.feedback-modal {
    background: #eff6ff; border: 1px solid #bfdbfe;
    border-radius: 14px; padding: 16px; font-size: 13px;
    line-height: 1.7; color: #1e293b; white-space: pre-wrap;
    max-height: 320px; overflow-y: auto;
}

/* ══════════════════════════════════════
   TEXTAREA COM CONTADOR DE LINHAS — ESTILO CADERNO
══════════════════════════════════════ */

.textarea-wrapper {
    display: flex;
    align-items: flex-start;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid #cbd5e1;
    height: auto;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    overflow: visible;
    position: relative;
    font-family: 'DM Mono', monospace;
    font-size: 15px;
}

.textarea-wrapper:focus-within {
    border-color: #06b6d4;
    box-shadow: 0 0 0 3px rgba(6,182,212,0.15);
}

/* Margem esquerda decorativa (vermelha) — fixa na posição da sidebar */
.textarea-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1.5px;
    background: rgba(244, 114, 182, 0.45);
    pointer-events: none;
    z-index: 1;
    left: 70px;
}

/*
   Margem direita decorativa — marcador de 70 chars.
   O JS (calibrarTexto) atualiza --margem-direita-pos com recuo de 24px
   para que a linha fique com espaço confortável antes da borda.
*/
.textarea-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1.5px;
    background: rgba(244, 114, 182, 0.45);
    pointer-events: none;
    z-index: 1;
    left: var(--margem-direita-pos, calc(64px + 24px + 70ch));
    right: auto;
}

@media (max-width: 640px) {
    .textarea-wrapper::before { left: 14px; }
    .textarea-wrapper::after { display: none; }
}

.line-numbers {
    display: flex; flex-direction: column; align-items: center;
    width: 52px;
    flex-shrink: 0;
    padding: 8px 0;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    border-radius: 16px 0 0 16px;
    user-select: none;
    overflow: visible;
    align-self: stretch;
}

/* ── MOBILE: oculta a sidebar numérica ── */
@media (max-width: 640px) {
    .line-numbers { display: none; }

    .textarea-wrapper {
        border-radius: 16px;
        flex-direction: column;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }
    .redacao-textarea {
        width: 100% !important;
        min-width: 0;
        padding: 8px 24px 20px 36px !important;
        font-size: 15px !important;
        letter-spacing: normal !important;
        field-sizing: content !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        background-image: none !important;
        line-height: 1.65 !important;
        resize: none !important;
    }
}

/* ── STICKY TEMA MOBILE ── */
.sticky-tema-mobile {
    display: none;
}
@media (max-width: 640px) {
    .sticky-tema-mobile {
        display: flex;
        flex-direction: column;
        gap: 2px;
        width: calc(100% - 32px);
        margin: 0 16px;
        padding: 0 14px;
        max-height: 0;
        overflow: hidden;
        background: #e8f4fd;
        border: 1px solid transparent;
        border-radius: 20px;
        box-shadow: none;
        position: sticky;
        top: 12px;
        z-index: 11;
        opacity: 0;
        pointer-events: none;
        transition: max-height .25s ease, padding .25s ease, opacity .25s,
                    margin .25s ease, border-color .25s, box-shadow .25s;
    }
    .sticky-tema-mobile.visivel {
        max-height: 120px;
        padding: 10px 14px;
        margin: 0 16px 0;
        opacity: 1;
        pointer-events: auto;
        border-color: #bae6fd;
        box-shadow: 0 6px 24px rgba(14,116,144,0.16);
    }
    .sticky-tema-mobile .stm-label {
        font-size: 9px;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: .6px;
        color: #0891b2;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .sticky-tema-mobile .stm-texto {
        font-size: 13px;
        font-weight: 700;
        color: #0c4a6e;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
        line-height: 1.3;
    }
    .sticky-tema-mobile .stm-bottom {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-top: 3px;
    }
    .sticky-tema-mobile .stm-linhas {
        font-size: 10px;
        font-weight: 700;
        color: #0891b2;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .sticky-tema-mobile .stm-barra {
        flex: 1;
        height: 5px;
        background: #e0f2fe;
        border-radius: 99px;
        overflow: hidden;
    }
    .sticky-tema-mobile .stm-fill {
        height: 100%;
        border-radius: 99px;
        background: #e2e8f0;
        transition: width .3s, background .3s;
    }
}

/* ── BANNER DE PROGRESSO MOBILE ── */
.mobile-progress-banner {
    display: none;
}
@media (max-width: 640px) {
    .mobile-progress-banner {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        padding: 10px 14px 8px;
        background: #f8fafc;
        border-bottom: 1px solid #e2e8f0;
        border-radius: 16px 16px 0 0;
        flex-shrink: 0;
        position: sticky;
        top: 37px;
        z-index: 10;
    }
    .mobile-progress-banner .mpb-label {
        font-size: 11px;
        font-weight: 800;
        white-space: nowrap;
        flex-shrink: 0;
        transition: color .2s;
    }
    .mobile-progress-banner .mpb-barra {
        flex: 1; height: 8px;
        background: #e0f2fe;
        border-radius: 99px;
        overflow: hidden;
    }
    .mobile-progress-banner .mpb-fill {
        height: 100%;
        border-radius: 99px;
        transition: width .3s, background .3s;
    }
    .mobile-progress-banner.mpb-vazio  .mpb-label { color: #94a3b8; }
    .mobile-progress-banner.mpb-vazio  .mpb-fill  { background: #e2e8f0; }
    .mobile-progress-banner.mpb-aviso  .mpb-label { color: #ea580c; }
    .mobile-progress-banner.mpb-aviso  .mpb-fill  { background: #f97316; }
    .mobile-progress-banner.mpb-ok     .mpb-label { color: #065f46; }
    .mobile-progress-banner.mpb-ok     .mpb-fill  { background: #10b981; }
    .mobile-progress-banner.mpb-erro   .mpb-label { color: #991b1b; }
    .mobile-progress-banner.mpb-erro   .mpb-fill  { background: #dc2626; }
    .status-linhas .barra-progresso { display: none; }
}

.line-num {
    font-size: 11px; font-weight: 700; color: #bae6fd;
    display: flex; align-items: center; justify-content: center;
    width: 100%;
    height: var(--linha-altura);
    flex-shrink: 0;
    transition: color .15s, background .15s;
}
.line-num span {
    display: flex; align-items: center;
}

.line-num.valida      { color: #0891b2; }
.line-num.abaixo-min  { color: #f97316; }
.line-num.acima-max   { color: #dc2626; background: rgba(220,38,38,0.08); font-weight: 900; }
.line-num.limite      { color: #059669; font-weight: 900; border-top: 1.5px dashed rgba(5,150,105,0.4); }

/* ══════════════════════════════════════
   INPUT DE TEMA — fonte mono para harmonizar com o corpo da redação
══════════════════════════════════════ */
#tema_redacao {
    font-family: 'DM Mono', monospace;
    font-weight: 500;
    font-size: 1rem;
    color: #0f172a;
}

.redacao-textarea {
    flex: 1;
    min-width: 0;
    padding: 8px 24px 20px 24px !important;
    font-family: 'DM Mono', monospace !important;
    color: #334155;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    resize: none !important;
    overflow: hidden !important;
    height: auto;
    /* Altura mínima sempre cobre 30 linhas — garante pauta visível mesmo vazio */
    min-height: calc(var(--linha-altura) * 30);

    /*
        font-size, line-height, letter-spacing e background-image
        são aplicados pelo JS (calibrarTexto) via element.style.
        Os valores abaixo são apenas fallbacks antes do JS rodar.
    */
    font-size: 15px;
    line-height: var(--linha-altura);
    letter-spacing: normal;

    /*
        Pauta de fundo — repeating-linear-gradient sincronizado com
        a line-height. background-attachment: local garante que a pauta
        cobre toda a área do textarea, incluindo linhas vazias,
        pois o gradiente se ancora ao conteúdo scrollável do elemento.
    */
    background-image: repeating-linear-gradient(
        transparent, transparent 31px,
        #c4ddf7b2 31px, #f1f5f9 32px
    );
    background-attachment: local !important;
    background-origin: padding-box;
}

@media (max-width: 640px) {
    .redacao-textarea {
        min-height: 0;
        font-family: 'DM Sans', sans-serif !important;
        font-size: 15px;
    }
}

/* ══════════════════════════════════════
   OVERLAY DE JUSTIFICAÇÃO TIPOGRÁFICA
   Renderiza o texto justificado por cima do textarea transparente.
   O textarea mantém caret-color visível para o cursor funcionar.
══════════════════════════════════════ */
.redacao-overlay {
    position: absolute;
    top: 0;
    left: 52px; /* coincide com a largura do .line-numbers */
    right: 0;
    bottom: 0;
    padding: 8px 24px 20px 24px;
    font-family: 'DM Mono', monospace;
    color: #334155;
    pointer-events: none;
    white-space: pre;
    overflow: hidden;
    z-index: 2;
    background: transparent;
    text-align: left;
}

/* Cada linha vira um <div>; word-spacing é aplicado inline pelo JS nas linhas cheias */
.redacao-overlay div {
    display: block;
    white-space: pre;
    word-spacing: normal;
}

/* Quando o overlay está ativo, o texto do textarea fica invisível
   mas o cursor continua aparecendo via caret-color */
.redacao-textarea.com-overlay {
    color: transparent !important;
    caret-color: #334155 !important;
    background-color: transparent !important;
}

/* Ao focar (editar), revela o texto real do textarea */
.redacao-textarea.com-overlay.editando {
    color: #334155 !important;
}

/* No mobile: overlay desativado, textarea volta ao normal */
@media (max-width: 640px) {
    .redacao-overlay {
        display: none;
    }
    .redacao-textarea.com-overlay {
        color: #334155 !important;
        caret-color: #334155 !important;
    }
}

/* Status bar */
.textarea-statusbar {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 8px 12px; font-size: 11px; font-weight: 700;
}
.status-linhas { display: flex; align-items: center; gap: 8px; }
.badge-linhas {
    padding: 3px 10px; border-radius: 99px;
    font-size: 11px; font-weight: 800; border: 1.5px solid; transition: all .2s;
}
.badge-linhas.ok { background: #ecfdf5; color: #065f46; border-color: #6ee7b7; }
.badge-linhas.aviso { background: #fff7ed; color: #9a3412; border-color: #fdba74; }
.badge-linhas.erro { background: #fef2f2; color: #991b1b; border-color: #fca5a5; }
.barra-progresso {
    flex: 1; height: 6px; background: #e0f2fe;
    border-radius: 99px; overflow: hidden; margin: 0 12px; max-width: 200px;
}
@media (max-width: 640px) {
    .barra-progresso {
        max-width: none;
        height: 8px;
        margin: 0 10px;
    }
    .badge-linhas {
        font-size: 12px;
        padding: 4px 12px;
    }
    .textarea-statusbar {
        padding: 10px 12px;
    }
}
.barra-fill { height: 100%; border-radius: 99px; transition: width .3s, background .3s; }

/* COIN */
.coin { display: inline-flex; align-items: center; gap: 4px; background: linear-gradient(135deg, #fde68a, #fbbf24); border-radius: 99px; padding: 3px 12px; font-weight: 900; font-size: 13px; color: #92400e; border: 1px solid #fcd34d; }

/* TABLE */
.table-row { transition: background .15s; }
.table-row:hover { background: rgba(255,255,255,0.55); }

/* CHART */
.chart-wrap { position: relative; height: 220px; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #a5f3fc; border-radius: 99px; }

/* MOBILE NAV SCROLL */
.nav-scroll { overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
.nav-scroll::-webkit-scrollbar { display: none; }

/* SECTION HIDDEN */
.section-page { display: none; }
.section-page.active { display: block; }

/* Range duplo */
.range-double { -webkit-appearance: none; appearance: none; outline: none; }
.range-double::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 18px; height: 18px; background: #06b6d4;
    border-radius: 50%; cursor: pointer; pointer-events: auto;
    border: 2px solid white;
}
.range-double::-moz-range-thumb {
    width: 18px; height: 18px; background: #06b6d4;
    border-radius: 50%; cursor: pointer; pointer-events: auto; border: 2px solid white;
}
#filtro_hist_nota_max::-webkit-slider-thumb { background: #fb923c; }
#filtro_hist_nota_max::-moz-range-thumb { background: #fb923c; }

/* Sidebar de Ferramentas */
.sidebar-ferramentas {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.widget-card {
    background: rgba(255, 255, 255, 0.7);
    border: 1.5px solid rgba(255, 255, 255, 0.8);
    border-radius: 24px;
    padding: 1.25rem;
    box-shadow: 0 8px 32px rgba(14, 116, 144, 0.05);
}

/* Estilo do Cronómetro */
.timer-display {
    font-family: 'DM Mono', monospace;
    font-size: 2.25rem;
    font-weight: 700;
    color: #0c4a6e;
    text-align: center;
    margin: 0.5rem 0;
}

/* Inputs do Esqueleto */
.esqueleto-input {
    width: 100%;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 12px;
    outline: none;
    transition: all 0.2s;
    resize: none;
}
.esqueleto-input:focus {
    border-color: #06b6d4;
    ring: 2px #06b6d4;
}

/* Fundo Técnico Blueprint */
.blueprint-lines {
    background-image: linear-gradient(rgba(6, 182, 212, 0.06) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(6, 182, 212, 0.06) 1px, transparent 1px);
    background-size: 40px 40px;
}

/* Linha de Scanner Animada */
.scanner-line {
    position: absolute;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.4), transparent);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.3);
    animation: scan 8s ease-in-out infinite;
}
@keyframes scan { from { top: 0%; } to { top: 100%; } }

.modal-conteudo-nota, .card-nota-mural {
    max-width: 100%;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
}

.modal-body-scroll {
    max-height: 70vh;
    overflow-y: auto;
    padding-right: 8px;
}