/* Additions to the original madonnelle.css.
   Desktop: only small helpers (the look comes from madonnelle.css + Bootstrap, unchanged).
   Phones (< 992px): the original page hid every panel; here the same markup becomes a
   bottom tab bar + bottom sheets. */

/* ---------- Gallery (styles that the old script wrote inline) ---------- */
.mainImageContainer {
  margin-bottom: 10px;
  text-align: center;
  position: relative;
}
.mainImage {
  max-width: 100%;
  height: auto;
  cursor: pointer;
  transition: opacity 0.15s;
}
.mainImage.fading {
  opacity: 0;
}
.leftArrow,
.rightArrow {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20%;
  display: flex;
  align-items: center;
  font-size: 30px;
  color: white;
  background: rgba(0, 0, 0, 0);
  cursor: pointer;
  z-index: 10;
  transition: background 0.2s;
  user-select: none;
}
.leftArrow {
  left: 0;
  justify-content: flex-start;
  padding-left: 10px;
}
.rightArrow {
  right: 0;
  justify-content: flex-end;
  padding-right: 10px;
}
.leftArrow:hover,
.rightArrow:hover {
  background: rgba(0, 0, 0, 0.2);
}
.mainImageCaption {
  margin-top: 5px;
}
.thumbnailContainer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 10px;
}
.thumbnailContainer .thumbnail {
  max-height: 50px;
  width: auto;
}
.thumbnail.current {
  border: 3px solid rgb(255, 251, 0);
}

/* Filter-tab results (same spacing as the original rows) */
#tableBody table {
  color: #fff;
}
#tableBody tr {
  cursor: pointer;
}
#feature-notes3,
#feature-inscription3,
#feature-imagedetails3,
#rufini-text {
  white-space: pre-line;
}
.directions-link {
  display: inline-block;
  margin-left: 14px;
}

/* Messages (offline, install, update) */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 7000;
  max-width: 92vw;
  padding: 10px 16px;
  border-radius: 6px;
  background: #102233;
  color: #fff;
  font-family: "Lato", sans-serif;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ======================= Phones / small tablets ======================= */
@media (max-width: 991.98px) {
  :root {
    --tabbar: calc(58px + env(safe-area-inset-bottom, 0px));
    --navbar: 53px;
  }
  html,
  body {
    overflow: hidden;
    overscroll-behavior: none;
  }

  /* Navbar: same content, scaled to fit a phone */
  .navbar {
    padding: 0.4rem 0.6rem;
    padding-top: calc(0.4rem + env(safe-area-inset-top, 0px));
    flex-wrap: nowrap;
  }
  .navbar-brand {
    margin-right: 0;
    min-width: 0;
  }
  .navbar-brand img {
    height: 30px;
  }
  .navbar-brand > span {
    font-size: 1.15rem !important;
  }
  .navbar > span {
    margin-left: 10px !important;
    font-size: 0.62em !important;
  }
  .navbar > a[href*="comune.roma"] img {
    height: 26px;
    margin-left: 6px !important;
  }
  @media (max-width: 430px) {
    .navbar > span {
      display: none !important; /* "With the support of": the Roma logo stays */
    }
    .navbar-brand > span {
      font-size: 1.05rem !important;
    }
  }
  .navbar-toggler {
    margin-left: auto;
    padding: 0.25rem 0.5rem;
  }
  .navbar-collapse {
    position: fixed;
    top: calc(var(--navbar) + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    max-height: calc(100dvh - var(--navbar) - var(--tabbar));
    overflow-y: auto;
    background: var(--background-color);
    padding: 0.5rem 1rem 1rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  }
  .navbar-nav .nav-link {
    padding: 0.6rem 0;
  }
  .navbar-nav .dropdown-menu {
    background: rgba(255, 255, 255, 0.06);
    border: 0;
  }
  .navbar-nav .dropdown-item {
    color: #fff;
    white-space: normal;
    padding: 0.5rem 1rem;
  }

  /* Map fills the screen above the tab bar */
  #map {
    top: calc(var(--navbar) + env(safe-area-inset-top, 0px)) !important;
    left: 0 !important;
    width: 100% !important;
    bottom: var(--tabbar);
  }
  #legend {
    top: calc(var(--navbar) + 8px + env(safe-area-inset-top, 0px));
    right: auto;
    left: 8px;
    font-size: 11px;
  }
  #legend h6 {
    font-size: 12px;
    margin-bottom: 3px;
  }
  #legend .legend-item {
    margin-bottom: 2px;
  }
  .maplibregl-ctrl-top-right {
    top: calc(var(--navbar) - 53px);
  }

  /* Tab bar: the original vertical tabs, laid out along the bottom */
  #menuNew .sideways-tabs {
    position: fixed !important;
    left: 0 !important;
    right: 0;
    bottom: 0;
    z-index: 1200;
    height: var(--tabbar);
    margin: 0 !important;
    padding: 0 0 env(safe-area-inset-bottom, 0px) !important;
    flex-direction: row !important;
    border: 0 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.15) !important;
    background: var(--background-color);
    min-width: 0;
  }
  #menuNew .sideways-tabs .nav-item {
    flex: 1;
    transform: none !important;
    height: auto !important;
    margin: 0 !important;
  }
  #menuNew .sideways-tabs .nav-link {
    width: auto !important;
    height: 100%;
    margin: 0 !important;
    padding: 9px 0 0 !important;
    border: 0 !important;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #c9d4de;
    background: none !important;
  }
  #menuNew .sideways-tabs .nav-link i {
    font-size: 19px;
  }
  .tab-gap {
    display: none;
  }
  body.sheet-open #menuNew .sideways-tabs .nav-link.active,
  #menuNew .sideways-tabs #maptab.active {
    color: rgb(239, 203, 0) !important;
  }
  body:not(.sheet-open) #menuNew .sideways-tabs .nav-link.active:not(#maptab) {
    color: #c9d4de;
  }

  /* Sidebar → bottom sheet */
  #menuNew {
    z-index: 1000; /* original: 1 – must sit above the map controls */
  }
  .map-overlay {
    display: block !important;
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    width: auto !important;
    bottom: var(--tabbar);
    height: 0;
    padding: 0 !important;
    border: 0;
    border-radius: 14px 14px 0 0;
    z-index: 1000;
    overflow: hidden;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
    transition: height 0.25s ease;
  }
  body.sheet-open .map-overlay {
    height: 60dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 22px 0 20px !important;
  }
  body.sheet-full .map-overlay {
    height: calc(100dvh - var(--navbar) - var(--tabbar) - env(safe-area-inset-top, 0px));
  }
  body.sheet-open .map-overlay::before {
    /* grab handle */
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    width: 42px;
    height: 5px;
    margin-left: -21px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.45);
  }
  #menuNew > .row {
    margin: 0;
  }
  #menuNew > .row > .col-md-2 {
    position: static;
    padding: 0 !important;
    flex: 0 0 0;
    max-width: 0;
  }
  #menuNew > .row > .col-md-10 {
    flex: 0 0 100%;
    max-width: 100%;
    padding: 0 16px !important;
  }
  #mainContent .tab-pane {
    margin-top: 0;
    padding: 0;
  }
  .map-overlay input {
    width: 100%;
    margin: 6px 0;
    font-size: 16px; /* no iOS zoom on focus */
    padding: 6px 8px;
  }
  .filter-group select {
    font-size: 16px;
    height: 38px;
  }
  #feature-listing a,
  #tableBody td {
    padding-top: 6px !important;
    padding-bottom: 6px !important;
  }
  #imageWall {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-bottom: 8px;
  }
  #imageWall > div {
    flex: 0 0 26%;
    max-width: 26%;
  }
  .image-wall-thumb {
    height: 80px;
  }
  .slider {
    position: static;
    width: 45%;
    vertical-align: middle;
  }
  #layers section > a {
    vertical-align: middle;
  }
  .slider input {
    width: 100% !important;
  }

  /* Hover card is a mouse-only feature */
  .map-overlay2,
  #menuNew2 {
    display: none !important;
  }

  /* Detail panel → bottom sheet over the map */
  .map-overlay3 {
    position: fixed;
    top: 34dvh;
    left: 0;
    right: 0;
    bottom: 0 !important;
    width: auto;
    min-width: 0;
    max-height: none;
    z-index: 1300;
    border-radius: 14px 14px 0 0;
    padding: 0 15px calc(30px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
    overscroll-behavior: contain;
  }
  #testicky {
    top: 0;
    padding-top: 12px;
    border-radius: 14px 14px 0 0;
    flex-wrap: nowrap;
  }
  #testicky > .col-md-10 {
    flex: 1;
    min-width: 0;
  }
  #testicky > .col-md-2 {
    flex: none;
    width: auto;
    padding: 0;
  }
  #closePanel3 {
    min-width: 44px;
    min-height: 40px;
  }
  /* label / value rows stay side by side on phones */
  .map-overlay3 .row > .col-md-4 {
    flex: 0 0 34%;
    max-width: 34%;
  }
  .map-overlay3 .row > .col-md-8 {
    flex: 0 0 66%;
    max-width: 66%;
  }
  .map-overlay3 .row > .col-md-2:empty,
  .map-overlay3 .row > .col-md-2:has(> b:empty) {
    display: none;
  }
  #feature-image3 {
    flex: 0 0 100%;
    max-width: 100%;
    padding: 0 !important;
  }
  .mainImage {
    max-height: 42dvh;
  }

  /* About / Bibliography dialogs fill the screen */
  #aboutModal .modal-dialog,
  #bibliographyModal .modal-dialog {
    margin: 0;
    max-width: none;
    height: 100%;
  }
  #aboutModal .modal-content,
  #bibliographyModal .modal-content {
    height: 100%;
    border-radius: 0;
  }
  #aboutModal .modal-body,
  #bibliographyModal .modal-body {
    height: 100% !important;
  }
  #splashModal {
    margin: 0;
    width: 100%;
    max-width: 100%;
  }
  #splashModal .modal-dialog {
    margin: 0;
    height: 100dvh;
  }
  .app-toast {
    bottom: calc(var(--tabbar) + 14px);
  }
}
