/* ===================== MusicHub – giao diện tối ===================== */
:root {
    --mh-bg: #0f1115;
    --mh-panel: #171a21;
    --mh-panel-2: #1f232c;
    --mh-border: #2a2f3a;
    --mh-track: #3a3f4b;
    --mh-text: #e8eaed;
    --mh-muted: #9aa0a6;
    --mh-accent: #1ed760;
    --mh-accent-2: #3be477;
    --mh-player-h: 84px;
    --mh-sidebar-w: 236px;
    --mh-side-w: 360px;
}

* { scrollbar-width: thin; scrollbar-color: var(--mh-track) transparent; }

body {
    background: var(--mh-bg);
    color: var(--mh-text);
    font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding-bottom: var(--mh-player-h);
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--mh-accent); }
.min-w-0 { min-width: 0; }
kbd { background: var(--mh-panel-2); color: var(--mh-text); border: 1px solid var(--mh-border); font-size: .75em; padding: .1em .4em; }

/* ---------- Bố cục ---------- */
.app-shell { display: flex; min-height: calc(100vh - var(--mh-player-h)); }

.sidebar {
    width: var(--mh-sidebar-w);
    flex-shrink: 0;
    flex-direction: column;
    background: #000;
    padding: 20px 12px;
    position: sticky;
    top: 0;
    height: calc(100vh - var(--mh-player-h));
    overflow-y: auto;
}
.brand { font-size: 1.35rem; font-weight: 700; padding: 0 12px 20px; display: flex; gap: 8px; align-items: center; }
.brand i { color: var(--mh-accent); display: inline-block; }
.is-playing .sidebar .brand i { animation: spin 3s linear infinite; }
.sidebar .nav-link { color: var(--mh-muted); border-radius: 8px; padding: 9px 12px; display: flex; gap: 12px; align-items: center; }
.sidebar .nav-link:hover { color: var(--mh-text); background: var(--mh-panel); }
.sidebar .nav-link.active { color: var(--mh-text); background: var(--mh-panel-2); font-weight: 600; }
.nav-section { color: var(--mh-muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; padding: 20px 12px 6px; }
.sidebar-hint {
    background: none; border: 0; color: var(--mh-muted); font-size: .8rem;
    display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-radius: 8px;
}
.sidebar-hint:hover { color: var(--mh-text); background: var(--mh-panel); }

.main-col { flex: 1; min-width: 0; transition: margin-right .2s ease; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 28px;
    background: rgba(15, 17, 21, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--mh-border);
}

.content { padding: 28px; transition: opacity .15s; }
.content.loading { opacity: .5; pointer-events: none; }

/* ---------- Ô tìm kiếm + gợi ý ---------- */
.search-box { position: relative; width: min(460px, 100%); }
.search-box > i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--mh-muted); pointer-events: none; }
.search-box input { padding-left: 38px; padding-right: 36px; border-radius: 999px; background: var(--mh-panel-2); border-color: var(--mh-border); }
.search-box input:focus { border-color: var(--mh-accent); box-shadow: 0 0 0 .2rem rgba(30, 215, 96, .15); }
.search-kbd { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--mh-muted); }
.search-box:focus-within .search-kbd { display: none !important; }

.search-suggest {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: min(380px, 92vw);
    max-height: min(70vh, 560px); overflow-y: auto; z-index: 30;
    background: var(--mh-panel); border: 1px solid var(--mh-border); border-radius: 12px;
    padding: 6px; box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
}
.sg-head { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--mh-muted); padding: 8px 8px 4px; }
.sg-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; color: var(--mh-text); }
.sg-item:hover, .sg-item.active { background: var(--mh-panel-2); color: var(--mh-text); }
.sg-item img { width: 38px; height: 38px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.sg-item .btn-icon { opacity: 0; }
.sg-item:hover .btn-icon, .sg-item.active .btn-icon { opacity: 1; }
.sg-song.is-playing .song-title { color: var(--mh-accent); }
.sg-all { border-top: 1px solid var(--mh-border); margin-top: 4px; border-radius: 0 0 8px 8px; color: var(--mh-accent); }
.sg-all i { flex-shrink: 0; }
.sg-empty { padding: 10px 8px; color: var(--mh-muted); font-size: .85rem; }

/* ---------- Khối chung ---------- */
.hero {
    display: flex; align-items: center; justify-content: space-between;
    padding: 36px 40px; border-radius: 16px;
    background: radial-gradient(120% 140% at 0% 0%, #1f5a37 0%, #17322a 35%, #14181f 75%);
    border: 1px solid rgba(30, 215, 96, .12);
}
.hero-icon { font-size: 7rem; color: rgba(30, 215, 96, .35); }
.is-playing .hero-icon { animation: pulse 1.6s ease-in-out infinite; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { font-size: 1.25rem; font-weight: 700; margin: 0; }
.section-head > a { color: var(--mh-muted); font-size: .85rem; }

.chip { padding: 6px 14px; border-radius: 999px; background: var(--mh-panel-2); font-size: .85rem; border: 1px solid var(--mh-border); transition: all .15s; }
.chip.active, .chip:hover { background: var(--mh-accent); color: #000; border-color: var(--mh-accent); }

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

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; }
.media-card { display: block; background: var(--mh-panel); border-radius: 12px; padding: 14px; transition: background .15s, transform .15s; }
.media-card:hover { background: var(--mh-panel-2); color: var(--mh-text); }
.media-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; margin-bottom: 10px; background: var(--mh-panel-2); }
.media-thumb { position: relative; margin-bottom: 10px; }
.media-thumb img { margin-bottom: 0; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.card-play {
    position: absolute; right: 8px; bottom: 8px;
    width: 46px; height: 46px; border-radius: 50%;
    display: grid; place-items: center; font-size: 1.6rem;
    background: var(--mh-accent); color: #000;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .45);
    opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s, background .15s;
}
.media-card:hover .card-play, .card-play:focus { opacity: 1; transform: none; }
.card-play:hover { background: var(--mh-accent-2); color: #000; transform: scale(1.06) !important; }

.detail-header { display: flex; gap: 28px; align-items: flex-end; margin-bottom: 28px; }
.detail-header > img { width: 200px; height: 200px; object-fit: cover; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5); flex-shrink: 0; }
@media (max-width: 576px) {
    .detail-header { flex-direction: column; align-items: flex-start; }
    .detail-header > img { width: 140px; height: 140px; }
}
.lyrics { white-space: pre-line; color: var(--mh-muted); line-height: 1.8; }
.avatar-lg { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; }

.auth-card { max-width: 420px; margin: 40px auto; background: var(--mh-panel); border: 1px solid var(--mh-border); border-radius: 16px; padding: 32px; }

/* ---------- Danh sách bài hát ---------- */
.song-list { display: flex; flex-direction: column; gap: 2px; }
.song-row {
    display: grid;
    grid-template-columns: 36px 44px minmax(0, 1fr) minmax(0, .8fr) 90px auto;
    align-items: center; gap: 12px;
    padding: 6px 10px; border-radius: 8px;
    user-select: none;
}
.song-row:hover { background: var(--mh-panel-2); }
@media (max-width: 767px) { .song-row { grid-template-columns: 36px 44px minmax(0, 1fr) auto; } }
@media (min-width: 576px) and (max-width: 767px) { .song-row { grid-template-columns: 36px 44px minmax(0, 1fr) 80px auto; } }
/* Danh sách nằm trong cột hẹp (vd. "Mới phát hành", khi mở panel hàng đợi): bớt cột theo độ rộng thực của danh sách */
.song-list { container-type: inline-size; }
@container (max-width: 640px) {
    .song-row { grid-template-columns: 36px 44px minmax(0, 1fr) 64px auto; }
    .song-row .song-album { display: none !important; }
}
@container (max-width: 440px) {
    .song-row { grid-template-columns: 36px 44px minmax(0, 1fr) auto; }
    .song-row .song-plays { display: none !important; }
}

.song-index { position: relative; width: 36px; height: 36px; display: grid; place-items: center; color: var(--mh-muted); }
.song-index .num.top { color: var(--mh-accent); font-weight: 700; }
.song-index .js-play { display: none; position: absolute; inset: 0; margin: auto; padding: 0; }
.song-row:hover .song-index .num { visibility: hidden; }
.song-row:hover .song-index .js-play { display: block; }

.song-cover { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; }
.song-meta { display: flex; flex-direction: column; }
.song-title { font-weight: 600; }
.song-artist, .song-album, .song-plays, .song-duration { color: var(--mh-muted); font-size: .85rem; }
.song-actions { display: flex; align-items: center; gap: 2px; }
.song-duration { width: 42px; text-align: right; }

.row-hover, .song-row .js-row-menu { opacity: 0; transition: opacity .1s; }
.song-row:hover .row-hover, .song-row:hover .js-row-menu,
.song-row:focus-within .row-hover, .song-row:focus-within .js-row-menu { opacity: 1; }

/* Bài đang phát: hiệu ứng equalizer, di chuột vào thì hiện nút tạm dừng */
.song-row.is-playing .song-title { color: var(--mh-accent); }
.song-row.is-playing .song-index .num { visibility: hidden; }
.song-row.is-playing:not(.is-paused) .song-index .eq { display: flex; }
.song-row.is-playing:not(.is-paused):hover .song-index .eq { display: none; }
.song-row.is-playing.is-paused .song-index .js-play,
.song-row.is-playing:hover .song-index .js-play { display: block; color: var(--mh-accent); }

.eq { position: absolute; inset: 0; margin: auto; width: 16px; height: 14px; display: none; align-items: flex-end; justify-content: space-between; }
.eq i { width: 3px; height: 30%; background: var(--mh-accent); border-radius: 1px; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.45s; }
.eq i:nth-child(3) { animation-delay: -.2s; }
.eq i:nth-child(4) { animation-delay: -.7s; }

.btn-icon { color: var(--mh-muted); padding: 4px 6px; font-size: 1.1rem; line-height: 1; }
.btn-icon:hover, .btn-icon.active { color: var(--mh-accent); }
.js-fav.is-fav, #pl-fav.is-fav { color: #ff4d6d; }

/* ---------- Menu ngữ cảnh bài hát ---------- */
.row-menu { position: fixed; z-index: 1070; min-width: 240px; max-width: 320px; box-shadow: 0 16px 40px rgba(0, 0, 0, .55); }
.row-menu .dropdown-header { max-width: 300px; color: var(--mh-text); font-weight: 600; }
.row-menu .dropdown-item i { width: 22px; display: inline-block; color: var(--mh-muted); }
.row-menu .dropdown-item:hover i, .row-menu .dropdown-item:focus i { color: var(--mh-accent); }

/* ---------- Player ---------- */
.player {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    height: var(--mh-player-h);
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
    align-items: center; gap: 16px;
    padding: 0 20px;
    background: #000; border-top: 1px solid var(--mh-border);
}
.player-track { display: flex; align-items: center; gap: 12px; min-width: 0; }
.player-track img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; box-shadow: 0 4px 12px rgba(0, 0, 0, .5); }
#pl-title { color: var(--mh-text); }
#pl-title[href]:hover { text-decoration: underline; }
.player-center { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.player-controls { display: flex; align-items: center; gap: 10px; }
.btn-play { width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 1.4rem; display: grid; place-items: center; transition: transform .1s; }
.btn-play:hover { transform: scale(1.06); }
.player-progress { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 640px; font-size: .75rem; color: var(--mh-muted); font-variant-numeric: tabular-nums; }
.player-progress > span { min-width: 38px; }
.player-progress > span:first-child { text-align: right; }
.player-right { display: flex; justify-content: flex-end; align-items: center; gap: 2px; }
.player-right .btn-icon { position: relative; }
.player-volume { align-items: center; gap: 6px; margin-left: 4px; }
.player-volume input { width: 110px; }

.dot-badge {
    position: absolute; top: -3px; right: -5px; min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 8px; background: var(--mh-accent); color: #000;
    font-size: .62rem; font-weight: 700; line-height: 16px; text-align: center;
}
.sleep-left {
    position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
    font-size: .6rem; line-height: 1.4; padding: 0 4px; border-radius: 4px; white-space: nowrap;
    background: var(--mh-panel-2); color: var(--mh-accent); font-variant-numeric: tabular-nums;
}

/* Thanh tua tự vẽ */
.seekbar { position: relative; flex: 1; height: 16px; display: flex; align-items: center; cursor: pointer; touch-action: none; outline: none; }
.seek-track { position: relative; width: 100%; height: 4px; border-radius: 4px; background: var(--mh-track); overflow: hidden; transition: height .1s; }
.seek-buffer, .seek-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; }
.seek-buffer { background: #565c69; transition: width .3s; }
.seek-fill { background: var(--mh-text); }
.seekbar:hover .seek-track, .seekbar.dragging .seek-track { height: 6px; }
.seekbar:hover .seek-fill, .seekbar.dragging .seek-fill, .seekbar:focus-visible .seek-fill { background: var(--mh-accent); }
.seek-thumb {
    position: absolute; top: 50%; left: 0; width: 13px; height: 13px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); pointer-events: none;
    transform: translate(-50%, -50%) scale(0); transition: transform .1s;
}
.seekbar:hover .seek-thumb, .seekbar.dragging .seek-thumb, .seekbar:focus-visible .seek-thumb { transform: translate(-50%, -50%) scale(1); }
.seek-tip {
    position: absolute; bottom: 20px; left: 0; transform: translateX(-50%);
    padding: 2px 6px; border-radius: 4px; font-size: .72rem; white-space: nowrap; pointer-events: none;
    background: #000; border: 1px solid var(--mh-border); color: var(--mh-text);
    opacity: 0; transition: opacity .1s;
}
.seek-tip:empty { display: none; }
.seekbar:hover .seek-tip, .seekbar.dragging .seek-tip { opacity: 1; }

/* Thanh âm lượng: phần đã chọn tô màu */
#pl-volume { --val: 80%; height: 16px; }
#pl-volume::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--mh-text) var(--val), var(--mh-track) var(--val)); }
#pl-volume:hover::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--mh-accent) var(--val), var(--mh-track) var(--val)); }
#pl-volume::-webkit-slider-thumb { width: 12px; height: 12px; margin-top: -4px; background: #fff; }
#pl-volume::-moz-range-track { height: 4px; border-radius: 4px; background: var(--mh-track); }
#pl-volume::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--mh-accent); }
#pl-volume::-moz-range-thumb { width: 12px; height: 12px; background: #fff; border: 0; }
.form-range::-webkit-slider-thumb { background: var(--mh-accent); }
.form-range::-moz-range-thumb { background: var(--mh-accent); }

/* ---------- Panel phải: Hàng đợi / Lời bài hát ---------- */
.side-panel {
    position: fixed; top: 0; right: 0; bottom: var(--mh-player-h); z-index: 1032;
    width: var(--mh-side-w); max-width: 100vw;
    display: flex; flex-direction: column;
    background: var(--mh-panel); border-left: 1px solid var(--mh-border);
    box-shadow: -12px 0 40px rgba(0, 0, 0, .45);
    transform: translateX(100%); visibility: hidden;
    transition: transform .2s ease, visibility .2s;
}
.side-open .side-panel { transform: none; visibility: visible; }
@media (min-width: 1400px) { .side-open .main-col { margin-right: var(--mh-side-w); } }

.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--mh-border); }
.side-tabs { display: flex; gap: 4px; }
.side-tab { background: transparent; border: 0; color: var(--mh-muted); padding: 6px 12px; border-radius: 999px; font-size: .86rem; font-weight: 600; }
.side-tab:hover { color: var(--mh-text); }
.side-tab.active { background: var(--mh-panel-2); color: var(--mh-text); }
.side-body { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.side-label { color: var(--mh-muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; padding: 14px 6px 6px; }

.q-item { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 8px; cursor: pointer; user-select: none; }
.q-item:hover { background: var(--mh-panel-2); }
.q-item img { width: 42px; height: 42px; border-radius: 4px; object-fit: cover; flex-shrink: 0; }
.q-title { font-size: .9rem; font-weight: 600; }
.q-sub { font-size: .78rem; color: var(--mh-muted); }
.q-dur { font-size: .75rem; color: var(--mh-muted); font-variant-numeric: tabular-nums; }
.q-handle { color: var(--mh-muted); cursor: grab; padding: 4px 0; opacity: .45; touch-action: none; }
.q-item:hover .q-handle { opacity: 1; }
.q-remove { opacity: 0; font-size: .9rem; }
.q-item:hover .q-remove { opacity: 1; }
.q-now .q-item { background: var(--mh-panel-2); }
.q-item.is-now .q-title { color: var(--mh-accent); }
.q-item .eq { position: static; display: flex; flex-shrink: 0; margin: 0 2px; }
.q-item.is-paused .eq i { animation-play-state: paused; }
.q-tag {
    display: inline-block; margin-right: 6px; padding: 0 5px; border-radius: 4px; vertical-align: 1px;
    font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
    background: rgba(30, 215, 96, .15); color: var(--mh-accent);
}
.q-tag.auto { background: rgba(154, 160, 166, .15); color: var(--mh-muted); }
.q-ghost { opacity: .35; }
.q-chosen { background: var(--mh-panel-2); }
.q-empty { text-align: center; color: var(--mh-muted); padding: 22px 12px; }
.q-empty > i { font-size: 2rem; display: block; margin-bottom: 6px; }

.lyrics-head { display: flex; gap: 12px; align-items: center; padding: 12px 6px 14px; }
.lyrics-head img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; }
#lyrics-body { color: var(--mh-text); font-size: 1.05rem; line-height: 1.9; padding: 0 6px; }
#lyrics-body.empty { color: var(--mh-muted); font-size: .9rem; }

/* ---------- Khung YouTube (tối thiểu 200x200px theo chính sách YouTube) ---------- */
.yt-panel {
    position: fixed; right: 16px; bottom: calc(var(--mh-player-h) + 12px); z-index: 1033;
    width: 356px; max-width: calc(100vw - 32px);
    background: #000; border: 1px solid var(--mh-border); border-radius: 12px; overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
    transition: right .2s ease;
}
.yt-panel.yt-lg { width: 560px; }
.yt-panel.yt-lg .yt-frame { height: 315px; }
.yt-panel.dragging { transition: none; opacity: .92; }
.yt-panel.dragging iframe { pointer-events: none; }
.side-open .yt-panel:not(.yt-moved) { right: calc(var(--mh-side-w) + 16px); }
.yt-panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; background: var(--mh-panel); cursor: move; user-select: none; touch-action: none; }
.yt-panel-head .btn-icon { font-size: .9rem; }
.yt-frame { width: 100%; height: 200px; min-width: 200px; }
.yt-frame iframe { width: 100%; height: 100%; display: block; }

/* ---------- Bảng phím tắt ---------- */
.shortcuts td { padding: 6px 4px; }
.shortcuts td:first-child { white-space: nowrap; width: 1%; padding-right: 18px; }

/* ---------- Hiệu ứng ---------- */
@keyframes eq { 0%, 100% { height: 25%; } 50% { height: 100%; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: .8; } 50% { transform: scale(1.06); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    .eq i, .is-playing .sidebar .brand i, .is-playing .hero-icon { animation: none !important; }
}

/* Thiết bị cảm ứng: không có hover -> luôn hiện các nút */
@media (hover: none) {
    .row-hover, .song-row .js-row-menu, .q-remove, .card-play, .sg-item .btn-icon { opacity: 1; }
    .card-play { transform: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
    .player { grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; padding: 0 12px; }
    .player-progress { position: absolute; left: 0; right: 0; top: -8px; max-width: none; gap: 0; }
    .player-progress > span { display: none; }
    .player-controls { gap: 2px; }
    .player-controls #pl-shuffle, .player-controls #pl-repeat { display: none; }
    .content { padding: 18px; }
    .topbar { padding: 10px 14px; gap: 8px; }
    .topbar .btn { white-space: nowrap; }
    .topbar .btn-outline-light[href*="Register"] { display: none; }
    .side-panel { width: 100vw; }
    .side-open .yt-panel:not(.yt-moved) { right: 16px; }
    .yt-panel.yt-lg { width: calc(100vw - 32px); }
    .yt-panel.yt-lg .yt-frame { height: 220px; }
}
