/* bened-channels custom styles */

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 56px; /* h-14 nav height */
  left: 0;
  bottom: 0;
  z-index: 40;
  background: #0f0f0f;
  border-right: 1px solid rgba(255,255,255,.06);
  transition: width 200ms ease, transform 200ms ease;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
.sidebar:hover::-webkit-scrollbar-thumb { background: #555; }

/* Expanded (desktop default) */
.sidebar-expanded { width: 240px; }

/* Collapsed (mini icons) */
.sidebar-collapsed { width: 72px; }
.sidebar-collapsed .sidebar-label { display: none; }
.sidebar-collapsed .sidebar-section-title { display: none; }
.sidebar-collapsed .sidebar-divider { margin: 4px 8px; }
.sidebar-collapsed .sidebar-item {
  flex-direction: column;
  padding: 12px 0;
  gap: 4px;
  justify-content: center;
  align-items: center;
  border-radius: 8px;
}
.sidebar-collapsed .sidebar-icon { width: 24px; height: 24px; }
.sidebar-collapsed .sidebar-bottom-links { display: none; }

/* Hidden (mobile: off-screen, toggled via JS) */
.sidebar-hidden { transform: translateX(-100%); width: 240px; }

/* Mobile overlay open */
.sidebar-mobile-open { transform: translateX(0); }

/* Sidebar items */
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 12px;
  border-radius: 10px;
  color: #e5e7eb;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 150ms;
}
.sidebar-item:hover { background: rgba(255,255,255,.07); }
.sidebar-item-active {
  background: rgba(255,255,255,.1);
  font-weight: 500;
}

.sidebar-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: #e5e7eb;
}

.sidebar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px 4px;
  font-size: 14px;
  font-weight: 500;
  color: #e5e7eb;
}

.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.06);
  margin: 8px 12px;
}

/* Live red dot */
.live-dot {
  position: absolute;
  top: 0;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #0f0f0f;
}

/* ── Page layout with sidebar ──────────────────────────────── */
.page-with-sidebar {
  margin-left: 240px;
  transition: margin-left 200ms ease;
  min-height: calc(100vh - 56px);
}
.page-with-sidebar-collapsed {
  margin-left: 72px;
}

/* ── Studio sidebar ────────────────────────────────────────── */
.studio-sidebar {
  width: 220px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,.06);
  background: #0f0f0f;
}

.studio-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  font-size: 14px;
  color: #9ca3af;
  text-decoration: none;
  transition: background 150ms, color 150ms;
}
.studio-nav-item:hover {
  background: rgba(255,255,255,.05);
  color: #e5e7eb;
}
.studio-nav-item-active,
.studio-nav-active {
  background: rgba(255,255,255,.08);
  color: #fff;
  font-weight: 500;
}

.studio-nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ── Notification bell ─────────────────────────────────────── */
.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Sidebar overlay (mobile backdrop) ──────────────────────── */
#sidebar-overlay {
  z-index: 39;
}

/* ── Footer layout with sidebar ────────────────────────────── */
/* Pages with sidebar: footer gets same margin as content */
body:has(#sidebar) > footer {
  margin-left: 240px;
  transition: margin-left 200ms ease;
}
body:has(#sidebar).sidebar-collapsed-state > footer {
  margin-left: 72px;
}
body.watch-page:has(#sidebar) > footer {
  margin-left: 72px;
}

/* ── Responsive ────────────────────────────────────────────── */

/* Tablets and below: hide sidebar by default, show overlay on toggle */
@media (max-width: 1024px) {
  .sidebar-expanded {
    transform: translateX(-100%);
    width: 240px;
  }
  .sidebar-expanded.sidebar-mobile-open {
    transform: translateX(0);
  }
  .page-with-sidebar,
  .page-with-sidebar-collapsed {
    margin-left: 0;
  }
  body:has(#sidebar) > footer {
    margin-left: 0;
  }
}

/* Very small: no collapsed mode, just overlay */
@media (max-width: 640px) {
  .sidebar-collapsed {
    transform: translateX(-100%);
  }
  .sidebar-collapsed.sidebar-mobile-open {
    transform: translateX(0);
    width: 240px;
  }
  .page-with-sidebar-collapsed {
    margin-left: 0;
  }
}

/* Watch page: always collapsed sidebar on desktop to maximize video area */
body.watch-page .sidebar-expanded {
  width: 72px;
}
body.watch-page .sidebar-expanded .sidebar-label { display: none; }
body.watch-page .sidebar-expanded .sidebar-section-title { display: none; }
body.watch-page .sidebar-expanded .sidebar-divider { margin: 4px 8px; }
body.watch-page .sidebar-expanded .sidebar-item {
  flex-direction: column;
  padding: 12px 0;
  gap: 4px;
  justify-content: center;
  align-items: center;
  border-radius: 8px;
}
body.watch-page .page-with-sidebar {
  margin-left: 72px;
}
@media (max-width: 1024px) {
  body.watch-page .sidebar-expanded {
    transform: translateX(-100%);
    width: 240px;
  }
  body.watch-page .page-with-sidebar {
    margin-left: 0;
  }
  body.watch-page:has(#sidebar) > footer {
    margin-left: 0;
  }
}

/* Channel tabs */
.channel-tab {
  padding-bottom: 8px;
  border-bottom: 2px solid transparent;
  color: #9ca3af;
  font-size: 14px;
  font-weight: 500;
  transition: color 150ms, border-color 150ms;
}
.channel-tab:hover { color: #d1d5db; }
.channel-tab-active {
  border-color: #fff;
  color: #fff;
}

/* ── BENED's Storage Box Provenance Card ────────────────────── */
.storage-provenance {
  border: 1px solid #d97706;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 2rem;
}
.storage-provenance-header {
  background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.storage-provenance-header svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.storage-provenance-header .sp-title {
  font-size: 13px;
  font-weight: 600;
  color: #fbbf24;
  letter-spacing: 0.3px;
}
.storage-provenance-header .sp-badge {
  margin-left: auto;
  font-size: 10px;
  background: rgba(251,191,36,.15);
  color: #fbbf24;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.storage-provenance-body {
  background: #1f1a14;
  padding: 16px;
}
.sp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sp-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sp-item-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #92400e;
  font-weight: 600;
}
.sp-item-value {
  font-size: 13px;
  color: #d1d5db;
}
.sp-item-value.sp-green { color: #34d399; }
.sp-item-value.sp-yellow { color: #fbbf24; }
.sp-item-value.sp-red { color: #f87171; }
.sp-footer {
  padding: 10px 16px;
  background: #1a1510;
  border-top: 1px solid rgba(217,119,6,.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sp-footer-text {
  font-size: 10px;
  color: #6b7280;
}
.sp-footer-link {
  font-size: 11px;
  color: #d97706;
  text-decoration: none;
}
.sp-footer-link:hover { text-decoration: underline; }
@media (max-width: 600px) {
  .sp-grid { grid-template-columns: 1fr; }
}

/* ── Mobile responsive enhancements ────────────────────────── */
@media (max-width: 640px) {
  /* Watch page: tighter padding, full-width video */
  .watch-page #watch-layout { padding: 0; gap: 8px; }
  .watch-page #player-container { border-radius: 0; }
  .watch-page .flex-1.min-w-0 > h1 { font-size: 16px; padding: 0 12px; }
  /* Actions row: horizontal scroll on small screens */
  .watch-page .flex-wrap.items-center {
    padding: 0 12px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .watch-page .flex-wrap.items-center::-webkit-scrollbar { display: none; }
  .watch-page .flex-wrap.items-center > * { flex-shrink: 0; }
  .watch-page .flex-wrap.items-center .ml-auto { margin-left: 8px; }
  /* Description box */
  .watch-page .bg-gray-800\/50.rounded-xl { margin: 0 12px; padding: 10px; }
  /* Speed/Theater: stack in description bar */
  .watch-page #speed-wrap, .watch-page #theater-btn {
    padding: 2px 4px;
    font-size: 11px;
  }

  /* Studio sidebar hidden on mobile */
  .studio-sidebar { display: none; }

  /* Video grid: single column */
  .grid-cols-1.sm\:grid-cols-2 { grid-template-columns: 1fr !important; }

  /* Subscription feed / home: reduce gap on video grids only */
  .grid.gap-6, [class*="grid-cols"].gap-6 { gap: 12px; }

  /* Nav search bar: shrink and fix icon overlap */
  nav .flex-1.max-w-2xl { max-width: 180px; }
  nav .flex-1.max-w-2xl input {
    font-size: 13px;
    padding: 6px 32px 6px 12px;
  }

  /* Watch page: better button sizing */
  .watch-page button, .watch-page .rounded-full { font-size: 13px; }
  .watch-page .w-10.h-10 { width: 32px; height: 32px; }

  /* Video player: must be visible in BOTH Safari browser and PWA on mobile */
  body.watch-page #watch-layout {
    flex-direction: column !important;
    gap: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
  body.watch-page #watch-layout > .flex-1.min-w-0 {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
  body.watch-page #player-container {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    margin: 0 !important;
    position: relative;
    aspect-ratio: 16 / 9;
    background: #000 !important;
  }
  body.watch-page #player-container video {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    object-fit: contain;
  }
  body.watch-page #player-container > div:not(#video-error-overlay) {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
  }
}

/* Tablet: 2-column grid */
@media (min-width: 641px) and (max-width: 1024px) {
  .studio-sidebar { width: 60px; overflow: hidden; }
  .studio-sidebar .studio-nav-item span { display: none; }
  .studio-sidebar .studio-nav-item { padding: 10px 16px; justify-content: center; }
}

/* ── Mobile Landscape — Phone turned sideways ──────────────── */
/* When a phone is in landscape, width exceeds 640px but viewport height
   is very short (~340-420px). Without these rules the layout tries the
   tablet/desktop side-by-side view which makes the video invisible and
   stacks elements on top of each other. */

/* Detect phone-landscape: landscape + short viewport + touch device */
@media (orientation: landscape) and (max-height: 500px) {
  /* Watch page: force single-column like portrait mobile */
  body.watch-page #watch-layout {
    flex-direction: column !important;
    gap: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
  body.watch-page #watch-layout > .flex-1.min-w-0 {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /* Player: fill viewport width, let height scale to available space.
     Use 100vh minus nav/header so the video fills the screen edge-to-edge. */
  body.watch-page #player-container {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    margin: 0 !important;
    aspect-ratio: auto !important;
    height: calc(100vh - var(--pwa-header-h, 0px) - var(--pwa-bottom-h, 0px)) !important;
    max-height: 100vh;
    background: #000 !important;
  }
  body.watch-page #player-container video {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    object-fit: contain;
  }
  body.watch-page #player-container > div:not(#video-error-overlay) {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Hide nav elements in landscape to maximize video space */
  #main-nav { height: 40px !important; min-height: 40px !important; }
  .pwa-header { height: calc(36px + env(safe-area-inset-top, 0px)) !important; }
  :root { --pwa-header-h: calc(36px + env(safe-area-inset-top, 0px)); }

  /* Player transport bar: compact in landscape */
  body.watch-page #player-transport {
    padding: 2px 8px !important;
  }
  body.watch-page #player-transport button {
    padding: 4px 10px !important;
    font-size: 12px !important;
    min-height: 32px !important;
  }

  /* Title: compact below video */
  body.watch-page #video-title {
    font-size: 14px !important;
    padding: 6px 12px 0 !important;
    line-height: 1.3 !important;
  }

  /* Actions row: horizontal scroll, compact */
  body.watch-page .mt-3.pb-4 {
    padding: 4px 12px !important;
    border: none !important;
  }

  /* Description + comments: compact spacing */
  body.watch-page #video-info-section {
    max-height: 50vh;
    overflow-y: auto;
  }

  /* Merch shelf: horizontal scroll in landscape instead of grid */
  body.watch-page #merch-products {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px !important;
  }
  body.watch-page #merch-products::-webkit-scrollbar { display: none; }
  body.watch-page #merch-products > * {
    flex: 0 0 140px !important;
    min-width: 140px !important;
  }

  /* Sidebar panel (recommended videos): below, compact */
  body.watch-page #sidebar-panel {
    width: 100% !important;
    max-width: 100% !important;
    padding: 8px 12px !important;
  }

  /* Home/feed page: smaller cards in landscape */
  .grid.gap-6, [class*="grid-cols"].gap-6 { gap: 8px !important; }
}

/* PWA standalone + landscape: maximize video, minimize chrome */
@media all and (display-mode: standalone) and (orientation: landscape) and (max-height: 500px) {
  /* Smaller bottom nav in landscape */
  .pwa-bottom-nav {
    height: calc(44px + env(safe-area-inset-bottom, 0px)) !important;
    padding-top: 2px !important;
  }
  :root { --pwa-bottom-h: calc(44px + env(safe-area-inset-bottom, 0px)); }
  .pwa-tab { font-size: 9px !important; min-height: 36px !important; padding: 2px 6px !important; }
  .pwa-tab .pwa-icon { font-size: 1.2rem !important; }
  .pwa-tab-accent .pwa-icon { width: 26px !important; height: 26px !important; }

  /* Player fills available space */
  body.watch-page #player-container {
    height: calc(100vh - var(--pwa-header-h) - var(--pwa-bottom-h)) !important;
  }
}

/* ── Touch-safe interactions ───────────────────────────────── */
/* Video cards: prevent iOS double-tap by only showing hover overlay on true hover devices */
.watch-later-btn { opacity: 0; transition: opacity 200ms; }
@media (hover: hover) and (pointer: fine) {
  .group:hover .watch-later-btn { opacity: 1; }
}
/* Profile dropdown: same fix — click-toggle instead of hover on touch */
.profile-dropdown { opacity: 0; visibility: hidden; transition: all 200ms; }
@media (hover: hover) and (pointer: fine) {
  .group:hover .profile-dropdown { opacity: 1; visibility: visible; }
}
/* All card links: prevent 300ms delay on iOS */
a.group { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* ── Video player: robust sizing for all devices ───────────── */
#player-container {
  position: relative;
  width: 100%;
}
#player-container > video {
  object-fit: contain;
  background: #000;
}
/* Fallback for browsers that don't support aspect-ratio */
@supports not (aspect-ratio: 16 / 9) {
  #player-container.aspect-video {
    height: 0 !important;
    padding-bottom: 56.25%;
    overflow: hidden;
  }
  #player-container.aspect-video > video,
  #player-container.aspect-video > div {
    position: absolute !important;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
  }
}

/* ── PWA Standalone Mode — Bottom Nav + Header ─────────────── */
:root {
  --pwa-bottom-h: 0px;
  --pwa-header-h: 0px;
}
.pwa-bottom-nav { display: none; }
.pwa-header { display: none; }
.pwa-search-form { display: none; }

/* ── Capacitor Native App Styles (mirrors standalone mode) ───── */
html.capacitor-native {
  --pwa-bottom-h: calc(64px + env(safe-area-inset-bottom, 0px));
  --pwa-header-h: calc(52px + env(safe-area-inset-top, 0px));
}
html.capacitor-native body {
  padding-top: var(--pwa-header-h);
  padding-bottom: var(--pwa-bottom-h);
}

/* Hide desktop nav in Capacitor */
html.capacitor-native #main-nav { display: none !important; }
html.capacitor-native .sidebar {
  top: var(--pwa-header-h) !important;
  height: calc(100vh - var(--pwa-header-h)) !important;
}
html.capacitor-native #sidebar-overlay { z-index: 49; }
html.capacitor-native .pwa-search-form { display: block; }
html.capacitor-native .page-with-sidebar,
html.capacitor-native .page-with-sidebar-collapsed {
  margin-left: 0 !important;
  min-height: calc(100vh - var(--pwa-header-h) - var(--pwa-bottom-h)) !important;
}
html.capacitor-native body:has(#sidebar) > footer { margin-left: 0 !important; }

/* PWA top header */
html.capacitor-native .pwa-header {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--pwa-header-h);
  background: #0f0f0f;
  border-bottom: 1px solid rgba(255,255,255,.06);
  align-items: flex-end;
  padding: 0 12px 8px;
  gap: 8px;
  z-index: 100;
  font-weight: 600;
  font-size: 1rem;
  color: #e5e7eb;
}
html.capacitor-native .pwa-header-back {
  background: none;
  border: none;
  color: #e5e7eb;
  padding: 6px;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
html.capacitor-native .pwa-header-back:active { opacity: .5; }
html.capacitor-native #pwaHeaderTitle {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html.capacitor-native .pwa-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
html.capacitor-native .pwa-header-btn {
  background: none;
  border: none;
  color: #9ca3af;
  padding: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .15s, color .15s;
  text-decoration: none;
}
html.capacitor-native .pwa-header-btn:active { background: rgba(255,255,255,.08); }
html.capacitor-native .pwa-header-btn:hover { color: #e5e7eb; }

/* PWA inline search input */
html.capacitor-native #pwa-search-input:focus {
  border-color: #555;
  background: #222;
}
html.capacitor-native #pwa-search-form[style*="flex"] ~ .pwa-header-btn:not(#pwa-notif-bell) { display: none; }
html.capacitor-native .pwa-notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  background: #ef4444;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
html.capacitor-native .pwa-notif-dropdown {
  position: fixed;
  top: var(--pwa-header-h);
  right: 0;
  left: 0;
  background: #111;
  border-bottom: 1px solid rgba(255,255,255,.08);
  z-index: 200;
  max-height: 75vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
html.capacitor-native .pwa-notif-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 199;
}

/* Studio sidebar: hide in Capacitor */
html.capacitor-native .studio-sidebar { display: none !important; }
html.capacitor-native .flex.flex-1:has(.studio-sidebar) { display: block; }
html.capacitor-native .flex.flex-1:has(.studio-sidebar) > main {
  max-width: 100%;
  padding-left: 16px;
  padding-right: 16px;
}

/* PWA bottom tab bar */
html.capacitor-native .pwa-bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--pwa-bottom-h);
  background: #0f0f0f;
  border-top: 1px solid rgba(255,255,255,.06);
  align-items: flex-start;
  justify-content: space-around;
  padding-top: 6px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}
html.capacitor-native .pwa-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #777;
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
  padding: 4px 10px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
  min-height: 44px;
}
html.capacitor-native .pwa-tab .pwa-icon {
  font-size: 1.5rem;
  line-height: 1;
}
html.capacitor-native .pwa-tab.active { color: #e5e7eb; }
html.capacitor-native .pwa-tab.active .pwa-icon {
  filter: drop-shadow(0 0 4px rgba(217,119,6,.4));
}
html.capacitor-native .pwa-tab:hover {
  text-decoration: none;
  color: #f59e0b;
}
html.capacitor-native .pwa-tab-accent { color: #d97706 !important; }
html.capacitor-native .pwa-tab-accent .pwa-icon {
  background: rgba(217,119,6,.15);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
html.capacitor-native button.pwa-tab {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
  min-height: 44px;
}
html.capacitor-native button.pwa-tab:active {
  transform: scale(0.92);
  transition: transform 0.08s;
}

/* Footer hidden in Capacitor */
html.capacitor-native footer.border-t { display: none !important; }

/* Watch page: YouTube-mobile layout */
html.capacitor-native body.watch-page .page-with-sidebar {
  min-height: calc(100vh - var(--pwa-header-h) - var(--pwa-bottom-h)) !important;
  overflow-x: hidden !important;
  margin-left: 0 !important;
  padding: 0 !important;
}
html.capacitor-native body.watch-page #watch-layout {
  flex-direction: column !important;
  padding: 0 !important;
  gap: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
}
html.capacitor-native body.watch-page #watch-layout > .flex-1.min-w-0 {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}
html.capacitor-native body.watch-page #player-container {
  width: 100% !important;
  max-width: 100% !important;
  border-radius: 0 !important;
  margin: 0 !important;
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000 !important;
}
html.capacitor-native body.watch-page #player-container video {
  width: 100% !important;
  height: 100% !important;
  display: block !important;
  object-fit: contain;
}
html.capacitor-native body.watch-page #player-container > div:not(#video-error-overlay) {
  width: 100% !important;
  height: 100% !important;
  display: flex !important;
}
html.capacitor-native body.watch-page #watch-layout > .flex-1.min-w-0 > h1 {
  padding: 10px 14px 0 !important;
  font-size: 17px !important;
  line-height: 1.35 !important;
}
html.capacitor-native body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-3.pb-4 {
  padding-left: 14px !important;
  padding-right: 14px !important;
}
html.capacitor-native body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-4.p-3 {
  margin-left: 14px !important;
  margin-right: 14px !important;
}
html.capacitor-native body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-3:has(#transcript-toggle) {
  padding: 0 14px !important;
}
html.capacitor-native body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-6 {
  padding: 0 14px !important;
}
html.capacitor-native body.watch-page #sidebar-panel {
  width: 100% !important;
  max-width: 100% !important;
  padding: 12px 14px !important;
  flex-shrink: 1 !important;
}
html.capacitor-native body.watch-page #sidebar-panel > .flex.items-center.justify-between > h3 {
  display: block !important;
}
html.capacitor-native body.watch-page #sidebar-panel .space-y-3 > a {
  display: flex !important;
}
html.capacitor-native body.watch-page #sidebar-panel .space-y-3 > a > .w-40 {
  width: 160px !important;
  flex-shrink: 0;
}

/* Support widget above bottom nav */
html.capacitor-native #bened-support-widget { bottom: calc(var(--pwa-bottom-h) + 12px) !important; }

@media all and (display-mode: standalone) {
  :root {
    --pwa-bottom-h: calc(64px + env(safe-area-inset-bottom, 0px));
    --pwa-header-h: calc(52px + env(safe-area-inset-top, 0px));
  }
  body {
    padding-top: var(--pwa-header-h);
    padding-bottom: var(--pwa-bottom-h);
  }

  /* Hide desktop nav in PWA standalone; sidebar works as overlay */
  #main-nav { display: none !important; }
  .sidebar {
    top: var(--pwa-header-h) !important;
    height: calc(100vh - var(--pwa-header-h)) !important;
  }
  #sidebar-overlay { z-index: 49; }
  .pwa-search-form { display: block; }
  .page-with-sidebar,
  .page-with-sidebar-collapsed {
    margin-left: 0 !important;
    min-height: calc(100vh - var(--pwa-header-h) - var(--pwa-bottom-h)) !important;
  }
  body:has(#sidebar) > footer { margin-left: 0 !important; }

  /* PWA top header */
  .pwa-header {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--pwa-header-h);
    background: #0f0f0f;
    border-bottom: 1px solid rgba(255,255,255,.06);
    align-items: flex-end;
    padding: 0 12px 8px;
    gap: 8px;
    z-index: 100;
    font-weight: 600;
    font-size: 1rem;
    color: #e5e7eb;
  }
  .pwa-header-back {
    background: none;
    border: none;
    color: #e5e7eb;
    padding: 6px;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .pwa-header-back:active { opacity: .5; }
  #pwaHeaderTitle {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .pwa-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }
  .pwa-header-btn {
    background: none;
    border: none;
    color: #9ca3af;
    padding: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background .15s, color .15s;
    text-decoration: none;
  }
  .pwa-header-btn:active { background: rgba(255,255,255,.08); }
  .pwa-header-btn:hover { color: #e5e7eb; }

  /* PWA inline search input */
  #pwa-search-input:focus {
    border-color: #555;
    background: #222;
  }
  #pwa-search-form[style*="flex"] ~ .pwa-header-btn:not(#pwa-notif-bell) { display: none; }
  .pwa-notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    background: #ef4444;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
  }
  .pwa-notif-dropdown {
    position: fixed;
    top: var(--pwa-header-h);
    right: 0;
    left: 0;
    background: #111;
    border-bottom: 1px solid rgba(255,255,255,.08);
    z-index: 200;
    max-height: 75vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .pwa-notif-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 199;
  }

  /* Studio sidebar: hide in PWA standalone and fix layout */
  .studio-sidebar {
    display: none !important;
  }
  /* Studio pages: main content full width when sidebar hidden */
  .flex.flex-1:has(.studio-sidebar) {
    display: block;
  }
  .flex.flex-1:has(.studio-sidebar) > main {
    max-width: 100%;
    padding-left: 16px;
    padding-right: 16px;
  }

  /* PWA bottom tab bar */
  .pwa-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--pwa-bottom-h);
    background: #0f0f0f;
    border-top: 1px solid rgba(255,255,255,.06);
    align-items: flex-start;
    justify-content: space-around;
    padding-top: 6px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 100;
  }

  .pwa-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: #777;
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    padding: 4px 10px;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
    min-width: 56px;
    min-height: 44px;
  }
  .pwa-tab .pwa-icon {
    font-size: 1.5rem;
    line-height: 1;
  }
  .pwa-tab.active {
    color: #e5e7eb;
  }
  .pwa-tab.active .pwa-icon {
    filter: drop-shadow(0 0 4px rgba(217,119,6,.4));
  }
  .pwa-tab:hover {
    text-decoration: none;
    color: #f59e0b;
  }
  /* Accent tab (e.g. Upload button) */
  .pwa-tab-accent {
    color: #d97706 !important;
  }
  .pwa-tab-accent .pwa-icon {
    background: rgba(217,119,6,.15);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  /* Button variant tabs (watch context actions) */
  button.pwa-tab {
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    -webkit-tap-highlight-color: transparent;
    min-width: 56px;
    min-height: 44px;
  }
  button.pwa-tab:active {
    transform: scale(0.92);
    transition: transform 0.08s;
  }

  /* Footer hidden in PWA */
  footer.border-t { display: none !important; }

  /* ── Watch page: PWA standalone — YouTube-mobile layout ──── */
  body.watch-page .page-with-sidebar {
    min-height: calc(100vh - var(--pwa-header-h) - var(--pwa-bottom-h)) !important;
    overflow-x: hidden !important;
    margin-left: 0 !important;
    padding: 0 !important;
  }

  /* Force single-column layout (no side-by-side recommended) */
  body.watch-page #watch-layout {
    flex-direction: column !important;
    padding: 0 !important;
    gap: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  /* Left column — takes full width */
  body.watch-page #watch-layout > .flex-1.min-w-0 {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /* Player: fill parent width naturally, no 100vw hack */
  body.watch-page #player-container {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    margin: 0 !important;
    position: relative;
    aspect-ratio: 16 / 9;
    background: #000 !important;
  }
  body.watch-page #player-container video {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    object-fit: contain;
  }
  body.watch-page #player-container > div:not(#video-error-overlay) {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
  }

  /* Title + metadata below video — proper padding */
  body.watch-page #watch-layout > .flex-1.min-w-0 > h1 {
    padding: 10px 14px 0 !important;
    font-size: 17px !important;
    line-height: 1.35 !important;
  }
  /* Actions row */
  body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-3.pb-4 {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }
  /* Description box */
  body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-4.p-3 {
    margin-left: 14px !important;
    margin-right: 14px !important;
  }
  /* Transcript */
  body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-3:has(#transcript-toggle) {
    padding: 0 14px !important;
  }
  /* Comments section */
  body.watch-page #watch-layout > .flex-1.min-w-0 > .mt-6 {
    padding: 0 14px !important;
  }

  /* Right sidebar panel → becomes "Up next" section below */
  body.watch-page #sidebar-panel {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px 14px !important;
    flex-shrink: 1 !important;
  }
  /* Hide the "Up next" label on mobile — we use the section separator */
  body.watch-page #sidebar-panel > .flex.items-center.justify-between > h3 {
    display: block !important;
  }
  /* Recommended videos: stack vertically, full width cards */
  body.watch-page #sidebar-panel .space-y-3 > a {
    display: flex !important;
  }
  body.watch-page #sidebar-panel .space-y-3 > a > .w-40 {
    width: 160px !important;
    flex-shrink: 0;
  }

  /* Support widget above bottom nav */
  #bened-support-widget { bottom: calc(var(--pwa-bottom-h) + 12px) !important; }
}

/* ── Player transport bar ──────────────────────────────────────── */
#player-transport {
  -webkit-tap-highlight-color: transparent;
}
#player-transport button {
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}

/* ── Skeleton Loading Screens ──────────────────────────────────── */
@keyframes skeleton-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton-pulse {
  background: linear-gradient(90deg, #1f1f1f 25%, #2a2a2a 50%, #1f1f1f 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 8px;
}
.skeleton-card .skeleton-thumb {
  aspect-ratio: 16/9;
  border-radius: 12px;
  margin-bottom: 12px;
}
.skeleton-card .skeleton-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}
.skeleton-card .skeleton-title {
  height: 14px;
  width: 85%;
  margin-bottom: 8px;
}
.skeleton-card .skeleton-title-short {
  height: 14px;
  width: 55%;
  margin-bottom: 8px;
}
.skeleton-card .skeleton-meta {
  height: 12px;
  width: 40%;
}
.skeleton-comment .skeleton-comment-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}
.skeleton-comment .skeleton-comment-name {
  height: 12px;
  width: 100px;
  margin-bottom: 8px;
}
.skeleton-comment .skeleton-comment-body {
  height: 12px;
  width: 80%;
  margin-bottom: 6px;
}
.skeleton-comment .skeleton-comment-body-short {
  height: 12px;
  width: 50%;
}
.skeleton-rec .skeleton-rec-thumb {
  width: 160px;
  aspect-ratio: 16/9;
  border-radius: 8px;
  flex-shrink: 0;
}
.skeleton-rec .skeleton-rec-title {
  height: 12px;
  width: 90%;
  margin-bottom: 6px;
}
.skeleton-rec .skeleton-rec-title-short {
  height: 12px;
  width: 60%;
  margin-bottom: 6px;
}
.skeleton-rec .skeleton-rec-meta {
  height: 10px;
  width: 45%;
}

/* ── View Transitions ──────────────────────────────────────────── */
@view-transition {
  navigation: auto;
}
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 150ms;
  animation-timing-function: ease-out;
}

/* ── Optimistic state flash ────────────────────────────────────── */
.optimistic-flash {
  transition: transform 120ms ease, opacity 120ms ease;
}
.optimistic-flash-active {
  transform: scale(1.15);
  opacity: 0.7;
}
