/* =====================================================================
   13. LOADING STATES
   Shimmer/skeleton placeholders during loading and generation.
   ===================================================================== */

/* Generic skeleton shimmer */
.m-skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-input) 25%,
    var(--bg-input-hover) 50%,
    var(--bg-input) 75%
  );
  background-size: 200% 100%;
  animation: m-shimmer 1.8s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes m-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Slide skeleton placeholder */
.m-slide-skeleton {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  background: linear-gradient(
    90deg,
    var(--bg-input) 25%,
    var(--bg-input-hover) 50%,
    var(--bg-input) 75%
  );
  background-size: 200% 100%;
  animation: m-shimmer 1.8s ease-in-out infinite;
  position: relative;
}

.m-gen-status {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  z-index: 5;
  text-align: center;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}

/* Shimmer overlay during generation (on top of feed) */
.m-shimmer-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.06) 30%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.06) 70%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: m-shimmer 2s ease-in-out infinite;
  border-radius: var(--radius);
}

[data-theme="dark"] .m-shimmer-overlay {
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.03) 30%,
    rgba(255, 255, 255, 0.06) 50%,
    rgba(255, 255, 255, 0.03) 70%,
    transparent 100%
  );
  background-size: 200% 100%;
}

/* Text skeleton lines */
.m-skeleton-line {
  height: 12px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.m-skeleton-line:last-child {
  margin-bottom: 0;
}

.m-skeleton-line.short {
  width: 60%;
}

.m-skeleton-line.medium {
  width: 80%;
}

/* ─── Enhanced Slide Shimmer (aurora + placeholders) ───── */

.m-slide-skeleton .m-slide-canvas-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  aspect-ratio: 16 / 9;
}

.m-shimmer-aurora {
  position: absolute;
  inset: -40%;
  background: conic-gradient(
    from 0deg at 50% 50%,
    #667eea, #764ba2, #f093fb, #4facfe,
    #00f2fe, #43e97b, #fa709a, #fee140, #667eea
  );
  filter: blur(80px);
  opacity: 0.25;
  animation: m-aurora-rotate 10s linear infinite;
}

[data-theme="dark"] .m-shimmer-aurora {
  opacity: 0.15;
}

@keyframes m-aurora-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.m-shimmer-sweep {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 30%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 70%
  );
  animation: m-sweep-move 3s ease-in-out infinite;
}

[data-theme="dark"] .m-shimmer-sweep {
  background: linear-gradient(
    105deg,
    transparent 30%,
    rgba(255, 255, 255, 0.08) 50%,
    transparent 70%
  );
}

@keyframes m-sweep-move {
  0% { transform: translateX(-130%); }
  100% { transform: translateX(130%); }
}

.m-shimmer-placeholders {
  position: absolute;
  inset: 0;
  padding: 12% 8%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.m-shimmer-ph {
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .m-shimmer-ph {
  background: rgba(255, 255, 255, 0.05);
}

.m-shimmer-ph-title {
  width: 55%;
  height: 14%;
  border-radius: 8px;
}

.m-shimmer-ph-subtitle {
  width: 35%;
  height: 7%;
  border-radius: 5px;
}

.m-shimmer-ph-body {
  display: flex;
  gap: 12px;
  flex: 1;
  margin-top: 6px;
}

.m-shimmer-ph-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

.m-shimmer-ph-line {
  height: 8px;
  border-radius: 4px;
}

.m-shimmer-ph-line:nth-child(1) { width: 92%; }
.m-shimmer-ph-line:nth-child(2) { width: 78%; }
.m-shimmer-ph-line:nth-child(3) { width: 85%; }
.m-shimmer-ph-line:nth-child(4) { width: 65%; }

.m-shimmer-ph-image {
  flex: 0 0 38%;
  border-radius: 8px;
}

/* ─── Skeleton appearance ──────────────────────────────────
 * Single uniform fade for the whole skeleton set. No
 * per-element stagger: the inner aurora + sweep already
 * telegraph "loading" loudly enough; cascading the outer
 * fade on top of that reads as "loading more loading."
 * Pure opacity, 200ms, ease-out. Boring and right.
 * ────────────────────────────────────────────────────────── */
.m-slide-skeleton {
  animation: m-skeleton-appear 200ms cubic-bezier(0.32, 0.72, 0, 1) backwards;
  background: none;
}

@keyframes m-skeleton-appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── Forward path: skeleton → real slide ──────────────────
 * One strong dimension (scale 0.985 → 1) carried by opacity.
 * No blur, no translate, no overshoot — Apple's reveal
 * language for sheet/icon entry: geometry settles into place,
 * fade leads it home.
 *
 * Triggered by JS toggling .m-slide-card-enter on the card
 * right after parentNode.replaceChild. Fire-and-forget — JS
 * does not await it, so the sequential render queue stays
 * parallel-safe (slide N+1 can start its own animation
 * before slide N finishes).
 *
 * Reload-mid-gen: snapshot-restored cards get
 * data-skip-anim="1" set BEFORE class application, which the
 * selector below excludes — instant reveal, no flickering
 * cascade of fade-ins on F5 during generation.
 * ────────────────────────────────────────────────────────── */
.m-slide-card-enter:not([data-skip-anim]) {
  animation: m-slide-card-enter 220ms cubic-bezier(0.32, 0.72, 0, 1) backwards;
  /* GPU hints: only composited properties animate. */
  will-change: opacity, transform;
}

@keyframes m-slide-card-enter {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ─── Reverse path: existing slides → fresh skeletons ──────
 * When user asks "перепиши слайд 3" / "доработай" the feed
 * gets reset and rebuilt with skeletons. Cards fade out
 * (opacity-led, scale 1 → 0.985 mirrors the enter pole),
 * then JS clears and skeletons fade in.
 *
 * 160ms exit + 200ms skeleton fade = ~360ms total reset.
 * Quick acknowledgement, not a ceremony. No translate — exit
 * direction was unmotivated (slides don't go "up" in this
 * UI), pure opacity reads cleaner.
 * ────────────────────────────────────────────────────────── */
.m-slide-card-exit {
  animation: m-slide-card-exit 160ms cubic-bezier(0.4, 0, 1, 1) forwards;
  pointer-events: none;
  will-change: opacity, transform;
}

@keyframes m-slide-card-exit {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.985);
  }
}

/* ─── prefers-reduced-motion: collapse to instant ──────── */
@media (prefers-reduced-motion: reduce) {
  .m-slide-skeleton,
  .m-slide-card-enter:not([data-skip-anim]),
  .m-slide-card-exit {
    animation: none !important;
  }
  .m-slide-card-exit {
    /* Still hide instantly so the JS clear path looks consistent. */
    opacity: 0;
  }
}

/* ─── Generation Progress Bar (in slide counter area) ───── */

.m-gen-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 9999;
  background: var(--border);
  overflow: hidden;
}

.m-gen-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.6s ease;
  border-radius: 0 2px 2px 0;
}

/* ─── Reassurance Cards (mobile-optimized) ───── */

.m-reassurance {
  position: fixed;
  top: 16px;
  right: 16px;
  left: auto;
  z-index: 10001;
  width: 280px;
  max-width: calc(100vw - 32px);
  padding: 14px 16px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(0, 0, 0, 0.10);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.06);
  font-family: var(--font-body);
  animation: m-reassurance-in 0.4s var(--ease-spring);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

[data-theme="dark"] .m-reassurance {
  background: rgba(30, 30, 34, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.40), 0 2px 8px rgba(0, 0, 0, 0.25);
}

.m-reassurance.fade-out {
  animation: m-reassurance-out 0.3s ease forwards;
}

.m-reassurance-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  line-height: 1.3;
}

.m-reassurance-body {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
}

.m-reassurance-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.m-reassurance-close:active {
  background: var(--bg-hover);
  color: var(--text-1);
}

.m-reassurance-mute {
  align-self: flex-end;
  padding: 4px 10px;
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-3);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 2px;
}

[data-theme="dark"] .m-reassurance-mute {
  border-color: rgba(255, 255, 255, 0.12);
}

@keyframes m-reassurance-in {
  from { transform: translateX(40px) scale(0.95); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes m-reassurance-out {
  to { transform: translateX(40px) scale(0.95); opacity: 0; }
}

/* ─── Chat Shimmer Message ───── */

.m-chat-shimmer {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg-input);
  border: 1px solid var(--border);
  position: relative;
  overflow: visible;
}

.m-chat-shimmer .m-shimmer-text {
  display: block;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 13px;
  background: linear-gradient(
    90deg,
    #7b7f94 0%,
    #7b7f94 35%,
    var(--text-0) 50%,
    #7b7f94 65%,
    #7b7f94 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: m-text-shimmer 2s ease-in-out infinite;
}

[data-theme="dark"] .m-chat-shimmer .m-shimmer-text {
  background: linear-gradient(
    90deg,
    #8e8e96 0%,
    #8e8e96 35%,
    #f0f0f3 50%,
    #8e8e96 65%,
    #8e8e96 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

@keyframes m-text-shimmer {
  0% { background-position: 100% center; }
  100% { background-position: 0% center; }
}

.m-chat-shimmer .m-shimmer-progress {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border);
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
}

.m-chat-shimmer .m-shimmer-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.6s ease;
}

.m-shimmer-trail {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  margin-top: 4px;
}

.m-trail-step {
  font-size: 11px;
  color: var(--text-3);
  opacity: 0;
  line-height: 1.3;
  animation: m-trail-fade-in 0.3s ease-out forwards;
}

@keyframes m-trail-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 0.5; transform: translateY(0); }
}

/* Single-slide failed during V2 progressive generation. Keeps the skeleton
 * shape but fades the shimmer and surfaces the error message inline. The
 * `.m-gen-status` text is already injected by markSlideSkeletonError(). */
.m-slide-skeleton-error .m-shimmer-aurora,
.m-slide-skeleton-error .m-shimmer-sweep {
  animation-play-state: paused;
  opacity: 0.18;
}

.m-slide-skeleton-error {
  border: 1px solid color-mix(in srgb, var(--accent-error, #d22) 30%, transparent);
}

.m-slide-skeleton-error .m-gen-status {
  color: var(--accent-error, #d22);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  padding: 8px 16px;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}


