/* Quỳnh Anh Karaoke - TV + Phone */

:root {
    --bg: #070b14;
    --panel: #12182b;
    --border: rgba(255, 255, 255, 0.08);
    --text: #e8eef8;
    --muted: #8b9bb8;
    --pink: #ec4899;
    --purple: #8b5cf6;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.hidden { display: none !important; }

/* Ẩn hoàn toàn nút đóng tv-panel-close dư thừa */
.tv-panel-close {
    display: none !important;
}

/* Nút QR trên thanh điều khiển mặc định ẩn trên máy tính, chỉ hiện trên Tablet/Điện thoại */
.tv-btn-qr-mobile {
    display: none;
}

/* ========== TV FULLSCREEN ========== */
body.tv-mode {
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.tv-screen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: #070b14;
    overflow: hidden;
    z-index: 1;
}

#youtube-player,
#youtube-player iframe {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
}

.tv-welcome {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px;
    background: radial-gradient(ellipse at center, #0f1525 0%, #070b14 65%);
}
.tv-welcome .note-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(236, 72, 153, 0.15);
    color: #ff00a3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    margin-bottom: 20px;
}
.tv-welcome h3 {
    margin: 0 0 12px;
    font-size: clamp(1.25rem, 2.5vw, 1.75rem);
    font-weight: 700;
    line-height: 1.4;
    color: #f1f5f9;
    max-width: 560px;
}
.tv-welcome p {
    margin: 0;
    font-size: 14px;
    color: var(--muted);
    max-width: 400px;
    line-height: 1.5;
}

.floating-qr {
    position: absolute;
    left: 30px;
    top: 30px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    cursor: pointer;
}
.floating-qr img {
    width: 110px;
    height: 110px;
    display: block;
    border-radius: 4px;
}
.floating-qr-label {
    font-size: 11px;
    font-weight: 700;
    color: #7c3aed;
}
.floating-qr.is-fullscreen {
    position: fixed !important;
    left: 24px !important;
    top: 24px !important;
    z-index: 2147483646 !important;
}

.tv-next-strip {
    position: absolute;
    left: 200px;
    top: 30px;
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: rgba(15, 21, 37, 0.88);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
    color: var(--muted);
    max-width: min(420px, 45vw);
    backdrop-filter: blur(8px);
}
.tv-next-strip i { color: #ff00a3; }
.tv-next-strip strong {
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tv-top-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 80 !important;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.clock-inline {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 18px;
    color: var(--text);
    padding: 0 14px;
    background: rgba(18, 24, 43, 0.92);
    border: 1px solid var(--border);
    height: 48px;
    display: flex;
    align-items: center;
    border-radius: 14px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}

.tv-ctrl-btn {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(18, 24, 43, 0.92);
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.35);
    transition: 0.15s;
    pointer-events: auto;
}
.tv-ctrl-btn:hover {
    background: #1e293b;
    color: #f472b6;
    border-color: rgba(244, 114, 182, 0.4);
}
.tv-ctrl-play {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border: none;
    color: #fff;
}
.tv-ctrl-play:hover {
    filter: brightness(1.1);
    color: #fff;
}
.tv-open-search.is-open {
    color: #f472b6;
    border-color: rgba(244, 114, 182, 0.45);
}

.tv-hud-bottom {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.tv-hud-left { display: flex; gap: 8px; width: 100%; justify-content: space-between; }
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
}
.pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    animation: pulse 1.5s ease infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}
.pill strong { color: #ff00a3; letter-spacing: 0.04em; }

.tv-now-bar { display: none !important; }

.tv-side-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(400px, 90vw);
    z-index: 70 !important;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    background: var(--panel);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 32px rgba(0,0,0,0.45);
}
.tv-side-panel.open { transform: translateX(0); }

.tv-side-panel .search-panel {
    height: 100%;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
    padding: 80px 14px 14px 14px;
    overflow: hidden;
}

.search-panel { display: flex; flex-direction: column; gap: 12px; }
.tabs { display: flex; gap: 8px; }
.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.tab.active {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border-color: transparent;
    color: #fff;
}
.tab .badge {
    background: rgba(255,255,255,0.25);
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11px;
}
.search-row { display: flex; gap: 8px; }
.search-wrap { position: relative; flex: 1; }
.search-wrap input {
    width: 100%;
    background: #0f1525;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px 12px 40px;
    color: var(--text);
    font-size: 14px;
    outline: none;
}
.search-wrap i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}
.btn-mic {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #22d3ee, #a78bfa);
    color: #fff;
    cursor: pointer;
}
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #1a2238;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
}
.tag:hover { color: #fff; background: #2a3550; }
.results-head {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--muted);
}
.results-list {
    flex: 1;
    overflow-y: auto;
    min-height: 160px;
}
.search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 12px;
    background: rgba(15, 21, 37, 0.6);
    margin-bottom: 8px;
}
.search-item img {
    width: 120px;
    height: 68px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}
.search-item .meta { flex: 1; min-width: 0; }
.search-item .meta h5 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.search-item .meta p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.search-item .actions { display: flex; gap: 6px; }
.search-item .actions button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
}
.btn-add { background: #1e293b; color: var(--muted); }
.btn-play-now { background: linear-gradient(135deg, #ec4899, #8b5cf6); color: #fff; }
.empty-state, .error-state, .loading-state {
    text-align: center;
    padding: 32px 12px;
    color: var(--muted);
    font-size: 13px;
}
.error-state { color: #fbbf24; }

#search-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    gap: 10px;
}
.queue-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    gap: 8px;
}
.queue-panel.show { display: flex; }
.queue-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 12px;
    background: rgba(15, 21, 37, 0.6);
}
.queue-item.playing {
    background: rgba(236, 72, 153, 0.12);
    border: 1px solid rgba(236, 72, 153, 0.35);
}
.queue-item .num {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}
.queue-item.playing .num { background: var(--pink); color: #fff; }
.queue-item img { width: 56px; height: 32px; object-fit: cover; border-radius: 6px; }
.queue-item .meta { flex: 1; min-width: 0; }
.queue-item .meta h6 {
    margin: 0;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.queue-item .meta p { margin: 2px 0 0; font-size: 10px; color: var(--muted); }
.queue-item .btn-del {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: #1e293b;
    color: var(--muted);
    cursor: pointer;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-backdrop.hidden { display: none; }
.modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    position: relative;
}
.modal h3 { margin: 0 0 12px; font-size: 18px; }
.modal .close-x {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
}
.modal label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}
.modal input {
    width: 100%;
    background: #0f1525;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    margin-bottom: 12px;
    outline: none;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn-cancel {
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: #1e293b;
    color: var(--muted);
    cursor: pointer;
}
.btn-primary {
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

body.guest-mode {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    background:
        radial-gradient(ellipse 80% 40% at 50% 0%, rgba(139, 92, 246, 0.12), transparent),
        var(--bg);
}
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(18, 24, 43, 0.95);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #22d3ee, #a78bfa, #ec4899);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}
.brand h1 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
    background: linear-gradient(90deg, #22d3ee, #c4b5fd, #f9a8d4);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.brand p { margin: 0; font-size: 11px; color: var(--muted); }
.header-right { display: flex; gap: 8px; align-items: center; }

.guest-wrap {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px;
}
.guest-mode .search-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
}
.guest-mode .results-list {
    max-height: 45vh;
    min-height: 200px;
}
.guest-queue-box {
    font-size: 12px;
    color: var(--muted);
    max-height: 140px;
    overflow-y: auto;
}

.phone-remote {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}
.remote-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 4px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #1a2238;
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}
.remote-btn i { font-size: 18px; }
.remote-btn.remote-main {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.35), rgba(236, 72, 153, 0.25));
    border-color: rgba(167, 139, 250, 0.35);
}
.remote-btn:active { transform: scale(0.96); }

/* responsive Tablet & Điện thoại (<= 1024px) */
@media (max-width: 1024px) {
    /* Ẩn hình QR nổi góc trái */
    body.tv-mode .floating-qr { 
        display: none !important; 
    }

    /* Hiển thị nút QR dạng Icon trong cụm nút control */
    .tv-btn-qr-mobile {
        display: flex !important;
    }

    /* Đưa dòng Danh sách bài hát tiếp theo lệch sang góc trái */
    .tv-next-strip {
        left: 20px !important;
        top: 20px !important;
    }
}

.tv-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.tv-screen:fullscreen .tv-top-controls,
.tv-screen:-webkit-full-screen .tv-top-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2147483646;
}
.tv-screen:fullscreen .tv-side-panel,
.tv-screen:-webkit-full-screen .tv-side-panel {
    z-index: 2147483645;
}
.tv-screen:fullscreen .floating-qr,
.tv-screen:-webkit-full-screen .floating-qr {
    z-index: 2147483644;
}

body.tv-mode button:focus,
body.tv-mode input:focus,
body.tv-mode .tag:focus,
body.tv-mode .tab:focus {
    outline: 3px solid #f472b6 !important;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(244, 114, 182, 0.35) !important;
}
body.tv-mode .tv-ctrl-btn:focus,
body.tv-mode .tag:focus {
    transform: scale(1.12);
}
body.tv-mode .tv-side-panel {
    transition: transform 0.3s ease, visibility 0s linear 0.3s;
}
body.tv-mode .tv-side-panel:not(.open) {
    visibility: hidden;
}
body.tv-mode .tv-side-panel.open {
    visibility: visible;
    transition: transform 0.3s ease, visibility 0s;
}

body.tv-app *,
body.tv-app *::before,
body.tv-app *::after {
    animation: none !important;
    transition: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
}
body.tv-app .tv-side-panel,
body.tv-app .floating-qr,
body.tv-app .tv-ctrl-btn:not(:focus),
body.tv-app .tv-next-strip {
    box-shadow: none !important;
}
body.tv-app .tv-ctrl-btn,
body.tv-app .pill,
body.tv-app .tv-next-strip,
body.tv-app .clock-inline {
    background: rgba(15, 23, 42, 0.88) !important;
}
body.tv-app .modal-backdrop {
    background: rgba(0, 0, 0, 0.75) !important;
}

body.tv-app .tv-top-controls { zoom: 1.4; }
body.tv-app .tv-next-strip   { zoom: 1.4; }
body.tv-app .floating-qr     { zoom: 1.5; }
body.tv-app .tv-side-panel   { width: 640px; }
body.tv-app .tv-side-panel .search-panel { zoom: 1.5; }
body.tv-app .modal           { zoom: 1.5; }
