/* ── VARIABLES ── */
:root {
  --bg: #0f0f0f;
  --bg2: #181818;
  --bg3: #272727;
  --border: #3f3f3f;
  --text: #f1f1f1;
  --muted: #aaaaaa;
  --sidebar-w: 240px;
  --nav-h: 56px;
  --filter-h: 54px;
  --nav-border: rgba(255, 255, 255, 0.06);
}

body.light {
  --bg: #ffffff;
  --bg2: #f9f9f9;
  --bg3: #e5e5e5;
  --border: #cccccc;
  --text: #0f0f0f;
  --muted: #606060;
  --nav-border: rgba(0, 0, 0, 0.1);
}

/* ── RESET ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  width: 100%;
}

body {
  font-family: 'Roboto', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  width: 100%;
  transition: background 0.2s, color 0.2s;
}

/* ── NAVBAR ── */
nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--nav-h);
  background: var(--bg);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  border-bottom: 1px solid var(--nav-border);
  gap: 8px;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.hamburger:hover { background: var(--bg3); }

.yt-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

/* Search — takes up remaining space */
.nav-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.search-form {
  flex: 1;
  display: flex;
  align-items: center;
  height: 40px;
  min-width: 0;
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 20px 0 0 20px;
  padding: 0 16px;
  color: var(--text);
  font-size: 1rem;
  font-family: 'Roboto', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: #1c62b9; }
.search-input::placeholder { color: var(--muted); }

.search-btn {
  flex-shrink: 0;
  width: 56px;
  height: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 20px 20px 0;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.search-btn:hover { background: var(--border); }

.voice-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: var(--bg3);
  border: none;
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.voice-btn:hover { background: var(--border); }

/* Right nav items — fixed width, never shrink */
.nav-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.nav-icon-btn {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.nav-icon-btn:hover { background: var(--bg3); }

.theme-btn {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.theme-btn:hover { background: var(--bg3); }

.sign-in-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid #3ea6ff;
  background: transparent;
  color: #3ea6ff;
  padding: 0 14px;
  height: 36px;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
  font-family: 'Roboto', sans-serif;
}
.sign-in-btn:hover { background: rgba(62, 166, 255, 0.1); }

/* ── SIDEBAR ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 95;
  padding: 12px 0;
  padding-top: calc(var(--nav-h) + 12px);
  transition: transform 0.25s ease;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }
.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-section {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--bg3);
  margin-bottom: 12px;
}
.sidebar-section:last-child { border-bottom: none; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.875rem;
  border-radius: 10px;
  margin: 1px 8px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.sidebar-link:hover, .sidebar-link.active { background: var(--bg3); }
.sidebar-link.active { font-weight: 500; }

.sidebar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
}

.sidebar-section-title {
  padding: 8px 24px 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Sidebar backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 94;
}
.sidebar-backdrop.visible { display: block; }

/* ── MAIN CONTENT ── */
.main {
  margin-top: calc(var(--nav-h) + var(--filter-h));
  margin-left: var(--sidebar-w);
  min-height: calc(100vh - var(--nav-h) - var(--filter-h));
  transition: margin-left 0.25s;
  width: calc(100% - var(--sidebar-w));
  overflow-x: hidden;
  padding-top: 0;
}
.main.full {
  margin-left: 0;
  width: 100%;
}

/* ── FILTER CHIPS ── */
.filter-bar {
  position: fixed;
  top: var(--nav-h);
  left: var(--sidebar-w);
  right: 0;
  background: var(--bg);
  z-index: 90;
  display: flex;
  gap: 12px;
  padding: 12px 24px;
  overflow-x: auto;
  border-bottom: 1px solid var(--nav-border);
  width: auto;
}
.filter-bar::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  height: 32px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  font-family: 'Roboto', sans-serif;
  transition: background 0.15s;
  background: var(--bg3);
  color: var(--text);
  flex-shrink: 0;
}
.chip:hover { background: var(--border); }
.chip.active { background: var(--text); color: var(--bg); }

/* ── VIDEO GRID ── */
.video-grid,
.loading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  padding: 24px;
  width: 100%;
}

.video-card {
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  transition: transform 0.15s;
}
.video-card:hover { transform: translateY(-2px); }

.thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg3);
  border-radius: 12px;
  overflow: hidden;
}
.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.video-card:hover .thumb-wrap img { transform: scale(1.02); }

/* Shimmer animation */
.thumb-skeleton,
.skeleton-line,
.skeleton-avatar {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.thumb-skeleton { width: 100%; height: 100%; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.duration {
  position: absolute;
  bottom: 6px;
  right: 8px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 2px 5px;
  border-radius: 4px;
}

.video-info {
  display: flex;
  gap: 12px;
  padding: 12px 0 6px;
  min-width: 0;
}

.channel-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
}
.channel-avatar img { width: 100%; height: 100%; object-fit: cover; }

.video-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.video-title {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
  color: var(--text);
  word-break: break-word;
}

.channel-name {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-stats {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Skeleton lines */
.skeleton-line { height: 13px; border-radius: 4px; margin: 12px 0 6px; }
.skeleton-line.short { width: 55%; margin-top: 5px; }
.skeleton-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; }

/* ── ERROR STATE ── */
.error-msg {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}
.error-msg .icon { font-size: 3rem; margin-bottom: 1rem; }
.error-msg h3 { font-size: 1.1rem; color: var(--text); margin-bottom: 0.4rem; }
.error-msg p { font-size: 0.875rem; max-width: 360px; margin: 0 auto; }

.retry-btn {
  margin-top: 1rem;
  padding: 8px 20px;
  background: var(--bg3);
  border: none;
  border-radius: 20px;
  color: var(--text);
  cursor: pointer;
  font-family: 'Roboto', sans-serif;
  font-size: 0.875rem;
  transition: background 0.2s;
}
.retry-btn:hover { background: var(--border); }

/* ── VIDEO MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border-radius: 12px;
  width: 100%;
  max-width: 900px;
  max-height: 92vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.modal-close:hover { background: var(--bg3); color: var(--text); }

.modal-player { width: 100%; aspect-ratio: 16 / 9; background: #000; }
.modal-player iframe { width: 100%; height: 100%; border: none; }

.modal-info { padding: 16px 20px 20px; }
.modal-title { font-size: 1rem; font-weight: 600; line-height: 1.4; margin-bottom: 6px; }
.modal-channel { font-size: 0.875rem; color: var(--muted); margin-bottom: 12px; }
.modal-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-pill {
  background: var(--bg3);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── SENTINEL ── */
#scrollSentinel { height: 1px; width: 100%; }

/* ═══════════════════════════════
   RESPONSIVE BREAKPOINTS
═══════════════════════════════ */

/* Collapsed sidebar at 1100px */
@media (max-width: 1100px) {
  .sidebar { width: 72px; }
  .sidebar .sidebar-link span,
  .sidebar .sidebar-section-title { display: none; }
  .sidebar-link { gap: 0; justify-content: center; padding: 10px; }
  .main { margin-left: 72px; width: calc(100% - 72px); }
  .filter-bar { left: 72px; }
}

/* ── MOBILE ── */
@media (max-width: 768px) {
  /* Sidebar */
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar .sidebar-link span,
  .sidebar .sidebar-section-title { display: block; }
  .sidebar-link { gap: 24px; justify-content: flex-start; padding: 10px 24px; }

  /* Main full width */
  .main { margin-left: 0; width: 100%; }

  /* Nav: only hamburger, logo, search, theme */
  .voice-btn { display: none; }
  .hide-md { display: none; }
  .sign-in-btn { display: none; }
  nav { padding: 0 12px; gap: 6px; }

  /* Filter bar full width fixed */
  .filter-bar {
    left: 0;
    padding: 8px 12px;
    gap: 8px;
  }
  .chip { height: 30px; padding: 0 12px; font-size: 0.82rem; }

  /* Single column */
  .video-grid, .loading-grid {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

  /* Full-width card */
  .video-card { border-radius: 0; padding: 0 0 16px; }
  .thumb-wrap { border-radius: 0; }
  .video-info { padding: 10px 12px 0; gap: 10px; }
  .video-title { font-size: 0.9rem; }
  .channel-name, .video-stats { font-size: 0.8rem; }
}
