/* =========================================
   MDKG WIDGET SYSTEM (Scoped)
   ========================================= */

/* --- MUSIC PLAYER --- */
.mdkg-widget-player {
    position: fixed;
    bottom: 40px;
    right: 40px;
    z-index: 9999;
    --w-bg: rgba(255, 255, 255, 0.75);
    --w-text: #111111;
    --w-sub: #767676;
    background: var(--w-bg);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px; /* Editorial squircle — slightly sharper than the app-like 16px */
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.05);
    color: var(--w-text);
    will-change: transform;
    transform: translateZ(0);
}

.mdkg-widget-player:hover {
    transform: translateY(-2px);
    border-color: rgba(0, 0, 0, 0.14);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.07);
}

/* The mobile nav overlay (.mobile-menu-overlay, z-index:998) sits well below this widget's
   z-index:9999, so the floating player kept showing on top of the full-screen menu instead
   of being covered by it. .navbar.menu-open is the class script.js already toggles when the
   mobile menu opens/closes — :has() lets this widget react to that without needing its own
   JS wiring. */
body:has(.navbar.menu-open) .mdkg-widget-player,
body:has(.navbar.menu-open) #mdkg-widget-container {
    display: none;
}

.mdkg-widget-player:active, .mdkg-widget-player.playing:active {
    transform: scale(0.98);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* --- [NEW] PLAYER COVER & TRACK INFO --- */
.mdkg-player-cover {
    width: 0; /* Default tertutup */
    height: 28px; /* Lebih kecil agar compact */
    border-radius: 50%; /* Vinyl record — kept circular, it's a physical disc metaphor */
    flex-shrink: 0;
    /* [FIX] Background dihapus, border ditangani langsung oleh image */
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    margin-right: 0;
    position: relative;
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
    transition: all 0.6s cubic-bezier(0.19, 1, 0.22, 1);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Mencegah gambar bocor saat transisi */
}

/* [NEW] Titik tengah (hole) piringan hitam dibuat lebih detail */
.mdkg-player-cover::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 4px;
    background: #e0e0e0;
    border: 1px solid #111;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
    box-sizing: border-box; /* [FIX] Memastikan titik tengah bulat sempurna */
}

/* [NEW] State Terbuka saat Play */
.mdkg-widget-player.playing .mdkg-player-cover {
    width: 28px;
    margin-right: 6px;
    opacity: 1;
    transform: scale(1) rotate(0deg);
    pointer-events: auto; /* [FIX] Aktifkan klik/hover di cover saat play */
    cursor: zoom-in; /* [NEW] Kursor khusus menandakan bisa di-zoom */
}

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

.mdkg-track-cover {
    min-width: 28px; /* [FIX] Paksa bentuk bulat konsisten di 28px */
    height: 28px;
    border: 2px solid #111; /* [FIX] Symmetrical sempurna */
    box-sizing: border-box;
    object-fit: cover;
    /* [NEW] Animasi putar yang di-pause secara default */
    animation: mdkgSpinRecord 4s linear infinite;
    animation-play-state: paused; 
    border-radius: 50%;
    z-index: 1;
    display: block; /* [FIX] Menghilangkan space kosong/miring bawaan elemen image */
    background-color: #111;
}

/* [NEW] Piringan berputar hanya saat lagu sedang play */
.mdkg-widget-player.playing .mdkg-track-cover {
    animation-play-state: running;
}

.mdkg-track-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 0;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 0.6s cubic-bezier(0.19, 1, 0.22, 1);
    margin-left: 0;
}

.mdkg-widget-player.playing .mdkg-track-info {
    max-width: 110px;
    opacity: 1;
}

.mdkg-track-title {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1;
    color: var(--w-text);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 100%;
    display: inline-block;
}

.mdkg-track-artist {
    font-family: inherit;
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    margin-top: 2px;
    letter-spacing: 0.02em;
    color: var(--w-sub);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 100%;
}

.mdkg-player-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.mdkg-player-icon svg {
    width: 16px;
    height: 16px;
}

.mdkg-player-content {
    display: flex;
    align-items: center;
    gap: 0; /* Children (title/artist, visualizer) are collapsed to 0-width while idle —
        without zeroing this too, the empty container still occupies the parent's own
        gap on both sides, reading as an oversized space between the mute and next icons. */
    margin: 0 -5px; /* Offsets half the parent's 10px gap on each side while idle, so the
        icons either side sit at a normal, even spacing instead of double gap. */
    transition: gap 0.4s cubic-bezier(0.19, 1, 0.22, 1), margin 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.mdkg-widget-player.playing .mdkg-player-content {
    gap: 8px;
    margin: 0;
}

/* Empty by design now (both "PLAY" and "PAUSED" labels removed) — kept as an element only
   so JS doesn't need special-casing, but takes up no space. */
.mdkg-player-text {
    display: none;
}

.mdkg-visualizer {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 12px;
    width: 0; /* Collapsed until playing — no static/idle waveform shown */
    overflow: hidden;
    opacity: 0;
    transition: width 0.4s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.3s ease;
}

.mdkg-widget-player.playing .mdkg-visualizer {
    width: 14px;
    opacity: 1;
}

.mdkg-bar {
    width: 3px;
    background-color: var(--w-text);
    height: 2px;
    transition: height 0.2s ease;
}

/* Animation State */
.mdkg-widget-player.playing .mdkg-bar {
    animation: mdkgEqualizer 0.5s infinite ease-in-out alternate;
}

.mdkg-widget-player.playing .mdkg-bar:nth-child(1) { animation-duration: 0.4s; }
.mdkg-widget-player.playing .mdkg-bar:nth-child(2) { animation-duration: 0.5s; }
.mdkg-widget-player.playing .mdkg-bar:nth-child(3) { animation-duration: 0.35s; }

@keyframes mdkgEqualizer {
    0% { height: 20%; }
    100% { height: 100%; }
}

/* Next Button */
.mdkg-next-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 8px;
    transition: all 0.2s ease;
    margin-left: 4px;
    opacity: 0.7;
    color: var(--w-text);
}
.mdkg-next-btn:hover {
    background: rgba(0,0,0,0.08);
    opacity: 1;
    transform: scale(1.1);
}
.mdkg-next-btn svg {
    width: 12px;
    height: 12px;
}

/* [NEW] Playlist Toggle — back inside the player (moved to the navbar and back per
   feedback). Same footprint/behavior as Next so the two sit evenly. */
.mdkg-player-playlist-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.nav-playlist-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    transition: all 0.2s ease;
    margin-left: 2px;
    opacity: 0.7;
    color: var(--w-text);
    background: transparent;
    border: none;
    cursor: pointer;
}
.nav-playlist-btn:hover {
    background: rgba(0,0,0,0.08);
    opacity: 1;
    transform: scale(1.1);
}
.nav-playlist-btn[aria-expanded="true"] {
    background: rgba(0,0,0,0.1);
    opacity: 1;
}
.nav-playlist-btn svg {
    width: 15px;
    height: 15px;
}

/* [NEW] Playlist Panel — floats above the player, same glass material language as
   .mdkg-widget-player. Hidden by default (display:none avoids it intercepting clicks/
   being tab-reachable while closed) and revealed via .is-open (toggled in widget.js). */
.nav-playlist-panel {
    display: none;
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    min-width: 200px;
    max-width: 260px;
    max-height: 280px;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    padding: 6px;
    flex-direction: column;
    gap: 2px;
    cursor: default; /* overrides the player's own cursor:pointer */
}

.nav-playlist-panel.is-open {
    display: flex;
    animation: mdkgPlaylistOpen 0.25s cubic-bezier(0.19, 1, 0.22, 1);
}

@keyframes mdkgPlaylistOpen {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.nav-playlist-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 7px 10px;
    border-radius: 9px;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease;
    font-family: inherit;
}

.nav-playlist-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.nav-playlist-item.is-active {
    background: rgba(0, 0, 0, 0.08);
}

.nav-playlist-item-title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--w-text);
    line-height: 1.3;
}

.nav-playlist-item.is-active .nav-playlist-item-title::before {
    content: '♪ ';
}

.nav-playlist-item-artist {
    font-size: 10px;
    font-weight: 500;
    color: var(--w-sub);
    line-height: 1.3;
}

/* --- [NEW] MDKG WIDGET LIGHTBOX & TOOLTIP --- */
.mdkg-cover-tooltip {
    position: absolute;
    bottom: 100%;
    left: 14px;
    transform: translateY(-8px) scale(0.95);
    background: rgba(17, 17, 17, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    z-index: 10;
}

.mdkg-cover-tooltip::after {
    content: ''; position: absolute; top: 100%; left: 14px;
    border: 4px solid transparent; border-top-color: rgba(17, 17, 17, 0.95);
}

/* Menampilkan Tooltip saat cover di-hover */
.mdkg-player-cover:hover ~ .mdkg-cover-tooltip {
    opacity: 1; visibility: visible;
    transform: translateY(-12px) scale(1);
}

/* Lightbox Styles */
#mdkg-widget-lightbox {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 100000;
    display: none; align-items: center; justify-content: center; opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}
#mdkg-widget-lightbox.active { opacity: 1; }

.mdkg-lightbox-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    cursor: zoom-out;
}

.mdkg-lightbox-content {
    position: relative; z-index: 2; max-width: 90vw; max-height: 90vh;
    transform: scale(0.9); transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}
#mdkg-widget-lightbox.active .mdkg-lightbox-content { transform: scale(1); }

.mdkg-lightbox-content img {
    max-width: 100%; max-height: 90vh; border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5); display: block; object-fit: contain;
}

.mdkg-lightbox-close {
    position: absolute;
    top: 32px;
    right: 40px;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%; /* Circle, not squircle — per feedback on close/X buttons site-wide */
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    padding: 0;
    transition: all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    z-index: 10001;
}

.mdkg-lightbox-close svg {
    width: 20px;
    height: 20px;
    transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}
.mdkg-lightbox-close:hover { background: #fff; color: #000; transform: scale(1.05); }
.mdkg-lightbox-close:hover svg { transform: rotate(90deg); }

/* --- LIVE STATUS WIDGET --- */
.mdkg-widget-status {
    position: fixed;
    bottom: 40px;
    left: 40px;
    z-index: 9990;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    padding: 20px 24px;
    border-radius: 14px; /* Editorial squircle — slightly sharper than the app-like 16px */
    color: #111111;
    font-family: var(--font-primary, 'Inter', sans-serif);
    width: max-content;
    min-width: 260px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1), border-color 0.4s ease, box-shadow 0.4s ease;
    text-decoration: none;
}

.mdkg-widget-status.widget-hidden,
.mdkg-widget-player.widget-hidden {
    transform: translateY(200%) !important;
    opacity: 0;
    pointer-events: none;
}

.mdkg-widget-status:hover {
    border-color: rgba(0, 0, 0, 0.14);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.07);
}

.mdkg-widget-header {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #999999;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin: 0;
    padding: 0;
    border: none;
    font-weight: 500;
}

.mdkg-widget-status-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.mdkg-status-dot {
    width: 6px;
    height: 6px;
    /* Available state. When fully booked again, swap this for #999 (neutral gray)
       and update the status text in widget.js. */
    background-color: #28cd41; /* Apple Green */
    border-radius: 50%;
}

.mdkg-status-text {
    font-size: 15px;
    color: #000000;
    font-weight: 500;
    letter-spacing: -0.005em;
    position: relative;
    white-space: nowrap; /* Memastikan teks tidak turun ke bawah */
}

/* --- Animasi Kursor Ketik --- */
.mdkg-typing-cursor {
    font-weight: 400;
    color: #111;
    animation: mdkgBlink 0.8s step-end infinite;
}

@keyframes mdkgBlink {
    from, to { opacity: 1; }
    50% { opacity: 0; }
}

.mdkg-book-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 14px 0 0;
    background: transparent;
    color: #111111;
    text-align: left;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    border-radius: 0;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    transition: color 0.3s ease;
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
}

.mdkg-book-btn:hover {
    color: #767676;
}

.mdkg-book-btn > svg:first-child {
    flex-shrink: 0;
    order: 2;
    transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1);
}

.mdkg-book-btn:hover > svg:first-child {
    transform: translateX(3px);
}

/* --- TABLET RESPONSIVE --- */
@media (max-width: 991px) {
    .mdkg-widget-player {
        bottom: 30px;
        right: 30px;
    }
    .mdkg-widget-status {
        bottom: 30px;
        left: 30px;
    }
}

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 767px) {
    .mdkg-widget-player {
        bottom: 20px;
        right: 20px;
        padding: 0 12px;
        height: 48px; /* [FIX] Tinggi sedikit dinaikkan agar lebih pas dan nyaman ditekan */
        box-sizing: border-box;
        gap: 6px;
        border-radius: 14px; /* [FIX] Bentuk squircle di mobile */
        max-width: min(max-content, calc(100vw - 40px)); /* [FIX] Was plain max-content
            (unbounded) — on very narrow screens (~320px) with a long status message on
            the left, an unbounded player could get squeezed against or overlap
            .mdkg-widget-status; this caps it to the viewport regardless. */
        border: none; /* [FIX] Menghapus border transparan di mobile */
    }

    .mdkg-player-text,
    .mdkg-track-info,
    .mdkg-widget-player.playing .mdkg-track-info,
    .mdkg-player-cover,
    .mdkg-widget-player.playing .mdkg-player-cover {
        display: none !important;
    }

    .mdkg-visualizer {
        display: flex !important;
        margin: 0 4px;
    }

    .mdkg-player-icon svg {
        width: 20px; /* Diperkecil agar widget tidak terlalu lebar */
        height: 20px;
    }

    /* [FIX] .mdkg-next-btn/.nav-playlist-btn keep their compact 20-24px visual size (so
       the player itself doesn't get wider) but gain an invisible ::before hitbox padded
       out to the ~44px touch target accessibility guidelines call for — a 20px box alone
       is under half that, and real thumbs miss it often on a phone. position:relative is
       needed on the button itself for the pseudo-element's absolute positioning to anchor
       to it rather than the page. */
    .mdkg-next-btn,
    .nav-playlist-btn {
        position: relative;
    }
    .mdkg-next-btn::before,
    .nav-playlist-btn::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 44px;
        height: 44px;
        transform: translate(-50%, -50%);
    }

    .mdkg-next-btn {
        width: 20px; /* Diperkecil agar proporsional */
        height: 20px;
        margin-left: 0;
    }

    .nav-playlist-btn {
        width: 24px;
        height: 24px;
        margin-left: 0;
    }

    .nav-playlist-panel {
        right: -8px; /* Compensate for the mobile player's tighter 12px side padding */
        max-width: calc(100vw - 40px);
    }

    .mdkg-cover-tooltip {
        display: none !important; /* Tooltip tak relevan di Mobile Touch */
    }

    .mdkg-lightbox-close {
        top: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
    }
    .mdkg-lightbox-close svg {
        width: 18px;
        height: 18px;
    }

    /* Compact Live Status Widget */
    .mdkg-widget-status {
        position: fixed;
        bottom: 20px;
        left: 20px;
        transform: none;
        z-index: 990;
        width: auto;
        min-width: 0;
        max-width: calc(100vw - 120px); /* Ruang diperlebar agar teks muat penuh */
        height: 48px; /* [FIX] Tinggi disamakan presisi dengan Music Player */
        padding: 0 10px;
        box-sizing: border-box; /* [FIX] Memastikan padding tidak menambah tinggi asli kotak */
        border-radius: 14px; /* [FIX] Bentuk squircle di mobile */
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    }
    .mdkg-widget-header { display: none; } /* Hide clock on mobile */
    .mdkg-widget-status-row {
        margin-bottom: 0;
        margin-right: auto;
        min-width: 0; /* Lets the row actually shrink below its content size so the ellipsis
            below can kick in — a flex child defaults to min-width:auto, which ignores
            overflow rules entirely and instead pushes the sibling .mdkg-book-btn out. */
    }
    .mdkg-status-text {
        font-size: 11px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis; /* [FIX] Safety valve for very narrow screens (~320px): the
            fixed-position status card and player card sit on the same row with a shared,
            tight budget (max-width: calc(100vw - 120px) below), and nowrap alone with no
            way to shrink could force the two cards to overlap or push the player off-
            screen. Ellipsis here means the text truncates instead. */
    }
    
    .mdkg-book-btn {
        width: 32px; height: 32px; padding: 0; border-radius: 0; flex-shrink: 0;
        display: flex; align-items: center; justify-content: center; gap: 0;
        background: transparent; color: #111; border: none;
    }
    .mdkg-book-btn span {
        display: none; /* Sembunyikan teks di mobile */
    }
}