/* ==========================================================================
   Gebäude-Check: Adresssuche, Luftbild (swisstopo) und GWR-Angaben
   Baut auf den Variablen aus styles.css auf; Rückfallwerte, falls das Widget
   ohne styles.css eingebunden wird. Inhalt erzeugt assets/js/gebaeude.js.
   ========================================================================== */

.gebaeude {
  --gb-navy: var(--navy, #00378c);
  --gb-navy-900: var(--navy-900, #0a2246);
  --gb-navy-950: var(--navy-950, #061730);
  --gb-blue: var(--blue, #2874bb);
  --gb-blue-700: var(--blue-700, #1d5c99);
  --gb-cyan: var(--cyan, #20c1f2);
  --gb-sky-50: var(--sky-50, #f3f8fc);
  --gb-sky-100: var(--sky-100, #e6f1fa);
  --gb-sky-200: var(--sky-200, #cde3f4);
  --gb-ink: var(--ink, #0d1f3a);
  --gb-text: var(--text, #34455d);
  --gb-muted: var(--muted, #5a6a80);
  --gb-line: var(--line, #dde6f0);
  --gb-radius: var(--radius-lg, 26px);
  --gb-ease: var(--ease, cubic-bezier(.2, .7, .2, 1));
  container-type: inline-size;
  position: relative;
  color: var(--gb-text);
}
.gebaeude [hidden] { display: none !important; }
.gebaeude__icon { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.gebaeude__sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Suchfeld (ARIA-Combobox) ---------- */
.gebaeude__suche { max-width: 640px; }
.gebaeude__label { display: block; margin-bottom: 8px; font-size: .95rem; font-weight: 600; color: var(--gb-ink); }
.gebaeude__feld { position: relative; }
.gebaeude__lupe { position: absolute; left: 17px; top: 50%; width: 21px; height: 21px; margin-top: -10.5px; color: var(--gb-muted); pointer-events: none; }
.gebaeude__eingabe {
  display: block; width: 100%; min-height: 58px; margin: 0; padding: 14px 58px 14px 50px;
  border: 1.5px solid #7d8fa6; border-radius: 14px; background: #fff;
  color: var(--gb-ink); font: inherit; font-size: 1.05rem; line-height: 1.3;
  transition: border-color .2s, box-shadow .2s;
  -webkit-appearance: none; appearance: none;
}
.gebaeude__eingabe::placeholder { color: #6b7a8f; opacity: 1; }
.gebaeude__eingabe:hover { border-color: #a9bcd2; }
/* Fokus wie die Formularfelder der Website (styles.css .field input:focus) */
.gebaeude__eingabe:focus { outline: none; border-color: var(--gb-blue); box-shadow: 0 0 0 4px rgba(40, 116, 187, .16); }
.gebaeude__eingabe[aria-expanded="true"] { border-color: var(--gb-blue); border-bottom-left-radius: 0; border-bottom-right-radius: 0; box-shadow: 0 0 0 4px rgba(40, 116, 187, .16); }

.gebaeude__leeren {
  position: absolute; right: 7px; top: 50%; width: 44px; height: 44px; margin-top: -22px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--gb-muted); cursor: pointer;
  transition: background-color .2s, color .2s;
}
.gebaeude__leeren:hover { background: var(--gb-sky-100); color: var(--gb-ink); }
.gebaeude__leeren .gebaeude__icon { width: 18px; height: 18px; stroke-width: 2.2; }

/* Ladeanzeige: links neben dem Löschknopf */
.gebaeude__lader {
  position: absolute; right: 56px; top: 50%; width: 18px; height: 18px; margin-top: -9px;
  border: 2px solid var(--gb-sky-200); border-top-color: var(--gb-blue); border-radius: 50%;
  opacity: 0; visibility: hidden; transition: opacity .2s;
}
.gebaeude__feld.is-laedt .gebaeude__lader { opacity: 1; visibility: visible; animation: gebaeude-dreh .8s linear infinite; }
@keyframes gebaeude-dreh { to { transform: rotate(360deg); } }

.gebaeude__vorschlaege {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30;
  margin: 0; padding: 6px; list-style: none;
  max-height: min(372px, 60vh); overflow-y: auto; overscroll-behavior: contain;
  background: #fff; border: 1.5px solid var(--gb-blue); border-top: 1px solid var(--gb-line);
  border-radius: 0 0 14px 14px;
  box-shadow: 0 26px 50px -24px rgba(10, 34, 70, .45);
}
.gebaeude__vorschlag {
  position: relative; display: flex; flex-direction: column; justify-content: center; gap: 1px;
  min-height: 52px; padding: 8px 14px 8px 18px; border-radius: 10px;
  cursor: pointer; line-height: 1.3;
}
.gebaeude__vorschlag::before {
  content: ""; position: absolute; left: 6px; top: 12px; bottom: 12px; width: 3px; border-radius: 3px;
  background: var(--gb-cyan); transform: scaleY(0); transition: transform .2s var(--gb-ease);
}
.gebaeude__vorschlag:hover { background: var(--gb-sky-50); }
.gebaeude__vorschlag.is-aktiv { background: var(--gb-sky-100); }
.gebaeude__vorschlag.is-aktiv::before { transform: none; }
.gebaeude__vorschlag-strasse { color: var(--gb-ink); font-weight: 600; overflow-wrap: anywhere; }
.gebaeude__vorschlag-ort { color: var(--gb-muted); font-size: .9rem; }
/* Windows-Kontrastmodus: aktive Option bleibt erkennbar */
@media (forced-colors: active) {
  .gebaeude__vorschlag.is-aktiv { outline: 2px solid Highlight; outline-offset: -2px; }
}

.gebaeude__meldung { margin: 12px 0 0; padding: 12px 16px; border-radius: 12px; font-size: .95rem; line-height: 1.5; }
.gebaeude__meldung.is-fehler { background: #fdecea; color: #8a1c13; }
.gebaeude__meldung.is-info { background: var(--gb-sky-50); color: var(--gb-ink); border: 1px solid var(--gb-sky-200); }
.gebaeude__hilfe { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 0; font-size: .86rem; line-height: 1.5; color: var(--gb-muted); }
.gebaeude__hilfe .gebaeude__icon { width: 17px; height: 17px; margin-top: 2px; color: var(--gb-blue); }

/* ---------- Ergebnis: Karte und Datenkarte ---------- */
.gebaeude__ergebnis { display: grid; gap: 20px; margin-top: 28px; }
@container (min-width: 760px) {
  .gebaeude__ergebnis { grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr); align-items: start; }
  /* Karte bleibt beim Lesen der Datenkarte im Blick */
  .gebaeude__ergebnis .gebaeude__karte {
    position: sticky; top: calc(var(--header-h, 84px) + 20px);
    aspect-ratio: auto; height: clamp(440px, calc(100vh - var(--header-h, 84px) - 60px), 620px);
  }
}

.gebaeude__karte {
  position: relative; overflow: hidden; isolation: isolate;
  aspect-ratio: 16 / 11; min-height: 240px;
  border-radius: var(--gb-radius);
  background: radial-gradient(120% 90% at 50% 40%, #183a63 0%, var(--gb-navy-900) 60%, var(--gb-navy-950) 100%);
  box-shadow: var(--shadow, 0 18px 40px -18px rgba(10, 34, 70, .22));
  -webkit-user-select: none; user-select: none;
}
@container (max-width: 480px) { .gebaeude__karte { aspect-ratio: 1 / 1; } }
/* Feiner Rand und Vignette für Ruhe an den Kanten */
.gebaeude__karte::after {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
  background:
    radial-gradient(130% 110% at 50% 45%, transparent 58%, rgba(6, 23, 48, .32) 100%),
    linear-gradient(to top, rgba(6, 23, 48, .55), transparent 26%);
}
/* Ladeschimmer, bis die erste Kachelstufe da ist */
.gebaeude__karte::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .06) 50%, transparent 70%) 0 0 / 220% 100%;
  animation: gebaeude-schimmer 1.6s linear infinite;
}
.gebaeude__karte.is-bereit::before { animation: none; opacity: 0; }
@keyframes gebaeude-schimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.gebaeude__buehne { position: absolute; inset: 0; z-index: 1; }
.gebaeude__ebene { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-origin: 0 0; }
.gebaeude__karte.is-flug .gebaeude__ebene { will-change: transform, opacity; }
.gebaeude__kachel {
  position: absolute; display: block; width: 257px; height: 257px; max-width: none;
  opacity: 0; transition: opacity .45s ease-out;
}
.gebaeude__kachel.is-da { opacity: 1; }
.gebaeude__kachel.is-fehler { visibility: hidden; }
/* Übersichtsstufe leicht entsättigt, damit das Ziel beim Ankommen aufleuchtet */
.gebaeude__ebene--weit { filter: saturate(.85) brightness(.92); }

/* Markierung genau in der Kartenmitte (dort liegt das Gebäude) */
.gebaeude__ueber { position: absolute; left: 50%; top: 50%; z-index: 2; width: 0; height: 0; pointer-events: none; }
.gebaeude__marke { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.gebaeude__punkt, .gebaeude__ring { position: absolute; left: 0; top: 0; border-radius: 50%; }
.gebaeude__punkt {
  width: 16px; height: 16px; margin: -8px 0 0 -8px;
  background: var(--gb-cyan); border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(6, 23, 48, .25), 0 6px 16px rgba(6, 23, 48, .45);
  animation: gebaeude-landung .6s var(--gb-ease) both;
}
.gebaeude__ring {
  width: 64px; height: 64px; margin: -32px 0 0 -32px;
  border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: 0 0 0 1px rgba(32, 193, 242, .55), inset 0 0 0 1px rgba(32, 193, 242, .55);
  opacity: 0;
  animation: gebaeude-puls 2.2s cubic-bezier(.2, .6, .3, 1) .35s 2 both;
}
.gebaeude__ring--2 { animation-delay: 1.45s; animation-iteration-count: 1; }
/* Nach dem Pulsieren bleibt ein ruhiger Ring stehen */
.gebaeude__marke::after {
  content: ""; position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .85); box-shadow: 0 0 0 1px rgba(6, 23, 48, .2), 0 0 24px rgba(32, 193, 242, .35);
  opacity: 0; animation: gebaeude-ein .8s ease-out 4.6s forwards;
}
@keyframes gebaeude-landung { from { transform: scale(0) translateY(-6px); opacity: 0; } 60% { transform: scale(1.25); opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes gebaeude-puls { 0% { transform: scale(.25); opacity: 0; } 15% { opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }
@keyframes gebaeude-ein { to { opacity: 1; } }

/* Grundstücksgrenze (amtliche Vermessung) */
.gebaeude__parzelle { position: absolute; left: 0; top: 0; width: 1px; height: 1px; max-width: none; overflow: visible; }
.gebaeude__parzelle path { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.gebaeude__parzelle-schatten { stroke: rgba(6, 23, 48, .45); stroke-width: 4; }
.gebaeude__parzelle-linie { stroke: #fff; stroke-width: 2; stroke-dasharray: 1; stroke-dashoffset: 1; animation: gebaeude-zeichnen 1.4s var(--gb-ease) .5s forwards; }
.gebaeude__parzelle-schatten { stroke-dasharray: 1; stroke-dashoffset: 1; animation: gebaeude-zeichnen 1.4s var(--gb-ease) .5s forwards; }
@keyframes gebaeude-zeichnen { to { stroke-dashoffset: 0; } }

.gebaeude__copy, .gebaeude__massstab, .gebaeude__legende {
  position: absolute; z-index: 4; margin: 0;
  color: #fff; font-size: .78rem; font-weight: 500; line-height: 1.2; letter-spacing: .01em;
  text-shadow: 0 1px 2px rgba(6, 23, 48, .7);
}
.gebaeude__copy { right: 14px; bottom: 12px; opacity: .92; }
.gebaeude__massstab { left: 16px; bottom: 12px; display: flex; align-items: flex-end; gap: 8px; opacity: 0; transition: opacity .6s .3s; }
.gebaeude__massstab-balken { display: block; height: 7px; border: 2px solid #fff; border-top: 0; box-shadow: 0 1px 2px rgba(6, 23, 48, .5); }
.gebaeude__legende { left: 16px; bottom: 34px; display: flex; align-items: center; gap: 8px; opacity: 0; transition: opacity .6s 1s; }
.gebaeude__legende-linie { display: block; width: 22px; height: 0; border-top: 2px solid #fff; box-shadow: 0 1px 2px rgba(6, 23, 48, .6); }
.gebaeude__karte.is-gelandet .gebaeude__massstab, .gebaeude__karte.is-gelandet .gebaeude__legende { opacity: 1; }

/* Datenkarte */
.gebaeude__daten {
  display: flex; flex-direction: column; min-width: 0;
  padding: clamp(22px, 3.2vw, 34px);
  border: 1px solid var(--gb-line); border-radius: var(--gb-radius); background: #fff;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(10, 34, 70, .06), 0 2px 10px rgba(10, 34, 70, .05));
}
.gebaeude__kicker { display: inline-flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: .78rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--gb-blue-700); }
.gebaeude__kicker::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gb-cyan); box-shadow: 0 0 0 4px rgba(32, 193, 242, .18); }
.gebaeude__titel { margin: 0; color: var(--gb-ink); font-size: clamp(1.4rem, 2.4vw, 1.75rem); font-weight: 600; line-height: 1.15; letter-spacing: -.02em; overflow-wrap: anywhere; }
.gebaeude__ort { margin: 6px 0 0; color: var(--gb-muted); font-size: .98rem; }
.gebaeude__eingaenge { margin: 10px 0 0; font-size: .9rem; line-height: 1.5; color: var(--gb-text); }

.gebaeude__kennzahlen { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 22px 0 0; }
.gebaeude__kennzahl { margin: 0; padding: 14px 16px 13px; border-radius: 14px; background: var(--gb-sky-50); border: 1px solid var(--gb-sky-100); }
.gebaeude__kennzahl dt { font-size: .74rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--gb-muted); }
.gebaeude__kennzahl dd { margin: 4px 0 0; color: var(--gb-ink); font-size: 1.65rem; font-weight: 600; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.gebaeude__kennzahl--text dd { font-size: 1.12rem; line-height: 1.3; letter-spacing: -.01em; }
/* Schmale Spalten (Handy ab 320 px): 2 × 2 bleibt, Beschriftung kompakter und ohne Versalien */
@container (max-width: 340px) {
  .gebaeude__kennzahlen { gap: 8px; }
  .gebaeude__kennzahl { padding: 11px 12px 10px; }
  .gebaeude__kennzahl dt { font-size: .8rem; letter-spacing: 0; text-transform: none; -webkit-hyphens: manual; hyphens: manual; }
  .gebaeude__kennzahl dd { font-size: 1.4rem; }
  .gebaeude__kennzahl--text dd { font-size: 1rem; }
}
@container (max-width: 240px) { .gebaeude__kennzahlen { grid-template-columns: 1fr; } }

.gebaeude__hinweis { display: flex; gap: 10px; align-items: flex-start; margin: 18px 0 0; padding: 12px 14px; border-radius: 12px; background: #fff7e6; border: 1px solid #f3dca6; color: #5c4105; font-size: .93rem; line-height: 1.5; }
.gebaeude__hinweis .gebaeude__icon { width: 19px; height: 19px; margin-top: 1px; }

.gebaeude__angaben { margin: 20px 0 0; border-top: 1px solid var(--gb-line); }
.gebaeude__zeile { display: grid; grid-template-columns: minmax(7.5em, 32%) minmax(0, 1fr); gap: 4px 16px; padding: 11px 0; border-bottom: 1px solid var(--gb-line); }
.gebaeude__zeile dt { font-size: .9rem; color: var(--gb-muted); line-height: 1.5; }
.gebaeude__zeile dd { margin: 0; min-width: 0; color: var(--gb-ink); font-size: .96rem; line-height: 1.5; overflow-wrap: anywhere; }
.gebaeude__zusatz { display: block; margin-top: 2px; color: var(--gb-muted); font-size: .84rem; line-height: 1.45; }
@container (max-width: 420px) {
  .gebaeude__zeile { grid-template-columns: 1fr; gap: 2px; }
}

/* Wohnungsmix als schmaler Balken über dem Text */
.gebaeude__mix { display: flex; gap: 3px; height: 8px; margin: 6px 0 9px; border-radius: 6px; overflow: hidden; }
.gebaeude__mix-teil { display: block; flex: 1 1 0; min-width: 6px; }
.gebaeude__mix-teil--1 { background: #8fdcf6; }
.gebaeude__mix-teil--2 { background: #20c1f2; }
.gebaeude__mix-teil--3 { background: #368fce; }
.gebaeude__mix-teil--4 { background: #2874bb; }
.gebaeude__mix-teil--5 { background: #1d5c99; }
.gebaeude__mix-teil--6 { background: #00378c; }
.gebaeude__mix-teil--ohne { background: repeating-linear-gradient(-45deg, #dde6f0 0 4px, #c6d4e3 4px 8px); }

.gebaeude__quelle { margin: 18px 0 0; font-size: .84rem; line-height: 1.55; color: var(--gb-muted); }
.gebaeude__quelle strong { color: var(--gb-ink); font-weight: 600; }
.gebaeude__neu { align-self: flex-start; margin-top: 18px; gap: 8px; }
.gebaeude__neu .gebaeude__icon { width: 1.05em; height: 1.05em; }
.gebaeude__neu:hover .gebaeude__icon { transform: none; }

/* Ruhiges Einblenden der Datenkarte */
.gebaeude__daten.is-neu > * { animation: gebaeude-auf .6s var(--gb-ease) both; }
.gebaeude__daten.is-neu > :nth-child(2) { animation-delay: .06s; }
.gebaeude__daten.is-neu > :nth-child(3) { animation-delay: .12s; }
.gebaeude__daten.is-neu > :nth-child(4) { animation-delay: .18s; }
.gebaeude__daten.is-neu > :nth-child(5) { animation-delay: .24s; }
.gebaeude__daten.is-neu > :nth-child(n+6) { animation-delay: .3s; }
@keyframes gebaeude-auf { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.gebaeude__ergebnis { animation: gebaeude-ein-sanft .5s ease-out both; }
@keyframes gebaeude-ein-sanft { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .gebaeude__feld.is-laedt .gebaeude__lader { animation-duration: 2.4s; }
  .gebaeude__karte::before, .gebaeude__ergebnis, .gebaeude__daten.is-neu > *,
  .gebaeude__punkt, .gebaeude__ring, .gebaeude__kachel { animation: none !important; transition: none !important; }
  .gebaeude__ring { display: none; }
  .gebaeude__marke::after { animation: none !important; opacity: 1; }
  .gebaeude__parzelle path { animation: none !important; stroke-dashoffset: 0; }
  .gebaeude__massstab, .gebaeude__legende { transition: none !important; }
}

@media print {
  .gebaeude__suche, .gebaeude__neu { display: none; }
  .gebaeude__karte { box-shadow: none; }
}
