:root {
  --bg: #0f1013;
  --panel: #17181d;
  --panel-2: #1e2027;
  --border: #2a2c35;
  --text: #e8e8ec;
  --muted: #9a9aa5;
  --accent: #ffb454;
  --accent-dim: rgba(255, 180, 84, 0.14);
  --danger: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- Barra superior ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15, 16, 19, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.unifrakturcook-bold {
  font-family: "UnifrakturCook", cursive;
  font-weight: 700;
  font-style: normal;
}
.brand.unifrakturcook-bold {
  font-size: 30px;
  line-height: 1;
  color: var(--accent);
}

.search-wrap { position: relative; flex: 1; max-width: 480px; }

#search {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  outline: none;
}
#search:focus { border-color: var(--accent); }

.actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }

.sync-status { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.sync-status.saved { color: #7bd88f; }
.sync-status.error { color: var(--danger); }

#btn-user { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

/* ---------- Selector de perfil ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(9, 10, 12, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 460px;
  width: 100%;
  text-align: center;
}
.gate-brand { font-size: 48px; line-height: 1; color: var(--accent); margin-bottom: 6px; }
.gate-q { color: var(--muted); margin: 0 0 22px; font-size: 15px; }
.gate-users { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 22px; }
.gate-users:empty { display: none; }
.gate-user {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 15px;
  cursor: pointer;
}
.gate-user:hover { border-color: var(--accent); color: var(--accent); }
.gate-new { display: flex; gap: 8px; }
.gate-new input {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  outline: none;
}
.gate-new input:focus { border-color: var(--accent); }
.gate-msg { color: var(--muted); font-size: 14px; }
.gate-msg.error, .gate-error { color: var(--danger); }
.gate-error { min-height: 18px; margin-top: 12px; font-size: 13px; }
.gate-note { color: var(--muted); font-size: 12px; margin: 20px 0 0; line-height: 1.4; }
.gate code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.shake { animation: shake 0.25s ease; }

/* ---------- Botones ---------- */

button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1204;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }

button.secondary {
  background: var(--accent-dim);
  border-color: transparent;
  color: var(--accent);
  font-weight: 500;
}

button.ghost { background: transparent; }
button.sm { padding: 4px 10px; font-size: 13px; border-radius: 6px; }
button.danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }

/* ---------- Tags ---------- */

.tagbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 0;
  max-width: 1280px;
  margin: 0 auto;
}
.tagbar:empty { display: none; }

.chip {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.chip:hover { border-color: var(--muted); color: var(--text); }
.chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.chip .count { opacity: 0.6; margin-left: 4px; }

.chip .pencil, .chip .x { display: none; margin-left: 6px; }
.chip:hover .pencil, .chip:hover .x { display: inline; }
.chip .pencil:hover, .chip .x:hover { color: var(--accent); }

.chip.view { color: var(--text); border-style: dashed; }
.chip.save-view { color: var(--accent); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: var(--panel-2);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  border: 1px solid transparent;
}
.tag:hover { color: var(--accent); border-color: var(--accent); }

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 20px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px 60px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.list-count { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

/* ---------- Cards ---------- */

#list { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--muted); }
.card.playing { border-color: var(--accent); background: linear-gradient(var(--accent-dim), transparent 60%) var(--panel); }

.card-main { display: flex; align-items: center; gap: 12px; }

.card-art {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--panel-2);
}
.card-art.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--muted);
}

.card-info { min-width: 0; flex: 1; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-artist { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.time-badge {
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.group-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.card-link {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
}
.card-link:hover { color: #1db954; }

/* ---------- Momentos dentro de una canción ---------- */

.moments { display: flex; flex-direction: column; gap: 6px; }

.moment {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid transparent;
  cursor: pointer;
}
.moment:hover { border-color: var(--muted); }
.moment.playing { border-color: var(--accent); }

.moment-body { flex: 1; min-width: 0; }
.moment-body p { margin: 0 0 5px; color: var(--muted); font-size: 13px; }
.moment-body:empty { display: none; }

.moment-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.moment:hover .moment-actions { opacity: 1; }
.moment-actions button {
  padding: 2px 7px;
  font-size: 13px;
  background: transparent;
  border: none;
  color: var(--muted);
}
.moment-actions button:hover { color: var(--accent); }

/* ---------- Estado vacío ---------- */

.empty {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  color: var(--muted);
}
.empty h3 { margin: 0 0 10px; color: var(--text); }
.empty ol { margin: 0; padding-left: 20px; }
.empty li { margin: 6px 0; }

/* ---------- Paneles laterales ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; font-size: 16px; }

.panel label {
  display: block;
  position: relative; /* ancla del desplegable de autocompletado */
  font-size: 13px;
  color: var(--muted);
  margin-top: 12px;
}
.panel label:first-of-type { margin-top: 0; }

.panel input, .panel textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  color: var(--text);
  resize: vertical;
}
.panel input:focus, .panel textarea:focus { border-color: var(--accent); }

.opt { opacity: 0.6; font-weight: 400; }
.req { color: var(--accent); opacity: 0.85; font-weight: 400; }

.row { display: flex; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }

.time-cell { display: flex; gap: 6px; margin-top: 4px; }
.time-cell input { margin-top: 0; min-width: 0; }
.time-cell .cap { flex-shrink: 0; padding: 6px 10px; }

.field-status { font-size: 12.5px; color: var(--muted); margin-top: 4px; min-height: 16px; }
.helper-row { align-items: center; margin-top: 4px; }
.helper-row .field-status { margin-top: 0; }
a.secondary {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
}
a.secondary:hover { filter: brightness(1.15); }

.linkish {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
}
.field-status.ok { color: #7bd88f; }
.field-status.error { color: var(--danger); }

.helper-row #btn-yt-auto { padding: 6px 10px; font-size: 13px; white-space: nowrap; }

/* ---------- Candidatos de YouTube ---------- */

.yt-candidates {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}
.yt-cand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
button.yt-cand:hover { border-color: var(--accent); }
.yt-cand img {
  width: 68px;
  height: 38px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--panel);
}
.yt-cand-info { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.yt-cand-title {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.yt-cand-meta { font-size: 11.5px; color: var(--muted); }
.yt-cand-msg { font-size: 13px; color: var(--muted); padding: 6px 2px; }
.yt-cand-msg.error { color: var(--danger); }

.meta-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}
.meta-preview img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; }

.form-actions { margin-top: 16px; }
.form-actions button { width: 100%; }

/* ---------- Autocompletado ---------- */

.ac-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-height: 260px;
  overflow-y: auto;
  z-index: 30;
}
.ac-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}
.ac-item:hover, .ac-item.sel { background: var(--accent-dim); }
.ac-kind { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }

/* ---------- Sonando ahora ---------- */

.np-main { display: flex; align-items: center; gap: 12px; }
#np-artwork { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; }
.np-info { min-width: 0; flex: 1; }
#np-title { font-weight: 600; }
#np-artist { color: var(--muted); font-size: 13px; }
#np-replay { white-space: nowrap; font-variant-numeric: tabular-nums; }
.loop-toggle { margin-top: 10px; width: 100%; font-variant-numeric: tabular-nums; }
.loop-toggle.off { opacity: 0.55; }
#now-playing .tags { margin-top: 10px; }
.np-desc { margin: 10px 0 0; color: var(--muted); font-size: 13.5px; }
.np-desc:empty { display: none; }
.np-link {
  display: inline-block;
  margin-top: 10px;
  color: #1db954;
  font-size: 13px;
  text-decoration: none;
}
.np-link:hover { text-decoration: underline; }

/* ---------- Reproductor ---------- */

.player-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.player-shell iframe { display: block; width: 100%; height: 100%; }

#player-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 20px;
}

/* ---------- Responsive ---------- */

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; order: -1; }
  .topbar { flex-wrap: wrap; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .actions { margin-left: 0; }
}
