/* =============================================================================
   TOKENS
   ============================================================================= */
:root {
  --bg: #110c1c;
  --bg-soft: #171125;
  --panel-bg: #1a1428;
  --panel-bg-raised: #211a33;
  --border: #4a2f80;
  --border-soft: #362459;
  --purple: #a480e0;
  --purple-dim: #7a5cb0;
  --gold: #eaa63f;
  --gold-hover: #f7bb5c;
  --gold-dim: #c98f38;
  --white: #f4f1fa;
  --muted: #9186a8;
  --red: #e2483f;
  --red-hover: #f16158;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  font-size: 16px;
}

* { box-sizing: border-box; }

/* Cualquier elemento con el atributo "hidden" se oculta SIEMPRE, sin
   importar si su propia clase fija un display explicito (flex/grid/etc).
   Sin esto, reglas como ".modal { display:flex }" ganan contra el estilo
   por defecto del navegador para [hidden] y el elemento queda visible
   permanentemente. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 15% -10%, rgba(122,74,180,.16), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(234,166,63,.07), transparent 55%);
  color: var(--white);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
}

button { font-family: inherit; }

::selection { background: var(--gold); color: #241705; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--purple-dim); }

.icon { width: 18px; height: 18px; display: inline-block; vertical-align: middle; fill: none; }
.icon-xl { width: 40px; height: 40px; }

/* =============================================================================
   LAYOUT
   ============================================================================= */
.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 140px;
}

/* ---------- TOP NAV ---------- */
.topnav {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 14px 10px 18px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--purple);
  padding-right: 6px;
  border-right: 1px solid var(--border-soft);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: rgba(164,128,224,.12);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold);
}
.brand-text {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--white);
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 6px;
  flex: 1;
}
.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .08em;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.tab:hover { color: var(--white); }
.tab.active {
  color: var(--gold);
  border-color: var(--gold-dim);
  background: rgba(234,166,63,.08);
}

.btn-refresh {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn-refresh:hover { background: var(--gold); color: #241705; }
.btn-refresh .icon { width: 15px; height: 15px; }
.btn-refresh.spinning .icon { animation: spin .7s linear; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ---------- CONTENT PANEL ---------- */
.content { margin-top: 20px; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 26px 30px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
}
.panel-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  background: rgba(234,166,63,.10);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.panel-head h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: .1em;
  color: var(--gold);
  font-weight: 800;
}
.panel-sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  letter-spacing: .1em;
  color: var(--muted);
}

.divider {
  height: 1px;
  margin: 18px 0 22px;
  background: linear-gradient(90deg, var(--purple-dim), transparent 75%);
}

/* =============================================================================
   AUDIO — TABLA
   ============================================================================= */
.table-head {
  display: grid;
  grid-template-columns: 1fr 110px 110px 90px;
  gap: 10px;
  padding: 0 14px 10px;
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--purple);
  font-weight: 700;
  border-bottom: 1px solid var(--border-soft);
}
.col-action { text-align: right; }

.table-body { display: flex; flex-direction: column; }

.track-row {
  display: grid;
  grid-template-columns: 1fr 110px 110px 90px;
  gap: 10px;
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  transition: background .12s ease;
}
.track-row:hover { background: rgba(164,128,224,.06); }
.track-row.playing { background: rgba(234,166,63,.08); }
.track-row.playing .track-title { color: var(--gold); }

.track-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 10px;
}
.track-ext, .track-size { font-size: 12.5px; color: var(--muted); text-transform: uppercase; }

.track-play {
  justify-self: end;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--gold-dim);
  background: transparent;
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.track-play:hover { background: var(--gold); color: #241705; }
.track-play .icon { width: 14px; height: 14px; }

/* =============================================================================
   IMAGEN — GALERIA
   ============================================================================= */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.gallery-item {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-soft);
  background: var(--bg-soft);
  cursor: pointer;
  aspect-ratio: 1 / 1;
}
.gallery-item img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .25s ease;
}
.gallery-item:hover { border-color: var(--gold-dim); }
.gallery-item:hover img { transform: scale(1.06); }
.gallery-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 8px 10px 6px;
  font-size: 12px;
  color: var(--white);
  background: linear-gradient(0deg, rgba(0,0,0,.75), transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =============================================================================
   VIDEO — GRID
   ============================================================================= */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.video-card {
  background: var(--panel-bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}
.video-card:hover { border-color: var(--gold-dim); transform: translateY(-2px); }

.video-card-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.video-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-card-thumb .icon { width: 30px; height: 30px; color: var(--purple-dim); }

.video-card-play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(17,12,28,.25);
  opacity: 0;
  transition: opacity .15s ease;
}
.video-card:hover .video-card-play { opacity: 1; }
.video-card-play-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: rgba(234,166,63,.92);
  color: #241705;
  display: flex; align-items: center; justify-content: center;
}
.video-card-play-btn .icon { width: 20px; height: 20px; }

.video-card-body { padding: 12px 14px 14px; }
.video-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--white);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-card-tag {
  font-size: 10.5px;
  letter-spacing: .08em;
  color: var(--purple);
}

/* =============================================================================
   EMPTY STATE
   ============================================================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 50px 20px 30px;
  color: var(--muted);
}
.empty-state .icon-xl { color: var(--purple-dim); margin-bottom: 8px; }
.empty-state p { margin: 0; font-size: 14px; }
.empty-sub { font-size: 12.5px !important; color: var(--muted); opacity: .8; }

/* =============================================================================
   BARRA DE AUDIO (PERSISTENTE)
   ============================================================================= */
.audio-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto minmax(200px, 2fr) auto;
  align-items: center;
  gap: 22px;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  padding: 12px 22px;
  box-shadow: 0 -10px 30px rgba(0,0,0,.5);
}

.audio-bar-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--gold);
}
.audio-bar-icon { display: flex; }
.audio-bar-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-bar-controls { display: flex; align-items: center; gap: 8px; }

.ctrl-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.ctrl-btn:hover { border-color: var(--gold-dim); color: var(--gold); }
.ctrl-btn-sm { width: 28px; height: 28px; }
.ctrl-btn-sm .icon { width: 14px; height: 14px; }

.ctrl-btn-main {
  width: 42px; height: 42px;
  background: var(--gold);
  border-color: var(--gold);
  color: #241705;
}
.ctrl-btn-main:hover { background: var(--gold-hover); border-color: var(--gold-hover); color: #241705; }

.ctrl-btn-close {
  position: absolute;
  top: 14px; right: 14px;
  border-color: var(--red);
  color: var(--red);
  z-index: 5;
}
.ctrl-btn-close:hover { background: var(--red); color: var(--white); border-color: var(--red-hover); }

.audio-bar-seek {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.time { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.time-sep { color: var(--muted); font-size: 11.5px; }

.audio-bar-volume { display: flex; align-items: center; gap: 8px; }

/* Sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-soft);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid #241705;
  cursor: pointer;
  margin-top: -1px;
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid #241705;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 3px; }
#audioVolume, #videoVolume { width: 80px; }

/* =============================================================================
   MODALES
   ============================================================================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 6, 15, .82);
  backdrop-filter: blur(3px);
}
.modal-box {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 1;
}

/* --- lightbox imagen --- */
.modal-image {
  max-width: 92vw;
  max-height: 88vh;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.modal-image img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: var(--radius-md);
  object-fit: contain;
}
.modal-caption {
  margin-top: 12px;
  color: var(--white);
  font-size: 13.5px;
  font-weight: 600;
}
.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(26,20,40,.85);
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.modal-nav:hover { border-color: var(--gold-dim); color: var(--gold); }
.modal-nav-prev { left: 8px; }
.modal-nav-next { right: 8px; }

/* --- reproductor video --- */
.modal-video {
  width: min(920px, 92vw);
  max-height: 90vh;
  overflow: auto;
  padding: 18px;
}
.video-stage {
  position: relative;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.video-stage video {
  width: 100%;
  max-height: 62vh;
  display: block;
  background: #000;
}
.video-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 8px 14px 12px;
  background: linear-gradient(0deg, rgba(0,0,0,.82), transparent);
}
.video-seek { margin-bottom: 8px; }
.video-controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.video-controls-spacer { flex: 1; }
.video-volume { width: 70px; }

.video-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(10, 6, 16, .85);
  color: var(--red);
  text-align: center;
  padding: 20px;
  font-size: 13px;
  z-index: 2;
}
.video-error .icon { width: 30px; height: 30px; }
.video-error span { max-width: 320px; color: var(--white); }

.video-meta { padding: 18px 6px 4px; }
.video-meta h2 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--gold);
  letter-spacing: .02em;
}
.video-desc {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
@media (max-width: 760px) {
  .topnav { flex-wrap: wrap; border-radius: var(--radius-lg); }
  .brand { border-right: none; padding-right: 0; }
  .tabs { order: 3; width: 100%; justify-content: space-between; }
  .tab span { display: none; }
  .btn-refresh span { display: none; }
  .btn-refresh { padding: 9px; }

  .table-head { grid-template-columns: 1fr 60px; }
  .table-head span:nth-child(2), .table-head span:nth-child(3) { display: none; }
  .track-row { grid-template-columns: 1fr 60px; }
  .track-ext, .track-size { display: none; }

  .audio-bar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    row-gap: 8px;
  }
  .audio-bar-info { grid-column: 1 / 2; grid-row: 1; }
  .audio-bar-controls { grid-column: 2 / 3; grid-row: 1; }
  .audio-bar-seek { grid-column: 1 / 3; grid-row: 2; }
  .audio-bar-volume { display: none; }

  .app { padding-bottom: 170px; }
}

/* Foco visible para accesibilidad de teclado */
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Respeta preferencia de reducir movimiento */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* =============================================================================
   BOTON DE SOLO ICONO (ajustes, junto a "actualizar")
   ============================================================================= */
.btn-icon-only {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
  flex-shrink: 0;
}
.btn-icon-only:hover { border-color: var(--gold-dim); color: var(--gold); }
.btn-icon-only .icon { width: 17px; height: 17px; }

/* =============================================================================
   ASISTENTE DE CONFIGURACION (primer uso / ajustes)
   ============================================================================= */
.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 700px at 50% 20%, rgba(122,74,180,.16), transparent 60%), rgba(6, 4, 12, .9);
  backdrop-filter: blur(3px);
}

.setup-box {
  width: min(560px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px 28px;
  box-shadow: var(--shadow);
}

.setup-head {
  display: flex;
  align-items: center;
  gap: 14px;
}
.setup-head h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: .08em;
  color: var(--gold);
  font-weight: 800;
}
.ctrl-btn-close-inline {
  margin-left: auto;
  border-color: var(--border);
  color: var(--muted);
}
.ctrl-btn-close-inline:hover { border-color: var(--red); color: var(--red); }

.setup-intro {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 22px;
}

.setup-field { margin-bottom: 18px; }
.setup-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: .08em;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 8px;
}
.setup-field label .icon { width: 14px; height: 14px; }

.setup-field-row {
  display: flex;
  gap: 8px;
}
.setup-field-row input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--white);
  font-size: 12.5px;
  font-family: inherit;
}
.setup-field-row input[type="text"]:focus {
  outline: none;
  border-color: var(--gold-dim);
}
.btn-browse {
  flex-shrink: 0;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--purple-dim);
  background: transparent;
  color: var(--purple);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.btn-browse:hover { background: var(--purple-dim); color: var(--white); }

.setup-field-error {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--red);
}
.setup-field-hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--muted);
  opacity: .85;
}

.setup-note {
  margin: 14px 0 0;
  font-size: 12px;
  text-align: center;
  color: var(--red);
}

/* =============================================================================
   NAVEGADOR DE CARPETAS DEL SERVIDOR
   ============================================================================= */
.browse-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.browse-box {
  position: relative;
  z-index: 1;
  width: min(520px, 94vw);
  height: min(560px, 82vh);
  display: flex;
  flex-direction: column;
  background: var(--panel-bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.browse-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.browse-path {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--white);
  white-space: nowrap;
  overflow-x: auto;
  font-family: 'Courier New', monospace;
}

.browse-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.browse-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--white);
  transition: background .12s ease;
}
.browse-item:hover { background: rgba(164,128,224,.09); }
.browse-item .icon { width: 16px; height: 16px; color: var(--gold); flex-shrink: 0; }
.browse-empty, .browse-error {
  padding: 30px 16px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}
.browse-error { color: var(--red); }

.browse-foot {
  padding: 14px 16px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}
