/*
 * MERIDIAN — App-Stylesheet
 * AÜ Corporate Design (Frontify-Stand September 2025)
 *
 * Fonts: Merriweather + PT Sans werden hier als lokaler Stack definiert.
 * Schrift-Files können später unter /static/vendor/fonts/ gevendort werden.
 * Kein Google-Fonts-CDN (CSP default-src 'self' erlaubt keine externen Font-URLs).
 */

/* ──────────────────────────────────────────────────────────────────────────────
   Custom Properties — AÜ Corporate Design
   ──────────────────────────────────────────────────────────────────────────── */
:root {
  /* Primärfarben */
  --au-rot:        #e20613;
  --au-rot-dunkel: #9a1d28;
  --au-beige:      #faf6e5;
  --au-hellgrau:   #f4f4f4;
  --au-dunkelgrau: #666b6e;
  --au-text:       #676767;
  --au-heading:    #000000;
  --au-link:       #4a90e2;

  /* Marktbereichsfarben (CD-nah, kontrastfest auf hellem Kartengrund) */
  --mb-nord:       #174476; /* Kaufmännisch-Blau  */
  --mb-west:       #436c59; /* GaLa-Grün          */
  --mb-ost:        #914056; /* Multimedia-Weinrot */
  --mb-mitte-sued: #c97c45; /* Holz-Orange        */
  --mb-apm:        #666b6e; /* Grau               */
  --mb-sonstige:   #92c4cf; /* Lager-Logistik     */
  --mb-unbekannt:  #ffc378; /* Orientierung/Ocker */

  /* Layout */
  --header-h:       52px;
  --filter-h:       48px;
  --panel-w:        380px;
  --z-map:          0;
  --z-header:       100;
  --z-panel:        200;
  --z-modal:        300;
  --z-overlay:      400;
  --z-toast:        500;

  /* Typografie (lokal) */
  --font-heading: 'Merriweather', Georgia, 'Times New Roman', serif;
  --font-body:    'PT Sans', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;

  /* Transitions */
  --ease: 0.2s ease;
}

/* ──────────────────────────────────────────────────────────────────────────────
   Reset / Base
   ──────────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width:  100%;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  color: var(--au-text);
  /* KEIN weißer Grund — AÜ CD-Pflicht */
  background: var(--au-hellgrau);
}

a { color: var(--au-link); }
button { cursor: pointer; font-family: var(--font-body); }

/* Sichtbarer Tastatur-Fokus für ALLE Bedienelemente (Codex-Audit 12.06.:
   Border-Farbwechsel allein ist auf Beige/Hellgrau zu schwach) */
button:focus-visible,
input:focus-visible,
.chip:focus-visible,
.suche-treffer:focus-visible {
  outline: 2px solid var(--au-rot);
  outline-offset: 2px;
}

/* ──────────────────────────────────────────────────────────────────────────────
   App-Schale
   ──────────────────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width:  100%;
}

/* ──────────────────────────────────────────────────────────────────────────────
   Kopfleiste
   ──────────────────────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  background: var(--au-beige);
  border-bottom: 2px solid var(--au-rot);
  padding: 0 16px;
  z-index: var(--z-header);
  flex-shrink: 0;
}

#header-logo {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: var(--au-rot);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

#header-datenstand {
  flex: 1;
  font-size: 12px;
  color: var(--au-dunkelgrau);
  text-align: center;
}

/* AÜ-Logo rechts in der Kopfleiste (extrahiert aus dem CD-Master, transparent) */
#header-aue-logo {
  height: 30px;
  width: auto;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-drag: none;
}

#header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--au-dunkelgrau);
}

#btn-logout {
  background: none;
  border: 1px solid var(--au-dunkelgrau);
  border-radius: 4px;
  color: var(--au-dunkelgrau);
  font-size: 12px;
  padding: 4px 10px;
  min-height: 28px;
  transition: border-color var(--ease), color var(--ease);
}
#btn-logout:hover {
  border-color: var(--au-rot);
  color: var(--au-rot);
}

/* ──────────────────────────────────────────────────────────────────────────────
   Filter-Leiste
   ──────────────────────────────────────────────────────────────────────────── */
#filterbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--filter-h);
  background: var(--au-beige);
  border-bottom: 1px solid #e0ddd0;
  padding: 0 16px;
  z-index: var(--z-header);
  flex-shrink: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Trennlinie zwischen Gruppen */
.filter-sep {
  width: 1px;
  height: 24px;
  background: #ddd;
  flex-shrink: 0;
}

/* Marktbereich-Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 16px;
  border: 1.5px solid transparent;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--chip-color, var(--au-dunkelgrau));
  color: #fff;
  opacity: 0.35;
  transition: opacity var(--ease), transform var(--ease);
  min-height: 28px; /* Touch-Target ≥28px — Leiste hat 48px Höhe */
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.chip.aktiv { opacity: 1; }
.chip:hover { transform: scale(1.04); }

/* Platzhalter-Chip für kommende Marktbereiche (z. B. Digital):
   sichtbar angekündigt, aber noch nicht klickbar — gestrichelt statt „kaputt". */
.chip.deaktiviert {
  opacity: 0.55;
  background: transparent;
  color: var(--chip-color, var(--au-dunkelgrau));
  border: 1.5px dashed var(--chip-color, var(--au-dunkelgrau));
  cursor: default;
}
.chip.deaktiviert:hover { transform: none; }
.chip-bald {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.8;
}

/* Ebenen-Schalter */
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1.5px solid var(--au-dunkelgrau);
  font-size: 12px;
  color: var(--au-dunkelgrau);
  background: var(--au-hellgrau);
  white-space: nowrap;
  min-height: 28px;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
  flex-shrink: 0;
}
.toggle-btn.aktiv {
  background: var(--au-rot);
  border-color: var(--au-rot);
  color: #fff;
}
.toggle-btn:hover { border-color: var(--au-rot); color: var(--au-rot); }
.toggle-btn.aktiv:hover { background: var(--au-rot-dunkel); border-color: var(--au-rot-dunkel); color: #fff; }

/* Such-Container in Filterbar */
#suche-container {
  margin-left: auto;
  position: relative;
  flex-shrink: 0;
}

#suche-input {
  width: 200px;
  padding: 4px 10px 4px 28px;
  border: 1.5px solid #ccc;
  border-radius: 16px;
  font-size: 13px;
  font-family: var(--font-body);
  background: #fff;
  color: var(--au-text);
  transition: border-color var(--ease);
  min-height: 28px;
}
#suche-input:focus {
  border-color: var(--au-rot);
}
/* Maus-Fokus ohne Ring, Tastatur-Fokus behält den globalen :focus-visible-Ring */
#suche-input:focus:not(:focus-visible) {
  outline: none;
}
#suche-input::placeholder { color: #bbb; }

.suche-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  pointer-events: none;
  color: var(--au-dunkelgrau);
}

#suche-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 300px;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: var(--z-overlay);
}
#suche-dropdown.offen { display: block; }

.suche-treffer {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  color: var(--au-text);
  transition: background var(--ease);
}
.suche-treffer:last-child { border-bottom: none; }
.suche-treffer:hover { background: var(--au-hellgrau); }
.suche-treffer strong { color: var(--au-heading); }

/* ──────────────────────────────────────────────────────────────────────────────
   Karten-Bereich
   ──────────────────────────────────────────────────────────────────────────── */
#karten-bereich {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

#map {
  flex: 1;
  position: relative;
  z-index: var(--z-map);
  min-height: 0;
}

/* MapLibre-Attributions-Stil überschreiben */
.maplibregl-ctrl-attrib {
  font-size: 10px !important;
}

/* Fallback-Banner wenn Kacheln nicht erreichbar */
#karten-fallback-banner {
  display: none;
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(226, 6, 19, 0.92);
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 6px;
  z-index: 10;
  pointer-events: none;
  text-align: center;
  max-width: 90%;
}
#karten-fallback-banner.sichtbar { display: block; }

/* Offline-Banner (PWA — Verbindungsverlust) */
#offline-banner {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(102, 107, 110, 0.95);
  color: #fff;
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 6px;
  z-index: var(--z-toast, 500);
  pointer-events: none;
  text-align: center;
  max-width: 90%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#offline-banner.sichtbar { display: block; }

/* ──────────────────────────────────────────────────────────────────────────────
   Steckbrief-Panel — die Standort-Sidebar
   Desktop: DAUERHAFT sichtbare rechte Leiste (kein weißer Streifen, kein
   Heraus-Schieben); ohne Auswahl zeigt sie einen gestalteten Leerzustand.
   Mobil: Bottom-Sheet wie bisher (erscheint erst bei Standort-Klick).
   ──────────────────────────────────────────────────────────────────────────── */
#steckbrief-panel {
  width: var(--panel-w);
  background: var(--au-beige);
  border-left: 2px solid #e0ddd0;
  display: flex;
  flex-direction: column;
  z-index: var(--z-panel);
  overflow: hidden;
}

/* Sidebar-Kopf: bewusst farblich abgesetzt von der beigen Haupt-Kopfleiste —
   dunkler AÜ-Rot-Verlauf mit weißer Schrift (CD-Farben Akzentrot → AÜ-Rot). */
.panel-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #7c1520 0%, var(--au-rot-dunkel) 55%, #c00511 100%);
  border-bottom: 3px solid var(--au-rot);
  flex-shrink: 0;
}
.panel-kopf-text {
  flex: 1;
  padding-right: 12px;
  min-width: 0;
}
.panel-kopf-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  /* 0.92 statt 0.75: kleine Schrift braucht vollen Kontrast auf dem Verlauf */
  color: rgba(255, 255, 255, 0.92);
  margin-bottom: 2px;
}
.panel-name {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}
.panel-close {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  font-size: 18px;
  line-height: 1;
  color: #fff;
  padding: 4px;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-shrink: 0;
  transition: background var(--ease);
}
.panel-close:hover { background: rgba(255, 255, 255, 0.28); }

.panel-inhalt {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Sektionen als helle Karten auf beigem Grund — moderner Karten-Look */
.panel-sektion {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #fff;
  border: 1px solid #ece8da;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Leerzustand: kein Standort gewählt — oben angebunden statt verloren zentriert */
.panel-leer {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  text-align: center;
  padding: 52px 18px 24px;
  color: var(--au-dunkelgrau);
}
.panel-leer-icon {
  width: 56px;
  height: 56px;
  color: var(--au-rot);
  opacity: 0.85;
}
.panel-leer-titel {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  color: var(--au-heading);
}
.panel-leer-text {
  font-size: 13px;
  line-height: 1.5;
  max-width: 260px;
}
.panel-leer-legende {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  background: #fff;
  border: 1px solid #ece8da;
  border-radius: 8px;
  padding: 12px 16px;
}
.panel-leer-legende-titel {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--au-dunkelgrau);
  margin-bottom: 2px;
}
.legende-zeile {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--au-text);
}
.legende-punkt {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.panel-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--au-dunkelgrau);
}
.panel-wert {
  font-size: 14px;
  color: var(--au-text);
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
}
.badge-org-au      { background: var(--au-rot); }
.badge-org-apm     { background: var(--au-dunkelgrau); }
.badge-org-sonstige{ background: #888; }

.badge-stempel-stammdaten { background: #436c59; }
.badge-stempel-abgeleitet { background: #c97c45; }
.badge-stempel-unbekannt  { background: var(--au-dunkelgrau); }

/* Datenqualitäts-Ampel */
.dq-ampel {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.dq-punkt {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dq-gruen { background: #4caf50; }
.dq-gelb  { background: #f9a825; }
.dq-rot   { background: var(--au-rot); }

.dq-reasons {
  font-size: 12px;
  color: var(--au-dunkelgrau);
  list-style: none;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dq-reasons li::before {
  content: "–";
  margin-right: 4px;
  color: #999;
}

/* Personal-Block */
.personal-veraltet-hinweis {
  font-size: 12px;
  color: var(--au-rot);
  font-style: italic;
}

.panel-datenstand {
  font-size: 11px;
  color: #999;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid #e8e6dc;
}

/* ──────────────────────────────────────────────────────────────────────────────
   Login-Modal
   ──────────────────────────────────────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 36, 30, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}
#login-overlay.versteckt { display: none; }

.login-karte {
  background: var(--au-beige);
  border-radius: 10px;
  padding: 32px 28px;
  width: 340px;
  max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-titel {
  font-family: var(--font-heading);
  font-size: 22px;
  color: var(--au-rot);
  text-align: center;
  font-weight: 700;
}
.login-untertitel {
  font-size: 13px;
  color: var(--au-dunkelgrau);
  text-align: center;
}

.login-feld {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.login-feld label {
  font-size: 13px;
  font-weight: 600;
  color: var(--au-heading);
}
.login-feld input {
  padding: 9px 12px;
  border: 1.5px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--au-text);
  background: #fff;
  min-height: 44px;
  transition: border-color var(--ease);
}
.login-feld input:focus {
  outline: none;
  border-color: var(--au-rot);
}

.login-fehler {
  font-size: 13px;
  color: var(--au-rot);
  text-align: center;
  min-height: 18px;
}

.btn-primary {
  background: var(--au-rot);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 16px;
  min-height: 44px;
  transition: background var(--ease);
}
.btn-primary:hover { background: var(--au-rot-dunkel); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

/* Passwort-Wechsel-Dialog (gleiche Karte, anderer Inhalt) */
.pw-staerke {
  font-size: 11px;
  color: var(--au-dunkelgrau);
}

/* ──────────────────────────────────────────────────────────────────────────────
   Toast-Benachrichtigungen
   ──────────────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #333;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  opacity: 0;
  transform: translateY(8px);
  animation: toast-in 0.25s ease forwards;
}
.toast.fehler { background: var(--au-rot); }
@keyframes toast-in {
  to { opacity: 1; transform: translateY(0); }
}

/* ──────────────────────────────────────────────────────────────────────────────
   Lade-Spinner (für Steckbrief-Abruf)
   ──────────────────────────────────────────────────────────────────────────── */
.lade-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
}
.lade-spinner::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid #e0ddd0;
  border-top-color: var(--au-rot);
  border-radius: 50%;
  animation: drehen 0.7s linear infinite;
}
@keyframes drehen { to { transform: rotate(360deg); } }

/* ──────────────────────────────────────────────────────────────────────────────
   Responsiv — Mobil (≤ 768px): Bottom-Sheet
   ──────────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --panel-w: 100%;
  }

  #steckbrief-panel {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-height: 70vh;
    border-left: none;
    border-top: 2px solid var(--au-rot);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
    transition: transform 0.25s ease;
  }
  #steckbrief-panel.offen {
    transform: translateY(0);
  }

  /* Bottom-Sheet Griff */
  .panel-kopf::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #ccc;
  }
  .panel-kopf { position: relative; }

  #suche-input { width: 140px; }

  /* Filterbar: kleinere Chips auf Mobil */
  .chip, .toggle-btn { min-height: 36px; }

  /* Headerleiste: etwas höher für Touch, Logo kompakter */
  :root { --header-h: 56px; }
  #header-aue-logo { height: 22px; }
}

@media (max-width: 480px) {
  /* Sehr schmale Geräte: Logo weicht dem Nutzernamen */
  #header-aue-logo { display: none; }
}

/* Tablet / kleine Laptops (769–1100px): schmalere Sidebar, damit die Karte
   nicht zusammengedrückt wird (Codex-Audit 12.06.) */
@media (min-width: 769px) and (max-width: 1100px) {
  :root { --panel-w: 320px; }
  .panel-inhalt { padding: 12px 12px; }
  #suche-input { width: 160px; }
}

/* Touch-Geräte (egal welche Breite): Bedienelemente auf 44px Mindesthöhe */
@media (pointer: coarse) {
  .chip, .toggle-btn, #suche-input { min-height: 44px; }
  .panel-close { min-width: 44px; min-height: 44px; }
  .suche-treffer { padding: 12px; }
}

/* ──────────────────────────────────────────────────────────────────────────────
   Utility
   ──────────────────────────────────────────────────────────────────────────── */
.versteckt { display: none !important; }
