/* =========================================================
   TOKENS DE DISEÑO
   Tema claro y limpio: fondo blanco, con el azul del logo
   como acento principal. El vinilo (siempre negro, como uno
   real) y las barras del ecualizador son los detalles con
   personalidad sobre una base minimalista.
   ========================================================= */
:root {
    --bg: #ffffff;
    --bg-elevated: #ffffff;
    --bg-elevated-2: #f1f4f9;
    --border: #e2e7f0;
    --text: #141b2d;
    --text-dim: #6b7488;
    --accent: #0047ba;      /* azul de marca (del logo) */
    --accent-2: #2f6fe0;    /* azul secundario, para el ecualizador y detalles */
    --danger: #dc4c41;
    --radius: 10px;
    --radius-lg: 18px;
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transport-h: 96px;
}

* { box-sizing: border-box; }

img, video { max-width: 100%; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
}

button {
    font-family: inherit;
    cursor: pointer;
}

button:focus-visible,
input:focus-visible,
li:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

/* =========================================================
   LAYOUT GENERAL
   ========================================================= */
.app {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    height: 100vh;
    padding-bottom: var(--transport-h);
}

/* ---------- SIDEBAR ---------- */
.sidebar {
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 12px;
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.brand-logo {
    height: 30px;
    width: auto;
    border-radius: 6px;
}

.brand-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.role-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 14px;
    font-size: 12px;
}

.role-badge {
    color: var(--text-dim);
    font-weight: 600;
}

.role-badge.role-admin { color: var(--accent-2); }
.role-badge.role-visitor { color: var(--text-dim); }

.role-link {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 12px;
    text-decoration: none;
    padding: 0;
    cursor: pointer;
}

.role-badge { margin-right: auto; }

.role-link:hover { color: var(--accent-2); }

.upload-zone {
    margin: 0 16px 16px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-dim);
    transition: border-color .15s, background .15s;
}

.upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(0, 71, 186, 0.06);
    color: var(--text);
}

.upload-zone button {
    display: block;
    margin: 10px auto 0;
    background: var(--accent);
    color: #ffffff;
    border: none;
    font-weight: 700;
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 999px;
}

.upload-zone button:hover { filter: brightness(1.08); }

.upload-progress-list {
    margin: 0 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.upload-progress-item {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
}

.upload-progress-item.upload-error {
    color: var(--danger);
}

.upload-progress-bar {
    height: 4px;
    background: var(--bg-elevated-2);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 4px;
}

.upload-progress-bar > span {
    display: block;
    height: 100%;
    background: var(--accent-2);
    width: 0%;
    transition: width .15s;
}

.search-wrap { padding: 0 16px 12px; }

.search-wrap input {
    width: 100%;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 9px 14px;
    color: var(--text);
    font-size: 13px;
}

.search-wrap input::placeholder { color: var(--text-dim); }

/* Selector de carpeta al subir + botón de crear */
.folder-picker {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.folder-picker select {
    flex: 1;
    min-width: 0;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 10px;
    color: var(--text);
    font-size: 12px;
}

.folder-create-btn {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
}

.folder-create-btn:hover { filter: brightness(1.15); }

.new-folder-row {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.new-folder-row input {
    flex: 1;
    min-width: 0;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 12px;
    color: var(--text);
    font-size: 12px;
}

.new-folder-row button {
    flex-shrink: 0;
    border: none;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 700;
    background: var(--bg-elevated-2);
    color: var(--text);
}

.new-folder-row button:first-of-type { background: var(--accent); color: #fff; }
.new-folder-row button:hover { filter: brightness(1.1); }

/* Tarjeta de carpeta (como una playlist) dentro de la lista */
.folder-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius);
    cursor: pointer;
}

.folder-card:hover { background: var(--bg-elevated-2); }

.folder-icon {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(0,71,186,0.08);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-card-info { min-width: 0; }

.folder-card-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-card-count {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
}

.track-list-divider {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-dim);
    padding: 12px 10px 4px;
}

/* Migas de pan: "← Todas las carpetas · NombreCarpeta" */
.folder-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px 10px;
    font-size: 12px;
}

.folder-breadcrumb[hidden] { display: none; }

#backToFoldersBtn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 12px;
    padding: 0;
}

#backToFoldersBtn:hover { color: var(--accent); }

#currentFolderName {
    font-weight: 700;
    color: var(--text);
}

#currentFolderName::before { content: '· '; color: var(--text-dim); font-weight: 400; }

.track-list {
    list-style: none;
    margin: 0;
    padding: 0 8px 16px;
    overflow-y: auto;
    flex: 1;
}

.track-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    position: relative;
}

.track-item:hover { background: var(--bg-elevated-2); }

.track-item.active {
    background: rgba(0, 71, 186, 0.08);
}

.track-item.active .track-title { color: var(--accent); }

.track-index {
    width: 22px;
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
}

.track-item.active .track-index { color: var(--accent); }

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

.track-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.track-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-type-badge {
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 1px 4px;
}

.track-artist {
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-folder {
    color: var(--accent-2);
}

.track-move,
.track-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 6px;
    flex-shrink: 0;
}

.track-item:hover .track-move,
.track-item:hover .track-delete { opacity: 1; }
.track-move:hover { color: var(--accent-2); background: rgba(47,111,224,0.12); }
.track-delete:hover { color: var(--danger); background: rgba(226,87,76,0.12); }

.empty-state {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

/* ---------- MAIN / NOW PLAYING ---------- */
.main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    min-width: 0;
}

.now-playing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    max-width: 480px;
    width: 100%;
    min-width: 0; /* evita que el <video> fuerce overflow horizontal en flexbox */
    transition: max-width .2s ease;
}

.now-playing.video-active {
    max-width: 720px;
}

.media-visual {
    position: relative;
    width: 280px;
    height: 280px;
    min-width: 0;
    max-width: 100%;
}

.vinyl-wrap {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.media-visual.mode-video .vinyl-wrap { display: none; }

.video-display {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    max-width: 100%;
    object-fit: contain;
    background: #0b0d12;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(20,27,45,0.25);
}

.media-visual.mode-video {
    width: 100%;
    max-width: 720px;
    aspect-ratio: 16 / 9;
    height: auto;
    min-width: 0;
}

.media-visual.mode-video .video-display { display: block; }

.vinyl {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background:
        repeating-radial-gradient(circle at center, #15181f 0px, #15181f 2px, #1c202a 3px, #1c202a 4px),
        radial-gradient(circle at center, #2a2f3b 0 24%, #15181f 25%);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: spin 6s linear infinite;
    animation-play-state: paused;
    box-shadow: 0 20px 50px rgba(0,0,0,0.45);
}

.vinyl.spinning { animation-play-state: running; }

.vinyl-label {
    width: 34%;
    height: 34%;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 6px #15181f;
    overflow: hidden;
}

.vinyl-label img {
    width: 68%;
    height: auto;
}

.tonearm {
    position: absolute;
    top: -14px;
    right: -6px;
    width: 90px;
    height: 90px;
    transform-origin: 88px 8px;
    transform: rotate(-18deg);
    transition: transform .4s ease;
    pointer-events: none;
}

.tonearm.playing { transform: rotate(6deg); }

.tonearm::before {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
}

.tonearm::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 9px;
    width: 4px;
    height: 74px;
    background: var(--text-dim);
    border-radius: 2px;
    transform: rotate(28deg);
    transform-origin: top center;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.track-meta { text-align: center; }

.track-meta h1 {
    font-family: var(--font-display);
    font-size: 22px;
    margin: 0 0 4px;
    font-weight: 700;
}

.track-meta p {
    margin: 0;
    color: var(--text-dim);
    font-size: 14px;
}

.equalizer {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 28px;
}

.equalizer span {
    width: 4px;
    background: var(--accent-2);
    border-radius: 2px;
    height: 4px;
    animation: bounce 1.2s ease-in-out infinite;
    animation-play-state: paused;
    opacity: 0.4;
}

.equalizer.playing span { animation-play-state: running; opacity: 1; }

.equalizer span:nth-child(1) { animation-delay: 0s; }
.equalizer span:nth-child(2) { animation-delay: .15s; }
.equalizer span:nth-child(3) { animation-delay: .3s; }
.equalizer span:nth-child(4) { animation-delay: .45s; }
.equalizer span:nth-child(5) { animation-delay: .2s; }

@keyframes bounce {
    0%, 100% { height: 4px; }
    50% { height: 26px; }
}

/* ---------- TRANSPORT (barra inferior fija) ---------- */
.transport {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--transport-h);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px 24px 16px;
    gap: 8px;
}

.progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.time {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    width: 40px;
    text-align: center;
    flex-shrink: 0;
}

.progress-bar {
    flex: 1;
    height: 5px;
    background: var(--bg-elevated-2);
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    touch-action: none; /* evita que arrastrar el dedo scrollee la página */
}

.progress-bar > .progress-fill {
    position: absolute;
    inset: 0;
    width: 0%;
    background: var(--accent);
    border-radius: 4px;
}

.progress-bar > .progress-handle {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 4px rgba(0,71,186,0.15);
}

.controls-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.transport-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
}

.transport-controls button {
    background: none;
    border: none;
    color: var(--text);
    font-size: 18px;
    padding: 6px;
    border-radius: 8px;
    display: flex;
}

.transport-controls button:hover { color: var(--accent); }
.transport-controls button.toggled { color: var(--accent-2); }

.transport-controls button {
    position: relative;
    min-width: 32px;
    min-height: 32px;
}

#repeatBtn.mode-one::after {
    content: '1';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-2);
    color: #fff;
    font-size: 8px;
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.play-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #ffffff !important;
    border: 2px solid var(--accent) !important;
    color: #111318 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px !important;
    box-shadow: 0 2px 8px rgba(20,27,45,0.12);
}

.play-btn:hover { background: var(--bg-elevated-2) !important; color: #111318 !important; }

.now-playing-mini {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-size: 12px;
}

.now-playing-mini .mini-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.now-playing-mini .mini-artist { color: var(--text-dim); }

.volume-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-self: end;
}

.volume-wrap input[type="range"] {
    width: 90px;
    accent-color: var(--accent);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
html, body { overflow-x: hidden; }

/* Tablet / celular en horizontal: la barra lateral pasa arriba */
@media (max-width: 860px) {
    .app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto 1fr;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 45vh;
    }
    .now-playing-mini, .volume-wrap { display: none; }
    .controls-row { grid-template-columns: 1fr; }
    .main { padding: 20px 16px; }
}

/* Celular */
@media (max-width: 480px) {
    .brand { padding: 16px 16px 10px; font-size: 15px; }
    .brand-logo { height: 26px; }
    .role-bar { padding: 0 16px 12px; flex-wrap: wrap; row-gap: 6px; }
    .upload-zone { margin: 0 12px 12px; padding: 14px; }
    .search-wrap { padding: 0 12px 10px; }
    .track-list { padding: 0 6px 12px; }
    .sidebar { max-height: 38vh; }

    .main { padding: 16px 12px; }
    .media-visual { width: 190px; height: 190px; }
    .media-visual.mode-video { max-width: 100%; }
    .track-meta h1 { font-size: 18px; }
    .track-meta p { font-size: 13px; }
    .now-playing { gap: 16px; }

    .transport { padding: 8px 12px 14px; gap: 6px; }
    .transport-controls { gap: 10px; }
    .transport-controls button { min-width: 40px; min-height: 40px; }
    .play-btn { width: 46px; height: 46px; }
    .time { width: 32px; font-size: 10px; }

    .modal-card { max-width: 92vw; padding: 20px; }
    .login-card { max-width: 90vw; padding: 24px 20px; }
}

/* Asegura un mínimo de área táctil cómoda en cualquier pantalla táctil */
@media (hover: none) and (pointer: coarse) {
    .transport-controls button { min-width: 40px; min-height: 40px; }
    .track-item { padding: 10px; }
    .track-move, .track-delete { opacity: 1; } /* en táctil no hay ":hover" para revelarlo */
}

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

/* =========================================================
   LOGIN (login.php)
   ========================================================= */
.login-body {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 50% 0%, rgba(0,71,186,0.08), transparent 60%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(20,27,45,0.08);
}

.login-logo { height: 40px; margin-bottom: 18px; border-radius: 6px; }

.login-card h1 {
    font-family: var(--font-display);
    font-size: 19px;
    margin: 0 0 8px;
}

.login-sub {
    color: var(--text-dim);
    font-size: 13px;
    margin: 0 0 20px;
    line-height: 1.5;
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin: 0 0 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-form input {
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 11px 14px;
    color: var(--text);
    font-size: 14px;
}

.login-form button {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 11px;
    font-weight: 700;
    font-size: 14px;
}

.login-form button:hover { filter: brightness(1.15); }

.login-back {
    display: inline-block;
    margin-top: 18px;
    color: var(--text-dim);
    font-size: 12px;
    text-decoration: none;
}

.login-back:hover { color: var(--accent-2); }

/* =========================================================
   MODAL DE AJUSTES (solo admin)
   ========================================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 7, 14, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: 0 20px 60px rgba(20,27,45,0.25);
}

.modal-card h2 {
    font-family: var(--font-display);
    font-size: 17px;
    margin: 0 0 16px;
}

.modal-label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.modal-card input,
.modal-card select {
    width: 100%;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 9px 12px;
    color: var(--text);
    font-size: 13px;
    margin-bottom: 10px;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
}

.modal-btn {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 9px;
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 4px;
}

.modal-btn:hover { filter: brightness(1.15); }

.modal-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 18px 0;
}

.modal-msg {
    min-height: 16px;
    font-size: 12px;
    color: var(--accent-2);
    margin: 10px 0 4px;
}

.modal-close {
    width: 100%;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: var(--radius);
    padding: 8px;
    font-size: 12px;
    margin-top: 8px;
}

.modal-close:hover { color: var(--text); border-color: var(--text-dim); }
