/* ============================================================
   PRAKTIKO - style_components-crop-modal.css
   Bildzuschnitt-Dialog (Logo / Banner / Profilbild).

   Wird von assets/js/image-upload.js komplett selbst aufgebaut
   (createCropModal) und deshalb auf ALLEN Seiten einheitlich
   verwendet: unternehmensprofil.php, enterprise-onboarding.php,
   profil.php, onboarding.php. Kein Markup in den PHP-Seiten.

   Das geerbte Seitenverhaeltnis kommt aus PHP
   (core/functions.php -> getBannerAspectRatio()), wird als
   CSS-Variable --banner-aspect gesetzt und gilt fuer:
     - die Anzeige-Container (.profile-hero-banner, .ob-banner-preview-co)
     - die Vorschau-Rahmen im Dialog
   Crop-Rahmen, Ausgabe-Pixel und Anzeige sind dadurch garantiert
   identisch — daher ist die Vorschau exakt das, was danach zu sehen ist.
   ============================================================ */

/* ── Dialog ─────────────────────────────────────────────────── */

@keyframes crop-spin {
  to {
    transform: rotate(360deg);
  }
}

.anim-spin {
  animation: crop-spin 0.8s linear infinite;
}

.crop-modal {
  max-width: 46rem;
}

/* .modal-body ist ein Flex-Column mit overflow-y: auto. Ohne
   flex-shrink: 0 quetschen die Kinder statt zu scrollen — die Crop-Buehne
   wird dann winzig und die Vorschau kollabiert auf 0 px Hoehe. */
.crop-modal-body>* {
  flex-shrink: 0;
}

.crop-modal-heading {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.crop-modal-heading-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

.crop-modal-subtitle {
  margin: 2px 0 0;
  font-size: var(--text-xs);
  color: var(--color-muted);
}

/* ── Buehne (Cropper) ───────────────────────────────────────────
   Cropper.js 1.x misst seinen Arbeitsbereich aus dem ELTERNelement
   des <img> (.crop-modal-image-wrap) — nicht aus dem Bild selbst
   (das Original-<img> wird auf display:none gesetzt). Deshalb bekommt
   der Wrap seine Groesse hier explizit ueber aspect-ratio + max-height
   und NICHT ueber die Bildhoehe. Ohne diese Festlegung misst Cropper
   0 bzw. greift auf minContainerWidth/Height zurueck und der
   Crop-Rahmen wird am unteren Rand abgeschnitten bzw. zeigt ein
   voellig anderes Format als das Ergebnis.

   Das aspect-ratio der Buehne folgt NICHT dem Banner-Format,
   sondern dem Format des gewaehlten Ausgangsbildes
   (--crop-stage-aspect, setzt image-upload.js). Grund: Cropper legt
   das Bild bei viewMode 0 "contain" in die Buehne. Passt die Buehne
   zum Banner (flach), bleibt bei einem 4:3-Foto die halbe Buehne
   leer und der 3:1-Crop-Rahmen klebt winzig mittig drin. Eine
   Buehne im Bildformat laesst das Bild die Buehne fuellen und
   laesst genau so viel Spielraum fuer das Verschieben, wie das Bild
   hergibt. Das Banner-Format steckt weiterhin im Crop-Rahmen. */

.crop-modal-stage {
  position: relative;
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--color-surface-3);
  overflow: hidden;
}

.crop-modal-image-wrap {
  position: relative;
  width: 100%;
  max-width: var(--crop-stage-max-width, 100%);
  margin-inline: auto;
  aspect-ratio: var(--crop-stage-aspect, 4 / 3);
  max-height: min(46vh, 420px);
  overflow: hidden;
  border-radius: var(--radius-md);
}

.crop-modal-hint {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-muted);
  text-align: center;
}

/* ── Werkzeugleiste: Zoom + Drehen + Zuruecksetzen ───────────── */

.crop-modal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
}

.crop-tool-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.crop-tool-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-ink-2);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.crop-tool-btn:hover {
  background: var(--color-surface-3);
  color: var(--color-ink);
}

.crop-tool-btn:active {
  transform: translateY(1px);
}

.crop-zoom {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1 1 180px;
  min-width: 0;
}

.crop-zoom-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  color: var(--color-muted);
  flex-shrink: 0;
}

.crop-zoom-range {
  flex: 1;
  min-width: 90px;
  height: 22px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.crop-zoom-value {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--color-ink);
  min-width: 2.6em;
  text-align: right;
  flex-shrink: 0;
}

/* ── Vorschau ───────────────────────────────────────────────────
   Zeigt exakt den Ausschnitt, der gespeichert wird — einmal in der
   Breite des Hero-Banners und einmal so schmal wie am Handy. Damit
   wird sichtbar, was "Ausfuellen (Cover)" auf kleinen Bildschirmen
   abschneidet bzw. wo "Einpassen (Contain)" die Farbe zeigen muss. */

.crop-modal-preview {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  overflow: hidden;
}

.crop-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.crop-preview-title {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--color-ink);
}

.crop-preview-note {
  font-size: var(--text-2xs, 0.6875rem);
  color: var(--color-muted);
  text-align: right;
}

.crop-preview-stage {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
}

.crop-preview-frame {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  /* --crop-preview-color kommt aus dem Farbwähler und zeigt in
     contain-Modus genau die Farbe, die auch live am Banner erscheint. */
  background-color: var(--crop-preview-color, #ffffff);
}

.crop-preview-frame-wide {
  flex: 1;
  min-width: 0;
  aspect-ratio: var(--banner-aspect, 4 / 1);
}

.crop-preview-frame-narrow {
  /* Bewusst NICHT das Banner-Format: der Hero wechselt am Handy auf 16:9
     (style_components-profile-hero.css, ohne Kappung, also konstant).
     Erst dadurch wird sichtbar, was
     "Ausfuellen (Cover)" dort abschneidet bzw. wo "Einpassen (Contain)"
     die Randfarbe zeigen muss. Weil das Verhaeltnis auf jedem Handy und
     Tablet identisch ist, stimmt dieser Rahmen exakt. */
  width: 104px;
  flex-shrink: 0;
  aspect-ratio: 16 / 7;
}

.crop-preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.crop-preview-stage[data-fit="contain"] .crop-preview-canvas {
  object-fit: contain;
}

.crop-preview-devices {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  flex-shrink: 0;
}

.crop-preview-devices[hidden] {
  display: none;
}

.crop-preview-device {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.crop-preview-device figcaption {
  font-size: var(--text-2xs, 0.6875rem);
  color: var(--color-muted);
  text-align: center;
}

/* Leerlauf, solange das Bild noch geladen wird */
.crop-preview-frame.is-empty::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--color-surface-3) 25%, var(--color-surface-2) 50%, var(--color-surface-3) 75%);
  background-size: 200% 100%;
  animation: crop-preview-shimmer 1.2s linear infinite;
}

@keyframes crop-preview-shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ── Fit-Modus + Hintergrundfarbe ─────────────────────────────── */

.crop-modal-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  flex-wrap: wrap;
}

.crop-modal-controls[hidden] {
  display: none;
}

.crop-fit-toggle {
  display: flex;
  gap: var(--space-2);
  padding: 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.crop-fit-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  flex: 1 1 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.crop-fit-option input {
  margin: 0;
  accent-color: var(--color-primary);
  flex-shrink: 0;
}

.crop-fit-option span {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.crop-fit-option strong {
  color: var(--color-ink);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.crop-fit-option small {
  color: var(--color-muted);
  font-size: var(--text-2xs, 0.6875rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crop-fit-option:has(input:checked) {
  background: var(--color-surface);
  border-color: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ── Hintergrundfarbe + Pipette ──────────────────────────────── */

.crop-modal-color-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* Nur relevant bei "Einpassen" — bei "Ausfuellen" wird nichts
   weggeschnitten und die Farbe kommt im Ergebnis nie vor. */
.crop-modal-controls.is-cover .crop-modal-color-group {
  display: none;
}

.crop-color-picker {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  cursor: pointer;
}

.crop-color-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.crop-color-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-muted);
}

.crop-color-label {
  font-size: var(--text-2xs, 0.6875rem);
  color: var(--color-muted);
  line-height: 1.2;
}

.crop-color-value {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: 0.02em;
  color: var(--color-ink);
  line-height: 1.2;
}

.crop-color-picker input[type="color"] {
  width: 40px;
  height: 32px;
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.crop-color-picker input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.crop-color-picker input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.crop-color-picker input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 4px;
}

.crop-eyedropper-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-ink-2);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.crop-eyedropper-btn:hover {
  background: var(--color-surface-3);
  color: var(--color-ink);
}

.crop-eyedropper-btn[hidden] {
  display: none;
}

/* ── Fusszeile: Metadaten links, Aktionen rechts ─────────────── */

.crop-modal-meta {
  flex: 1;
  min-width: 0;
  font-size: var(--text-xs);
  color: var(--color-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Ziel-Container (Standard-Aktualisierung ohne Neuladen) ───── */

/* Damit ein per applyToPage() eingefuegtes <img> genauso sitzt wie ein
   server-gerendertes (style="width:100%;height:100%;object-fit:cover"). */
[data-image-upload-preview]>img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Aktionen, die erst nach einem Upload sinnvoll sind (z. B. "Loeschen").
   Ohne diese Regel heben Klassen mit eigener display-Angabe (.btn,
   .profile-hero-avatar-edit) das hidden-Attribut auf. */
[data-image-upload-actions][hidden] {
  display: none !important;
}

[data-image-upload-drop].is-dragover {
  outline: 2px dashed var(--color-primary);
  outline-offset: 2px;
}

/* ── Handy ───────────────────────────────────────────────────── */

@media (max-width: 640px) {

  /* Weniger Rahmen = mehr Buehne. Der Knopfbereich bleibt bewusst
     zweispaltig und waagerecht (siehe unten). */
  #cropModalOverlay {
    padding: var(--space-2);
  }

  .crop-modal {
    max-width: 100%;
    max-height: min(94dvh, 100dvh - 1rem);
  }

  .crop-modal .modal-header {
    padding: var(--space-3) var(--space-4);
  }

  .crop-modal .modal-body {
    padding: var(--space-3);
    gap: var(--space-3);
  }

  /* Kopf einzeilig halten: "Unternehmensbanner anpassen" passt dann,
     ohne dass der Titel umbricht. */
  .crop-modal-heading {
    gap: var(--space-2);
  }

  .crop-modal-heading-icon {
    width: 30px;
    height: 30px;
  }

  .crop-modal .modal-title {
    font-size: var(--text-base);
  }

  .crop-modal-subtitle {
    font-size: var(--text-2xs, 0.6875rem);
  }

  .crop-modal-stage {
    padding: var(--space-2);
  }

  /* Am Handy wird die Buehne bewusst hoeher als das Bildformat: ein
     3:1-Banner ist sonst nur wenige Pixel hoch und laesst kaum Platz
     zum Verschieben. Der Crop-Rahmen bleibt unveraendert beim
     Banner-Format. */
  .crop-modal-image-wrap {
    aspect-ratio: auto;
    height: clamp(200px, 30vh, 280px);
  }

  .crop-modal-hint {
    font-size: var(--text-2xs, 0.6875rem);
    line-height: 1.4;
  }

  /* Werkzeugleiste: Drehen oben, Zoombalken darueber ueber die
     volle Breite — Touch-Ziele bleiben >= 42 px. */
  .crop-modal-toolbar {
    padding: var(--space-2);
    gap: var(--space-2);
  }

  .crop-tool-btn {
    width: 44px;
    height: 44px;
  }

  .crop-zoom {
    flex: 1 1 100%;
    order: 2;
    gap: var(--space-2);
  }

  .crop-zoom-range {
    height: 32px;
  }

  /* Vorschau: Hinweis unter die Ueberschrift statt daneben, damit er
     nicht in zwei winzige Zeilen zerhackt wird. */
  .crop-preview-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
  }

  .crop-preview-note {
    text-align: left;
    line-height: 1.4;
  }

  .crop-preview-stage {
    padding: var(--space-3);
    gap: var(--space-3);
  }

  .crop-preview-frame-narrow {
    width: 88px;
  }

  /* Fit-Modus: untereinander statt nebeneinander, sonst zerbricht der
     Text auf dem Handy in drei bis vier Zeilen. */
  .crop-modal-controls {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    padding: var(--space-3);
  }

  .crop-fit-toggle {
    flex-direction: column;
    gap: var(--space-2);
  }

  .crop-fit-option {
    flex: none;
    width: 100%;
    padding: var(--space-3);
  }

  .crop-fit-option small {
    font-size: var(--text-xs);
  }

  .crop-modal-color-group {
    flex-wrap: nowrap;
  }

  .crop-color-picker {
    flex: 1;
    min-width: 0;
    padding: var(--space-2);
  }

  .crop-eyedropper-btn {
    width: 44px;
    height: 44px;
  }

  /* Metazeile ist redundant (Format steht schon im Kopf). */
  .crop-modal-footer-meta {
    display: none;
  }
}

/* Sehr schmale Geraete (bis 380 px) */
@media (max-width: 380px) {

  .crop-zoom-label,
  .crop-modal-hint {
    font-size: var(--text-2xs, 0.6875rem);
  }

  .crop-preview-frame-narrow {
    width: 72px;
  }
}