/* /css/modals.css – Überarbeitete Version (komplett, inkl. Actions-Base)
   ============================================================
   GFC – Modals (ruhig, seriös, on-brand)
   - Soft-Glass Dark, Blur, weiche Tiefen, starke Fokusindikatoren
   - Perfektes Mobile-Bottom-Sheet
   - Konsistente Buttons, Radii, Typografie
   - FIX: Language-Switch Klassen scoped (kein global leak)
   - HARDENING: min-width/overflow-safety gegen Clipping + iOS Safe-Area
   - Safety-Mode: px -> rem 1:1 (16px Basis), Verhalten bleibt unverändert
   ============================================================ */

/* ---------------------------------
   BACKDROP
---------------------------------- */
[data-modal-backdrop] {
  position: fixed;
  inset: 0;
  background: var(--backdrop-color);
  -webkit-backdrop-filter: blur(var(--backdrop-blur));
  backdrop-filter: blur(var(--backdrop-blur));
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 1000;
}
[data-modal-backdrop]:not([hidden]) {
  opacity: 1;
  visibility: visible;
}

/* ---------------------------------
   MODAL WRAPPER
---------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem; /* 16px */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 1001;
}
.modal:not([hidden]) {
  opacity: 1;
  visibility: visible;
}

/* ---------------------------------
   DIALOG
---------------------------------- */
.modal-dialog {
  width: 100%;
  max-width: var(--md-maxw);
  color: var(--md-ink);

  background: linear-gradient(180deg, var(--md-surface), var(--md-surface-2));
  border: 1px solid var(--md-border);
  border-radius: var(--md-radius-lg);
  box-shadow: var(--md-shadow);
  overflow: hidden;

  transform: translateY(0.5rem) scale(0.98); /* 8px */
  animation: md-in 0.18s ease forwards;

  max-height: min(90vh, 45rem); /* 720px */
  display: flex;
  flex-direction: column;

  /* Hardening: prevent edge clipping in nested flex/grid */
  min-width: 0;
}

@keyframes md-in {
  to { transform: translateY(0) scale(1); }
}

/* ---------------------------------
   HEADER
---------------------------------- */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem; /* 12px */

  padding: var(--md-pad);
  border-bottom: 1px solid var(--md-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), transparent);

  min-width: 0;
}
.modal-header h2 {
  margin: 0;
  font-size: clamp(1.1rem, 1.2vw + 0.9rem, 1.4rem);
  font-weight: 800;
  letter-spacing: -0.01em;

  /* Hardening: long titles shouldn't push close button off-screen */
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ---------------------------------
   CLOSE BUTTON
---------------------------------- */
.modal-close {
  appearance: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.04));
  border: 1px solid var(--md-border);
  color: var(--md-ink);

  inline-size: 2.5rem; /* 40px */
  block-size: 2.5rem;  /* 40px */
  border-radius: 0.625rem; /* 10px */

  display: grid;
  place-items: center;
  font-size: 1.375rem; /* 22px */
  line-height: 1;
  cursor: pointer;

  transition:
    transform 0.12s ease,
    background-color 0.12s ease,
    border-color 0.12s ease,
    box-shadow 0.12s ease;
  font: inherit;

  /* Keep stable in header */
  flex: 0 0 auto;
}
.modal-close:hover {
  transform: translateY(-0.0625rem); /* -1px */
  border-color: rgba(92,200,255,0.35);
  box-shadow: 0 0.375rem 1.125rem rgba(92,200,255,0.28); /* 6px 18px */
}
.modal-close:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-color: var(--md-accent);
}

/* ---------------------------------
   BODY
---------------------------------- */
.modal-body {
  padding: var(--md-pad);
  display: grid;
  gap: var(--md-gutter);
  line-height: 1.6;

  /* Keeps body scrollable while header/footer stay fixed */
  max-height: calc(90vh - 2 * var(--md-pad) - 6rem); /* 96px */
  overflow-y: auto;

  overflow-wrap: break-word;
  min-width: 0;
}
.modal-body p { margin: 0; }
.modal-body p + p { margin-top: 0.375rem; } /* 6px */

.modal-body ul,
.modal-body ol {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.375rem; /* 6px */
  line-height: 1.55;
}
.modal-body ul.plain {
  list-style: none;
  padding-left: 0;
}
.modal-body a {
  color: inherit;
  text-underline-offset: 0.1875rem; /* 3px */
}
.modal-body a:hover { color: var(--md-accent); }

/* ---------------------------------
   ACTIONS (BASE)
---------------------------------- */
.modal .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem; /* 10px */
  min-width: 0;
}

/* ---------------------------------
   FOOTER
---------------------------------- */
.modal-footer {
  padding: calc(var(--md-pad) - 0.375rem) var(--md-pad); /* -6px */
  border-top: 1px solid var(--md-border);

  background: linear-gradient(0deg, rgba(255,255,255,0.06), transparent);
  display: flex;
  gap: 0.625rem; /* 10px */
  justify-content: flex-end;

  min-width: 0;
}

/* ---------------------------------
   BUTTONS (LOCAL ENHANCEMENTS) — SCOPED
---------------------------------- */
.modal .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  gap: 0.5rem; /* 8px */
  padding: 0.6875rem 1rem; /* 11px 16px */
  font-weight: 700;
  border-radius: 0.75rem; /* 12px */
  cursor: pointer;

  border: 1px solid transparent;
  text-decoration: none;

  font: inherit;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    background-color 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease;

  min-width: 0;
}

/* Primary CTA (Alias): unterstützt sowohl .btn-secondary (legacy) als auch .btn-primary */
.modal .btn-primary,
.modal .btn-secondary {
  background: linear-gradient(180deg, var(--md-accent), #8fdcff);
  color: var(--md-accent-ink);
  box-shadow: 0 0.375rem 1.125rem rgba(92,200,255,0.35); /* 6px 18px */
}
.modal .btn-primary:hover,
.modal .btn-secondary:hover { transform: translateY(-0.0625rem); } /* -1px */
.modal .btn-primary:active,
.modal .btn-secondary:active { transform: translateY(0); }

.modal .btn:disabled,
.modal .link-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* ---------------------------------
   LINK-BUTTONS — SCOPED
---------------------------------- */
.modal .link-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--md-border);
  color: var(--md-ink);

  padding: 0.5rem 0.75rem; /* 8px 12px */
  border-radius: 0.75rem; /* 12px */
  cursor: pointer;

  font: inherit;
  transition:
    transform 0.12s ease,
    background-color 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease,
    box-shadow 0.12s ease;

  min-width: 0;
}
.modal .link-btn:hover {
  background: rgba(92,200,255,0.10);
  border-color: rgba(92,200,255,0.35);
  transform: translateY(-0.0625rem); /* -1px */
}
.modal .link-btn:focus-visible,
.modal .btn:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-color: var(--md-accent);
}

/* ---------------------------------
   LANGUAGE SWITCH (SCOPED)
---------------------------------- */
.modal .modal-lang-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem; /* 4px */
  margin: 0.75rem 0 1.25rem; /* 12px 0 20px */
  font-size: 0.95rem;
}

.modal .modal-lang-switch .lang-pill-btn {
  padding: 0.25rem 0.75rem; /* 4px 12px */
  border-radius: 999px;
  border: 1px solid transparent;
  background: none;

  opacity: 0.8;
  cursor: pointer;

  font-family: inherit;
  font-size: inherit;
  line-height: 1.2;
  transition: opacity 0.12s ease, border-color 0.12s ease;
}
.modal .modal-lang-switch .lang-pill-btn:hover { opacity: 1; }
.modal .modal-lang-switch .lang-pill-btn.is-active {
  font-weight: 600;
  opacity: 1;
  border-color: rgba(148,163,184,0.65);
}
.modal .modal-lang-switch .lang-sep { opacity: 0.6; }

/* ---------------------------------
   REDUCED MOTION
---------------------------------- */
@media (prefers-reduced-motion: reduce) {
  [data-modal-backdrop],
  .modal { transition: none; }

  .modal-dialog { animation: none; transform: none; }

  .modal-close,
  .btn,
  .link-btn,
  .lang-pill-btn { transition: none; }
}

/* ---------------------------------
   PRINT
---------------------------------- */
@media print {
  [data-modal-backdrop],
  .modal { display: none !important; }
}

/* ---------------------------------
   MOBILE BOTTOM SHEET
---------------------------------- */
@media (max-width: 56.25rem) { /* 900px */
  [data-modal-backdrop] {
    -webkit-backdrop-filter: blur(0.25rem); /* 4px */
    backdrop-filter: blur(0.25rem);
  }

  .modal {
    place-items: end center;
    padding: 1rem; /* 16px */
    background: transparent;
  }

  .modal-dialog {
    width: 100%;
    max-width: 35rem; /* 560px */
    border-radius: 1rem 1rem 0.75rem 0.75rem; /* 16 16 12 12 */
    margin-bottom: 0.5rem; /* 8px */
    box-shadow: var(--md-shadow);
  }

  .modal .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem; /* 10px */
    margin-top: 0.75rem; /* 12px */
  }
}

@media (max-width: 32.5rem) { /* 520px */
  .modal-dialog { border-radius: 1rem; } /* 16px */
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: clamp(1rem, 4vw, 1.25rem); /* 16..20 */
  }

  /* Safety: more usable footer spacing on tiny devices */
  .modal-footer { gap: 0.5rem; } /* 8px */
}

@media (max-width: 26.25rem) { /* 420px */
  .modal .actions { grid-template-columns: 1fr; }
}

/* ---------------------------------
   SAFE AREA (iOS)
---------------------------------- */
@supports (padding: env(safe-area-inset-top)) {
  .safe-area {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ---------------------------------
   LANGUAGE MODAL — MOBILE SIZE
---------------------------------- */
@media (max-width: 40rem) { /* 640px */
  .modal[data-modal="language-modal"] {
    place-items: center;
    padding: 1rem; /* 16px */
  }

  .modal[data-modal="language-modal"] .modal-dialog {
    width: 100%;
    max-width: 20rem; /* 320px */
    border-radius: 0.9rem;
    padding: 0;
  }

  .modal[data-modal="language-modal"] .modal-header,
  .modal[data-modal="language-modal"] .modal-body,
  .modal[data-modal="language-modal"] .modal-footer {
    padding: 0.75rem 1rem;
  }

  .modal[data-modal="language-modal"] .modal-header h2 { font-size: 0.95rem; }

  .modal[data-modal="language-modal"] .modal-body {
    font-size: 0.9rem;
    line-height: 1.4;
  }

  .modal[data-modal="language-modal"] .modal-lang-switch {
    margin-top: 0.35rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
  }

  .modal[data-modal="language-modal"] .lang-pill-btn {
    padding: 0.35rem 0.9rem;
    font-size: 0.9rem;
  }

  .modal[data-modal="language-modal"] .modal-footer .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
  }
}

/* ---------------------------------
   Extra-small safety: <=380px
   - prevents header overflow and ensures buttons remain tappable
---------------------------------- */
@media (max-width: 23.75rem) { /* 380px */
  .modal-header h2 { font-size: 1.02rem; }
  .modal-close { inline-size: 2.375rem; block-size: 2.375rem; } /* 38px */
  .modal .btn { width: 100%; }
  .modal-footer { justify-content: stretch; }
}
