:root {
  --bg: #eef1ef;
  --panel: #fbfcfb;
  --ink: #1f2723;
  --muted: #64706a;
  --line: #d4ddd7;
  --accent: #355f77;
  --accent-soft: #e4eef2;
  --selected: #fff1d9;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(420px, 1fr) minmax(360px, 470px);
  height: 100vh;
  min-height: 680px;
}

.app-shell.detail-closed {
  grid-template-columns: minmax(330px, 390px) minmax(420px, 1fr);
}

.app-shell.detail-closed .detail-panel {
  display: none;
}

.reader-panel,
.detail-panel {
  background: var(--panel);
  min-height: 0;
  overflow: hidden;
}

.reader-panel {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.reader-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.reader-header h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: 0;
}

.reader-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.reader-header a,
.source-link {
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
}

.reader-brand {
  display: flex;
  align-items: stretch;
  gap: 11px;
  min-width: 0;
  --brand-logo-height: 58px;
}
.brand-copy { min-width: 0; }
.reader-header > a { flex: 0 0 auto; }

.brand-logo-link {
  flex: 0 0 auto;
  display: inline-flex;
  width: var(--brand-logo-height);
  height: var(--brand-logo-height);
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
}

.brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.search-tools {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

input[type="search"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.category-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 10px;
  margin-top: 11px;
}

.category-filters label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.category-filters input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.record-list-wrap {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.result-summary {
  padding: 10px 16px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}

.record-list {
  min-height: 0;
  overflow: auto;
}

.record-button {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 10px 16px;
  text-align: left;
  font: inherit;
}

.record-button:hover,
.record-button.active {
  background: var(--selected);
}

.record-button strong {
  display: block;
  font-size: 13px;
  line-height: 1.3;
}

.record-button span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.map-panel {
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.detail-panel {
  border-left: 1px solid var(--line);
  overflow: auto;
  padding: 18px;
}

.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.detail-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.detail-close:hover,
.detail-close:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
}

.detail-title {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: 0;
}

.detail-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 12px 0 16px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.bridge-panel {
  border: 1px solid #c9d6de;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: #f1f5f8;
  padding: 10px 12px;
  margin: 10px 0 16px;
}

.bridge-panel--empty {
  border-left-color: var(--muted);
  background: #f3f4f3;
}

.bridge-panel header {
  margin-bottom: 4px;
}

.bridge-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bridge-line {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.4;
}

.bridge-meta {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 11px;
}

.bridge-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.bridge-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  border: 1px solid var(--accent);
  cursor: pointer;
  font-family: inherit;
}

.bridge-btn:hover {
  filter: brightness(1.08);
}

.bridge-btn--ghost {
  background: transparent;
  color: var(--accent);
}

.waze-panel {
  border: 1px solid #c9d6de;
  border-left: 3px solid #1f6f8b;
  border-radius: 6px;
  background: #f1f7fa;
  padding: 10px 12px;
  margin: 0 0 16px;
}

.waze-panel header {
  margin-bottom: 6px;
}

.waze-kicker {
  color: #1f6f8b;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.waze-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #1f6f8b;
  color: #fff;
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  border: 1px solid #1f6f8b;
}

.waze-btn:hover {
  filter: brightness(1.08);
}

.waze-btn-icon {
  font-size: 10px;
  line-height: 1;
}

.waze-warn {
  margin: 8px 0 0;
  color: #7a4f1f;
  font-size: 11px;
  line-height: 1.4;
}

.field-grid,
.tombamento-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 10px;
  margin: 14px 0;
  font-size: 13px;
}

.field-grid dt,
.tombamento-list dt {
  color: var(--muted);
  font-weight: 800;
}

.field-grid dd,
.tombamento-list dd {
  margin: 0;
}

.content-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.content-section h3,
.gallery h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.content-section .section-body {
  color: #2f3834;
  font-size: 14px;
  line-height: 1.58;
}

.content-section p {
  margin: 0 0 10px;
}

.gallery {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 14px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.gallery-grid a,
.gallery-item {
  display: block;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #e7ece8;
  width: 100%;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}

.gallery-item:hover { filter: brightness(1.04); }
.gallery-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.gallery-grid img {
  display: block;
  width: 100%;
  height: 112px;
  object-fit: cover;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 22, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 28px;
}

.lightbox[hidden] { display: none; }

.lightbox img {
  max-width: 92vw;
  max-height: 80vh;
  background: #fff;
  border-radius: 6px;
  display: block;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 0;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.lightbox-close:hover { background: #fff; }

.lightbox-meta {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  align-items: center;
  color: #f4f1ea;
  font-size: 12px;
  background: rgba(15, 25, 22, 0.7);
  padding: 8px 14px;
  border-radius: 999px;
  max-width: 92vw;
}

.lightbox-meta a {
  color: #f4f1ea;
  font-weight: 750;
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  text-decoration: none;
  white-space: nowrap;
}

body.no-scroll { overflow: hidden; }

.image-source {
  display: block;
  padding: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.leaflet-popup-content {
  color: var(--ink);
}

.popup-title {
  display: block;
  max-width: 260px;
  font-weight: 800;
  line-height: 1.3;
}

.popup-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(320px, 380px) minmax(420px, 1fr);
    grid-template-rows: minmax(410px, 52vh) minmax(360px, 48vh);
  }

  .map-panel {
    grid-column: 2;
    grid-row: 1 / 3;
  }

  .detail-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .app-shell.detail-closed .reader-panel {
    grid-row: 1 / 3;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
    height: auto;
    min-height: 0;
  }

  .reader-panel,
  .detail-panel {
    height: auto;
    overflow: visible;
  }

  .map-panel {
    height: 52vh;
    min-height: 360px;
  }

  .record-list {
    max-height: 360px;
  }
}

/* dvh aceito = melhor; sem suporte cai no vh acima */
.lightbox img { max-height: 80dvh; }

/* Tabs Lista/Mapa: invisiveis em desktop */
.mobile-view-tabs { display: none; }

/* Botao fullscreen do mapa */
.map-fullscreen-btn {
  position: absolute;
  bottom: 14px;
  left: 14px;
  z-index: 500;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 25, 22, 0.16);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.map-fullscreen-btn:hover { background: var(--accent-soft); }

@media (max-width: 760px) {
  html, body { overscroll-behavior: none; }

  .map-panel { height: 52dvh; }

  /* Em mobile o conteudo rico fica no bottom-sheet; popup nativo seria redundante e cobriria o sheet */
  .leaflet-popup { display: none !important; }

  /* Detail-panel vira bottom-sheet animado.
     Override do `display: none` do desktop e do atributo [hidden] pra que a transicao de transform funcione. */
  .app-shell.detail-closed .detail-panel,
  .detail-panel[hidden] {
    display: block;
  }

  .detail-panel {
    position: fixed;
    inset: auto 0 0 0;
    height: auto;
    max-height: 78vh;
    max-height: 78dvh;
    margin: 0;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 28px rgba(15, 25, 22, 0.16);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 18px 16px 24px;
    transform: translateY(105%);
    transition: transform 0.22s ease;
    z-index: 900;
  }

  .detail-panel::before {
    content: '';
    position: sticky;
    top: 0;
    display: block;
    width: 40px;
    height: 4px;
    margin: 0 auto 10px;
    background: var(--line);
    border-radius: 2px;
  }

  .app-shell:not(.detail-closed) .detail-panel {
    transform: translateY(0);
  }

  body.detail-sheet-open { overflow: hidden; }
  body.detail-sheet-open .leaflet-bottom {
    bottom: 56px;
    transition: bottom 0.22s ease;
  }

  /* URLs/citacoes longas nao devem vazar a largura em telas estreitas */
  .popup-title,
  .popup-meta,
  .detail-title,
  .detail-meta,
  .field-grid dd,
  .tombamento-list dd,
  .content-section .section-body,
  .image-source {
    overflow-wrap: anywhere;
  }

  /* Tabs Lista/Mapa em mobile: visivel, sticky no topo */
  .mobile-view-tabs {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 800;
    gap: 6px;
    padding: 6px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .mvt-btn {
    flex: 1;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 8px 10px;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
  }
  .mvt-btn.is-active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }

  /* Modo lista: reader-panel ocupa o resto do viewport, mapa some */
  .app-shell.mobile-view-list .reader-panel {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    height: calc(100dvh - 52px);
    overflow: hidden;
  }
  .app-shell.mobile-view-list .record-list {
    max-height: none;
    min-height: 0;
    overflow: auto;
  }
  .app-shell.mobile-view-list .map-panel { display: none; }

  /* Modo mapa: map-panel ocupa o resto do viewport, lista some */
  .app-shell.mobile-view-map .map-panel {
    height: calc(100dvh - 52px);
    min-height: 0;
  }
  .app-shell.mobile-view-map .reader-panel { display: none; }

  /* Em mobile, fullscreen-btn afastado dos controles do leaflet bottom */
  .map-fullscreen-btn {
    bottom: 14px;
    left: 14px;
  }
}
