/*
 * Responsive layer shared by the Anuario website.
 * Loaded after page-specific styles so legacy desktop layouts adapt safely.
 */
html {
  width: 100%;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

img,
picture,
video {
  max-width: 100%;
  height: auto;
}

iframe {
  max-width: 100%;
}

main,
section,
header,
footer,
.container,
.container-fluid,
.container-sm,
.container-md,
.container-lg,
.container-xl,
.container-xxl {
  min-width: 0;
}

p,
li,
a,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* Excel-exported statistical tables remain legible through horizontal scrolling. */
body > table {
  display: block;
  width: 100% !important;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

body > table > tbody {
  width: max-content;
  min-width: 100%;
}

.table-responsive {
  -webkit-overflow-scrolling: touch;
}

/* Prevent overlays and dialogs from exceeding the viewport. */
.custom-modal,
.modal,
.modal-dialog,
.custom-modal-content,
.acess-modal,
.acess-modal-panel {
  max-width: 100vw;
}

.custom-modal-content,
.acess-modal-panel {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}

@media (max-width: 991.98px) {
  .navbar {
    min-height: 64px;
  }

  .navbar-brand {
    max-width: calc(100% - 76px);
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 1rem !important;
    padding-right: .5rem !important;
  }

  .navbar-brand h1,
  .navbar-brand .h1 {
    margin: .75rem 0 !important;
    font-size: clamp(1.25rem, 6vw, 1.75rem);
  }

  .navbar-toggler {
    flex: 0 0 auto;
    margin-right: 1rem !important;
  }

  .navbar-collapse {
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .navbar-nav {
    width: 100%;
    padding: .75rem 1rem !important;
  }

  .navbar .dropdown-menu,
  .acess-dropdown {
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    transform: none !important;
  }

  .hero-section {
    min-height: min(78dvh, 680px);
  }

  .hero-section-modern,
  .hero-content {
    min-height: calc(100vh - 64px);
    min-height: calc(100dvh - 64px);
  }

  .hero-content {
    width: 100%;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .hero-text-wrapper,
  .hero-cta-single {
    animation: none;
  }

  .page-header {
    min-height: auto !important;
  }

  .page-header .container {
    padding-top: 1.5rem !important;
    padding-bottom: 1.5rem !important;
  }

  .section-title,
  .mapa-title {
    font-size: clamp(1.45rem, 7vw, 2rem) !important;
  }

  .iframe-container {
    width: 100%;
    padding: .25rem !important;
    overflow: hidden;
  }

  .iframe-container iframe,
  main iframe[allowfullscreen] {
    width: 100% !important;
    height: 72dvh !important;
    min-height: 500px !important;
    border-radius: 6px !important;
  }

  .footer-main .row,
  .footer .row {
    --bs-gutter-y: 1.75rem;
  }

  .footer-main iframe,
  .footer iframe {
    min-height: 220px;
  }

  .mapas-page-shell,
  .repository-container,
  .repo-shell {
    width: auto !important;
    max-width: none !important;
    margin: 10px !important;
    border-radius: 16px !important;
  }

  .mapas-header,
  .repository-header,
  .repo-header {
    padding: 1.5rem 1rem !important;
  }

  .controls-panel .row,
  .map-controls .row {
    row-gap: .75rem;
  }

  #map,
  .map-container,
  .map-wrapper {
    max-width: 100%;
  }

  .portfolio-text {
    opacity: 1;
    visibility: visible;
    justify-content: flex-end;
    background: linear-gradient(180deg, transparent 38%, rgba(0,0,0,.74) 100%);
  }

  .portfolio-inner:hover img {
    transform: none;
  }
}

@media (max-width: 767.98px) {
  .container,
  .container-fluid,
  .container-sm,
  .container-md,
  .container-lg,
  .container-xl,
  .container-xxl {
    padding-left: .85rem;
    padding-right: .85rem;
  }

  .row {
    --bs-gutter-x: 1rem;
  }

  .card,
  .card-feature,
  .product-card,
  .mapas-card {
    max-width: 100%;
  }

  #repositorio .repo-col,
  .repo-grid-2 .repo-col,
  .repo-grid-3 .repo-col,
  .repo-grid-4-3 .repo-col {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .mapas-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .mapas-download {
    width: 100%;
  }

  .mapa-hero {
    padding: 1.5rem 1rem !important;
  }

  .controls-panel {
    padding: 1rem !important;
  }

  .controls-panel select,
  .controls-panel input,
  .controls-panel button,
  .map-controls select,
  .map-controls input,
  .map-controls button {
    width: 100%;
    min-height: 44px;
  }

  .btn-group,
  .portfolio-text .d-flex {
    max-width: 100%;
    flex-wrap: wrap;
  }

  .custom-modal {
    width: calc(100% - 20px);
    max-height: calc(100dvh - 20px) !important;
    overflow: hidden;
  }

  .custom-modal-content {
    width: 100%;
    margin: 0;
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
  }

  .custom-modal-body {
    min-height: 0;
    overflow: auto;
  }

  .custom-modal-footer {
    flex-wrap: wrap;
    padding: 12px;
  }

  #btnTop,
  .back-to-top,
  .repo-home-btn {
    right: 14px !important;
    bottom: 14px !important;
  }

  #site-language-switcher,
  #trilang {
    top: auto !important;
    left: max(12px, env(safe-area-inset-left)) !important;
    right: auto !important;
    bottom: max(12px, env(safe-area-inset-bottom)) !important;
  }
}

@media (max-width: 575.98px) {
  body {
    font-size: .95rem;
  }

  h1,
  .h1 {
    font-size: clamp(1.6rem, 9vw, 2rem);
  }

  h2,
  .h2 {
    font-size: clamp(1.35rem, 7vw, 1.75rem);
  }

  .py-5 {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  .px-4,
  .px-5 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .card-feature.card-animated,
  #principais-temas .card-feature.card-animated,
  #repositorio .card-feature.card-animated {
    min-height: 0 !important;
    padding: 1.25rem 1rem !important;
  }

  .downloads-section .btn,
  .quick-access-section .btn,
  .btn-card-modern {
    width: 100%;
    max-width: 100%;
  }

  .iframe-container iframe,
  main iframe[allowfullscreen] {
    height: 68dvh !important;
    min-height: 460px !important;
  }

  .mapas-grid {
    padding: .65rem !important;
  }

  .mapas-section,
  .mapas-info-box,
  .mapas-footer {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* Landscape phones: prioritize the dashboard content height. */
@media (max-width: 900px) and (orientation: landscape) {
  .iframe-container iframe,
  main iframe[allowfullscreen] {
    height: calc(100dvh - 80px) !important;
    min-height: 360px !important;
  }
}
/* Legacy mobile refinements */
[x\:publishsource="Excel"] {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
  .institutional-bar,
  .mapas-institutional-bar {
    white-space: normal !important;
    overflow-wrap: anywhere;
    padding: .75rem 1rem !important;
    font-size: .72rem !important;
    line-height: 1.45;
  }

  .header h1,
  .repository-header h1,
  .repo-header h1,
  .mapas-header h1 {
    max-width: 100% !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    overflow-wrap: anywhere;
    font-size: clamp(1.45rem, 7vw, 2rem) !important;
  }

  .titlecenter {
    width: 100%;
    max-width: 100vw;
    margin-bottom: .75rem !important;
    padding: .5rem !important;
    font-size: clamp(1.2rem, 7vw, 1.75rem) !important;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  body > table:first-of-type {
    margin-left: 0;
    margin-right: 0;
  }

  body > table:first-of-type .logo td {
    width: auto !important;
    min-width: 72px;
    padding: .25rem;
  }

  body > table:first-of-type .logo img {
    max-width: 110px;
    object-fit: contain;
  }
}
/* Narrow-phone overflow guard */
@media (max-width: 767.98px) {
  body > table,
  [x\:publishsource="Excel"] {
    overflow-x: auto;
  }

  body > .container,
  .repository-container,
  .repo-shell,
  .page-shell {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .header,
  .repository-header,
  .repo-header,
  .grid,
  .card {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .header h1,
  .repository-header h1,
  .repo-header h1,
  .mapas-header h1 {
    font-size: clamp(1.3rem, 6vw, 1.75rem) !important;
  }

  .section-title {
    max-width: 100%;
    padding-left: .5rem;
    padding-right: .5rem;
    font-size: clamp(1.05rem, 5.5vw, 1.45rem) !important;
    letter-spacing: .04em !important;
    white-space: normal !important;
  }

}
/* Repository shell sizing fix */
@media (max-width: 767.98px) {
  body:has(> .container > .institutional-bar) {
    padding: 10px !important;
  }

  body > .container:has(> .institutional-bar) {
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .header h1 {
    width: 100% !important;
    padding: 0 .25rem;
    word-break: normal;
  }
}
/* Cover images must fill the hero; intrinsic image sizing applies elsewhere. */
.hero-background .hero-image {
  height: 100%;
}

/* Canvas and SVG dimensions belong to the chart/map libraries, not image resets. */
@media (max-width: 991.98px) {
  .navbar-brand {
    min-width: 0;
    margin-right: 0;
  }

  .navbar .nav-link {
    white-space: normal;
  }

  .hero-title {
    margin-top: clamp(4rem, 18svh, 10rem);
  }

  .hero-content {
    padding-bottom: 2rem;
  }

  body:has(#map) .col-lg-4 {
    max-height: none;
    overflow: visible;
  }

  #map.fullscreen-territorio,
  .map-container.fullscreen-territorio {
    width: 100% !important;
    margin-left: 0;
  }
}

@media (max-width: 767.98px) {
  .hero-section-modern,
  .hero-content {
    min-height: calc(100vh - 64px);
    min-height: calc(100dvh - 64px);
  }

  .btn-hero {
    white-space: normal;
  }

  .map-container {
    padding: .75rem;
  }

  #map,
  #map.fullscreen-territorio {
    height: clamp(300px, 60svh, 500px);
    min-height: 300px;
  }

  .info-grid.show {
    max-height: none;
    overflow: visible;
  }

  .acess-control {
    min-width: 0;
    white-space: normal;
    min-height: 44px;
  }

  #btnTop,
  .back-to-top,
  .repo-home-btn {
    bottom: max(14px, env(safe-area-inset-bottom)) !important;
    right: max(14px, env(safe-area-inset-right)) !important;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .iframe-container iframe,
  main iframe[allowfullscreen] {
    min-height: 240px !important;
  }
}

/* Mobile content is readable immediately, independent of reveal observers. */
@media (max-width: 991.98px) {
  html.js .js-reveal,
  html.js .reveal-stagger > * {
    opacity: 1;
    transform: none;
    transition: none;
    will-change: auto;
  }

  .navbar.sticky-top {
    top: 0 !important;
  }

  .navbar-nav {
    padding: .25rem 1rem .75rem !important;
  }

  .navbar .nav-link {
    padding: .5rem 0;
    min-height: 44px;
  }

  #acess-open-btn .d-none.d-lg-inline {
    display: inline !important;
  }
}

@media (max-width: 767.98px) {
  .hero-cta-group {
    align-items: center;
  }

  .hero-cta-single .btn-hero {
    justify-content: center;
  }

  .footer-products {
    margin-top: 0;
    padding: 2rem 0 !important;
  }

  .footer-products h3 {
    margin-bottom: 1.5rem !important;
  }

  .footer-main .row {
    --bs-gutter-y: 0;
    row-gap: 2rem;
  }

  .footer-main .footer-title {
    margin-bottom: 1rem !important;
  }

  .footer-main .text-light,
  .footer-main a {
    color: #f1f7ff !important;
  }

  .footer-main .text-primary {
    color: #b5e0ff !important;
  }

  .footer-main .map-embed {
    height: 240px;
    padding-bottom: 0;
  }
}
