/*
 * Öffentliches Web-Frontend. Zwei Ausprägungen desselben Detailbereichs:
 * ab 900 px schiebt er sich von rechts herein, darunter von unten wie in den Apps.
 */

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --border: #dcdce1;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --accent: #8a5a2b;
  --accent-soft: #f2e8dd;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, .10);
  --topbar: 132px;          /* wird per JS an die echte Höhe angepasst */
  --panel-width: 420px;

  /* Ebenen von unten nach oben. Leaflet legt seine Bedienleisten selbst auf 1000 —
     alles, was darüber liegen soll, muss das ausdrücklich überbieten. */
  --z-karte-bedienung: 1000;   /* von Leaflet gesetzt, hier nur dokumentiert */
  --z-rechtliches: 1050;       /* über der Karte, aber unter dem Detailbereich */
  --z-panel: 1100;
  --z-kopfzeile: 1200;
  --z-hinweis: 1300;
  --z-vollbild: 1400;
}

* { box-sizing: border-box; }

/* Muss stehen, bevor eigene display-Regeln kommen: eine Klasse mit `display: grid`
   überstimmt sonst das hidden-Attribut, und der Bereich bleibt sichtbar. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;                       /* die Karte scrollt, nicht die Seite */
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------- Kopfzeile */

.topbar {
  position: relative;
  z-index: var(--z-kopfzeile);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-top, 0px));
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: grid;
  gap: 10px;
}

.topbar h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.01em; }

.search { position: relative; }

.search input {
  width: 100%;
  padding: 11px 40px 11px 16px;
  font: inherit;
  color: var(--text);
  background: #eeeef1;
  border: 1px solid transparent;
  border-radius: 999px;
  -webkit-appearance: none;
  appearance: none;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.search input::-webkit-search-cancel-button { display: none; }

.search-clear {
  position: absolute;
  top: 50%; right: 10px;
  transform: translateY(-50%);
  width: 26px; height: 26px;
  border: none; border-radius: 999px;
  background: #c9c9d0; color: #fff;
  font-size: 17px; line-height: 1;
  cursor: pointer;
}

.results {
  position: absolute;
  top: calc(100% + 6px); left: 0; right: 0;
  z-index: 900;
  margin: 0; padding: 6px;
  list-style: none;
  max-height: 60vh; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.results li > button {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 8px;
  border: none; border-radius: 10px;
  background: none; font: inherit; color: inherit;
  text-align: left; cursor: pointer;
}
.results li > button:hover, .results li > button:focus-visible { background: var(--bg); }
.results img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; background: #e6e6ea; flex: none; }
.results .title { font-weight: 550; }
.results .sub { color: var(--muted); font-size: 14px; }
.results .none { padding: 14px 10px; color: var(--muted); }

.filter { display: flex; align-items: center; gap: 12px; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 16px;
  font: inherit; font-weight: 550;
  color: var(--accent);
  background: var(--accent-soft);
  border: none; border-radius: 999px;
  cursor: pointer;
}
.chip[disabled] { opacity: .5; cursor: not-allowed; }

.count { margin-left: auto; color: var(--muted); font-size: 15px; }

.linklike {
  border: none; background: none; padding: 0;
  font: inherit; color: var(--accent);
  text-decoration: underline; cursor: pointer;
}

.period-panel {
  display: grid; gap: 10px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.period-panel label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.period-panel output { font-size: 17px; font-weight: 600; color: var(--text); }
.period-panel input[type=range] { width: 100%; accent-color: var(--accent); }
.period-panel .note { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------- Karte */

main { position: relative; height: calc(100% - var(--topbar)); }

#karte { position: absolute; inset: 0; background: #e8e6e1; }
.leaflet-container { font: inherit; background: #e8e6e1; }

/* Runder Bild-Marker — dieselbe Anmutung wie in den Apps. */
.marker {
  width: 52px; height: 52px;
  border-radius: 999px;
  border: 3px solid #fff;
  background: #ded6cc center/cover no-repeat;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  cursor: pointer;
}
.marker.active { outline: 3px solid var(--accent); outline-offset: 2px; }

.cluster {
  display: flex; align-items: center; justify-content: center;
  width: 52px; height: 52px;
  border-radius: 999px;
  border: 3px solid #fff;
  background: var(--accent);
  color: #fff; font-weight: 650; font-size: 17px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  cursor: pointer;
}

/* ---------------------------------------------------------- Detailbereich */

.panel {
  position: absolute;
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: var(--z-panel);
}

.panel-close {
  position: absolute; top: 12px; right: 12px;
  z-index: 2;
  width: 34px; height: 34px;
  border: none; border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
  font-size: 22px; line-height: 1; color: var(--text);
  cursor: pointer;
}

.panel-body { overflow-y: auto; padding: 22px 22px 40px; -webkit-overflow-scrolling: touch; }

.grabber { display: none; }

/* Desktop: von rechts hereingeschoben. */
@media (min-width: 900px) {
  .panel {
    top: 0; right: 0; bottom: 0;
    width: var(--panel-width);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, .10);
    transform: translateX(100%);
    transition: transform .28s cubic-bezier(.2, .7, .3, 1);
  }
  .panel.open { transform: translateX(0); }
}

/* Mobil: Blatt von unten, wie in den Apps. */
@media (max-width: 899px) {
  .panel {
    left: 0; right: 0; bottom: 0;
    /* Anteil am *Bildschirm*, nicht am Kartenbereich — sonst wären es faktisch nur 60 %.
       dvh folgt der ein- und ausfahrenden Browserleiste, vh ist der Rückfall. */
    height: 75vh;
    height: 75dvh;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, .18);
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.2, .7, .3, 1), height .28s cubic-bezier(.2, .7, .3, 1);
  }
  .panel.open { transform: translateY(0); }
  .panel.full { height: 94vh; height: 94dvh; }

  .grabber {
    display: block;
    flex: none;
    width: 42px; height: 5px;
    margin: 10px auto 4px;
    border-radius: 999px;
    background: #d0d0d6;
    cursor: grab;
  }
  .panel-body { padding: 8px 20px calc(32px + env(safe-area-inset-bottom, 0px)); }
  .panel-close {
    top: 10px; right: 12px;
    width: 40px; height: 40px;     /* Daumengerecht */
    font-size: 24px;
  }
}

/* ---------------------------------------------------------- Inhalt des Details */

.jahr { margin: 0 0 14px; font-size: 34px; font-weight: 700; letter-spacing: -.02em; }

.galerie {
  position: relative;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  margin-bottom: 14px;
  /* Die Höhe setzt JS aus dem Seitenverhältnis des gerade sichtbaren Bildes.
     Ohne das richtet sich der Kasten nach dem *größten* Bild, und unter flachen
     Aufnahmen klafft eine Lücke bis zu den Jahres-Feldern.
     Bewusst ohne Übergang: eine hängende Höhen-Animation ließe die Galerie dauerhaft
     falsch stehen, und die Bewegung der Galerie selbst reicht als Rückmeldung. */
}
.galerie::-webkit-scrollbar { display: none; }
.galerie figure {
  flex: 0 0 100%;
  margin: 0;
  height: 100%;
  scroll-snap-align: center;
}
.galerie img {
  width: 100%; height: 100%; display: block;
  object-fit: contain;
  border-radius: 10px; background: #e9e9ee;
  cursor: zoom-in;
}

.zeitstrahl {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  scrollbar-width: none;
  /* Eigene Zeichen-Ebene. Der Streifen verschiebt sich vertikal, sobald die Galerie ihre
     Höhe ändert; ohne eigene Ebene lassen manche mobile Browser dabei Reste des alten
     Anstriches stehen — dann wirken zwei Jahres-Felder je zur Hälfte gefüllt. */
  transform: translateZ(0);
}
.zeitstrahl::-webkit-scrollbar { display: none; }
.zeitstrahl button {
  flex: none;
  padding: 8px 16px;
  font: inherit;
  color: var(--text);
  background: #eeeef1;
  border: none; border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.zeitstrahl button[aria-current=true] { background: var(--accent); color: #fff; font-weight: 600; }

.bild-unterschrift { margin: 0 0 8px; color: var(--muted); }
.bild-text { margin: 0 0 20px; }

.ort-titel { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.ort-text { margin: 0 0 20px; color: var(--muted); }

.herkunft { margin: 0 0 20px; }
.herkunft h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: none; }
.herkunft dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; font-size: 15px; }
.herkunft dt { color: var(--text); }
.herkunft dd { margin: 0; color: var(--muted); text-align: right; }

.aktionen { display: flex; gap: 10px; }
.aktionen a, .aktionen button {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px;
  font: inherit; font-weight: 550;
  color: var(--accent);
  background: var(--accent-soft);
  border: none; border-radius: 12px;
  text-decoration: none;
  cursor: pointer;
}

.laedt, .fehler { padding: 40px 0; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------- Vollbild */

.lightbox {
  position: fixed; inset: 0; z-index: var(--z-vollbild);
  display: flex; align-items: center; justify-content: center;
  background: #000;
  border: none; padding: 0; margin: 0;
  width: 100%; height: 100%;
  max-width: none; max-height: none;
}
.lightbox::backdrop { background: #000; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .panel-close { background: rgba(255, 255, 255, .9); }

/* ---------------------------------------------------------- Hinweise */

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: var(--z-hinweis);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  background: rgba(28, 28, 30, .94);
  color: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 15px;
}

.leer {
  position: absolute; inset: 0;
  z-index: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 32px;
  text-align: center;
  background: rgba(245, 245, 247, .94);
}
.leer h2 { margin: 0; font-size: 19px; }
.leer p { margin: 0; color: var(--muted); }
.leer button {
  margin-top: 6px;
  padding: 10px 20px;
  font: inherit; font-weight: 550;
  color: #fff; background: var(--accent);
  border: none; border-radius: 12px; cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}

/* ---------------------------------------------------------- Pflichtangaben */

.rechtliches {
  position: absolute;
  right: 8px; bottom: 4px;
  z-index: var(--z-rechtliches);
  display: flex;
  gap: 12px;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .82);
  font-size: 12px;
}
.rechtliches a { color: var(--muted); text-decoration: none; }
.rechtliches a:hover { color: var(--accent); text-decoration: underline; }

/* Mobil sitzt unten rechts die Leaflet-Zuschreibung — dann nach links ausweichen. */
@media (max-width: 899px) {
  .rechtliches { right: auto; left: 8px; bottom: 4px; }
}
