/* ─────────────────────────────────────────────────────────────────
   WB-536 (وحش بلال 2026-05-25): Extracted lipsync modal CSS.
   Source: static/css/cinema_studio.css (rules touching .cs-lipsync-*).
   Why: the lipsync modal needs to be reused on /create/video page
   without loading the entire cinema_studio.css (which has class
   collisions with the video page's existing styles).
   Auto-generated by .wb536_extract_lipsync_css.py — do not hand-edit.
   ───────────────────────────────────────────────────────────────── */


.cs-lipsync-overlay {
  position: fixed;
  inset: 0;
  z-index: 11500;
  background: rgba(3, 4, 9, 0.86);
  backdrop-filter: blur(14px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.cs-lipsync-box {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  background: linear-gradient(180deg,
    rgba(18, 19, 32, 0.98), rgba(8, 9, 16, 0.98));
  border: 1px solid rgba(168, 85, 247, 0.32);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  direction: rtl;
}

.cs-lipsync-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.cs-lipsync-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #d8b4fe;
  text-shadow: 0 0 12px rgba(168, 85, 247, 0.35);
}

.cs-lipsync-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
}

.cs-lipsync-close:hover { color: rgba(255, 255, 255, 0.9); }

.cs-lipsync-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cs-lipsync-player {
  width: 100%;
  max-height: 50vh;
  background: #000;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cs-lipsync-slider-wrap,
.cs-lipsync-audio-wrap,
.cs-lipsync-tier-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cs-lipsync-slider-label,
.cs-lipsync-audio-label,
.cs-lipsync-tier-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 600;
}

.cs-lipsync-slider { width: 100%; accent-color: #a855f7; }

.cs-lipsync-slider-info {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  text-align: start;
}

/* WB-464 (وحش بلال 2026-05-20): trimmer-style timeline modelled after
   iOS Photos / WhatsApp / Instagram. Thumbnails from the live video
   (via canvas — see _extractTrimmerThumbs in JS) make the strip; two
   vertical white grip handles overlay the strip; the region outside
   the selected window dims so the chosen segment pops. */
.cs-lipsync-range {
  position: relative;
  margin: 28px 4px 36px;   /* room for bubbles top/bottom */
  user-select: none;
  -webkit-user-select: none;
}

.cs-lipsync-range[hidden] { display: none; }


.cs-lipsync-trimmer-strip {
  position: relative;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  /* Fallback gradient if thumbnail extraction fails (CORS-tainted canvas). */
  background:
    linear-gradient(90deg,
      rgba(168, 85, 247, 0.32),
      rgba(126, 34, 206, 0.32),
      rgba(168, 85, 247, 0.32));
}


.cs-lipsync-trimmer-frames {
  display: flex;
  height: 100%;
  width: 100%;
}

.cs-lipsync-trimmer-frame {
  flex: 1;
  min-width: 0;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  border-inline-start: 1px solid rgba(0, 0, 0, 0.25);
}

.cs-lipsync-trimmer-frame:first-child { border-inline-start: none; }


.cs-lipsync-trimmer-dim {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(8, 9, 16, 0.58);
  pointer-events: none;
  z-index: 2;
}

.cs-lipsync-trimmer-dim--left  { left: 0; }

.cs-lipsync-trimmer-dim--right { right: 0; }


.cs-lipsync-trimmer-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-top: 3px solid #fff;
  border-bottom: 3px solid #fff;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.3),
    0 0 14px rgba(168, 85, 247, 0.5);
  pointer-events: none;
  z-index: 3;
}


.cs-lipsync-trimmer-handle {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 14px;
  background: #fff;
  border-radius: 5px;
  cursor: ew-resize;
  z-index: 5;
  transform: translateX(-50%);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.3),
    0 6px 18px rgba(168, 85, 247, 0.45);
  transition: transform 0.1s, box-shadow 0.15s;
}

.cs-lipsync-trimmer-handle:hover,
.cs-lipsync-trimmer-handle:focus-visible {
  outline: none;
  transform: translateX(-50%) scaleY(1.05);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.4),
    0 8px 24px rgba(168, 85, 247, 0.6);
}

.cs-lipsync-trimmer-handle.is-dragging {
  cursor: grabbing;
  transform: translateX(-50%) scaleY(1.08);
}

.cs-lipsync-trimmer-handle::before {
  /* Small inward grip mark — three dim horizontal lines feel. */
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 22px;
  background: rgba(120, 120, 140, 0.85);
  border-radius: 2px;
  box-shadow:
    0 -7px 0 rgba(120, 120, 140, 0.85),
    0  7px 0 rgba(120, 120, 140, 0.85);
}


.cs-lipsync-trimmer-bubble {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  color: #f3e8ff;
  background: rgba(168, 85, 247, 0.22);
  border: 1px solid rgba(168, 85, 247, 0.55);
  padding: 3px 7px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  z-index: 6;
  text-shadow: 0 0 8px rgba(168, 85, 247, 0.4);
}

.cs-lipsync-trimmer-bubble--start { bottom: calc(100% + 8px); }

.cs-lipsync-trimmer-bubble--end   { top:    calc(100% + 8px); }

.cs-lipsync-audio-input {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.85);
  padding: 10px;
  border-radius: 8px;
  border: 1px dashed rgba(168, 85, 247, 0.32);
}

.cs-lipsync-audio-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

/* WB-465 (وحش بلال 2026-05-20): audio playback + trim. Mirrors the video
   trimmer styling but with a synthetic purple bar in place of frames. */
.cs-lipsync-audio-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.cs-lipsync-audio-section[hidden] { display: none; }

.cs-lipsync-audio-player {
  width: 100%;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  accent-color: #a855f7;
}

.cs-lipsync-audio-trim {
  position: relative;
  margin: 24px 4px 30px;
  user-select: none;
  -webkit-user-select: none;
}

.cs-lipsync-audio-strip {
  position: relative;
  height: 38px;
  border-radius: 6px;
  overflow: hidden;
  /* Decorative purple bar — now only a FALLBACK behind the WB-481 canvas
     waveform (shows if decodeAudioData can't handle the uploaded codec). */
  background:
    linear-gradient(90deg,
      rgba(168, 85, 247, 0.55) 0%,
      rgba(126, 34, 206, 0.55) 50%,
      rgba(168, 85, 247, 0.55) 100%),
    repeating-linear-gradient(90deg,
      rgba(255, 255, 255, 0.08) 0px,
      rgba(255, 255, 255, 0.08) 1px,
      transparent 1px,
      transparent 8px);
}

/* WB-481 (وحش بلال 2026-05-20): real decoded waveform. Fills the strip and
   sits at the bottom of the stacking order — the dim overlays + fill + grip
   handles are appended AFTER it in the DOM, so they render on top (the
   selected window stays bright, the rest is dimmed). pointer-events:none so
   drags pass through to the handles. */
.cs-lipsync-audio-wave {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  pointer-events: none;
}

.cs-lipsync-audio-dim {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(8, 9, 16, 0.62);
  pointer-events: none;
  z-index: 2;
}

.cs-lipsync-audio-dim--left  { left: 0; }

.cs-lipsync-audio-dim--right { right: 0; }

.cs-lipsync-audio-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-top: 2px solid #fff;
  border-bottom: 2px solid #fff;
  pointer-events: none;
  z-index: 3;
}

.cs-lipsync-audio-handle {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 12px;
  background: #fff;
  border-radius: 4px;
  cursor: ew-resize;
  z-index: 5;
  transform: translateX(-50%);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.3),
    0 4px 14px rgba(168, 85, 247, 0.4);
}

.cs-lipsync-audio-handle:hover,
.cs-lipsync-audio-handle:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.4),
    0 6px 18px rgba(168, 85, 247, 0.6);
}

.cs-lipsync-audio-handle.is-dragging {
  cursor: grabbing;
}

.cs-lipsync-audio-handle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 16px;
  background: rgba(120, 120, 140, 0.85);
  border-radius: 1px;
}

.cs-lipsync-audio-bubble {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  color: #f3e8ff;
  background: rgba(168, 85, 247, 0.22);
  border: 1px solid rgba(168, 85, 247, 0.55);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  z-index: 6;
}

.cs-lipsync-audio-bubble--start { bottom: calc(100% + 6px); }

.cs-lipsync-audio-bubble--end   { top:    calc(100% + 6px); }

.cs-lipsync-tier-group { display: flex; gap: 6px; }

.cs-lipsync-tier-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.75);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.cs-lipsync-tier-btn:hover { background: rgba(168, 85, 247, 0.12); }

.cs-lipsync-tier-btn.is-active {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.32),
    rgba(168, 85, 247, 0.16));
  border-color: rgba(168, 85, 247, 0.6);
  color: #f3e8ff;
}

.cs-lipsync-cost {
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  text-align: start;
}

.cs-lipsync-cost strong {
  color: #d8b4fe;
  font-size: 16px;
  margin-inline: 4px;
}

.cs-lipsync-foot {
  display: flex;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.cs-lipsync-btn {
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s, transform 0.1s;
}

.cs-lipsync-btn--primary {
  background: linear-gradient(135deg, #a855f7, #7e22ce);
  color: #fff;
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.35);
  flex: 1;
}

.cs-lipsync-btn--primary:hover:not(:disabled) { transform: translateY(-1px); }

.cs-lipsync-btn--primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.cs-lipsync-btn--ghost {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  border-color: rgba(255, 255, 255, 0.14);
}

.cs-lipsync-btn--ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }


.cs-lipsync-result-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  background: rgba(3, 4, 9, 0.86);
  backdrop-filter: blur(14px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.cs-lipsync-result-box {
  width: 100%;
  max-width: 560px;
  background: linear-gradient(180deg,
    rgba(18, 19, 32, 0.98), rgba(8, 9, 16, 0.98));
  border: 1px solid rgba(168, 85, 247, 0.32);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  direction: rtl;
}

.cs-lipsync-result-title {
  margin: 0;
  font-size: 17px;
  color: #d8b4fe;
  text-align: start;
  font-weight: 700;
}

.cs-lipsync-result-video {
  width: 100%;
  max-height: 60vh;
  border-radius: 10px;
  background: #000;
}

.cs-lipsync-result-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
}

/* (req 4) video filmstrip must read left→right so frame 0 = left edge,
   matching the timeline + drag handles (the RTL page was flipping it). */
.cs-lipsync-trimmer-frames { direction: ltr !important; }

/* (req 6) native <audio controls> is gone — playback is via the cyan button. */
.cs-lipsync-audio-player { display: none !important; }

/* (req 5 + 6) put a play button beside each strip: make the wrappers flex. */
.cs-lipsync-range,
.cs-lipsync-audio-trim {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
}

.cs-lipsync-range .cs-lipsync-trimmer-strip,
.cs-lipsync-audio-trim .cs-lipsync-audio-strip {
  flex: 1 1 auto !important;
  min-width: 0 !important;
}

/* cyan circular play / pause button */
.cs-lipsync-play-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(111, 228, 254, 0.55);
  background: rgba(111, 228, 254, 0.12);
  color: #6FE4FE;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding-left: 2px;            /* optical-center the ▶ glyph */
  transition: background .15s, transform .12s, box-shadow .15s;
}

.cs-lipsync-play-btn:hover {
  background: rgba(111, 228, 254, 0.22);
  transform: scale(1.06);
  box-shadow: 0 0 14px rgba(111, 228, 254, 0.40);
}

.cs-lipsync-play-btn.is-playing {
  padding-left: 0;
  background: rgba(111, 228, 254, 0.30);
  box-shadow: 0 0 16px rgba(111, 228, 254, 0.55);
}

/* (req 7) cyan accent pass — tidy, cohesive Cinema-Studio cyan theme. */
.cs-lipsync-box {
  border: 1px solid rgba(111, 228, 254, 0.28) !important;
  box-shadow:
    0 24px 70px -20px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(111, 228, 254, 0.06) inset,
    0 0 40px -18px rgba(111, 228, 254, 0.45) !important;
}

.cs-lipsync-slider-label,
.cs-lipsync-audio-label,
.cs-lipsync-tier-label {
  color: #A7F3F9 !important;
  letter-spacing: 0.01em;
}

.cs-lipsync-trimmer-strip,
.cs-lipsync-audio-strip {
  border: 1px solid rgba(111, 228, 254, 0.22) !important;
}

.cs-lipsync-trimmer-handle,
.cs-lipsync-audio-handle {
  background: #6FE4FE !important;
  box-shadow: 0 0 10px rgba(111, 228, 254, 0.6) !important;
}

.cs-lipsync-tier-btn.is-active {
  border-color: rgba(111, 228, 254, 0.6) !important;
  background: rgba(111, 228, 254, 0.16) !important;
  color: #6FE4FE !important;
}

.cs-lipsync-btn--primary {
  background: linear-gradient(135deg, #6FE4FE 0%, #38bdf8 60%, #0ea5e9 100%) !important;
  color: #04222b !important;
  border: none !important;
  box-shadow: 0 8px 22px -8px rgba(111, 228, 254, 0.65) !important;
}

.cs-lipsync-btn--primary:disabled { opacity: 0.5 !important; box-shadow: none !important; }

/* (3)+(4) move the play buttons to the LEFT of each strip. In the RTL flex
   row, order:0 items sit at the right (main-start); a higher order pushes the
   button to the left edge. */
.cs-lipsync-range .cs-lipsync-play-btn,
.cs-lipsync-audio-trim .cs-lipsync-play-btn { order: 1 !important; }

/* (1) cyan upload button replacing the native file picker */
.cs-lipsync-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 10px;
  border: 1px solid rgba(111, 228, 254, 0.5);
  background: rgba(111, 228, 254, 0.10);
  color: #6FE4FE;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .12s, box-shadow .15s;
}

.cs-lipsync-upload-btn:hover {
  background: rgba(111, 228, 254, 0.20);
  transform: translateY(-1px);
  box-shadow: 0 0 14px rgba(111, 228, 254, 0.35);
}

.cs-lipsync-upload-name {
  margin-inline-start: 12px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
  vertical-align: middle;
}

/* (2) prominent length-mismatch warning box */
.cs-lipsync-slider-info--warn {
  margin-top: 8px !important;
  background: rgba(245, 158, 11, 0.12) !important;
  border: 1px solid rgba(245, 158, 11, 0.5) !important;
  border-radius: 10px !important;
  padding: 10px 13px !important;
  color: #fcd9a0 !important;
  font-weight: 600 !important;
  font-size: 12.5px !important;
  line-height: 1.55 !important;
}

/* (5) playhead cursor — a thin white line that tracks playback */
.cs-lipsync-playhead {
  position: absolute;
  top: 0; bottom: 0;
  left: 0;
  width: 2px;
  background: #ffffff;
  box-shadow: 0 0 8px rgba(111, 228, 254, 0.95), 0 0 2px #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 8;
  transition: opacity .15s;
}

.cs-lipsync-playhead.is-active { opacity: 1; }

/* (6) cost line → cyan theme */
.cs-lipsync-cost {
  color: #A7F3F9 !important;
  background: rgba(111, 228, 254, 0.08) !important;
  border: 1px solid rgba(111, 228, 254, 0.25) !important;
  border-radius: 10px !important;
  padding: 9px 14px !important;
}

.cs-lipsync-cost strong { color: #6FE4FE !important; }

/* ============================================================================
   WB-489 (وحش بلال 2026-05-20): corner speaker toggle on the lip-sync modal
   player, so the user can hear the original video audio.
   ============================================================================ */
.cs-lipsync-player-wrap {
  position: relative;
  display: block;
  width: 100%;
}

.cs-lipsync-player-sound {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(7, 8, 15, 0.70);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background .15s, box-shadow .15s, transform .12s;
}

.cs-lipsync-player-sound:hover {
  background: rgba(7, 8, 15, 0.92);
  transform: scale(1.06);
}

.cs-lipsync-player-sound.is-on {
  background: rgba(111, 228, 254, 0.32);
  border-color: rgba(111, 228, 254, 0.65);
  box-shadow: 0 0 12px rgba(111, 228, 254, 0.55);
  color: #6FE4FE;
}

/* ─────────────────────────────────────────────────────────────────
   WB-536 (وحش بلال 2026-05-25): the 👄✓ "lip-synced" badge.
   Reused on /create/video cards (same look as Cinema Studio).
   Source: cinema_studio.css L919 + L6215-6248 (the WB-491 redesign).
   Class name `.cs-clip-card-lipsync-tag` kept identical so future
   tweaks to the badge in cinema_studio.css can be mirrored here.
   Positioned via the host card's `position: relative` (the host
   element on /create/video is `.history-list-thumb`; we add
   inline position:relative on the parent in template/JS).
   ───────────────────────────────────────────────────────────────── */
.cs-clip-card-lipsync-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(7, 8, 15, 0.80);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid rgba(111, 228, 254, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.42);
  z-index: 6;
  pointer-events: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.cs-clip-card-lipsync-tag .cs-lip-tag-icon {
  font-size: 14px;
  line-height: 1;
}
.cs-clip-card-lipsync-tag .cs-lip-tag-check {
  color: #34d399;
  font-size: 11px;
  font-weight: 900;
  text-shadow: 0 0 6px rgba(52, 211, 153, 0.6);
}

/* WB-537 (وحش بلال 2026-05-25): inline variant for the /create/video chip
   row — sits beside aspect/duration chips instead of floating absolutely
   over the video thumb. Bilal: "البادج خليه يظهر مو فوق الفديو خليه يظهر
   فوق الاسبكت ريشيو". Drops the absolute positioning, keeps the same
   visual treatment so the user instantly recognizes it. */
.cs-clip-card-lipsync-tag--inline {
  position: static !important;
  top: auto !important;
  left: auto !important;
  z-index: auto !important;
  pointer-events: auto !important;
  vertical-align: middle;
}
