.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  flex: 0 0 auto;
  background: var(--header-bg);
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease;
  overflow-x: hidden;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
}

.sidebar.collapsed {
  width: 72px;
}

.sidebar.collapsed .label {
  display: none;
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  overflow: hidden;
}

.logo-mark {
  color: var(--accent);
  font-size: 1.1rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.6rem;
  gap: 0.15rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

/* Legal footer pinned to bottom of the left column */
.sidebar .sidebar-footer,
.sidebar .site-footer.sidebar-footer {
  margin-top: auto;
  flex: 0 0 auto;
  padding: 0.65rem 0.75rem 0.85rem;
  border-top: 1px solid var(--border);
  background: transparent;
  text-align: left;
}

.sidebar .sidebar-footer .site-footer-meta {
  margin: 0.45rem 0 0;
  font-size: 0.72rem;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.sidebar .sidebar-footer .site-footer-nav {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.1rem 0;
  font-size: 0.68rem;
  line-height: 1.4;
}

.sidebar .sidebar-footer .site-footer-sep {
  display: inline;
  margin: 0 0.1rem;
  color: var(--border);
}

.sidebar .sidebar-footer .site-footer-nav a {
  padding: 0.05rem 0.2rem;
  color: var(--muted);
  white-space: nowrap;
}

.sidebar .sidebar-footer .site-footer-nav a:hover {
  color: var(--text);
}

.sidebar .sidebar-footer .site-footer-rta {
  min-width: 1.6rem;
  font-size: 0.55rem;
  padding: 0.05rem 0.3rem;
}

/* Collapsed sidebar: hide long legal list, keep copyright mark */
.sidebar.collapsed .sidebar-footer .site-footer-nav {
  display: none;
}

.sidebar.collapsed .sidebar-footer .site-footer-meta span:first-child {
  display: none;
}

.sidebar.collapsed .sidebar-footer {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0.35rem 0.75rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.6rem 0.6rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}

.nav-item:hover {
  background: var(--btn-bg);
}

.nav-item.active {
  background: var(--btn-bg);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-icon {
  flex: 0 0 auto;
  display: inline-flex;
  width: 20px;
  justify-content: center;
}

.nav-section-title {
  margin: 0.9rem 0 0.2rem;
  padding: 0 0.6rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.affiliate-list {
  display: flex;
  flex-direction: column;
  max-height: 340px;
  overflow-y: auto;
}

.affiliate-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-sm, .avatar-lg {
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: 0 0 auto;
}

.avatar-sm { width: 28px; height: 28px; font-size: 0.75rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.3rem; }

/* ---------- Main column ---------- */
.main-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  /* Sticky categories bar sits under the topbar */
  --topbar-height: 3.75rem;
}

.topbar {
  background: var(--header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 6;
  min-height: var(--topbar-height);
  box-sizing: border-box;
}

.search-form {
  /* Wide enough for "Search videos, images, galleries, groups…" */
  flex: 0 1 22rem;
  max-width: 26rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--btn-bg);
  border-radius: 20px;
  padding: 0.5rem 0.9rem;
  color: var(--muted);
  min-width: 12rem;
}

.search-form input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.9rem;
}

.topbar-explore {
  display: flex;
  align-items: center;
  justify-content: center;
  column-gap: 2.5rem;
  row-gap: 0.35rem;
  flex: 1 1 auto;
  flex-wrap: wrap;
  min-width: 0;
  padding: 0 1rem;
}

.topbar-link {
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 0.55rem 0.15rem 0.4rem;
  margin: 0;
  border-radius: 0;
  opacity: 0.9;
  white-space: nowrap;
  line-height: 1.2;
  border-bottom: 2px solid transparent;
  background: transparent;
}

.topbar-link:hover {
  opacity: 1;
  color: var(--text);
}

/* Active page: underline only */
.topbar-link.is-active {
  opacity: 1;
  font-weight: 700;
  border-bottom-color: var(--accent);
  color: var(--text);
}

.auth-buttons {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 0 0 auto;
}

.auth-buttons .profile-icon.is-active,
.auth-buttons .profile-icon:hover {
  background: var(--btn-bg);
  border-radius: 8px;
}

/* ---------- Language switcher ---------- */
.lang-switcher {
  position: relative;
  flex: 0 0 auto;
}

.lang-toggle .lang-flag {
  font-size: 1.15rem;
  line-height: 1;
}

/* Neutral language code badge (e.g. EN) instead of a national flag */
.lang-flag--badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55rem;
  height: 1.15rem;
  padding: 0 0.28rem;
  border-radius: 4px;
  font-size: 0.62rem !important;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--btn-text, #fff);
  background: var(--accent, #e11d48);
  box-sizing: border-box;
}

.lang-toggle .lang-flag--badge {
  min-width: 1.7rem;
  height: 1.25rem;
  font-size: 0.68rem !important;
}

.lang-menu {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 180px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 20;
  display: none;
}

.lang-switcher.is-open .lang-menu {
  display: block;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.88rem;
  text-align: left;
}

.lang-option:hover,
.lang-option:focus-visible {
  background: var(--btn-bg);
}

.lang-option.is-active {
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}

.lang-option .lang-flag {
  font-size: 1.1rem;
  flex: 0 0 auto;
  width: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lang-option .lang-flag--badge {
  width: auto;
}

/* ---------- Categories bar ---------- */
.categories-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  /* Sit just under the sticky topbar while the page scrolls */
  top: var(--topbar-height, 3.75rem);
  z-index: 5;
}

.categories-track {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  scroll-behavior: smooth;
}

.categories-track::-webkit-scrollbar {
  display: none;
}

.cat-btn {
  background: var(--btn-bg);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  white-space: nowrap;
  flex: 0 0 auto;
}

.cat-btn.active,
.cat-btn:hover {
  background: var(--accent);
}

.cat-scroll {
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  font-size: 1.1rem;
}

.cat-scroll.is-hidden {
  display: none;
}

/* ---------- Content ---------- */
.content {
  padding: 1.5rem;
  flex: 1 1 auto;
}

.section {
  margin-bottom: 2.25rem;
}

.section-title {
  font-size: 1.1rem;
  margin: 0 0 1rem;
}

.muted { color: var(--muted); font-size: 0.85rem; }

.empty-state {
  color: var(--muted);
  padding: 2rem 0;
}

/* 5 videos per row.
   listing_per_page() serves 25 items → 5 rows + paginator
   (categories, tags, search, latest, top-rated, popular, history). */
.grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1.25rem;
}

/* Alias kept for home markup; same as .grid. */
.grid--home-latest,
.grid--for-you,
.grid--being-watched,
.grid--live-thumbs {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.row-scroll {
  display: flex;
  gap: 1.25rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.row-scroll .video-card {
  flex: 0 0 260px;
}

.video-card {
  display: block;
}

.thumb-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: var(--btn-bg);
}

.thumb-wrap img,
.thumb-wrap .thumb-static,
.thumb-wrap .thumb-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Hover-to-play preview video (lazy-loaded on mouseenter) */
.thumb-wrap .thumb-video,
.short-card .thumb-video {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  background: #000;
}

.thumb-wrap.is-previewing .thumb-video,
.short-card.is-previewing .thumb-video {
  opacity: 1;
}

.badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.75);
}

.badge-live {
  background: var(--accent);
  left: 6px;
  right: auto;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.video-meta {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.video-meta-text {
  min-width: 0;
}

.video-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-sub {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ---------- Shorts ---------- */
.shorts-row .short-card {
  flex: 0 0 160px;
}

.short-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 9 / 16;
  background: var(--btn-bg);
  display: block;
}

.short-card img,
.short-card .thumb-static {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.short-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 0.6rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
}

.thumb-wrap .badge,
.short-card .badge {
  z-index: 3;
}

.short-card .badge-duration {
  bottom: auto;
  top: 6px;
}

.short-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
}

.short-sub {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---------- Tiles / tags / channels ---------- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.tile {
  background: var(--btn-bg);
  border-radius: 10px;
  padding: 1.5rem 1rem;
  text-align: center;
  font-weight: 600;
}

.tile:hover { background: var(--accent); }

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem;
}

.channel-tile {
  background: var(--btn-bg);
  border-radius: 10px;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
}

.channel-tile:hover { filter: brightness(1.15); }

.channel-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.channel-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ---------- Watch page ---------- */
.watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.5rem;
  align-items: start;
}

/*
 * Portrait (desktop only): 60% width for the player, 40% for details.
 * Player height nearly fills the viewport under topbar + categories bar.
 * Related videos sit full-width below.
 */
.watch-layout--portrait {
  /* topbar + sticky categories bar + .content top padding + small bottom gap */
  --watch-chrome-height: calc(
    var(--topbar-height, 3.75rem) /* sticky topbar */
    + 3.5rem                      /* categories bar (~padding + pills) */
    + 1.5rem                      /* .content padding-top */
    + 0.75rem                     /* breathing room under player */
  );
  --watch-player-height: calc(100dvh - var(--watch-chrome-height));
  grid-template-columns: minmax(0, 6fr) minmax(0, 4fr); /* 60% / 40% */
  grid-template-rows: auto auto;
  gap: 1.25rem 1.5rem;
  align-items: start;
}

.watch-layout--portrait .watch-player-col {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  height: var(--watch-player-height);
}

.watch-layout--portrait .watch-details-col {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  height: var(--watch-player-height);
  max-height: var(--watch-player-height);
  overflow-y: auto;
  padding-right: 0.35rem;
}

.watch-layout--portrait .watch-related {
  grid-column: 1 / -1;
  grid-row: 2;
  margin-top: 0.25rem;
}

.player-wrap {
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: #000;
  position: relative;
}

.player-wrap--portrait {
  aspect-ratio: 9 / 16;
  max-width: 420px;
  margin-inline: auto;
}

/* Full-viewport-height portrait player in the 60% column */
.watch-layout--portrait .player-wrap--fullheight,
.player-wrap--fullheight {
  aspect-ratio: auto;
  max-width: none;
  width: 100%;
  margin-inline: 0;
  height: 100%;
  min-height: 0;
  max-height: none;
}

.watch-layout--portrait .player-wrap--fullheight {
  height: var(--watch-player-height);
}

.player-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.player-missing {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--muted);
  padding: 1rem;
  text-align: center;
}

.player-missing img {
  max-width: 100%;
  max-height: 70%;
  object-fit: contain;
}

.watch-description {
  margin: 0.5rem 0 0;
  line-height: 1.45;
  color: var(--text);
}

.watch-title {
  font-size: 1.3rem;
  margin: 1rem 0 0.35rem;
}

.watch-layout--portrait .watch-title {
  margin-top: 0;
  font-size: 1.15rem;
}

.watch-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.grid--related {
  margin-top: 0.5rem;
}

@media (max-width: 1000px) {
  .watch-layout,
  .watch-layout--portrait {
    grid-template-columns: 1fr;
  }
  .watch-layout--portrait .watch-player-col,
  .watch-layout--portrait .watch-details-col,
  .watch-layout--portrait .watch-related {
    grid-column: 1;
    grid-row: auto;
    height: auto;
    max-height: none;
  }
  .watch-layout--portrait .player-wrap--fullheight,
  .player-wrap--fullheight {
    height: auto;
    min-height: 0;
    max-height: 75vh;
    aspect-ratio: 9 / 16;
  }
}
