/* css/styles.css — tema escuro moderno, layout responsivo. */

:root {
  --bg: #0e1015;
  --bg-elev: #161a22;
  --bg-elev-2: #1e232e;
  --border: #2a3140;
  --text: #e7ecf3;
  --text-dim: #9aa4b2;
  --text-faint: #6b7482;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --danger: #ff5b6e;
  --star: #ffcb45;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --topbar-h: 60px;
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

/* Garante que o atributo `hidden` sempre esconda o elemento, mesmo quando
   ele tem `display: grid/flex` no CSS (senão os overlays ficam visíveis). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

body.no-scroll { overflow: hidden; }

/* Com o player aberto, remove o conteúdo de fundo da árvore de renderização.
   Isso evita que o navegador continue pintando/compondo o grid (que pode ter
   centenas de imagens) a cada frame do vídeo — o que causava travamentos. */
body.player-open .layout,
body.player-open .topbar { display: none; }

/* ------------------------------- Botões ------------------------------ */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  color: var(--text);
  background: var(--bg-elev-2);
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-elev-2); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }

/* ------------------------------- Topbar ------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: rgba(14, 16, 21, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 18px;
  white-space: nowrap;
}
.brand-logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 15px;
}
.brand-name { font-weight: 500; color: var(--text-dim); }
.brand-name strong { color: var(--text); font-weight: 800; }

.search-wrap { flex: 1; max-width: 560px; margin: 0 auto; }
.search-input {
  width: 100%;
  height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}
.search-input::placeholder { color: var(--text-faint); }

.topbar-actions { display: flex; gap: 8px; }

/* ------------------------- Switcher de playlists --------------------- */

.playlist-switcher { position: relative; flex-shrink: 0; }

.playlist-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.playlist-btn:hover { border-color: var(--accent); }
.playlist-btn-icon { color: var(--text-dim); font-size: 16px; }
.playlist-btn-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-btn-caret { color: var(--text-faint); font-size: 11px; }

.playlist-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 55;
  width: 280px;
  max-width: 84vw;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.playlist-menu-list { list-style: none; margin: 0; padding: 6px; max-height: 320px; overflow-y: auto; }
.playlist-menu-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-radius: var(--radius-sm);
}
.playlist-menu-item.active { background: var(--bg-elev-2); }
.pl-pick {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 9px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 14px;
}
.pl-pick:hover { background: var(--bg-elev-2); }
.pl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-kind {
  flex-shrink: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}
.playlist-menu-item.active .pl-name { color: var(--accent); font-weight: 700; }
.pl-remove {
  flex-shrink: 0;
  width: 34px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.pl-remove:hover { background: rgba(255, 91, 110, 0.15); color: var(--danger); }
.playlist-menu-add {
  width: 100%;
  padding: 11px;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.playlist-menu-add:hover { background: var(--bg-elev-2); }
.playlist-menu-empty { padding: 14px 12px; color: var(--text-faint); font-size: 13px; text-align: center; }

/* --------------------------- Escopo de busca ------------------------- */

.search-scope {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.search-scope-label { font-size: 13px; color: var(--text-dim); }
.scope-chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.scope-chip:hover { border-color: var(--accent); }
.scope-chip.active {
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.22), rgba(124, 91, 255, 0.22));
  border-color: var(--accent);
  color: var(--text);
}

/* ------------------------------- Layout ------------------------------ */

.layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  height: calc(100vh - var(--topbar-h));
  position: sticky;
  top: var(--topbar-h);
}

.nav-types { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14.5px;
  font-weight: 600;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.18), rgba(124, 91, 255, 0.18));
  color: var(--text);
}
.nav-item.active .nav-icon { filter: none; }
.nav-icon { font-size: 17px; width: 22px; text-align: center; }
.nav-label { flex: 1; }
.nav-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-faint);
  background: var(--bg-elev-2);
  border-radius: 999px;
  padding: 2px 8px;
  min-width: 26px;
  text-align: center;
}
.nav-item.active .nav-badge { color: var(--text); }

.nav-section { margin-top: 22px; }
.nav-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 8px 12px;
}

.category-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.category-item:hover { background: var(--bg-elev); color: var(--text); }
.category-item.active { background: var(--bg-elev-2); color: var(--text); font-weight: 600; }
.category-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }
.category-empty { color: var(--text-faint); padding: 8px 12px; list-style: none; }

/* ------------------------------ Conteúdo ----------------------------- */

.content { flex: 1; padding: 22px 26px; min-width: 0; }
.content-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; }
.view-title { font-size: 22px; font-weight: 800; margin: 0; }
.view-count { color: var(--text-faint); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 40vh;
  color: var(--text-faint);
}

/* -------------------------------- Card ------------------------------- */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.card:hover,
.card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.card-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-elev-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.card-thumb-img { width: 100%; height: 100%; object-fit: contain; padding: 12px; }
/* Quando não há imagem, mostra a inicial do nome como placeholder. */
.card-thumb.no-img::before {
  content: attr(data-initials);
  font-size: 42px;
  font-weight: 800;
  color: var(--text-faint);
  opacity: 0.5;
}

.card-fav {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.15s, transform 0.1s;
}
.card:hover .card-fav { opacity: 1; }
.card-fav.active { opacity: 1; color: var(--star); }
.card-fav:hover { transform: scale(1.12); }

.card-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 34px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.15s;
  /* Puramente decorativo: não deve capturar cliques, senão fica por cima do
     botão de favoritar e o clique acaba abrindo o player. */
  pointer-events: none;
}
.card:hover .card-play { opacity: 1; }

.card-body { padding: 10px 12px 12px; }
.card-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-sub {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.load-more { grid-column: 1 / -1; justify-self: center; margin-top: 10px; }

/* ------------------------------- Player ------------------------------ */

.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  /* Fundo opaco em vez de backdrop-filter: borrar a página inteira a cada
     frame do vídeo é muito custoso e trava a reprodução na janela. */
  background: rgba(6, 8, 12, 0.96);
  display: grid;
  place-items: center;
  padding: 20px;
}

.player-box {
  width: min(960px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.player-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.player-logo { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: var(--bg-elev-2); }
.player-title { font-size: 16px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta { font-size: 12px; color: var(--text-faint); margin: 2px 0 0; }
.player-head-actions { display: flex; gap: 4px; flex-shrink: 0; }
.player-head-actions .active { color: var(--star); }

.video-wrap { position: relative; background: #000; aspect-ratio: 16 / 9; }
.video-wrap video { width: 100%; height: 100%; display: block; }

/* ---------------------------- Modo teatro ---------------------------- */
/* O player ocupa toda a largura e altura da tela. */
.player-overlay.theater { padding: 0; }
.player-overlay.theater .player-box {
  width: 100%;
  height: 100%;
  max-width: none;
  border: none;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}
.player-overlay.theater .video-wrap {
  flex: 1;
  aspect-ratio: auto;   /* preenche toda a altura disponível */
  min-height: 0;
}
.player-overlay.theater video { object-fit: contain; }
.player-head-actions .theater-btn.active { color: var(--accent); }

.player-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--danger);
  background: rgba(0, 0, 0, 0.6);
  font-weight: 600;
}

/* ------------------------------- Modal ------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  /* Sem backdrop-filter: borrar a viewport inteira força o navegador a
     re-compor o fundo a cada repaint, o que trava com listas grandes atrás.
     Um fundo opaco resolve visualmente e é muito mais barato. */
  background: rgba(6, 8, 12, 0.86);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-box {
  width: min(440px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; margin: 0; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.field .req { color: var(--accent); }
.field input[type="text"],
.field input[type="url"],
.field input[type="file"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.field input[type="text"]:focus,
.field input[type="url"]:focus { border-color: var(--accent); }

.divider { display: flex; align-items: center; gap: 10px; color: var(--text-faint); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.load-status { font-size: 13px; color: var(--text-dim); margin: 0; }
.load-status.error { color: var(--danger); }

/* ------------------------------- Sobre ------------------------------- */

.about-body { gap: 16px; }
.about-brand { display: flex; align-items: center; gap: 14px; }
.about-logo { border-radius: 12px; flex-shrink: 0; }
.about-title { margin: 0; font-size: 18px; }
.about-tagline { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }
.about-text { margin: 0; font-size: 14px; color: var(--text-dim); line-height: 1.55; }
.about-text code {
  background: var(--bg-elev-2);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12.5px;
}
.about-links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.about-links li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.about-links li:last-child { border-bottom: none; padding-bottom: 0; }
.about-label {
  flex-shrink: 0;
  width: 92px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}
.about-links a { color: var(--accent); text-decoration: none; word-break: break-all; }
.about-links a:hover { text-decoration: underline; }
.about-cta { text-align: center; text-decoration: none; margin-top: 4px; }

/* ------------------------------- Toast ------------------------------- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.error { border-color: var(--danger); color: #ffd7dc; }

/* ------------------------------ Responsivo --------------------------- */

.only-mobile { display: none; }
.backdrop {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 45;
}

@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .brand-name { display: none; }
  .playlist-btn { max-width: 130px; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 50;
    background: var(--bg-elev);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .content { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
}

@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .brand { display: none; }
  .playlist-btn-name { display: none; }
  .playlist-btn { max-width: none; }
  .topbar-actions .btn { padding: 9px 10px; font-size: 0; }
  .topbar-actions .btn::before { content: "＋"; font-size: 18px; }
}

/* Barra de rolagem discreta */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #38414f; }
