/* Modern Styling for YouTube Video Controller & Player */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0a0c;
  --bg-secondary: #121216;
  --bg-card: rgba(30, 30, 38, 0.6);
  --bg-hover: rgba(255, 255, 255, 0.08);
  --accent: #ff0055;
  --accent-glow: rgba(255, 0, 85, 0.4);
  --accent-muted: #d9004c;
  --text-primary: #f5f5f7;
  --text-secondary: #a1a1aa;
  --text-muted: #6b7280;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.59);
  --glass-blur: blur(12px);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  height: 100vh;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* Controller Layout */
.app-container {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  height: 100vh;
  background: radial-gradient(circle at 50% 0%, #1e112a 0%, var(--bg-primary) 70%);
}

/* Mobile tab bar: hidden on desktop, shown only via mobile media query */
.mobile-tab-bar {
  display: none;
}

/* Sidebar & Panels */
.sidebar, .main-content, .queue-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--border);
  background: transparent;
  overflow: hidden;
}

.queue-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel-header {
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.panel-header h1, .panel-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-header h1 span {
  color: var(--accent);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Buttons & Inputs */
.btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
}

.btn:hover {
  background: var(--text-primary);
  color: var(--bg-primary);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-muted);
  color: white;
  box-shadow: 0 0 15px var(--accent-glow);
}

.btn-danger {
  background: rgba(220, 38, 38, 0.2);
  border-color: rgba(220, 38, 38, 0.4);
  color: #fca5a5;
}

.btn-danger:hover {
  background: rgb(220, 38, 38);
  color: white;
}

.input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

input[type="text"] {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: var(--transition);
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 0, 85, 0.2);
}

/* Playlists Sidebar */
.playlist-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.playlist-item {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.playlist-item:hover, .playlist-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.playlist-item.active {
  border-left: 3px solid var(--accent);
  background: rgba(255, 0, 85, 0.05);
}

.playlist-item i {
  font-size: 1.1rem;
}

.playlist-item.custom-item {
  justify-content: space-between;
}

.playlist-item .delete-btn {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.playlist-item:hover .delete-btn {
  opacity: 1;
}

.playlist-item .delete-btn:hover {
  color: var(--accent);
}

/* Video Cards & Grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.video-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.video-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: rgba(255, 0, 85, 0.3);
}

.video-thumbnail-container {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 Aspect Ratio */
  background: #000;
}

.video-thumbnail {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.8);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.video-info {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.video-channel {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Controller / Queue Panel styling */
.active-player-state {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
}

.player-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  width: fit-content;
}

.status-connected {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.status-disconnected {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.now-playing-title {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

/* Remote Control Controls */
.playback-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
}

.control-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.control-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.control-btn.btn-play-pause {
  font-size: 1.5rem;
  width: 50px;
  height: 50px;
  background: var(--accent);
  color: white;
}

.control-btn.btn-play-pause:hover {
  background: var(--accent-muted);
  transform: scale(1.05);
}

/* Progress and Volume Bars */
.progress-container {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.slider-bar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-hover);
  outline: none;
  cursor: pointer;
  transition: height 0.1s;
}

.slider-bar:hover {
  height: 6px;
}

.slider-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.1s;
}

.slider-bar::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
}

.volume-control i {
  font-size: 1rem;
  color: var(--text-secondary);
  cursor: pointer;
  width: 20px;
}

/* Queue List */
.queue-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--border);
  transition: var(--transition);
}

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

.queue-item.active {
  border-color: var(--accent);
  background: rgba(255, 0, 85, 0.03);
}

.queue-thumb {
  width: 60px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
}

.queue-info {
  flex: 1;
  min-width: 0;
}

.queue-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.queue-actions {
  display: flex;
  gap: 4px;
}

.queue-actions button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px;
  border-radius: 4px;
  transition: var(--transition);
}

.queue-actions button:hover {
  color: var(--accent);
  background: var(--bg-hover);
}

/* Fullscreen Player Styles */
.fullscreen-body {
  background-color: #000;
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Block user direct iframe interaction for fully remote feel */
}

/* Allow interaction when double click or helper keys are used if desired, but default is remote control */
.player-wrapper.allow-clicks {
  pointer-events: auto;
}

#yt-player {
  width: 100%;
  height: 100%;
  border: none;
}

/* Fullscreen HUD Overlays */
.player-hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 40px;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.player-hud.visible {
  opacity: 1;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

.hud-logo span {
  color: var(--accent);
}

.hud-status {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 30px;
  color: white;
  font-weight: 500;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-bottom {
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
  margin: -40px;
  padding: 60px 40px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hud-now-playing {
  display: flex;
  align-items: center;
  gap: 20px;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.hud-thumbnail {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}

.hud-meta h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: white;
  margin-bottom: 4px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

.hud-meta p {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.hud-progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.hud-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width 0.2s linear;
}

/* Volume/Play HUD indicator (Apple TV style center HUD) */
.hud-center-alert {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: white;
  min-width: 120px;
  min-height: 120px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hud-center-alert.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.hud-center-alert i {
  font-size: 2.5rem;
}

.hud-center-alert span {
  font-size: 1rem;
  font-weight: 600;
}

/* Animations */
@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤ 1024px)
═══════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 240px 1fr;
    grid-template-rows: 1fr auto;
    height: 100vh;
  }
  .queue-panel {
    grid-column: 1 / -1;
    height: 280px;
    border-left: none;
    border-top: 1px solid var(--border);
    flex-direction: row;
    overflow: hidden;
  }
  .queue-panel .active-player-state {
    width: 320px;
    border-right: 1px solid var(--border);
    border-bottom: none;
    flex-shrink: 0;
    overflow-y: auto;
  }
  .queue-panel > div:last-child {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — Mobile (≤ 768px)
═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Layout: single column with tab switching ── */
  body {
    height: 100dvh;   /* dynamic viewport height for mobile browsers */
    overflow: hidden;
  }

  .app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    background: var(--bg-primary);
  }

  /* All panels stack; visibility toggled by .mobile-active class */
  .sidebar,
  .main-content,
  .queue-panel {
    position: fixed;          /* use fixed so it fills the whole screen reliably */
    top: 0;
    left: 0;
    right: 0;
    bottom: 60px;             /* tab bar height */
    height: auto;
    border: none;
    display: none;            /* hidden by default, JS adds .mobile-active */
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
  }

  .sidebar.mobile-active,
  .main-content.mobile-active,
  .queue-panel.mobile-active {
    display: flex;
  }

  /* Inner scroll on panel body */
  .panel-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Mobile Tab Bar ── */
  .mobile-tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(12, 12, 18, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    z-index: 500;
  }

  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: color 0.2s;
    padding: 8px 4px;
  }

  .tab-btn i {
    font-size: 1.1rem;
    transition: transform 0.2s;
  }

  .tab-btn.active {
    color: var(--accent);
  }

  .tab-btn.active i {
    transform: translateY(-2px);
  }

  /* ── Compact Player Mini-Bar (always visible on mobile, inside queue-panel) ── */
  .queue-panel {
    bottom: 60px;
  }

  .queue-panel .active-player-state {
    padding: 12px 16px;
    gap: 10px;
    background: rgba(255,255,255,0.02);
  }

  /* Mini now-playing row */
  .queue-panel .active-player-state > div:nth-child(2) {
    gap: 10px;
  }

  /* Compact controls */
  .control-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  .control-btn.btn-play-pause {
    width: 52px;
    height: 52px;
    font-size: 1.3rem;
  }

  /* ── Sidebar mobile tweaks ── */
  .panel-header {
    padding: 16px;
  }

  .panel-header h1,
  .panel-header h2 {
    font-size: 1.1rem;
  }

  .panel-body {
    padding: 14px;
  }

  /* ── Video grid: 2 columns on mobile ── */
  .video-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .video-card .video-info {
    padding: 10px;
  }

  .video-title {
    font-size: 0.8rem;
  }

  /* ── Queue items: larger touch targets ── */
  .queue-item {
    padding: 10px;
    gap: 10px;
  }

  .queue-thumb {
    width: 52px;
    height: 36px;
  }

  .queue-title {
    font-size: 0.8rem;
  }

  /* Bigger tap area for queue action buttons */
  .queue-actions button {
    width: 32px;
    height: 32px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Inputs & buttons ── */
  input[type="text"] {
    font-size: 1rem;       /* prevent iOS zoom on focus */
    padding: 10px 14px;
  }

  .btn {
    padding: 9px 14px;
    font-size: 0.88rem;
  }

  /* ── Playlist items ── */
  .playlist-item {
    padding: 13px 14px;
    font-size: 0.9rem;
  }

  /* ── Progress bar touch-friendly ── */
  .slider-bar {
    height: 6px;
  }

  .slider-bar::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
  }

  /* ── Now playing title in queue panel ── */
  .now-playing-title {
    font-size: 0.85rem;
  }

  /* ── "Abrir Visor" button — hide label on very small screens ── */
  @media (max-width: 380px) {
    #btn-open-player span { display: none; }
  }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — Small phones (≤ 480px)
   Video grid goes to 1 column
═══════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .video-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Cuenta de usuario y selector de player ───────────── */
#account-bar {
  padding: 12px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
}

.account-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-secondary);
  min-width: 0;
}

.account-user span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.account-players {
  display: flex;
  gap: 6px;
}

.account-players select {
  flex: 1;
  min-width: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
}

.btn.account-mini {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.account-menu[hidden] {
  display: none;
}

.account-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Página de login / registro ───────────────────────── */
.auth-page {
  min-height: 100vh;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.auth-card h1 span {
  color: var(--accent);
}

.auth-card p.auth-sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
}

.auth-tabs .btn {
  flex: 1;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-card input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-error {
  color: #fca5a5;
  font-size: 0.85rem;
  min-height: 1.2em;
}
