/* MagistrIA — estilo único dos editores de texto rich-text.
 *
 * Acompanha `editor_rico.js`. Todo seletor é prefixado por `ed-` ou
 * `.editor-conteudo` para não vazar sobre o resto da interface (o
 * Tailwind é carregado por CDN local e reseta muita coisa).
 */

/* ===================== Envoltório ===================== */

.ed-wrap {
    position: relative;
}

.ed-wrap.ed-tela-cheia {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: #fff;
    padding: 0.75rem;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.ed-wrap.ed-tela-cheia .editor-conteudo,
.ed-wrap.ed-tela-cheia [contenteditable] {
    max-height: none !important;
}

.ed-wrap.ed-tela-cheia > .ed-area,
.ed-wrap.ed-tela-cheia .ed-regua-wrap {
    flex: 1 1 auto;
    min-height: 0;
}

body.ed-sem-rolagem {
    overflow: hidden;
}

/* ===================== Barra ===================== */

.ed-barra {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 5px 6px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 12px;
    line-height: 1.2;
    position: sticky;
    top: 0;
    z-index: 20;
}

.ed-btn {
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #374151;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.ed-btn:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
}

.ed-btn:active {
    background: #d1d5db;
}

.ed-btn sup, .ed-btn sub { font-size: 9px; }
.ed-negrito { font-weight: 700; }
.ed-italico { font-style: italic; font-family: Georgia, serif; }
.ed-sublinhado { text-decoration: underline; }
.ed-tachado { text-decoration: line-through; }

.ed-sep {
    width: 1px;
    height: 18px;
    background: #d1d5db;
    margin: 0 4px;
    display: inline-block;
}

.ed-select {
    height: 26px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #374151;
    font-size: 12px;
    padding: 0 4px;
    max-width: 9.5rem;
    cursor: pointer;
}

.ed-select-tam, .ed-select-zoom { max-width: 5rem; }

.ed-swatch {
    display: inline-block;
    width: 14px;
    height: 10px;
    border: 1px solid #9ca3af;
    border-radius: 2px;
    vertical-align: middle;
}

.ed-caret { font-size: 9px; opacity: .7; }

/* ===================== Menus ===================== */

.ed-menu { position: relative; display: inline-block; }

.ed-menu-painel {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 3px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .12);
    padding: 4px;
    z-index: 40;
    min-width: 12rem;
    max-height: 60vh;
    overflow: auto;
}

.ed-oculto { display: none !important; }

.ed-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 5px 8px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #374151;
    font-size: 12px;
    cursor: pointer;
}

.ed-menu-item:hover { background: #eff6ff; color: #1d4ed8; }

.ed-menu-titulo {
    padding: 6px 8px 2px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #9ca3af;
}

.ed-menu-nota {
    padding: 4px 8px 6px;
    font-size: 10.5px;
    color: #6b7280;
    line-height: 1.35;
}

/* ---------- paletas de cor ---------- */

.ed-paleta {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 3px;
    padding: 4px;
}

.ed-cor {
    width: 20px;
    height: 20px;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    cursor: pointer;
    padding: 0;
}

.ed-cor:hover { transform: scale(1.15); }

/* ---------- símbolos ---------- */

.ed-simbolos {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 2px;
    padding: 4px;
}

.ed-simbolo {
    height: 24px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    font-size: 13px;
    cursor: pointer;
    color: #111827;
}

.ed-simbolo:hover { background: #eff6ff; border-color: #bfdbfe; }

/* ---------- campos dentro de menus ---------- */

.ed-linha-campos {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    font-size: 12px;
    color: #374151;
}

.ed-campo-num {
    width: 3.2rem;
    height: 24px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 0 4px;
    font-size: 12px;
}

.ed-label-check {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 12px;
    color: #374151;
    cursor: pointer;
}

/* ===================== Localizar e substituir ===================== */

.ed-busca {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 7px 8px;
    background: #eff6ff;
    border-bottom: 1px solid #bfdbfe;
}

.ed-busca-linha {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.ed-campo {
    height: 26px;
    min-width: 12rem;
    flex: 1 1 12rem;
    border: 1px solid #93c5fd;
    border-radius: 4px;
    padding: 0 7px;
    font-size: 12px;
    background: #fff;
}

.ed-btn-acao {
    height: 26px;
    padding: 0 9px;
    border: 1px solid #93c5fd;
    border-radius: 4px;
    background: #fff;
    color: #1d4ed8;
    font-size: 12px;
    cursor: pointer;
}

.ed-btn-acao:hover { background: #dbeafe; }

.ed-btn-primario {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #fff;
}

.ed-btn-primario:hover { background: #1e40af; }

/* ===================== Rodapé de contadores ===================== */

.ed-status {
    padding: 4px 8px;
    font-size: 11px;
    color: #6b7280;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    font-family: ui-sans-serif, system-ui, sans-serif;
}

/* ===================== Aviso transitório ===================== */

.ed-toast {
    position: absolute;
    right: 10px;
    bottom: 10px;
    max-width: 22rem;
    padding: 7px 11px;
    border-radius: 6px;
    background: #111827;
    color: #f9fafb;
    font-size: 12px;
    line-height: 1.35;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .2);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .15s ease, transform .15s ease;
    pointer-events: none;
    z-index: 70;
}

.ed-toast-visivel { opacity: 1; transform: translateY(0); }


/* ===================== Área de edição =====================
 *
 * Tudo escopado em `.ed-wrap` de propósito. Várias telas usam a classe
 * `.editor-conteudo` apenas para EXIBIR conteúdo já gravado (detalhe da
 * fonte, busca, relatório, lista de argumentos) — essas não devem mudar
 * de aparência. E o escopo duplo (0,2,0) vence as utilidades do
 * Tailwind (`text-sm`, `font-sans`) sem precisar de !important.
 */

.ed-wrap .editor-conteudo {
    font-family: "Times New Roman", Times, serif;
    font-size: 1rem;
    line-height: 1.6;
    color: #1f2937;
}

.ed-wrap [contenteditable]:focus { outline: none; }

.ed-wrap .editor-conteudo p {
    margin-bottom: 0.7rem;
    text-align: justify;
    text-indent: 1.5em;
}

.ed-wrap .editor-conteudo h1, .ed-wrap .editor-conteudo h2,
.ed-wrap .editor-conteudo h3, .ed-wrap .editor-conteudo h4 { text-indent: 0; }

.ed-wrap .editor-conteudo h1 + p, .ed-wrap .editor-conteudo h2 + p,
.ed-wrap .editor-conteudo h3 + p, .ed-wrap .editor-conteudo h4 + p { text-indent: 0; }

.ed-wrap .editor-conteudo h1 { font-size: 1.45em; font-weight: 600; margin: .9em 0 .35em; }
.ed-wrap .editor-conteudo h2 { font-size: 1.3em; font-weight: 600; margin: .8em 0 .3em; }
.ed-wrap .editor-conteudo h3 { font-size: 1.15em; font-weight: 600; margin: .6em 0 .3em; }
.ed-wrap .editor-conteudo h4 { font-size: 1.05em; font-weight: 600; margin: .5em 0 .3em; }

.ed-wrap .editor-conteudo ul { list-style: disc; padding-left: 1.5rem; margin-bottom: .5rem; }
.ed-wrap .editor-conteudo ol { list-style: decimal; padding-left: 1.5rem; margin-bottom: .5rem; }
.ed-wrap .editor-conteudo li { text-align: justify; }

.ed-wrap .editor-conteudo blockquote {
    margin-left: 1.5rem;
    padding-left: .75rem;
    border-left: 2px solid #e5e7eb;
}

/* --------- regras válidas para QUALQUER editor sob .ed-wrap --------- */
/* (o parágrafo-modelo da Dosimetria e a prévia das Admonitórias não
   usam a classe .editor-conteudo, mas ganham a mesma barra) */

.ed-wrap strong, .ed-wrap b { font-weight: 600; }
.ed-wrap em, .ed-wrap i { font-style: italic; }
.ed-wrap u { text-decoration: underline; }
.ed-wrap s, .ed-wrap strike { text-decoration: line-through; }
.ed-wrap sup { vertical-align: super; font-size: .75em; }
.ed-wrap sub { vertical-align: sub; font-size: .75em; }

.ed-wrap [contenteditable] table,
.ed-wrap table.ed-tabela {
    border-collapse: collapse;
    margin: .6em 0;
    width: 100%;
}

.ed-wrap [contenteditable] td, .ed-wrap [contenteditable] th {
    border: 1px solid #9ca3af;
    padding: 4px 6px;
    text-indent: 0;
    text-align: left;
    vertical-align: top;
}

.ed-wrap [contenteditable] th { background: #f3f4f6; font-weight: 600; }

.ed-wrap [contenteditable] hr {
    border: 0;
    border-top: 1px solid #d1d5db;
    margin: .8em 0;
}

/* Citação em bloco criada pela barra: o recuo já vem do style inline
   (4,5 cm), então a borda decorativa sairia deslocada. */
.ed-wrap blockquote[data-bloco="citacao"] {
    border-left: 0;
    padding-left: 0;
}

/* Quebra de página: marcador visual. A exportação DOCX segue o padrão
   do gabinete e não quebra a página por causa dele. */
.ed-wrap hr[data-bloco="quebra-pagina"] {
    border-top: 2px dashed #9ca3af;
    position: relative;
    margin: 1.4em 0;
}

.ed-wrap hr[data-bloco="quebra-pagina"]::after {
    content: "quebra de página";
    position: absolute;
    top: -.65em;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 0 .5em;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 10px;
    color: #9ca3af;
    letter-spacing: .04em;
}

/* Bloco de ementa: realce leve para localizar de relance. */
.ed-wrap [data-bloco="ementa"] {
    background: linear-gradient(90deg, rgba(37, 99, 235, .06), transparent 60%);
}

/* Marcas de parágrafo (botão ¶). */
.ed-wrap .ed-marcas p::after,
.ed-wrap .ed-marcas h1::after,
.ed-wrap .ed-marcas h2::after,
.ed-wrap .ed-marcas h3::after,
.ed-wrap .ed-marcas h4::after,
.ed-wrap .ed-marcas li::after,
.ed-wrap p.ed-marcas::after {
    content: "¶";
    color: #cbd5e1;
    margin-left: 2px;
    font-family: ui-sans-serif, system-ui, sans-serif;
}

/* ===================== Réguas (opcional) ===================== */

.ed-wrap .editor-regua-wrap {
    display: grid;
    grid-template-columns: 0.7cm 1fr;
    grid-template-rows: 1.05cm 1fr;
    max-width: 100%;
    overflow: auto;
    background: #fff;
}

.ed-wrap .editor-regua-h {
    grid-column: 2; grid-row: 1;
    position: relative;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-family: ui-sans-serif, system-ui, sans-serif;
    color: #6b7280;
    min-width: 16cm;
}

.ed-wrap .editor-regua-v {
    grid-column: 1; grid-row: 2;
    position: relative;
    background: #f9fafb;
    border-right: 1px solid #e5e7eb;
    color: #6b7280;
    overflow: hidden;
}

.ed-wrap .editor-regua-wrap .editor-conteudo { grid-column: 2; grid-row: 2; }

.ed-wrap .editor-regua-h .marca-num {
    position: absolute; bottom: 0.42cm;
    transform: translateX(-50%);
    font-size: 9px; line-height: 1; padding: 0 2px;
    background: #f9fafb;
}

.ed-wrap .editor-regua-h .marca-tick {
    position: absolute; bottom: 0; width: 1px; height: 0.25cm;
    background: #9ca3af;
}

.ed-wrap .editor-regua-h .marca-tick-meio {
    position: absolute; bottom: 0; width: 1px; height: 0.12cm;
    background: #d1d5db;
}

.ed-wrap .editor-regua-h .marca-recuo-pl,
.ed-wrap .editor-regua-h .marca-recuo-cit {
    position: absolute; top: 0.18cm; width: 0; height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 8px solid #2563eb;
    transform: translateX(-50%);
    cursor: help;
}

.ed-wrap .editor-regua-h .marca-recuo-cit { border-top-color: #9ca3af; }

.ed-wrap .editor-regua-h .marca-margem-dir {
    position: absolute; top: 0; bottom: 0; width: 2px;
    background: #dc2626;
    transform: translateX(-50%);
    cursor: help;
}

.ed-wrap .editor-regua-v .marca-num-v {
    position: absolute; right: 0.22cm;
    transform: translateY(-50%);
    font-size: 9px; line-height: 1; padding: 1px 0;
    background: #f9fafb;
}

.ed-wrap .editor-regua-v .marca-tick-v {
    position: absolute; right: 0; width: 0.15cm; height: 1px;
    background: #9ca3af;
    transform: translateY(-50%);
}
