/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #0d1117;
    --surface:   #161b22;
    --surface2:  #1e242d;
    --border:    #30363d;
    --text:      #e6edf3;
    --text-muted:#8b949e;
    --accent:    #ff0055;
    --accent2:   #ff6600;
    --radius:    10px;
    --search-h:  56px;
}

html {
    width: 100%;
    height: 100%;
}

body {
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* ── Layout principal: dos columnas ───────────────────── */
.app {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: row;
}

/* Columna izquierda: player */
.player-col {
    flex: 0 0 60%;
    width: 60%;
    height: 100%;
    background: #000;
    overflow: hidden;
    position: relative;
}

.player-wrap {
    position: absolute;
    inset: 0;
}

/* Dos capas superpuestas para el crossfade de audio/video entre videos.
   Solo la capa .active se ve; al cruzar, ambas quedan visibles 5s mientras
   el JS anima el volumen de cada una en direcciones opuestas. */
.yt-layer {
    position: absolute;
    inset: 0;
    opacity: 0;
    z-index: 0;
    transition: opacity 5s linear;
}
.yt-layer.active {
    opacity: 1;
    z-index: 1;
}
.yt-layer iframe {
    width: 100% !important;
    height: 100% !important;
    display: block;
    border: none;
}

.player-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
    z-index: 1;
}

/* Ocultar placeholder cuando hay video */
.player-empty.hidden { display: none; }

/* Columna derecha: sidebar */
.sidebar-col {
    flex: 1 1 40%;
    width: 40%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow: hidden;
}

/* ── Barra de búsqueda ────────────────────────────────── */
.search-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    height: var(--search-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.search-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrap input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 36px 8px 38px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .2s;
}

.search-input-wrap input::placeholder { color: var(--text-muted); }
.search-input-wrap input:focus        { border-color: var(--accent); }

/* Lupa DENTRO del input, sin color de acento */
.search-icon-btn {
    position: absolute;
    left: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: color .15s, background .15s;
}
.search-icon-btn:hover { color: var(--text); background: var(--border); }

.btn-clear {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
}
.btn-clear:hover { color: var(--text); }

/* Botones de la barra (carpetas / settings) */
.btn-folders,
.btn-settings {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s, border-color .15s;
    background: var(--surface2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-folders:hover,
.btn-settings:hover {
    color: var(--text);
    border-color: var(--text-muted);
}
.btn-folders.active,
.btn-settings.active {
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Paneles ──────────────────────────────────────────── */
.panel {
    display: none !important;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.panel.active {
    display: flex !important;
}

/* ── Info resultados + spinner ────────────────────────── */
.results-info {
    flex-shrink: 0;
    padding: 8px 12px 4px;
    color: var(--text-muted);
    font-size: 12px;
}

.loading {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

/* ── Grid de videos ───────────────────────────────────── */
/* Columnas configurables desde Settings (JS fija --cols según el dispositivo). */
.video-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
    gap: 8px;
    padding: 8px 12px 12px;
}

.video-card {
    background: var(--surface2);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid transparent;
    transition: border-color .15s, transform .1s;
}

.video-card:hover         { border-color: var(--border); transform: translateY(-1px); }
.video-card.playing       { border-color: var(--accent); }
.video-card.unavailable   { opacity: .4; }
.video-card.unavailable::after { content: '⚠ No disponible'; display: block; font-size: 10px; color: var(--accent); padding: 2px 8px 6px; }

.thumb-wrap { position: relative; }

.video-thumb {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    display: block;
    background: #000;
}

/* ── Iconos de esquina sobre la miniatura (feed de búsqueda) ──────────── */
.vicon {
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(13, 17, 23, .78);
    border: 1px solid rgba(255,255,255,.12);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.vicon:hover   { background: var(--accent); transform: scale(1.08); }
.vicon:active  { transform: scale(.94); }
.vicon svg     { width: 14px; height: 14px; }

.vicon-tl { top: 5px;    left: 5px; }
.vicon-tr { top: 5px;    right: 5px; }
.vicon-bl { bottom: 5px; left: 5px; }
.vicon-br { bottom: 5px; right: 5px; }

/* Feedback breve al poner en cola / guardar */
.vicon.flash { background: #2ea043; }

/* ── Botón eliminar (tabs Recientes / Guardados) ──────────────────────── */
.vicon-delete {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(13, 17, 23, .78);
    border: 1px solid rgba(255,255,255,.12);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.vicon-delete:hover { background: var(--accent); transform: scale(1.08); }
.vicon-delete svg   { width: 14px; height: 14px; }

.video-info   { padding: 6px 8px 8px; }

.video-title {
    font-size: 12px;
    line-height: 1.4;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 3px;
}

.video-channel {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-badge {
    display: inline-block;
    background: red;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    margin-bottom: 3px;
    letter-spacing: .5px;
}

/* ── Placeholders de paneles ──────────────────────────── */
.panel-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 14px;
    padding: 40px;
    text-align: center;
}

/* ── Settings: lista de opciones ──────────────────────── */
.settings-list {
    padding: 16px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
}

.settings-row-text { flex: 1; min-width: 0; }

.settings-row-title {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 2px;
}

.settings-row-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.settings-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Toggle switch */
.switch {
    position: relative;
    flex-shrink: 0;
    width: 42px;
    height: 24px;
    display: inline-block;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 24px;
    cursor: pointer;
    transition: background .2s, border-color .2s;
}

.switch-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform .2s, background .2s;
}

.switch input:checked + .switch-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(18px);
    background: #fff;
}

/* Selector de columnas del feed */
.cols-options {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.cols-btn {
    width: 32px;
    height: 32px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.cols-btn:hover  { color: var(--text); border-color: var(--text-muted); }
.cols-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Botón Google Sign-In (solo visual, sin lógica aún) ── */
.google-signin-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    margin-top: 12px;
    padding: 10px 16px;
    background: #fff;
    color: #3c4043;
    border: 1px solid #dadce0;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: box-shadow .15s, background .15s;
}
.google-signin-btn:hover {
    background: #f8f9fa;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}

/* ── Sub-tabs (panel Mis Videos: Recientes / Guardados) ───────────────── */
.subtabs {
    flex-shrink: 0;
    display: flex;
    gap: 4px;
    padding: 10px 12px 0;
}

.subtab {
    flex: 1;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 10px;
    border-radius: var(--radius);
    font-size: 12.5px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.subtab:hover  { color: var(--text); }
.subtab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.subtab-content { display: none; }
.subtab-content.active { display: grid; }

.empty-msg {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 16px;
}

/* ── Modal: Cola de reproducción ───────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(480px, 92vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-header-actions { display: flex; align-items: center; gap: 10px; }

.modal-clear-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
}
.modal-clear-btn:hover { color: var(--accent); }

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    padding: 4px;
}
.modal-close-btn:hover { color: var(--text); }

.modal-body {
    overflow-y: auto;
    padding: 8px;
}

.queue-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 16px;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s;
}
.queue-item:hover { background: var(--surface2); }

.queue-item img {
    width: 72px;
    aspect-ratio: 16/9;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    background: #000;
}

.queue-item-title {
    flex: 1;
    min-width: 0;
    font-size: 12.5px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.queue-item-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    padding: 4px;
}
.queue-item-remove:hover { color: var(--accent); }

/* ── Scrollbar ────────────────────────────────────────── */
.panel::-webkit-scrollbar,
.modal-body::-webkit-scrollbar        { width: 4px; }
.panel::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track  { background: transparent; }
.panel::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 2px; }

/* ── Responsive móvil ─────────────────────────────────── */
@media (max-width: 768px) {
    .app { flex-direction: column; }

    /* Player arriba, con alto fijo por su aspect-ratio: no debe encogerse. */
    .player-col {
        flex: 0 0 auto;
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
        position: relative;
    }

    /* Sidebar ocupa el resto. min-height:0 es CLAVE: sin eso un hijo flex no
       puede ser más chico que su contenido y el panel nunca llega a scrollear
       (el .app es position:fixed y el body tiene overflow:hidden). */
    .sidebar-col {
        flex: 1 1 auto;
        width: 100%;
        height: auto;
        min-height: 0;
        overflow: hidden;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    /* El panel es el que scrollea (igual que en escritorio). */
    .panel {
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}
