/* SIGFAD — Mapas Temáticos V2 */

#thematic-institution {
    font-weight: 600;
}

#sheet-institution-logo {
    display: block;
    width: auto;
    max-width: 150px;
    max-height: 68px;
    object-fit: contain;
}

#sheet-institution-name {
    display: block;
    line-height: 1.15;
}

#sheet-institution-system {
    display: block;
    margin-top: 3px;
}

#sheet-stamp-institution {
    display: block;
    margin-top: 3px;
    font-size: 0.72rem;
    font-weight: 700;
}

/* Mantém a proporção cartográfica da captura V2. */
#sheet-map-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    object-position: center;
    background: #f3f4f6;
}

/* Correção de contraste do cabeçalho cartográfico */
#thematic-sheet .der-sheet-brand div,
#thematic-sheet .der-sheet-brand strong,
#thematic-sheet .der-sheet-brand span {
    color: #172033 !important;
}

#thematic-sheet .der-sheet-heading h1 {
    color: #10233f !important;
}

#thematic-sheet .der-sheet-heading p {
    color: #596579 !important;
}

/* Ajuste das marcas institucionais */
#thematic-sheet .der-sheet-brand {
    overflow: visible;
}

#thematic-sheet #sheet-institution-logo {
    width: auto;
    max-width: 170px;
    max-height: 54px;
    object-fit: contain;
}

/* Modelo: mapa limpo */
.der-thematic-sheet.template-limpo .der-sheet-header {
    height: 52px;
    min-height: 52px;
    grid-template-columns: 180px minmax(0, 1fr) 180px;
}

.der-thematic-sheet.template-limpo .der-sheet-main {
    grid-template-columns: minmax(0, 1fr);
}

.der-thematic-sheet.template-limpo .der-sheet-side {
    display: none;
}

.der-thematic-sheet.template-limpo .der-sheet-map-frame {
    padding-right: 27px;
}

.der-thematic-sheet.template-limpo .der-sheet-footer {
    height: 18px;
}

/* Modelo: interferências */
.der-thematic-sheet.template-interferencias {
    --sheet-blue: #8b1e1e;
}

.der-thematic-sheet.template-interferencias .der-sheet-header {
    background: #fffafa;
}

.der-thematic-sheet.template-interferencias .der-sheet-notes {
    border-color: #8b1e1e;
    background: #fff8f8;
}

/* Organização definitiva da hotbar cartográfica */
#thematic-sheet .der-sheet-header {
    grid-template-columns: 250px minmax(0, 1fr) 250px;
    padding: 7px 16px;
}

#thematic-sheet .der-sheet-brand {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 66px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
}

#thematic-sheet #sheet-institution-logo {
    width: 64px;
    height: 50px;
    max-width: 64px;
    max-height: 50px;
    object-fit: contain;
    justify-self: center;
}

#thematic-sheet .der-sheet-brand > div {
    min-width: 0;
    color: #172033 !important;
}

#thematic-sheet #sheet-institution-name {
    color: #172033 !important;
    font-size: 9px;
    line-height: 1.08;
    overflow-wrap: anywhere;
}

#thematic-sheet #sheet-institution-system {
    color: #405064 !important;
    font-size: 7.6px;
    line-height: 1.08;
    margin-top: 3px;
}

#thematic-sheet .der-sheet-heading {
    display: flex;
    min-width: 0;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#thematic-sheet .der-sheet-heading h1 {
    color: #10233f !important;
    max-width: 100%;
    font-size: 17px;
    line-height: 1.05;
    white-space: normal;
    overflow-wrap: anywhere;
}

#thematic-sheet .der-sheet-heading p {
    color: #596579 !important;
    max-width: 100%;
    white-space: normal;
}

/* Símbolo isolado da identidade SIGFAD */
#thematic-sheet[data-institution="sigfad"] #sheet-institution-logo {
    width: 50px;
    height: 50px;
    max-width: 50px;
    max-height: 50px;
    object-fit: contain;
}

/* =========================================================
   HOTBAR CARTOGRÁFICA — ORGANIZAÇÃO FINAL
   ========================================================= */

#thematic-sheet .der-sheet-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;

    height: 72px;
    min-height: 72px;

    padding: 8px 18px;
    border-bottom: 2px solid var(--sheet-blue);
    background: #ffffff;
}

/* Remove a terceira coluna vazia usada pelo modelo anterior */
#thematic-sheet .der-sheet-header::after {
    display: none !important;
    content: none !important;
}

/* Bloco institucional fixado à esquerda */
#thematic-sheet .der-sheet-brand {
    position: absolute;
    top: 50%;
    left: 18px;
    transform: translateY(-50%);

    display: grid;
    grid-template-columns: 54px minmax(0, 185px);
    align-items: center;
    gap: 9px;

    width: 248px;
    min-width: 0;
}

/* Logo institucional */
#thematic-sheet #sheet-institution-logo {
    display: block;
    width: 50px;
    height: 50px;
    max-width: 50px;
    max-height: 50px;

    object-fit: contain;
    object-position: center;
}

/* Textos institucionais */
#thematic-sheet .der-sheet-brand > div {
    display: flex;
    flex-direction: column;
    justify-content: center;

    min-width: 0;
    color: #172033 !important;
}

#thematic-sheet #sheet-institution-name {
    display: block;

    color: #172033 !important;
    font-size: 9px;
    font-weight: 700;
    line-height: 1.08;

    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
}

#thematic-sheet #sheet-institution-system {
    display: block;
    margin-top: 3px;

    color: #526174 !important;
    font-size: 7px;
    font-weight: 500;
    line-height: 1.08;

    white-space: normal;
}

/* Título centralizado em relação à largura total da folha */
#thematic-sheet .der-sheet-heading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    width: min(560px, calc(100% - 520px));
    min-width: 320px;
    min-height: 48px;

    margin: 0 auto;
    text-align: center;
}

#thematic-sheet .der-sheet-heading h1 {
    margin: 0;

    color: #10233f !important;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.08;
    letter-spacing: 0.01em;

    text-align: center;
    text-transform: uppercase;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
}

#thematic-sheet .der-sheet-heading p {
    margin: 4px 0 0;

    color: #596579 !important;
    font-size: 8px;
    line-height: 1.1;

    text-align: center;
    text-transform: uppercase;
}

/* DER/AL */
#thematic-sheet[data-institution="der_al"] #sheet-institution-logo {
    width: 46px;
    height: 52px;
    max-width: 46px;
    max-height: 52px;
}

/* SIGFAD — símbolo isolado */
#thematic-sheet[data-institution="sigfad"] #sheet-institution-logo {
    width: 48px;
    height: 48px;
    max-width: 48px;
    max-height: 48px;
}

#thematic-sheet[data-institution="sigfad"] .der-sheet-brand {
    grid-template-columns: 52px minmax(0, 190px);
}

/* Modelo compacto */
#thematic-sheet.template-compacto .der-sheet-header {
    height: 62px;
    min-height: 62px;
}

#thematic-sheet.template-compacto .der-sheet-heading h1 {
    font-size: 15px;
}

/* Orientação retrato */
#thematic-sheet.portrait .der-sheet-header {
    height: 78px;
    min-height: 78px;
}

#thematic-sheet.portrait .der-sheet-brand {
    left: 13px;
    width: 205px;
    grid-template-columns: 45px minmax(0, 150px);
    gap: 7px;
}

#thematic-sheet.portrait #sheet-institution-logo {
    width: 43px;
    height: 43px;
    max-width: 43px;
    max-height: 43px;
}

#thematic-sheet.portrait .der-sheet-heading {
    width: calc(100% - 420px);
    min-width: 260px;
}

#thematic-sheet.portrait .der-sheet-heading h1 {
    font-size: 15px;
}

/* =========================================================
   CONVENÇÕES CARTOGRÁFICAS
   ========================================================= */

#thematic-sheet #sheet-legend {
    padding: 7px 8px;
}

#thematic-sheet .der-legend-group + .der-legend-group {
    margin-top: 8px;
    padding-top: 7px;
    border-top: 1px solid #c9d0d8;
}

#thematic-sheet .der-legend-group-title {
    margin-bottom: 5px;
    color: #344255;
    font-size: 7px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: 0.045em;
    text-transform: uppercase;
}

#thematic-sheet .der-legend-group-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#thematic-sheet .der-sheet-legend-item {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    min-height: 13px;
}

#thematic-sheet .der-sheet-legend-label {
    color: #182231;
    font-size: 7.6px;
    font-weight: 500;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

#thematic-sheet .der-sheet-legend-symbol {
    position: relative;
    display: block;
    width: 25px;
    height: 11px;
    box-sizing: border-box;
}

/* Polígono */
#thematic-sheet .der-sheet-legend-symbol.polygon {
    border: 1.2px solid var(--legend-color);
    background: var(--legend-fill);
    opacity: var(--legend-opacity, 1);
}

/* Linha */
#thematic-sheet .der-sheet-legend-symbol.line::after {
    position: absolute;
    top: 50%;
    right: 0;
    left: 0;
    content: "";
    border-top: 2.2px solid var(--legend-color);
    opacity: var(--legend-opacity, 1);
    transform: translateY(-50%);
}

#thematic-sheet .der-sheet-legend-symbol.line.dashed::after {
    border-top-style: dashed;
}

/* Ponto */
#thematic-sheet .der-sheet-legend-symbol.point::after {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    content: "";
    border: 1.2px solid var(--legend-color);
    border-radius: 50%;
    background: var(--legend-fill);
    opacity: var(--legend-opacity, 1);
    transform: translate(-50%, -50%);
}

#thematic-sheet .der-legend-empty {
    color: #697586;
    font-size: 7.4px;
}

/* =========================================================
   CARIMBO CARTOGRÁFICO
   ========================================================= */

#thematic-sheet .der-sheet-stamp {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    min-height: 145px;
    overflow: hidden;
    border: 1px solid #303a45;
    background: #fff;
}

#thematic-sheet .der-sheet-number {
    display: flex;
    grid-row: auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 48px;
    padding: 6px 3px;
    background: #111820;
    color: #fff;
}

#thematic-sheet .der-sheet-number span {
    color: #d7dee6;
    font-size: 5.7px;
    font-weight: 700;
    letter-spacing: 0.12em;
    writing-mode: horizontal-tb;
}

#thematic-sheet .der-sheet-number strong {
    color: #fff;
    font-size: 24px;
    font-weight: 800;
    line-height: 1;
}

#thematic-sheet .der-sheet-stamp-content {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

#thematic-sheet .der-sheet-stamp-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 49px;
    padding: 6px 7px 5px;
    border-bottom: 1px solid #8b949e;
    background: #f8f9fa;
    text-align: center;
}

#thematic-sheet .der-sheet-stamp-title strong {
    color: #111b29;
    font-size: 8.5px;
    font-weight: 750;
    line-height: 1.12;
    text-transform: uppercase;
}

#thematic-sheet .der-sheet-stamp-title span {
    margin-top: 2px;
    color: #536173;
    font-size: 6.6px;
    line-height: 1.08;
}

#thematic-sheet #sheet-stamp-institution {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
    padding: 2px 6px;
    border: 1px solid #c2cad3;
    border-radius: 10px;
    background: #fff;
    color: #1d334e;
    font-size: 6.4px;
    font-weight: 750;
    letter-spacing: 0.035em;
}

#thematic-sheet .der-sheet-stamp-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex: 1;
    gap: 0;
    padding: 0;
}

#thematic-sheet .der-stamp-field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
    padding: 5px 6px;
    border-right: 1px solid #d4d9df;
    border-bottom: 1px solid #d4d9df;
}

#thematic-sheet .der-stamp-field:nth-child(2n) {
    border-right: 0;
}

#thematic-sheet .der-stamp-field-wide {
    grid-column: 1 / -1;
    border-right: 0;
}

#thematic-sheet .der-stamp-field:last-child {
    border-bottom: 0;
}

#thematic-sheet .der-stamp-label {
    color: #596676;
    font-size: 5.8px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.045em;
    text-transform: uppercase;
}

#thematic-sheet .der-stamp-field > span:last-child {
    color: #172230;
    font-size: 6.7px;
    font-weight: 500;
    line-height: 1.14;
    overflow-wrap: anywhere;
}

/* Melhor distribuição da lateral */
#thematic-sheet .der-sheet-side {
    gap: 7px;
}

#thematic-sheet #sheet-legend-box {
    flex: 0 0 auto;
}

#thematic-sheet .der-sheet-notes {
    flex: 1 1 auto;
    min-height: 90px;
}
/* Ajuste fino do carimbo */
.der-sheet-stamp,
#sheet-stamp {
    box-sizing: border-box;
    overflow: hidden;
    border: 1px solid #3d4650;
    background: #fff;
    min-height: 140px;
}

.der-sheet-stamp > * {
    box-sizing: border-box;
    min-width: 0;
}

.der-sheet-number {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 100%;
}

.der-sheet-stamp-title,
.der-sheet-stamp-meta {
    min-width: 0;
    overflow: hidden;
}

.der-sheet-stamp-title {
    padding: 6px 8px;
}

.der-sheet-stamp-meta {
    padding: 6px 8px;
}
/* Correção definitiva da área vazia inferior do carimbo */
#thematic-sheet .der-sheet-stamp {
    min-height: 140px !important;
    height: 140px !important;
    align-self: end;
    grid-template-columns: 70px minmax(0, 1fr);
}

#thematic-sheet .der-sheet-stamp-content {
    height: auto;
    min-height: 0;
}

#thematic-sheet .der-sheet-stamp-meta {
    flex: none;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: auto;
}

#thematic-sheet .der-sheet-number {
    height: auto;
    min-height: 100%;
    align-self: stretch;
}

#thematic-sheet .der-stamp-field {
    min-height: 29px;
}

#thematic-sheet .der-stamp-field-wide {
    min-height: 31px;
}

/* Remove bordas duplicadas no fechamento inferior */
#thematic-sheet .der-stamp-field:nth-last-child(-n + 1) {
    border-bottom: 0;
}
/* Preserva a proporção das logos institucionais */
#thematic-sheet .der-sheet-logo,
#thematic-sheet .der-sheet-header-logo,
#thematic-sheet #sheet-institution-logo {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 52px !important;
    object-fit: contain !important;
    object-position: left center !important;
    flex-shrink: 0 !important;
}

/* Ajuste específico para a marca horizontal do DER/AL */
#thematic-sheet[data-institution="der_al"] #sheet-institution-logo,
#thematic-sheet.institution-der-al #sheet-institution-logo {
    max-width: 210px !important;
    max-height: 48px !important;
}

/* Ajuste específico para o SIGFAD */
#thematic-sheet[data-institution="sigfad"] #sheet-institution-logo,
#thematic-sheet.institution-sigfad #sheet-institution-logo {
    max-width: 235px !important;
    max-height: 54px !important;
}

/* =========================================================
   MODELO COMPACTO — VERSÃO CONSERVADORA
   Mantém a estrutura funcional do Institucional
   ========================================================= */

#thematic-sheet.template-compacto .der-sheet-header {
    height: 58px;
    min-height: 58px;
    padding-top: 5px;
    padding-bottom: 5px;
}

#thematic-sheet.template-compacto .der-sheet-heading h1 {
    font-size: 14px;
}

#thematic-sheet.template-compacto .der-sheet-main {
    grid-template-columns: minmax(0, 1fr) 190px;
    gap: 6px;
    padding: 7px;
}

#thematic-sheet.template-compacto .der-sheet-side {
    gap: 5px;
}

#thematic-sheet.template-compacto .der-sheet-notes {
    display: none;
}

#thematic-sheet.template-compacto #sheet-legend-box {
    flex: 1 1 auto;
    min-height: 0;
}

#thematic-sheet.template-compacto #sheet-legend {
    padding: 5px 6px;
}

#thematic-sheet.template-compacto .der-sheet-legend-item {
    min-height: 12px;
    gap: 4px;
}

#thematic-sheet.template-compacto .der-sheet-legend-label {
    font-size: 6.4px;
}

#thematic-sheet.template-compacto .der-sheet-stamp {
    min-height: 126px !important;
    height: 126px !important;
    grid-template-columns: 56px minmax(0, 1fr);
}

#thematic-sheet.template-compacto .der-sheet-number {
    min-width: 56px;
}

#thematic-sheet.template-compacto .der-sheet-number strong {
    font-size: 21px;
}

#thematic-sheet.template-compacto .der-sheet-stamp-title {
    min-height: 41px;
    padding: 4px 5px;
}

#thematic-sheet.template-compacto .der-stamp-field {
    min-height: 25px;
    padding: 3px 4px;
}

#thematic-sheet.template-compacto .der-stamp-field-wide {
    min-height: 27px;
}

#thematic-sheet.template-compacto .der-sheet-footer {
    height: 17px;
    min-height: 17px;
    padding-top: 2px;
    padding-bottom: 2px;
}


/* Caixa de observações da folha temática */
#thematic-sheet .der-sheet-notes #sheet-notes {
    margin: 0;
    text-align: justify;
    text-align-last: left;
    line-height: 1.35;
    hyphens: auto;
    -webkit-hyphens: auto;
    overflow-wrap: break-word;
    word-break: normal;
}

/* Carimbo — título e subtítulo sem ultrapassar a célula */
#thematic-sheet .der-stamp-title-area {
    box-sizing: border-box;
    min-height: 0;
    padding: 10px 12px 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#thematic-sheet .der-stamp-title-area h3,
#thematic-sheet .der-stamp-title-area .der-stamp-title {
    margin: 0;
    line-height: 1.05;
}

#thematic-sheet .der-stamp-title-area p,
#thematic-sheet .der-stamp-title-area .der-stamp-subtitle {
    margin: 7px 0 0;
    padding: 0;
    font-size: clamp(9px, 1.05vw, 13px);
    line-height: 1.12;
    max-height: 3.36em;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: normal;
}

/* Ajuste automático do título e subtítulo do carimbo */

#thematic-sheet #sheet-title,
#thematic-sheet #sheet-stamp-title {
    margin: 0;
    line-height: 1.05;
}


#thematic-sheet #sheet-subtitle,
#thematic-sheet #sheet-stamp-subtitle {
    display: block;
    margin: 7px 0 0;
    padding: 0;
    font-size: clamp(9px, 1.05vw, 13px);
    line-height: 1.12;
    max-height: 3.36em;
    overflow: hidden;
    overflow-wrap: anywhere;
}

/* Carimbo — acomodação do título, subtítulo e instituição */
#thematic-sheet #sheet-stamp-title {
    margin: 0;
    font-size: clamp(10px, 1.15vw, 16px);
    line-height: 1.02;
    max-height: 3.1em;
    overflow: hidden;
    text-align: center;
}

#thematic-sheet #sheet-stamp-subtitle {
    margin: 4px 0 0;
    font-size: clamp(7px, 0.72vw, 10px);
    line-height: 1.05;
    max-height: 2.1em;
    overflow: hidden;
    text-align: center;
}

#thematic-sheet #sheet-stamp-institution {
    position: static !important;
    display: block;
    width: fit-content;
    max-width: calc(100% - 12px);
    margin: 4px auto 2px;
    padding: 1px 8px;
    font-size: clamp(6px, 0.62vw, 9px);
    line-height: 1.05;
    white-space: nowrap;
    text-align: center;
    box-sizing: border-box;
    transform: none !important;
}

#thematic-sheet .der-stamp-title-area,
#thematic-sheet .der-stamp-header,
#thematic-sheet .der-stamp-heading {
    box-sizing: border-box;
    min-height: 0;
    overflow: hidden;
    padding-top: 6px;
    padding-bottom: 3px;
}


/* Carimbo — ocultar subtítulo duplicado */
#thematic-sheet #sheet-stamp-subtitle {
    display: none !important;
}

/* Reorganização do cabeçalho do carimbo */
#thematic-sheet #sheet-stamp-title {
    margin: 0;
    padding: 0 8px;
    font-size: clamp(10px, 1.05vw, 15px);
    line-height: 1.05;
    max-height: none;
    overflow: visible;
    text-align: center;
}

#thematic-sheet #sheet-stamp-institution {
    position: static !important;
    display: block;
    width: fit-content;
    max-width: calc(100% - 12px);
    margin: 6px auto 3px;
    padding: 1px 8px;
    font-size: clamp(6px, 0.62vw, 9px);
    line-height: 1;
    white-space: nowrap;
    text-align: center;
    box-sizing: border-box;
    transform: none !important;
}

/* Ajuste final do cabeçalho do carimbo */
#thematic-sheet #sheet-stamp-title {
    margin: 0;
    padding: 2px 10px 0;
    font-size: clamp(8px, 0.78vw, 12px);
    line-height: 1.02;
    max-height: none;
    overflow: visible;
    text-align: center;
    word-break: normal;
    overflow-wrap: normal;
}

#thematic-sheet #sheet-stamp-institution {
    display: block;
    margin: 4px auto 2px;
    padding: 1px 8px;
    font-size: clamp(5px, 0.5vw, 8px);
    line-height: 1;
    white-space: nowrap;
    text-align: center;
}

#thematic-sheet .der-stamp-title-area,
#thematic-sheet .der-stamp-header,
#thematic-sheet .der-stamp-heading {
    padding: 4px 8px 2px;
    overflow: hidden;
}

/* Ajuste final — título do carimbo mais compacto */
#thematic-sheet #sheet-stamp-title {
    margin: 0;
    padding: 0 8px;
    font-size: clamp(6px, 0.58vw, 9px);
    line-height: 0.98;
    max-height: none;
    overflow: visible;
    text-align: center;
    word-break: normal;
    overflow-wrap: normal;
}

#thematic-sheet #sheet-stamp-institution {
    display: block;
    margin: 2px auto 1px;
    padding: 0 6px;
    font-size: clamp(4.5px, 0.42vw, 7px);
    line-height: 1;
    white-space: nowrap;
    text-align: center;
}

#thematic-sheet .der-stamp-title-area,
#thematic-sheet .der-stamp-header,
#thematic-sheet .der-stamp-heading {
    padding: 2px 6px 1px;
    overflow: hidden;
}
