/* ==========================================================================
   SMART COCKPIT HUB — NÚT THÔNG MINH
   Hỗ trợ giao diện Sáng / Tối, Danh sách bạn bè online, Chat & Đăng xuất
   ========================================================================== */

/* Nút thông minh trigger indicator */
#desktop-sidebar-theme-toggle {
    position: relative;
}
.hw-mobile-theme-pill {
    position: fixed;
    z-index: 9999995 !important;
}

.hw-cockpit-dot-indicator {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 9px;
    height: 9px;
    border-radius: 9999px;
    background: #10b981;
    border: 1.5px solid #ffffff;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.65);
    pointer-events: none;
    animation: hwCockpitPulse 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

html.dark .hw-cockpit-dot-indicator {
    border-color: #0f172a;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.85);
}

@keyframes hwCockpitPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.18); opacity: 0.8; }
}

/* Backdrop mờ nhẹ khi mở cockpit */
.hw-cockpit-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000001 !important;
    background: rgba(15, 23, 42, 0.25);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.hw-cockpit-backdrop.is-active {
    opacity: 1;
    pointer-events: auto;
}

/* Container Popover chính */
.hw-smart-cockpit-popover {
    position: fixed;
    right: 12px;
    width: calc(100vw - 24px);
    max-width: 330px;
    z-index: 10000002 !important;
    border-radius: 20px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-sizing: border-box;
    font-family: inherit;
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: calc(100dvh - 120px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    
    /* Giao diện Sáng (Pure White Glass) */
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow: 0 20px 40px -12px rgba(15, 23, 42, 0.16), 0 0 0 1px rgba(15, 23, 42, 0.05);
    color: #0f172a;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Xổ lên trên thông minh (Mở từ nút phía dưới lên) */
.hw-smart-cockpit-popover.popover-up {
    transform-origin: bottom right;
    transform: translateY(14px) scale(0.94);
    box-shadow: 0 -14px 40px -8px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(15, 23, 42, 0.06);
}

/* Giao diện Tối (Midnight Dark Glass) */
html.dark .hw-smart-cockpit-popover {
    background: rgba(15, 23, 42, 0.96);
    border: 1px solid rgba(51, 65, 85, 0.85);
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08);
    color: #f8fafc;
}

html.dark .hw-smart-cockpit-popover.popover-up {
    box-shadow: 0 -18px 46px -8px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.hw-smart-cockpit-popover.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Thanh cuộn tinh gọn cho Popover khi màn hình dọc */
.hw-smart-cockpit-popover::-webkit-scrollbar {
    width: 4px;
}
.hw-smart-cockpit-popover::-webkit-scrollbar-track {
    background: transparent;
}
.hw-smart-cockpit-popover::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 9999px;
}

/* Header */
.hw-cockpit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

html.dark .hw-cockpit-header {
    border-bottom-color: rgba(51, 65, 85, 0.6);
}

.hw-cockpit-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hw-cockpit-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #ffffff;
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.hw-cockpit-heading {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: inherit;
    line-height: 1.2;
}

.hw-cockpit-user-pill {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
}

html.dark .hw-cockpit-user-pill {
    color: #94a3b8;
}

.hw-cockpit-live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.7);
    animation: hwPulseLiveDot 2s infinite ease-in-out;
}

@keyframes hwPulseLiveDot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0.75; }
}

.hw-cockpit-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.hw-cockpit-close-btn,
.hw-cockpit-settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.hw-cockpit-close-btn:hover,
.hw-cockpit-settings-btn:hover {
    background: rgba(241, 245, 249, 0.8);
    color: #0f172a;
}

html.dark .hw-cockpit-close-btn:hover,
html.dark .hw-cockpit-settings-btn:hover {
    background: rgba(30, 41, 59, 0.8);
    color: #ffffff;
}

/* Tiêu đề từng phân mục */
.hw-cockpit-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 6px;
}

html.dark .hw-cockpit-section-title {
    color: #94a3b8;
}

/* 1. LỰA CHỌN SÁNG / TỐI (Theme Selector) */
.hw-cockpit-theme-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 12px;
}

html.dark .hw-cockpit-theme-selector {
    background: #1e293b;
}

.hw-cockpit-theme-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 9px;
    border: 1px solid transparent;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: all 0.18s ease;
}

html.dark .hw-cockpit-theme-option {
    color: #94a3b8;
}

.hw-cockpit-theme-option:hover {
    color: #0f172a;
}

html.dark .hw-cockpit-theme-option:hover {
    color: #f8fafc;
}

.hw-cockpit-theme-option.is-active {
    background: #ffffff;
    color: #0f172a;
    border-color: rgba(203, 213, 225, 0.8);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

html.dark .hw-cockpit-theme-option.is-active {
    background: #334155;
    color: #ffffff;
    border-color: rgba(148, 163, 184, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* 2. DANH SÁCH BẠN BÈ ONLINE TRỰC QUAN */
.hw-cockpit-online-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 750;
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

html.dark .hw-cockpit-online-badge {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.4);
}

.hw-cockpit-friends-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 155px;
    overflow-y: auto;
    padding-right: 2px;
}

.hw-cockpit-friends-container::-webkit-scrollbar {
    width: 4px;
}
.hw-cockpit-friends-container::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 4px;
}

.hw-cockpit-friend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 10px;
    background: rgba(248, 250, 252, 0.8);
    border: 1px solid rgba(226, 232, 240, 0.7);
    transition: background 0.15s ease;
}

html.dark .hw-cockpit-friend-item {
    background: rgba(30, 41, 59, 0.5);
    border-color: rgba(51, 65, 85, 0.5);
}

.hw-cockpit-friend-item:hover {
    background: rgba(241, 245, 249, 1);
}

html.dark .hw-cockpit-friend-item:hover {
    background: rgba(30, 41, 59, 0.9);
}

.hw-cockpit-friend-left {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    flex: 1;
}

.hw-cockpit-friend-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 11px;
    font-weight: 800;
    flex-shrink: 0;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.hw-cockpit-avatar-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    border: 1.5px solid #ffffff;
}

html.dark .hw-cockpit-avatar-dot {
    border-color: #0f172a;
}

.hw-cockpit-friend-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.hw-cockpit-friend-name {
    font-size: 12px;
    font-weight: 750;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
    line-height: 1.2;
}

.hw-cockpit-friend-sub {
    display: inline-flex;
    align-items: center;
    gap: 4.5px;
    font-size: 10px;
    color: #10b981;
    font-weight: 600;
    line-height: 1;
    margin-top: 2px;
}

.hw-cockpit-friend-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.hw-cockpit-friend-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(203, 213, 225, 0.6);
    background: #ffffff;
    color: #475569;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s ease;
}

html.dark .hw-cockpit-friend-btn {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
}

.hw-cockpit-friend-btn:hover {
    background: #6366f1;
    border-color: #6366f1;
    color: #ffffff;
    transform: translateY(-1px);
}

.hw-cockpit-friend-btn.is-challenge:hover {
    background: #f59e0b;
    border-color: #f59e0b;
    color: #ffffff;
}

/* Empty state bạn bè */
.hw-cockpit-empty-friends {
    padding: 12px 10px;
    text-align: center;
    border-radius: 12px;
    background: rgba(248, 250, 252, 0.6);
    border: 1px dashed rgba(203, 213, 225, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

html.dark .hw-cockpit-empty-friends {
    background: rgba(30, 41, 59, 0.3);
    border-color: rgba(71, 85, 105, 0.6);
}

.hw-cockpit-empty-text {
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
}

html.dark .hw-cockpit-empty-text {
    color: #94a3b8;
}

.hw-cockpit-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 8px;
    background: #6366f1;
    color: #ffffff;
    border: none;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.hw-cockpit-link-btn:hover {
    opacity: 0.9;
}

/* 3. GIAO DIỆN CHAT TRỰC QUAN THÔNG MINH */
.hw-cockpit-chat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}

.hw-cockpit-chat-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 7px 4px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid rgba(226, 232, 240, 0.9);
    color: #334155;
    cursor: pointer;
    transition: all 0.16s ease;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

html.dark .hw-cockpit-chat-tile {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
    box-shadow: none;
}

.hw-cockpit-chat-tile:hover {
    background: #f8fafc;
    border-color: #818cf8;
    color: #4f46e5;
    transform: translateY(-1px);
}

html.dark .hw-cockpit-chat-tile:hover {
    background: #334155;
    border-color: #818cf8;
    color: #a5b4fc;
}

.hw-cockpit-chat-tile i {
    font-size: 14px;
    transition: transform 0.15s ease;
}

.hw-cockpit-chat-tile:hover i {
    transform: scale(1.12);
}

.hw-cockpit-chat-tile span {
    font-size: 9.5px;
    font-weight: 750;
    white-space: nowrap;
}

.hw-cockpit-chat-tile .hw-cockpit-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    border-radius: 8px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #ffffff;
    font-size: 8.5px;
    font-weight: 800;
    line-height: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(220, 38, 38, 0.35);
    pointer-events: none;
    z-index: 5;
    animation: badgePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

html.dark .hw-cockpit-chat-tile .hw-cockpit-badge {
    background: linear-gradient(135deg, #f87171, #ef4444);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.45);
}

/* 4. NÚT ĐĂNG XUẤT NHỎ GỌN THÔNG MINH */
.hw-cockpit-logout-btn {
    width: 100%;
    min-height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 12px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 750;
    cursor: pointer;
    transition: all 0.16s ease;
    
    /* Light Mode: Sạch sẽ tinh khôi, hoàn toàn không xám bẩn */
    background: #fef2f2 !important;
    border: 1px solid #fecaca !important;
    color: #dc2626 !important;
    box-shadow: 0 1px 3px rgba(220, 38, 38, 0.06);
}

.hw-cockpit-logout-btn:hover {
    background: #fee2e2 !important;
    border-color: #f87171 !important;
    color: #b91c1c !important;
    transform: translateY(-1px);
}

html.dark .hw-cockpit-logout-btn {
    background: rgba(239, 68, 68, 0.12) !important;
    border: 1px solid rgba(239, 68, 68, 0.35) !important;
    color: #fca5a5 !important;
    box-shadow: none;
}

html.dark .hw-cockpit-logout-btn:hover {
    background: rgba(239, 68, 68, 0.22) !important;
    border-color: rgba(239, 68, 68, 0.55) !important;
    color: #ffffff !important;
    transform: translateY(-1px);
}
