/* Certidão de Uso e Ocupação do Solo - estilos da página e da impressão */
/* Custom styles for the application */
body {
    font-family: 'Inter', sans-serif;
}
#certificate-output {
    font-family: 'Times New Roman', Times, serif; /* Font for the certificate */
    font-size: 11pt; /* same as printed */
    position: relative;
    margin: 0 auto;
}
/* Screen: the certidão is shown as A4 sheets (21 x 29.7cm, 1.5cm margins), exactly as printed. The white sheets,
   their watermark, header (2nd sheet on) and footer are drawn behind/around the text by paginacao-tela.js, which
   also sets the height (number of sheets) and inserts the page break spacers (.quebra-tela) in the text. */
@media screen {
    #certificate-output { width: 21cm; padding: 1.5cm 1.5cm 0; box-sizing: border-box; }
}
#certificate-table { position: relative; z-index: 1; width: 100%; }
.paginas-tela { position: absolute; inset: 0; pointer-events: none; }
.folha-tela {
    position: absolute; left: 0; width: 21cm; height: 29.7cm; background: #fff;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}
/* Watermark: 15 x 15cm, centered on each sheet, as printed */
.folha-tela .marca-tela {
    position: absolute; left: 3cm; top: 7.35cm; width: 15cm; height: 15cm;
    background: url('../img/marca-dagua-pmv.png') center / 15cm 15cm no-repeat; opacity: 0.5;
}
/* Dashed guide frame on screen only (not printed nor saved in the drafts) */
.folha-tela .moldura-tela { position: absolute; inset: 0.5cm; border: 1px dashed #9ca3af; }
/* Footer of each sheet, as the printed @page @bottom-center (right below the text area, 8pt, gray) */
.folha-tela .rodape-tela {
    position: absolute; left: 1.5cm; right: 1.5cm; top: 28.2cm; text-align: center; white-space: pre-line;
    font-family: 'Times New Roman', Times, serif; font-size: 8pt; line-height: 1.2; color: #666;
}
/* Header repeated on the 2nd sheet on (a copy of #print-header, not editable) */
.cabecalho-repetido { position: absolute; left: 1.5cm; width: 18cm; z-index: 1; pointer-events: none; }
/* Page break spacer inserted in the text on screen; never printed nor saved */
.quebra-tela { display: block; }
span.quebra-tela { display: inline-block; width: 100%; vertical-align: top; text-indent: 0; }
/* Hidden copy of the text laid out in A4-sized columns: the browser breaks columns like printed pages */
.medida-paginas { position: absolute; left: -200cm; top: 0; visibility: hidden; column-gap: 0; column-fill: auto; }

/* Layout shared by screen and print, so the screen is an exact preview of the printed sheets */
.certificate-content p {
    text-indent: 4rem;
    line-height: 1.4; /* Adjusted line spacing */
}
#certificate-table { border-collapse: collapse; }
#certificate-table thead td { padding-bottom: 0.5rem; }
.cabecalho-certidao { text-align: center; }
.cabecalho-certidao h2, .cabecalho-certidao p { font-size: 16pt; font-weight: bold; }
.cabecalho-certidao img { display: block; height: 60px; margin: 0 auto; }
.corpo-certidao {
    text-align: justify;
    /* Hyphenation in Portuguese (lang="pt-BR" on <html>) avoids wide gaps in justified lines */
    -webkit-hyphens: auto;
    hyphens: auto;
    /* At least 3 lines of a paragraph at the bottom (orphans) and at the top (widows) of a page
       (the CSS default is 2); inherited by the paragraphs */
    orphans: 3;
    widows: 3;
}
/* Fixed spacing (the Tailwind classes pt-4 md:pt-6 lg:pt-8 px-8... changed with the window width) */
.print-body-content { padding: 1rem 0 0 !important; }
/* Avoid breaking signature block across pages */
.signature-block, footer { break-inside: avoid; page-break-inside: avoid; }
/* Place and date go to the next page together with the Emissor (as in the .docx/.odt draft) */
footer { break-after: avoid; page-break-after: avoid; }

/* Style to indicate the editable area (free edit mode only) */
#print-body[contenteditable="true"] {
    outline: 2px dashed #f59e0b;
    outline-offset: -6px;
    border-radius: 4px;
}

/* Inline fields typed directly in the certidão text */
.campo, .campo-auto {
    text-indent: 0;
    border-radius: 3px;
    padding: 0; /* no horizontal padding: lines wrap where they wrap when printed */
    outline: none;
    transition: background-color .15s;
}
.campo[contenteditable="true"] {
    background: rgba(219, 234, 254, .65);
    border-bottom: 1px dashed #3b82f6;
    cursor: text;
}
.campo[contenteditable="true"]:hover { background: rgba(191, 219, 254, .95); }
.campo:focus { background: #fff !important; box-shadow: 0 0 0 2px #3b82f6; }
.campo:empty { display: inline-block; min-width: 3ch; }
.campo:empty::before {
    content: attr(data-placeholder);
    color: #9ca3af;
    font-style: italic;
    font-weight: normal;
}
.campo.campo-pendente { background: rgba(254, 243, 199, .95); border-bottom-color: #f59e0b; }
.campo-auto { background: rgba(229, 231, 235, .7); border-bottom: 1px dotted #9ca3af; cursor: help; }
/* "esquina com" / "fundos com" switch: click to alternate */
.campo-opcao {
    position: relative;
    text-indent: 0;
    border-radius: 3px;
    padding: 0;
    background: rgba(237, 233, 254, .9);
    border-bottom: 1px dashed #7c3aed;
    cursor: pointer;
    outline: none;
}
/* out of the text flow, so it does not change where lines wrap */
.campo-opcao::after { content: '⇄'; position: absolute; left: 100%; top: -0.6em; font-size: .6em; color: #7c3aed; }
.campo-opcao:hover, .campo-opcao:focus { background: rgba(221, 214, 254, 1); }
@media print {
    .campo-opcao { background: none !important; border: none !important; padding: 0 !important; }
    .campo-opcao::after { content: '' !important; }
}
/* Field chosen from a list (e.g. Protocolo / Memorando / Processo Administrativo): click opens the menu in "Campos" mode */
.campo-lista {
    position: relative;
    text-indent: 0;
    border-radius: 3px;
    padding: 0;
    background: rgba(237, 233, 254, .9);
    border-bottom: 1px dashed #7c3aed;
    cursor: pointer;
    outline: none;
}
.campo-lista[contenteditable="false"]::after { content: '▾'; position: absolute; left: 100%; top: -0.6em; font-size: .6em; color: #7c3aed; }
.campo-lista:hover, .campo-lista:focus { background: rgba(221, 214, 254, 1); }
#print-body[contenteditable="true"] .campo-lista { cursor: text; background: rgba(254, 243, 199, .6); border-bottom-color: #f59e0b; }
.menu-opcoes { position: fixed; z-index: 60; min-width: 12rem; background: #fff; border: 1px solid #e5e7eb; border-radius: .375rem;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1); padding: .25rem 0; font-family: 'Inter', sans-serif; font-size: .875rem; }
.menu-opcoes [role="option"] { padding: .375rem .75rem; cursor: pointer; }
.menu-opcoes [role="option"][aria-selected="true"], .menu-opcoes [role="option"]:hover { background: #eef2ff; }
@media print {
    .campo-lista { background: none !important; border: none !important; padding: 0 !important; }
    .campo-lista::after { content: '' !important; }
    .menu-opcoes { display: none !important; }
}
/* "Esquina com" is optional: faded on screen while empty, not printed */
.esquina-vazia, .opcional-vazio { opacity: .45; }
/* Optional parts left empty are not printed, so on screen they take no room either (exact A4 preview): only a small
   "+ ..." mark out of the text flow. Clicking it opens the part to be typed in (.mostrar, certidao.js). */
@media screen {
    .esquina-vazia:not(.mostrar), .opcional-vazio:not(.mostrar) { position: relative; font-size: 0; opacity: 1; }
    .esquina-vazia:not(.mostrar) > *, .opcional-vazio:not(.mostrar) > * { display: none; }
    .esquina-vazia:not(.mostrar)::before, .opcional-vazio:not(.mostrar)::before {
        content: '+ ' attr(data-opcional);
        /* above the text of the line (the part has font-size 0, so the offset is in pt) */
        position: absolute; left: 0; bottom: 9pt; z-index: 2;
        width: 6.8em; overflow: hidden; text-overflow: ellipsis; box-sizing: border-box;
        padding: 0 3px; border: 1px dashed #7c3aed; border-radius: 3px; background: rgba(237, 233, 254, .95);
        font: italic 6.5pt/1.2 'Inter', sans-serif; text-indent: 0; color: #6d28d9; white-space: nowrap; cursor: pointer;
    }
    /* collapsed parts next to each other (e.g. Lote, Quadra, Loteamento of a rural property): marks side by side */
    .opcional-vazio:not(.mostrar) + .opcional-vazio:not(.mostrar)::before { left: 7em; }
    .opcional-vazio:not(.mostrar) + .opcional-vazio:not(.mostrar) + .opcional-vazio:not(.mostrar)::before { left: 14em; }
    .opcional-vazio:not(.mostrar) + .opcional-vazio:not(.mostrar) + .opcional-vazio:not(.mostrar) + .opcional-vazio:not(.mostrar)::before { left: 21em; }
}

/* CNAE result badges in the top bar */
.cnae-compatibility-input { font-weight: 600; font-size: .75rem; }
.compat-ok { background: #dcfce7 !important; color: #166534; border-color: #86efac !important; }
.compat-no { background: #fee2e2 !important; color: #991b1b; border-color: #fca5a5 !important; }
.compat-ceauos { background: #fef3c7 !important; color: #92400e; border-color: #fcd34d !important; }

.toolbar-disabled .toolbar-button { opacity: .35; pointer-events: none; }

/* Print-specific styles */
@media print {
    @page {
        size: A4;
        margin: 1.5cm; /* All certidões: A4 with 1.5cm margins on every side; the footer (3 lines of 8pt) fits in the bottom margin */
        @bottom-center {
            /* Fallback; the certidão number is filled in by updatePrintFooter() (#print-footer-style) */
            content: "PAÇO MUNICIPAL - PALÁCIO INDEPENDÊNCIA | Rua Antônio Carlos, 301 - Centro | Valinhos - SP | CEP 13270-005\A Fone: (19) 3849.8000 | site: www.valinhos.sp.gov.br\A CERTIDÃO DE USO E OCUPAÇÃO DO SOLO – SF/DCT/DCI - Folha " counter(page) " de " counter(pages);
            white-space: pre;
            /* Right below the text area, not centered in the margin: centered, the last line came ~0.2cm from the
               paper edge, where many printers cut */
            vertical-align: top;
            line-height: 1.2;
            font-family: 'Times New Roman', Times, serif;
            font-size: 8pt;
            color: #666;
        }
    }
    body {
        margin: 0;
        padding: 0;
        background-color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .no-print { display: none !important; }
    main#app { padding: 0 !important; }

    #certificate-output {
        display: block !important;
        box-shadow: none !important;
        border: none !important;
        width: 100% !important;
        height: auto !important;
        padding: 0 !important;
        max-width: none !important;
        color: black !important;
    }
    /* Screen-only A4 preview: sheets, repeated headers, page break spacers and the measuring copy */
    .paginas-tela, .cabecalho-repetido, .quebra-tela, .medida-paginas { display: none !important; }

    #certificate-table thead {
        display: table-header-group; /* CRITICAL for repeating headers across pages */
    }
    #certificate-table thead td { color: black !important; }
    .cabecalho-certidao, .cabecalho-certidao * { color: black !important; }
    #print-body[contenteditable="true"] {
        outline: none !important;
    }

    /* Inline fields print as plain text */
    .campo, .campo-auto {
        background: none !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
    }
    .campo:empty { display: inline; min-width: 0; }
    .campo:empty::before { content: '' !important; }
    .esquina-vazia, .opcional-vazio { display: none !important; }

    /* --- Watermark for Print ---
       15 cm x 15 cm, centered. A position: fixed element is repeated by the browser on every printed page.
       Same image as the screen watermark (already loaded); print-color-adjust keeps it even with
       "background graphics" turned off in the print dialog. */
    .print-watermark {
        display: block !important;
        position: fixed;
        top: 50%;
        left: 50%;
        width: 15cm;
        height: 15cm;
        transform: translate(-50%, -50%);
        background-image: url('../img/marca-dagua-pmv.png');
        background-position: center;
        background-repeat: no-repeat;
        background-size: 15cm 15cm;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        opacity: 0.5;
        z-index: -1;
    }
    #certificate-output { background: transparent !important; }
}

/* Hide print-only elements from screen */
.print-watermark, .cert-hash {
    display: none;
}
/* Log hash (log_cert.csv): printed as tiny white text at the end of the certidão, outside the text flow,
   so it is not seen but can be found by searching/copying the text of the PDF */
@media print {
    .cert-hash {
        display: block !important;
        position: absolute;
        left: 0;
        bottom: 0;
        color: #fff !important;
        font-size: 1px !important;
        line-height: 1px;
        white-space: nowrap;
    }
}

/* Log viewer table (Registros) */
.registros-tabela th,
.registros-tabela td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
}
.registros-tabela th { font-weight: 600; white-space: nowrap; }
.registros-tabela tbody tr:hover { background: #eef2ff; }
.registros-tabela .registro-hash { font-family: ui-monospace, Consolas, monospace; cursor: pointer; color: #4338ca; }
/* Certidão number: reserved on the server when printing (numerar_certidao.php), never typed */
.campo.campo-automatico { background: rgba(229, 231, 235, .7); border-bottom: 1px dotted #9ca3af; cursor: help; }
/* Print started without a number (browser menu): only the notice is printed */
.aviso-sem-numero { display: none; }
@media print {
    body.sem-numero-certidao > *:not(.aviso-sem-numero) { display: none !important; }
    body.sem-numero-certidao .aviso-sem-numero { display: block !important; font-size: 16pt; margin: 3cm 1cm; text-align: center; }
}/* Number reserved for content that was changed afterwards: a new number is reserved when printing */
.campo.campo-automatico.numero-desatualizado { text-decoration: line-through; color: #b45309; background: rgba(254, 243, 199, .95); }