/**
 * CapCut-style mobile editor layout (phone ≤ 900px)
 * Preview top → timeline bottom → tool dock → bottom sheets for panels
 */

:root {
  --me-dock-h: 56px;
  --me-timeline-h: 148px;
  --me-safe-b: env(safe-area-inset-bottom, 0px);
}

@media (max-width: 900px) {
  body.is-editing-mobile .view.active {
    padding: 0 !important;
  }

  /* ---------- Shared CapCut shell ---------- */
  #view-editor.active,
  #view-subtitles.active,
  #view-text-motion.active {
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    max-width: none !important;
  }

  #view-editor .editor-main,
  #view-subtitles .captions-main,
  #view-subtitles .editor-main {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }

  #view-editor .editor-top,
  #view-subtitles .editor-top {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    flex-direction: column !important;
    padding: 0 !important;
    gap: 0 !important;
    position: relative;
  }

  /* Preview fills remaining space */
  #view-editor .editor-video-area,
  #view-subtitles .captions-preview-area,
  #view-subtitles .editor-video-area {
    flex: 1 1 auto !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    min-height: 180px !important;
    max-height: none !important;
  }

  #view-editor #preview-video,
  #view-subtitles #captions-video,
  #view-subtitles video {
    max-height: none !important;
    height: 100% !important;
  }

  #view-editor .playback-controls,
  #view-subtitles .playback-controls {
    padding: 0.5rem 0.75rem !important;
  }

  /* Side panels → sheets (hidden by default) */
  #view-editor .editor-settings,
  #view-subtitles .captions-sidebar {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-height: min(68vh, 520px) !important;
    z-index: 1200 !important;
    border-left: none !important;
    border-top: 1px solid var(--border) !important;
    border-radius: 16px 16px 0 0 !important;
    transform: translateY(110%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
    padding-bottom: calc(0.75rem + var(--me-safe-b)) !important;
  }

  #view-editor.mobile-sheet-props .editor-settings,
  #view-subtitles.mobile-sheet-transcript .captions-sidebar {
    transform: translateY(0);
  }

  .mobile-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1190;
  }
  .mobile-sheet-backdrop.show {
    display: block;
  }

  /* Vertical tool rail → horizontal CapCut dock above timeline */
  #view-editor .floating-toolbar,
  #view-subtitles .floating-toolbar {
    position: relative !important;
    width: 100% !important;
    height: var(--me-dock-h) !important;
    flex-direction: row !important;
    justify-content: space-around !important;
    align-items: center !important;
    padding: 0 4px !important;
    gap: 0 !important;
    border-right: none !important;
    border-top: 1px solid var(--border) !important;
    border-bottom: 1px solid var(--border) !important;
    order: 2;
    flex-shrink: 0;
    background: var(--bg-panel) !important;
  }

  #view-editor .floating-toolbar > div,
  #view-subtitles .floating-toolbar > div {
    display: none !important; /* hide divider */
  }

  #view-editor .editor-video-area,
  #view-subtitles .editor-video-area,
  #view-subtitles .captions-preview-area {
    order: 1;
  }

  /* Timeline compact CapCut band */
  #view-editor .timeline-section,
  #view-subtitles .timeline-section,
  #view-subtitles .waveform-timeline {
    height: var(--me-timeline-h) !important;
    min-height: var(--me-timeline-h) !important;
    max-height: var(--me-timeline-h) !important;
  }

  #view-editor > .editor-main > div:last-child,
  #view-subtitles .captions-main > div:last-of-type {
    flex-shrink: 0;
    padding-bottom: calc(4px + var(--me-safe-b)) !important;
  }

  .track-label {
    width: 64px !important;
    font-size: 0.65rem !important;
    padding: 0 4px !important;
  }

  /* Mobile action chips under dock */
  .mobile-editor-actions {
    display: flex !important;
    gap: 6px;
    padding: 6px 8px calc(6px + var(--me-safe-b));
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
  }

  .mobile-editor-actions button {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
  }

  .mobile-editor-actions button.primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-color: transparent;
    color: #fff;
  }

  .mobile-editor-actions .material-symbols-outlined {
    font-size: 16px;
  }

  /* Top nav tighter on phone while editing */
  body.is-editing-mobile .topbar-center .main-nav .nav-link span:not(.material-symbols-outlined) {
    display: none;
  }

  /* ---------- Text Motion ---------- */
  #view-text-motion .tm-top-half {
    flex-direction: column !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  #view-text-motion .tm-left-col,
  #view-text-motion .tm-right-col {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-height: min(70vh, 540px) !important;
    z-index: 1200 !important;
    transform: translateY(110%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    border-radius: 16px 16px 0 0 !important;
    overflow: auto !important;
    background: var(--bg-panel) !important;
  }

  #view-text-motion.mobile-sheet-left .tm-left-col,
  #view-text-motion.mobile-sheet-right .tm-right-col {
    transform: translateY(0);
  }

  #view-text-motion .tm-center-col,
  #view-text-motion .tm-preview-wrap {
    flex: 1 1 auto !important;
    width: 100% !important;
    min-height: 200px !important;
  }

  #view-text-motion .tm-bottom-timeline,
  #view-text-motion .tm-timeline-wrap {
    height: var(--me-timeline-h) !important;
    max-height: 38vh !important;
    flex-shrink: 0 !important;
  }
}

/* Desktop: hide mobile-only chrome */
@media (min-width: 901px) {
  .mobile-editor-actions,
  .mobile-sheet-backdrop {
    display: none !important;
  }
}

/* Loading elapsed timer */
#loading-eta,
#loading-elapsed {
  display: none;
  color: rgba(255, 255, 255, 0.75);
  margin-top: 0.65rem;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
#loading-eta.show,
#loading-elapsed.show {
  display: block !important;
}

/* Advanced Editor phone (page-scoped) */
@media (max-width: 900px) {
  body.ae-page {
    --sidebar-width: 0px;
    --timeline-height: 160px;
  }

  body.ae-page > aside.w-sidebar-width {
    display: none !important;
  }

  body.ae-page header {
    height: 48px !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }

  body.ae-page header .text-headline-md {
    font-size: 0.95rem !important;
  }

  body.ae-page #btn-export {
    padding: 0.35rem 0.65rem !important;
    font-size: 0.65rem !important;
  }

  /* CapCut: preview column only; side panels as sheets */
  body.ae-page main > .flex-1 > .flex-1.flex.gap-gutter {
    flex-direction: column !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  body.ae-page main .w-80.custom-glass:first-child,
  body.ae-page #right-panels-container {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-height: min(70vh, 560px) !important;
    z-index: 90 !important;
    transform: translateY(110%);
    transition: transform 0.28s ease;
    border-radius: 16px 16px 0 0 !important;
    background: #12141c !important;
  }

  body.ae-page.ae-sheet-subs main .w-80.custom-glass:first-child,
  body.ae-page.ae-sheet-panel #right-panels-container {
    transform: translateY(0);
  }

  body.ae-page #right-panels-container {
    width: 100% !important;
    max-width: none !important;
  }

  body.ae-page .flex.shrink-0.h-full > .w-12 {
    display: none !important;
  }

  body.ae-page #tl-canvas {
    min-width: 100% !important;
  }

  body.ae-page [style*="h-timeline-height"],
  body.ae-page .h-timeline-height {
    height: var(--timeline-height) !important;
  }

  .ae-mobile-dock {
    display: flex;
    gap: 6px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: #0e1018;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    overflow-x: auto;
    flex-shrink: 0;
  }

  .ae-mobile-dock button {
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #171b28;
    color: #e8e8ef;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }

  .ae-mobile-dock button.primary {
    background: #6c63ff;
    border-color: transparent;
    color: #fff;
  }
}

@media (min-width: 901px) {
  .ae-mobile-dock {
    display: none !important;
  }
}

/* Advanced Edit — Dead Air queue applying overlay (desktop + mobile) */
.silence-apply-overlay {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.72), rgba(88, 28, 135, 0.55));
  border: 1px solid rgba(192, 132, 252, 0.45);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.silence-apply-overlay.silence-apply-active {
  border-color: rgba(52, 211, 153, 0.85);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
}
.silence-apply-inner {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  color: #f5f3ff;
  font-size: 10px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.silence-apply-icon {
  font-size: 16px;
  color: #c4b5fd;
}
.silence-apply-active .silence-apply-icon {
  color: #6ee7b7;
  animation: silenceApplyPulse 1s ease-in-out infinite;
}
.silence-apply-scan {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(90deg, transparent, rgba(167, 243, 208, 0.28), transparent);
  animation: silenceApplyScan 1.1s linear infinite;
}
.timeline-clip.silence-clip-applying {
  outline: 2px solid rgba(52, 211, 153, 0.95) !important;
}
@keyframes silenceApplyScan {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
@keyframes silenceApplyPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.08); }
}
