/* ============================================================================
   SYLLOVO STUDIO v8.8 — DEDICATED MOBILE & TABLET RESPONSIVENESS STYLESHEET
   Target Browsers: iOS Safari (iPhone / iPad) & Android Chrome (360px – 1024px)
   Breakpoints:
     • @media (max-width: 1024px) — Tablet & Compact Laptop
     • @media (max-width: 768px)  — Mobile Portrait & Phablet
     • @media (max-width: 480px)  — Narrow Mobile (375px iPhone SE/Mini/Pro, 360px Android)
     • @media (max-height: 540px) and (orientation: landscape) — Mobile Landscape Studio
   ============================================================================ */

/* Global Touch & Overflow Safeguards */
html,
body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Smooth Horizontal Touch Scroll Utility for Pill Strips, Filters & Timelines */
.outline-status-filter-bar,
.outline-subtabs,
.outline-sub-tabs,
.clip-pill-strip,
.studio-bottom-tabs,
.timeline-scroll-area,
.yt-control-bar,
.stage-bottom-bar {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.outline-status-filter-bar::-webkit-scrollbar,
.outline-subtabs::-webkit-scrollbar,
.outline-sub-tabs::-webkit-scrollbar,
.clip-pill-strip::-webkit-scrollbar,
.studio-bottom-tabs::-webkit-scrollbar,
.yt-control-bar::-webkit-scrollbar,
.stage-bottom-bar::-webkit-scrollbar {
  display: none;
}

/* ============================================================================
   1. TABLET & COMPACT WORKSPACE (@media max-width: 1024px)
   ============================================================================ */
@media (max-width: 1024px) {
  .workspace-scroll {
    padding: 16px 16px 96px 16px;
  }

  .top-header,
  .content-header {
    padding: 0 14px;
    gap: 8px;
  }

  .header-course-pill {
    max-width: 200px;
    font-size: 11.5px;
  }

  .studio-main-grid,
  .camtasia-workbench {
    grid-template-columns: 1fr !important;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Ensure timeline body has generous track scrolling room on tablets */
  .timeline-body-with-meter {
    grid-template-columns: 92px 1fr !important;
  }

  .camtasia-vu-meter {
    display: none !important;
  }
}

/* ============================================================================
   2. MOBILE & PORTRAIT TABLET (@media max-width: 768px)
   ============================================================================ */
@media (max-width: 768px) {
  /* App Shell & Sidebar Hiding */
  .app-sidebar {
    display: none !important;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only-logo {
    display: flex !important;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .mobile-only-inline {
    display: inline-flex !important;
  }

  .workspace-scroll {
    padding: 12px 12px calc(84px + env(safe-area-inset-bottom, 12px)) 12px !important;
    overflow-x: hidden;
  }

  /* --------------------------------------------------------------------------
     1. TOP HEADER BAR (.content-header, .top-header, .header-right-actions)
     Compact horizontal layout with zero overlapping pills or clipped text
     -------------------------------------------------------------------------- */
  .top-header,
  .content-header {
    height: 52px !important;
    min-height: 52px !important;
    padding: 0 10px !important;
    gap: 6px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    overflow: hidden;
  }

  .header-left {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden;
  }

  .page-current-title {
    font-size: 14px !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 150px;
  }

  .header-course-pill {
    display: none !important;
  }

  .header-right,
  .header-right-actions {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    flex-shrink: 0 !important;
    min-width: 0;
  }

  .role-select,
  #role-selector {
    padding: 4px 8px !important;
    font-size: 11.5px !important;
    max-width: 124px;
    height: 32px;
    border-radius: 999px;
    text-overflow: ellipsis;
  }

  #mobile-theme-toggle-btn {
    height: 32px;
    min-width: 32px;
    padding: 4px 7px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Mobile Course Selector Bar */
  #mobile-course-bar {
    display: block !important;
    margin-bottom: 10px !important;
  }

  #mobile-course-selector {
    width: 100% !important;
    font-size: 13px !important;
    padding: 8px 10px !important;
    height: 38px;
  }

  /* Guided "Next Step" Banner */
  .guided-banner {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 12px !important;
    gap: 10px !important;
    margin-bottom: 12px !important;
  }

  .guided-banner-left {
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .guided-text-title {
    font-size: 13px !important;
    line-height: 1.35;
  }

  .guided-text-sub {
    font-size: 11.5px !important;
    line-height: 1.4;
    margin-top: 2px;
  }

  .guided-banner .btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: 38px;
  }

  /* --------------------------------------------------------------------------
     2. COURSE OUTLINE PAGE
     - Status filter pills, Course Time Summary banner & Sub-tabs scroll/wrap
     - Clip rows stack cleanly with full-width tap targets
     -------------------------------------------------------------------------- */
  .approval-bar,
  .course-time-summary,
  .outline-time-summary,
  .time-summary-banner {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 12px !important;
    gap: 10px !important;
    margin-bottom: 12px !important;
  }

  .approval-badges {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    gap: 6px !important;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .approval-badges::-webkit-scrollbar {
    display: none;
  }

  .approval-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    width: 100%;
  }

  .approval-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 36px;
  }

  /* Status Filter Pills & Outline Sub-Tabs (Video Clips / Full Course Transcript) */
  .outline-status-filter-bar,
  .outline-filter-bar,
  .status-filter-pills,
  .outline-subtabs,
  .outline-sub-tabs {
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    gap: 6px !important;
    padding: 4px 2px 6px 2px !important;
    margin-bottom: 10px !important;
    width: 100% !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .outline-status-filter-bar > *,
  .outline-subtabs > *,
  .outline-sub-tabs > * {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  /* Outline Clip Rows -> Stacked Native Mobile Cards */
  .clean-table thead {
    display: none !important;
  }

  .clean-table,
  .clean-table tbody {
    display: block !important;
    width: 100% !important;
  }

  .clean-table tr,
  .clip-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    width: 100% !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-md) !important;
    padding: 12px !important;
    margin-bottom: 10px !important;
    background: var(--bg-surface) !important;
    box-shadow: var(--shadow-xs);
  }

  .clean-table td {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    width: 100% !important;
    border-bottom: none !important;
    padding: 2px 0 !important;
    text-align: left !important;
    font-size: 13px !important;
  }

  /* Title & LO cell takes full stacked block layout */
  .clean-table td:nth-child(2) {
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 4px 0 !important;
    border-top: 1px solid var(--bg-subtle);
    border-bottom: 1px solid var(--bg-subtle) !important;
  }

  /* Full-width tap targets for Owner <select>, Status badge, ⬇ MP4 link, and Open Clip -> */
  .clean-table td select,
  .clip-row select,
  .clip-owner-select,
  .owner-select {
    width: 100% !important;
    min-height: 38px !important;
    padding: 6px 10px !important;
    font-size: 12.5px !important;
    border-radius: 8px !important;
  }

  .clean-table td:last-child,
  .clip-row-actions,
  .outline-clip-actions {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
    padding-top: 6px !important;
    margin-top: 2px;
    border-top: 1px solid var(--border);
  }

  .clean-table td:last-child .btn,
  .clean-table td:last-child a.btn,
  .clip-row .btn,
  .clip-row a.btn {
    flex: 1 1 calc(50% - 4px) !important;
    width: 100% !important;
    min-height: 40px !important;
    justify-content: center !important;
    font-size: 12.5px !important;
    padding: 8px 12px !important;
  }

  /* --------------------------------------------------------------------------
     3. VIDEO STUDIO (.studio-player-shell, .stage-preview-box, .yt-control-bar,
        .stage-bottom-bar, .camtasia-transport-bar, .camtasia-timeline-dock)
     -------------------------------------------------------------------------- */
  .studio-toolbar {
    gap: 8px !important;
    margin-bottom: 10px !important;
  }

  .clip-pill-strip {
    width: 100% !important;
    order: 2;
    padding-bottom: 4px !important;
    gap: 6px !important;
  }

  .clip-tab-btn {
    padding: 6px 11px !important;
    font-size: 12px !important;
    min-height: 34px;
  }

  /* Video Stage fits cleanly in mobile portrait (max-height: 34vh) */
  .studio-player-shell {
    border-radius: 12px !important;
    margin-bottom: 10px !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  .stage-preview-box,
  #stage-preview-box {
    max-height: 34vh !important;
    width: 100% !important;
    aspect-ratio: 16 / 9 !important;
  }

  /* Compact Top Stage Overlay on Mobile so Slide Content stays 100% legible */
  .stage-top-overlay {
    top: 6px !important;
    left: 6px !important;
    right: 6px !important;
    gap: 4px !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .stage-top-overlay::-webkit-scrollbar {
    display: none;
  }

  .stage-fullscreen-btn,
  .stage-overlay-pill {
    padding: 4px 8px !important;
    font-size: 10.5px !important;
    border-radius: 6px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .stage-live-caption,
  #stage-live-caption-bar {
    bottom: 6px !important;
    left: 6px !important;
    right: 6px !important;
    padding: 4px 8px !important;
    font-size: 11px !important;
    line-height: 1.35 !important;
    max-height: 3.8em;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Interactive Scrub Bar — Larger touch target on mobile */
  .stage-video-scrub-wrap {
    height: 24px !important;
    padding: 0 10px !important;
    touch-action: none;
  }

  .stage-scrub-track {
    height: 6px !important;
  }

  .stage-scrub-thumb {
    width: 16px !important;
    height: 16px !important;
    transform: translate(-50%, -50%) scale(1) !important;
  }

  /* YouTube-Style Bottom Control Bar (.yt-control-bar, .stage-bottom-bar, .camtasia-transport-bar)
     Wraps cleanly so Play/Pause, timecode, 💬 + Comment, CC, ⚙️, Export MP4, and ⛶ Fullscreen
     are all visible and NEVER cut off on the right edge! */
  .yt-control-bar,
  .stage-bottom-bar,
  .camtasia-transport-bar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px 8px !important;
    padding: 8px 10px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  .yt-control-bar > div,
  .stage-bottom-bar > div,
  .camtasia-transport-bar > div,
  .yt-left-controls,
  .yt-right-controls {
    display: flex !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 5px !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .transport-btn,
  .yt-btn,
  .yt-control-btn {
    min-width: 30px !important;
    height: 30px !important;
    padding: 0 6px !important;
    font-size: 11.5px !important;
    flex-shrink: 0 !important;
  }

  .transport-btn.play-main,
  .yt-play-btn {
    width: 34px !important;
    height: 34px !important;
    font-size: 14px !important;
  }

  #camtasia-timecode-readout,
  .yt-timecode {
    font-size: 11px !important;
    letter-spacing: -0.02em;
    white-space: nowrap !important;
  }

  .yt-control-bar .btn-sm,
  .stage-bottom-bar .btn-sm,
  .camtasia-transport-bar .btn-sm {
    padding: 4px 8px !important;
    font-size: 11px !important;
    min-height: 30px !important;
    flex-shrink: 0 !important;
  }

  /* --------------------------------------------------------------------------
     FULLSCREEN MODE (#studio-player-shell.stage-fullscreen-active)
     Works smoothly on mobile portrait & landscape with safe-area-inset padding
     and floating comment drawer (#inline-cursor-comment-popover)
     -------------------------------------------------------------------------- */
  #studio-player-shell.stage-fullscreen-active,
  .studio-player-shell:fullscreen,
  .studio-player-shell:-webkit-full-screen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-right: env(safe-area-inset-right, 0px) !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    padding-left: env(safe-area-inset-left, 0px) !important;
    background: #000000 !important;
    z-index: 99999 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
  }

  #studio-player-shell.stage-fullscreen-active .stage-preview-box,
  .studio-player-shell:fullscreen .stage-preview-box,
  .studio-player-shell:-webkit-full-screen .stage-preview-box {
    max-height: none !important;
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0 !important;
  }

  /* Floating Comment Drawer inside or below stage (#inline-cursor-comment-popover) */
  #inline-cursor-comment-popover,
  .inline-cursor-comment-popover,
  .fullscreen-comment-drawer {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px !important;
    border-radius: 12px !important;
    box-sizing: border-box !important;
  }

  #studio-player-shell.stage-fullscreen-active #inline-cursor-comment-popover,
  #studio-player-shell.stage-fullscreen-active .inline-cursor-comment-popover {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    bottom: calc(64px + env(safe-area-inset-bottom, 8px)) !important;
    width: auto !important;
    max-height: 55dvh !important;
    overflow-y: auto !important;
    z-index: 100001 !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.75) !important;
  }

  /* --------------------------------------------------------------------------
     MULTI-TRACK CAMTASIA TIMELINE (.camtasia-timeline-dock)
     Smooth horizontal touch scrolling + compact headers
     -------------------------------------------------------------------------- */
  .camtasia-timeline-dock {
    border-radius: 10px !important;
    margin-bottom: 10px !important;
  }

  .timeline-top-toolbar {
    padding: 6px 8px !important;
    gap: 6px !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .timeline-top-toolbar::-webkit-scrollbar {
    display: none;
  }

  .timeline-top-toolbar > div {
    flex-wrap: nowrap !important;
    flex-shrink: 0 !important;
    gap: 5px !important;
  }

  .tl-tool-btn {
    padding: 4px 8px !important;
    font-size: 11px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .timeline-body-with-meter {
    grid-template-columns: 72px 1fr !important;
    min-height: 196px !important;
  }

  .th-ruler-spacer {
    height: 30px !important;
    padding: 0 6px !important;
    font-size: 9px !important;
  }

  .th-track-label {
    height: 78px !important;
    padding: 6px !important;
    font-size: 11px !important;
  }

  .th-track-sub {
    font-size: 9px !important;
  }

  .timeline-scroll-area {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x !important;
  }

  .timeline-ruler {
    height: 30px !important;
  }

  .timeline-track-lane {
    height: 78px !important;
  }

  .tl-chunk {
    top: 6px !important;
    height: 66px !important;
  }

  /* Studio Bottom Segmented Tabs */
  .studio-bottom-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    gap: 4px !important;
    padding: 4px !important;
  }

  .studio-bottom-tab,
  .studio-subtab-btn {
    flex: 0 0 auto !important;
    padding: 7px 10px !important;
    font-size: 11.5px !important;
  }

  /* Cards & Grids on Mobile */
  .card {
    padding: 14px !important;
    margin-bottom: 12px !important;
    border-radius: 12px !important;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* --------------------------------------------------------------------------
     4. BOTTOM MOBILE NAVIGATION BAR (.mobile-bottom-nav)
     Clean fixed glass bar with env(safe-area-inset-bottom) padding
     -------------------------------------------------------------------------- */
  .mobile-bottom-nav {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(58px + env(safe-area-inset-bottom, 0px)) !important;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px)) 6px !important;
    background: rgba(255, 255, 255, 0.88) !important;
    backdrop-filter: blur(16px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(16px) saturate(180%) !important;
    border-top: 1px solid var(--border) !important;
    z-index: 9000 !important;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06) !important;
  }

  [data-theme="dark"] .mobile-bottom-nav {
    background: rgba(18, 18, 21, 0.88) !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45) !important;
  }

  .mobile-nav-btn {
    min-height: 46px !important;
    border-radius: 10px !important;
    font-size: 10.5px !important;
    gap: 2px !important;
    -webkit-tap-highlight-color: transparent;
  }

  /* Keep Toast Notifications above Bottom Nav Bar */
  .studio-toast-container {
    bottom: calc(68px + env(safe-area-inset-bottom, 8px)) !important;
    left: 12px !important;
    right: 12px !important;
    max-width: none !important;
  }
}

/* ============================================================================
   3. NARROW MOBILE SCREENS (@media max-width: 480px — 375px iPhone / 360px Android)
   ============================================================================ */
@media (max-width: 480px) {
  .top-header,
  .content-header {
    height: 48px !important;
    min-height: 48px !important;
    padding: 0 8px !important;
    gap: 4px !important;
  }

  .page-current-title {
    font-size: 13px !important;
    max-width: 118px !important;
  }

  .role-select,
  #role-selector {
    font-size: 11px !important;
    padding: 3px 6px !important;
    max-width: 108px !important;
    height: 28px !important;
  }

  #mobile-theme-toggle-btn {
    height: 28px !important;
    min-width: 28px !important;
    padding: 2px 5px !important;
    font-size: 12px !important;
  }

  .workspace-scroll {
    padding: 10px 8px calc(80px + env(safe-area-inset-bottom, 10px)) 8px !important;
  }

  /* Stack Clip Row Action Buttons Full Width on 375px Screens */
  .clean-table td:last-child .btn,
  .clean-table td:last-child a.btn,
  .clip-row .btn,
  .clip-row a.btn {
    flex: 1 1 100% !important;
    width: 100% !important;
  }

  /* Video Stage Portrait Max Height 34vh */
  .stage-preview-box,
  #stage-preview-box {
    max-height: 34vh !important;
  }

  /* Hide non-essential secondary timing badge inside transport bar on 375px so buttons never clip */
  .camtasia-transport-bar .pill-emerald,
  .yt-control-bar .pill-emerald,
  .stage-bottom-bar .pill-emerald {
    display: none !important;
  }

  .yt-control-bar,
  .stage-bottom-bar,
  .camtasia-transport-bar {
    padding: 6px 8px !important;
    gap: 5px !important;
  }

  .yt-control-bar .btn-sm,
  .stage-bottom-bar .btn-sm,
  .camtasia-transport-bar .btn-sm {
    flex: 1 1 auto !important;
    justify-content: center !important;
    font-size: 10.5px !important;
    padding: 4px 6px !important;
  }

  .timeline-body-with-meter {
    grid-template-columns: 62px 1fr !important;
  }

  .th-track-label {
    font-size: 10px !important;
    padding: 4px !important;
  }
}

/* ============================================================================
   4. MOBILE LANDSCAPE MODE (@media max-height: 540px and orientation: landscape)
   Video Stage fits cleanly at max-height: 78vh with unobtrusive controls
   ============================================================================ */
@media (max-height: 540px) and (orientation: landscape) {
  .top-header,
  .content-header {
    height: 42px !important;
    min-height: 42px !important;
    padding: 0 12px !important;
  }

  .stage-preview-box,
  #stage-preview-box {
    max-height: 78vh !important;
    width: 100% !important;
  }

  #studio-player-shell.stage-fullscreen-active .stage-preview-box,
  .studio-player-shell:fullscreen .stage-preview-box,
  .studio-player-shell:-webkit-full-screen .stage-preview-box {
    max-height: calc(100dvh - 48px) !important;
    height: calc(100dvh - 48px) !important;
  }

  .mobile-bottom-nav {
    height: calc(48px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .mobile-nav-btn {
    flex-direction: row !important;
    gap: 5px !important;
    font-size: 11px !important;
    min-height: 38px !important;
  }
}
