/* ============================================================
   PRAKTIKO - style_components-story.css
   Unternehmens-Storys: bunter Ring um Logos, Upload-Verwaltung
   und Vollbild-Story-Viewer.
   Global geladen über components/header.php.
   ============================================================ */

/* ── Story-Ring um Logos ───────────────────────────────────────
   Das Logo selbst wird zum Ring: 3-4 px animierter Verlauf, danach
   eine weiße Lücke, dann das eigentliche (runde) Logo. Durch das
   Verschachteln bleibt der Ring auch bei overflow:hidden-Logos
   sichtbar. Die Größe kommt weiterhin aus der jeweiligen Seite. */

/* Registrierung als Winkel, damit der Verlauf weich rotieren kann.
   Browser ohne @property zeigen einfach den statischen Verlauf. */
@property --story-ring-angle {
  syntax: '<angle>';
  initial-value: 210deg;
  inherits: false;
}

@keyframes story-ring-rotate {
  from { --story-ring-angle: 210deg; }
  to { --story-ring-angle: 570deg; }
}

@keyframes story-ring-halo {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.07); }
}

.story-ring {
  position: relative;
  box-sizing: border-box;
  padding: 3px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  cursor: pointer;
  /* Hebt das Logo vom Karten-/Bannerhintergrund ab. Das Logo selbst
     bleibt von der Ausbleich-Animation unberührt. */
  filter: drop-shadow(0 4px 12px rgba(15, 23, 42, 0.32));
  transition: transform 0.22s ease, filter 0.22s ease;
  -webkit-tap-highlight-color: transparent;
}

/* Der bunte Kreis liegt auf einer eigenen Ebene hinter dem Logo.
   Nur diese Ebene rotiert und bleicht aus – nie das Logo selbst. */
.story-ring::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: 50%;
  pointer-events: none;
  /* Bewusst hier deklariert: nur so greift der animierte Winkel. */
  --story-ring-gradient: conic-gradient(from var(--story-ring-angle), #ffd166 0%, #ff8a3d 22%, #f2578a 48%, #a855f7 72%, #4f7cff 88%, #ffd166 100%);
  background: var(--story-ring-gradient);
}

/* Rotation und Pochen NUR bei mindestens einer ungesehenen Story. */
.story-ring.has-unseen::before {
  animation: story-ring-rotate 6s linear infinite;
}

/* Bereits gesehen: nur der Kreis wird etwas ausgeblasster. */
.story-ring:not(.has-unseen)::before {
  filter: saturate(0.55) opacity(0.72);
}

/* Weicher Lichtschein; nur bei ungesehenen Storys atmend. */
.story-ring::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.2);
  pointer-events: none;
}

.story-ring.has-unseen::after {
  border-color: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 18px rgba(168, 85, 247, 0.45);
  animation: story-ring-halo 2.6s ease-in-out infinite;
}

.story-ring__gap,
.story-ring__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.story-ring__gap {
  position: relative;
  z-index: 1;
  padding: 3px;
  background: var(--color-surface);
}

.story-ring__logo {
  overflow: hidden;
  background: var(--color-surface);
  font-family: var(--font-display);
  font-weight: var(--weight-black);
}

.story-ring__logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-ring:hover,
.story-ring:focus-visible {
  transform: translateY(-2px) scale(1.05);
  filter: brightness(1.06) drop-shadow(0 10px 20px rgba(15, 23, 42, 0.42));
}

.story-ring:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 6px;
}

/* Firmenliste: Feature-Karten. Spezifität hoch genug, damit die
   Regeln aus style_firmen.css (inkl. Media Queries) überschrieben
   werden – Größe und Position bleiben dort unverändert. */
#companiesGrid .firm-logo.story-ring {
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.16);
  overflow: visible;
  cursor: pointer;
}

/* Initialen behalten ihren Firmen-Verlauf statt weißer Fläche */
#companiesGrid .story-ring__logo--initials {
  background-image: var(--firm-gradient, linear-gradient(135deg, #ede9fe, #ddd6fe));
}

/* Firmenliste: Raster-/Listenansicht (alte Karten) */
.company-logo.story-ring {
  padding: 3px;
  border-radius: 50%;
  background: transparent;
  box-shadow: var(--shadow-sm);
}

/* Eigenes Unternehmensprofil */
.profile-hero-avatar.story-ring {
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: var(--shadow-md);
  overflow: visible;
  cursor: pointer;
}

/* Öffentliches Firmenprofil (firma.php) */
.company-logo-large.story-ring {
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: var(--shadow-lg);
  overflow: visible;
  cursor: pointer;
}

/* Job-Detailseite (detail.php): Logo rund wie bei den anderen Stellen. */
.detail-logo.story-ring,
.similar-logo.story-ring {
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: var(--shadow-md);
  overflow: visible;
  cursor: pointer;
}

.similar-logo.story-ring {
  padding: 3px;
}

.similar-logo.story-ring .story-ring__gap {
  padding: 2px;
}

/* ── Upload-Verwaltung (Profil + Enterprise-Onboarding) ─────── */
.story-manager {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.story-manager__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
}

/* Icon und Titel links zusammenhalten, damit der Zähler rechts steht
   und der Titel linksbündig wie die übrigen Sektionsüberschriften bleibt. */
.story-manager__heading {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.story-manager__count {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-muted);
  background: var(--color-surface-3);
  border-radius: 999px;
  padding: 4px 12px;
}

.story-manager__hint {
  margin: 0;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border-left: 3px solid var(--color-primary);
  background: var(--color-primary-bg);
  color: var(--color-ink-2);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.story-manager__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: var(--space-3);
}

.story-manager__tile,
.story-manager__add {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.story-manager__tile {
  cursor: grab;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.story-manager__tile:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

.story-manager__tile.is-dragging {
  opacity: 0.45;
  cursor: grabbing;
  transform: scale(0.96);
}

.story-manager__tile:hover {
  box-shadow: var(--shadow-md);
}

.story-manager__tile {
  border: 1px solid var(--color-border);
  background: var(--color-surface-3);
}

.story-manager__tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.story-manager__remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.story-manager__remove:hover {
  background: var(--color-danger);
}

.story-manager__remove:focus-visible,
.story-manager__add:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* ── Pfeil-Buttons zum Verschieben ──────────────────────────── */
.story-manager__move {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  opacity: 0.75;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.story-manager__move--left { left: 4px; }
.story-manager__move--right { right: 4px; }

.story-manager__tile:hover .story-manager__move,
.story-manager__tile:focus-within .story-manager__move {
  opacity: 1;
}

@media (hover: none), (max-width: 768px) {
  .story-manager__move {
    opacity: 0.9;
  }
}

/* Auf Touch-Geräten (kein Hover) und kleinen Screens immer sichtbar. */
@media (hover: none), (max-width: 768px) {
  .story-manager__move {
    opacity: 0.85;
  }
}

.story-manager__move:hover {
  background: var(--color-primary);
}

.story-manager__move:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  opacity: 1;
}

.story-manager__add {
  border: 2px dashed var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  cursor: pointer;
  font-size: var(--text-xs, 0.75rem);
  font-weight: 700;
  text-align: center;
  line-height: 1.25;
}

.story-manager__add:hover:not(:disabled) {
  border-color: var(--color-primary);
  background: var(--color-primary-bg);
}

.story-manager__add:disabled,
.story-manager__add.is-full {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Statistik im Storys-Tab ────────────────────────────────── */
.story-stats-total {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.story-stats-total__item {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
}

.story-stats-total__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.story-stats-total__icon {
  flex: none;
  color: var(--color-primary);
}

.story-stats-total__item--visitors .story-stats-total__icon {
  color: #db2777;
}

.story-stats-total__value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--weight-black);
  color: var(--color-ink);
  line-height: 1.1;
}

.story-stats-total__label {
  font-size: var(--text-xs, 0.75rem);
  color: var(--color-muted);
}

.story-stats-total__item--current {
  border-color: rgba(236, 72, 153, 0.35);
  background: linear-gradient(180deg, rgba(236, 72, 153, 0.07), var(--color-surface-2));
}

/* ── Chart mit Zeitraumauswahl ───────────────────────────────── */
.story-chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.story-chart__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.story-chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  font-size: var(--text-xs, 0.75rem);
  color: var(--color-muted);
}

.story-chart__legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.story-chart__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.story-chart__dot--views { background: #7c3aed; }
.story-chart__dot--visitors { background: #f59e0b; }

.story-chart__periods {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}

.story-chart__period {
  padding: var(--space-1) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-muted);
  font-size: var(--text-xs, 0.75rem);
  font-weight: 600;
  cursor: pointer;
}

.story-chart__period:hover { color: var(--color-ink); }

.story-chart__period.is-active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-xs);
}

.story-chart__canvas-wrap {
  position: relative;
  width: 100%;
  height: 240px;
}

.story-chart__canvas-wrap canvas {
  width: 100%;
  height: 100%;
}

@media (max-width: 900px) {
  .story-stats-total {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 500px) {
  .story-stats-total {
    grid-template-columns: minmax(0, 1fr);
  }

  .story-chart__canvas-wrap {
    height: 200px;
  }

  .story-chart__head {
    flex-direction: column;
    align-items: flex-start;
  }
}

.story-stats-badge {
  position: absolute;
  left: 5px;
  bottom: 5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

.story-stats-badge__group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.story-stats-badge__group svg {
  flex: none;
  width: 13px;
  height: 13px;
}

.story-stats-badge__group--visitors {
  padding-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.32);
  color: #f9a8d4;
}

/* ── Rosa Aufmerksamkeits-Animation des Storys-Tabs ───────────
   Läuft einmal pro Seitenaufruf (Klasse im HTML), ohne Speicherung.
   Drei kräftige Impulse, damit die Funktion garantiert auffällt. */
@keyframes story-tab-shimmer {
  0%, 100% { box-shadow: 0 0 0 0 rgba(236, 72, 153, 0); background-color: transparent; }
  12% { box-shadow: 0 0 0 7px rgba(236, 72, 153, 0.42), 0 0 30px rgba(236, 72, 153, 0.9); background-color: rgba(236, 72, 153, 0.26); }
  30% { box-shadow: 0 0 0 2px rgba(236, 72, 153, 0.12), 0 0 10px rgba(236, 72, 153, 0.25); }
  48% { box-shadow: 0 0 0 9px rgba(236, 72, 153, 0.4), 0 0 36px rgba(236, 72, 153, 0.95); background-color: rgba(236, 72, 153, 0.3); }
  70% { box-shadow: 0 0 0 2px rgba(236, 72, 153, 0.1), 0 0 8px rgba(236, 72, 153, 0.2); }
  85% { box-shadow: 0 0 0 5px rgba(236, 72, 153, 0.3), 0 0 22px rgba(236, 72, 153, 0.7); }
}

.story-tab-highlight {
  animation: story-tab-shimmer 3.4s ease-out 0.3s 1;
}

/* ── Vollbild-Story-Viewer ──────────────────────────────────── */
/* Verhindert, dass Touch-Gesten im Viewer als Seiten-Scroll oder
   Pull-to-refresh interpretiert werden (side lädt sonst neu). */
body.story-viewer-open {
  overscroll-behavior: none;
}

.story-viewer,
.story-viewer__shell,
.story-viewer__stage {
  touch-action: none;
}

.story-viewer[hidden] {
  display: none;
}

.story-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.2s ease;
  font-family: var(--font-body, inherit);
}

.story-viewer.is-open {
  opacity: 1;
}

/* Beim Wischen nach unten soll der Viewer ohne Verzögerung dem Finger folgen. */
.story-viewer.is-swiping {
  transition: none;
}

.story-viewer__backdrop {
  position: absolute;
  inset: 0;
  background: #080d18;
}

.story-viewer__shell {
  position: relative;
  width: min(100%, 820px);
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  color: #fff;
}

.story-viewer__top {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 10px;
}

.story-viewer__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 52px;
  min-width: 0;
}

.story-viewer__avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  box-sizing: border-box;
  padding: 2px;
  border-radius: 50%;
  /* Statischer Verlauf: der Avatar im Viewer ist kein klickbarer Ring. */
  background: conic-gradient(from 210deg, #ffd166 0%, #ff8a3d 22%, #f2578a 48%, #a855f7 72%, #4f7cff 88%, #ffd166 100%);
  display: flex;
}

.story-viewer__avatar span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #080d18;
  font-size: var(--text-xs, 0.75rem);
  font-weight: 800;
}

.story-viewer__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.story-viewer__name-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  text-decoration: none;
  min-width: 0;
}

.story-viewer__name-link:hover .story-viewer__name,
.story-viewer__name-link:focus-visible .story-viewer__name {
  text-decoration: underline;
}

.story-viewer__arrow {
  flex: none;
  opacity: 0.85;
}

.story-viewer__name {
  font-size: var(--text-sm);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-viewer__segments {
  display: flex;
  gap: 4px;
  width: 100%;
}

/* Klickbarer Streifen: 16 px Trefferfläche, optisch bleibt der Balken
   3 px hoch. ::before = Spur, ::after = Fortschritt. */
.story-viewer__segment {
  position: relative;
  flex: 1;
  height: 16px;
  box-sizing: border-box;
  border: 0;
  padding: 6px 0;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.story-viewer__segment::before,
.story-viewer__segment::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  height: 3px;
  border-radius: 999px;
}

.story-viewer__segment::before {
  background: rgba(255, 255, 255, 0.3);
}

.story-viewer__segment::after {
  background: #fff;
  transform: scaleX(0);
  transform-origin: left center;
}

.story-viewer__segment:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.story-viewer__segment.is-done::after {
  transform: scaleX(1);
}

.story-viewer__segment.is-active::after {
  animation: story-progress 5s linear forwards;
}

.story-viewer__segment.is-paused.is-active::after {
  animation-play-state: paused;
}

@keyframes story-progress {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.story-viewer__close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 14px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.story-viewer__close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.story-viewer__stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.story-viewer__figure {
  margin: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* object-fit: contain zeigt Hoch- und Querformat immer vollständig
   und passend zum Display – ohne JS-Größenberechnung. */
.story-viewer__figure img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  /* Kein „Bild speichern"-Callout beim Halten auf Touch-Geräten. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.story-viewer__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.story-viewer__nav:hover {
  background: rgba(15, 23, 42, 0.85);
}

.story-viewer__nav--prev { left: 14px; }
.story-viewer__nav--next { right: 14px; }

.story-viewer__nav:disabled {
  opacity: 0.25;
  cursor: default;
}

.story-viewer__footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  font-size: var(--text-xs, 0.75rem);
  color: rgba(255, 255, 255, 0.72);
}

.story-viewer__counter {
  font-weight: 800;
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .story-ring,
  .story-ring.has-unseen::before,
  .story-ring.has-unseen::after,
  .story-tab-highlight {
    animation: none;
  }

  .story-ring {
    transition: none;
  }
}

@media (max-width: 480px) {
  .story-manager__grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }

  .story-viewer__shell {
    width: 100%;
  }

  .story-viewer__stage {
    padding: 0 6px;
  }

  /* Auf dem Handy keine Buttons – Navigation durch Tippen links/rechts. */
  .story-viewer__nav {
    display: none;
  }
}
