/* ================================================================
   VELVET THEME — User Panel  v6.0
   assets/css/user-panel.css

   BUGS FIXED IN THIS VERSION:
   ✓ Labels no longer leak outside collapsed panel
     (removed tooltip pseudo-elements that escaped overflow:hidden;
      replaced with a proper tooltip div injected by JS instead)
   ✓ Expand button now works — panel width is always wide enough
     for the button to be clickable (toggle area = full 56px column)
   ✓ Mobile no longer freezes — panel is pointer-events:none when
     off-screen, so it cannot intercept touch events
   ✓ No CSS hover expansion — toggle is click-only
   ✓ Body padding ONLY applied on desktop via @media (min-width:1025px)
   ================================================================ */

/* ── CONSTANTS — sync with JS VUP_COL/VUP_EXP ── */
:root {
    --vup-col: 56px;   /* collapsed width  */
    --vup-exp: 220px;  /* expanded width   */
    --vup-dur: 0.22s;
    --vup-fn:  cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================================================================
   BODY OFFSET — DESKTOP ONLY
   Wrapped in @media so mobile CSS physically cannot fire this.
   ================================================================ */
@media (min-width: 1025px) {
    html[data-panel="collapsed"] body { padding-left: var(--vup-col); }
    html[data-panel="expanded"]  body { padding-left: var(--vup-exp); }
    body.vup-ready {
        transition: padding-left var(--vup-dur) var(--vup-fn);
    }
}

/* ================================================================
   PANEL SHELL
   ================================================================ */
.velvet-user-panel {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 110;
    /* Start at collapsed width */
    width: var(--vup-col);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 16px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    /* overflow:hidden clips labels in collapsed mode */
    overflow: hidden;
    transition: width var(--vup-dur) var(--vup-fn),
                box-shadow var(--vup-dur) var(--vup-fn);
    user-select: none;
    -webkit-user-select: none;
}

.velvet-user-panel.vup-expanded {
    width: var(--vup-exp);
    box-shadow: 3px 0 28px rgba(0,0,0,0.5), 1px 0 0 var(--gold-dim);
}

/* Admin bar offset */
.admin-bar .velvet-user-panel { top: 32px; }

/* ================================================================
   MOBILE — pure transform slide, zero page-flow impact
   FIX: pointer-events:none when hidden so it cannot steal touches
   ================================================================ */
@media (max-width: 1024px) {
    .velvet-user-panel {
        width: var(--vup-exp) !important;
        transform: translateX(calc(-100% - 4px));
        transition: transform var(--vup-dur) var(--vup-fn);
        z-index: 300;
        top: 0 !important;
        /* CRITICAL FIX: no touch interception when off-screen */
        pointer-events: none;
        visibility: hidden;
    }
    .velvet-user-panel.vup-mobile-open {
        transform: translateX(0);
        pointer-events: auto;
        visibility: visible;
    }
    /* Labels always visible inside open mobile panel */
    .velvet-user-panel.vup-mobile-open .vup-label {
        opacity: 1 !important;
        visibility: visible !important;
        transition-delay: 0s !important;
    }
    .velvet-user-panel.vup-mobile-open .vup-identity {
        opacity: 1 !important;
        transform: none !important;
        pointer-events: auto !important;
    }
    .velvet-user-panel.vup-mobile-open .vup-badge {
        opacity: 1 !important;
    }
}

/* Admin bar on mobile */
@media screen and (max-width: 782px) {
    .admin-bar .velvet-user-panel { top: 46px !important; }
    .admin-bar .vup-mobile-btn    { bottom: calc(18px + 46px); }
}

/* ================================================================
   HEADER (avatar + identity)
   ================================================================ */
.vup-header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    min-height: 72px;
    /* MUST NOT have overflow:hidden — avatar notif badge must show */
    overflow: visible;
    border-bottom: 1px solid var(--border);
    position: relative;
}

/* Gold accent top line */
.vup-header::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0.4;
    pointer-events: none;
}

/* Avatar column — fixed width = collapsed panel width */
.vup-avatar-wrap {
    flex-shrink: 0;
    width: var(--vup-col);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.vup-avatar-link {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.vup-avatar-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--gold-dim);
    display: block;
    flex-shrink: 0;
    transition: border-color var(--transition-fast);
}
.vup-avatar-link:hover .vup-avatar-img {
    border-color: var(--gold);
    box-shadow: var(--neon-glow-sm);
}

.vup-avatar-initial {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--gold-dim);
    background: var(--bg-elevated);
    color: var(--gold);
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.vup-logo-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    text-decoration: none;
    flex-shrink: 0;
}
.vup-logo-link svg {
    display: block;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    stroke: var(--gold);
    fill: none;
}

.vup-avatar-notif {
    position: absolute;
    top: -2px; right: -3px;
    min-width: 15px; height: 15px;
    padding: 0 3px;
    background: var(--crimson);
    color: #fff;
    font-family: var(--font-label);
    font-size: 0.56rem;
    font-weight: 700;
    border-radius: 10px;
    border: 1.5px solid var(--bg-surface);
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
    pointer-events: none;
    z-index: 1;
}

/* Identity text — hidden in collapsed, slides in when expanded */
.vup-identity {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    padding-right: 10px;
    opacity: 0;
    transform: translateX(-6px);
    pointer-events: none;
    transition: opacity var(--vup-dur) var(--vup-fn),
                transform var(--vup-dur) var(--vup-fn);
    transition-delay: 0.04s;
}
.velvet-user-panel.vup-expanded .vup-identity {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.vup-name {
    display: block;
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}
.vup-role {
    display: block;
    font-family: var(--font-label);
    font-size: 0.56rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold);
    margin-top: 2px;
}

/* ================================================================
   DIVIDER
   ================================================================ */
.vup-divider {
    height: 1px;
    flex-shrink: 0;
    background: var(--border);
}

/* ================================================================
   NAV
   ================================================================ */
.vup-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}
.vup-nav::-webkit-scrollbar       { width: 3px; }
.vup-nav::-webkit-scrollbar-track { background: transparent; }
.vup-nav::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.vup-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.vup-item { position: relative; }

/* ── LINK ─────────────────────────────────────────────────────── */
.vup-link {
    display: flex;
    align-items: center;
    width: 100%;
    color: var(--text-secondary);
    font-size: 0.83rem;
    font-weight: 500;
    text-decoration: none;
    position: relative;
    overflow: hidden;
    transition: color var(--transition-fast), background var(--transition-fast);
    white-space: nowrap;
    min-height: 44px;
}
.vup-link:hover {
    color: var(--gold-light);
    background: rgba(201,168,76,0.07);
}

/* Active */
.vup-link--active {
    color: var(--gold);
    background: rgba(201,168,76,0.1);
}
.vup-link--active::before {
    content: '';
    position: absolute;
    left: 0; top: 20%; bottom: 20%;
    width: 3px;
    background: var(--gold);
    border-radius: 0 3px 3px 0;
    box-shadow: var(--neon-glow-sm);
}
.vup-link--active .vup-icon svg { stroke: var(--gold) !important; }

/* Danger (logout) */
.vup-link--danger { color: var(--text-muted); }
.vup-link--danger:hover {
    color: var(--crimson-light);
    background: rgba(192,32,48,0.07);
}
.vup-link--danger:hover .vup-icon svg { stroke: var(--crimson-light) !important; }

/* ── ICON CELL ────────────────────────────────────────────────── */
.vup-icon {
    flex-shrink: 0;
    width: var(--vup-col);     /* always the full collapsed width */
    min-width: var(--vup-col);
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.vup-icon svg {
    display: block;
    flex-shrink: 0;
    stroke: var(--text-muted);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke var(--transition-fast);
    /* Size is set by HTML width/height attributes in PHP */
}
.vup-link:hover .vup-icon svg { stroke: var(--gold-light); }

/* ── LABEL ────────────────────────────────────────────────────── */
.vup-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 8px;
    /* Hidden when collapsed */
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--vup-dur) var(--vup-fn),
                visibility 0s linear var(--vup-dur);
}
.velvet-user-panel.vup-expanded .vup-label {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--vup-dur) var(--vup-fn),
                visibility 0s linear 0s;
    transition-delay: 0.05s;
}

/* ── BADGE ────────────────────────────────────────────────────── */
.vup-badge {
    flex-shrink: 0;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-right: 10px;
    background: var(--crimson);
    color: #fff;
    font-family: var(--font-label);
    font-size: 0.58rem;
    font-weight: 700;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
    opacity: 0;
    transition: opacity var(--vup-dur) var(--vup-fn);
}
.velvet-user-panel.vup-expanded .vup-badge { opacity: 1; }

/* Badge dot in collapsed mode */
.vup-item:has(.vup-badge) .vup-icon::after {
    content: '';
    position: absolute;
    top: 6px; right: 8px;
    width: 7px; height: 7px;
    background: var(--crimson);
    border-radius: 50%;
    border: 1.5px solid var(--bg-surface);
    pointer-events: none;
}
.velvet-user-panel.vup-expanded .vup-item:has(.vup-badge) .vup-icon::after { opacity: 0; }

/* ================================================================
   TOOLTIP (desktop collapsed only)
   FIX: Tooltip is a real <span> injected by JS into the body,
   NOT a ::after pseudo-element on .vup-item.
   This means it cannot be clipped by the panel's overflow:hidden
   and always appears correctly at the correct position.
   The JS (user-panel.js) creates and positions these on hover.
   ================================================================ */
.vup-tooltip {
    position: fixed;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 0.76rem;
    font-family: var(--font-body);
    font-weight: 500;
    padding: 5px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    white-space: nowrap;
    pointer-events: none;
    z-index: 9999;
    box-shadow: var(--shadow-card);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.vup-tooltip.vup-tooltip--visible {
    opacity: 1;
    transform: translateX(0);
}

/* ================================================================
   FOOTER TOGGLE BUTTON
   FIX: Button takes full width, always clickable even in collapsed
   ================================================================ */
.vup-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
}

.vup-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.83rem;
    font-family: var(--font-body);
    font-weight: 500;
    overflow: hidden;
    white-space: nowrap;
    transition: color var(--transition-fast), background var(--transition-fast);
    /* Make sure button is always interactive */
    position: relative;
    z-index: 1;
}
.vup-toggle:hover {
    color: var(--gold);
    background: rgba(201,168,76,0.07);
}
.vup-toggle .vup-icon svg {
    transition: transform var(--vup-dur) var(--vup-fn),
                stroke var(--transition-fast);
}
.velvet-user-panel.vup-expanded .vup-toggle .vup-icon svg {
    transform: rotate(180deg);
}

/* ================================================================
   MOBILE TRIGGER BUTTON
   ================================================================ */
.vup-mobile-btn {
    display: none;
    position: fixed;
    bottom: 18px;
    left: 12px;
    z-index: 301;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--gold-dim);
    background: var(--bg-surface);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 3px 16px rgba(0,0,0,0.5), var(--neon-glow-sm);
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast),
                transform var(--transition-fast);
    overflow: hidden;
    /* Always interactive */
    pointer-events: auto;
}
.vup-mobile-btn:hover {
    border-color: var(--gold);
    box-shadow: 0 4px 20px rgba(0,0,0,0.6), var(--neon-glow-md);
    transform: scale(1.06);
}
.vup-mobile-btn svg {
    display: block;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke: var(--gold);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
}
.vup-mobile-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
.vup-mobile-badge {
    position: absolute;
    top: -2px; right: -2px;
    min-width: 15px; height: 15px;
    padding: 0 3px;
    background: var(--crimson);
    color: #fff;
    font-family: var(--font-label);
    font-size: 0.56rem;
    font-weight: 700;
    border-radius: 10px;
    border: 1.5px solid var(--bg-surface);
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
    pointer-events: none;
}

/* ================================================================
   BACKDROP (mobile)
   ================================================================ */
.vup-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 299;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}
.vup-backdrop.vup-open {
    opacity: 1;
    pointer-events: auto;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 1024px) {
    .vup-mobile-btn { display: flex; }
    .vup-backdrop   { display: block; }
    /* Hide tooltips on mobile */
    .vup-tooltip    { display: none !important; }
}

/* ================================================================
   PRINT
   ================================================================ */
@media print {
    .velvet-user-panel,
    .vup-mobile-btn,
    .vup-backdrop,
    .vup-tooltip { display: none !important; }
    html[data-panel] body { padding-left: 0 !important; }
}
