/* ============================================
   LAGGONE AI - SHARED LAYOUT & COMPONENTS
   Clean rewrite matching dashboard.html reference
   ============================================ */

/* ===== LAYOUT ===== */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-dark);
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--bg-card) 0%, rgba(139,92,246,0.03) 100%);
    border-right: 1px solid rgba(139,92,246,0.1);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: width .3s;
}

.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .sidebar-upgrade,
.sidebar.collapsed .user-info,
.sidebar.collapsed .user-menu-btn { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px; }

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(139,92,246,0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.1rem;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1rem;
}

.accent { color: #8b5cf6; }

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.nav-section { margin-bottom: 16px; }

.nav-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 8px 12px 4px;
    display: block;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.88rem;
    transition: all .2s;
    position: relative;
}

.nav-item:hover {
    background: rgba(139,92,246,0.08);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(139,92,246,0.12);
    color: #8b5cf6;
    font-weight: 600;
}

.nav-item i {
    font-size: 1.15rem;
    width: 20px;
    text-align: center;
}

.nav-badge {
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: 600;
}

.nav-badge.new {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
}

/* Sidebar Upgrade */
.sidebar-upgrade { padding: 12px 16px; }

.upgrade-card {
    background: linear-gradient(135deg, rgba(139,92,246,0.12), rgba(99,102,241,0.08));
    border: 1px solid rgba(139,92,246,0.2);
    border-radius: 14px;
    padding: 16px;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: border-color .3s, transform .2s;
}
.upgrade-card:hover {
    border-color: rgba(139,92,246,0.4);
    transform: translateY(-1px);
}
.upgrade-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg, transparent, rgba(139,92,246,0.08), transparent, rgba(139,92,246,0.04), transparent);
    animation: upgradeShimmer 6s linear infinite;
    pointer-events: none;
}
@keyframes upgradeShimmer {
    to { transform: rotate(360deg); }
}

.upgrade-card h4 {
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: var(--text-primary);
    position: relative;
}

.upgrade-card p {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    position: relative;
}

.upgrade-icon {
    font-size: 1.5rem;
    color: #8b5cf6;
    margin-bottom: 6px;
    position: relative;
    animation: rocketBounce 3s ease-in-out infinite;
}
@keyframes rocketBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* Sidebar User */
.sidebar-user {
    padding: 14px 16px;
    border-top: 1px solid rgba(139,92,246,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background .2s;
    position: relative;
}
.sidebar-user:hover {
    background: rgba(139,92,246,0.06);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
    position: relative;
    transition: transform .2s, box-shadow .2s;
}
.sidebar-user:hover .user-avatar {
    transform: scale(1.05);
    box-shadow: 0 0 16px rgba(139,92,246,0.3);
}
.user-avatar.plan-premium {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}
.user-avatar.plan-pro {
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
}
.user-avatar::after {
    content: '';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid var(--bg-dark, #030014);
    animation: pulse-online 2s infinite;
}
@keyframes pulse-online {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.4); }
    50% { box-shadow: 0 0 0 4px rgba(16,185,129,0); }
}

.user-info { flex: 1; min-width: 0; }

.user-name {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-plan {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}
.user-plan.plan-premium { color: #fbbf24; }
.user-plan.plan-pro { color: #e879f9; }
.user-plan::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

.user-menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color .2s, transform .2s;
    padding: 4px;
    border-radius: 6px;
}
.user-menu-btn:hover {
    color: #8b5cf6;
    transform: rotate(90deg);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 0;
    transition: margin-left .3s;
    height: 100vh;
    overflow-y: auto;
}

.sidebar.collapsed ~ .main-content,
.sidebar.collapsed + .main-content {
    margin-left: 72px;
}

/* Content Header */
.content-header {
    padding: 20px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg-dark);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-title h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

.header-title p {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.header-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid rgba(139,92,246,0.15);
    background: rgba(139,92,246,0.05);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    position: relative;
}

.header-btn:hover {
    background: rgba(139,92,246,0.12);
    color: #8b5cf6;
}

.notification-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ef4444;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.3rem;
    cursor: pointer;
}

/* Dashboard Content Area */
.dashboard-content {
    padding: 20px 28px;
    max-width: 1200px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    padding: 8px 16px;
    text-decoration: none;
    transition: all .2s;
}

.btn-primary {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    transition: transform .15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary:hover { transform: translateY(-1px); }

.btn-block { display: block; width: 100%; text-align: center; }

.btn-outline {
    background: transparent;
    border: 1px solid rgba(139,92,246,0.3);
    color: #8b5cf6;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    transition: all .2s;
}

.btn-outline:hover {
    background: rgba(139,92,246,0.1);
    border-color: #8b5cf6;
}

.btn-lg { padding: 12px 24px; font-size: 0.95rem; }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }

/* ===== USER DROPDOWN ===== */
.user-dropdown {
    display: none;
    position: fixed;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid rgba(139,92,246,0.15);
    border-radius: 12px;
    padding: 6px;
    min-width: 190px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
    transform-origin: bottom left;
    animation: dropdownIn .2s ease;
}

@keyframes dropdownIn {
    from { opacity: 0; transform: scale(0.95) translateY(4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.user-dropdown.show,
.user-dropdown.active { display: block; }

.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.82rem;
    transition: all .15s;
}

.user-dropdown a:hover {
    background: rgba(139,92,246,0.1);
    color: var(--text-primary);
    transform: translateX(2px);
}

.user-dropdown a i {
    font-size: 1rem;
    opacity: 0.7;
    transition: opacity .15s;
}
.user-dropdown a:hover i { opacity: 1; }

.user-dropdown hr {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.06);
    margin: 4px 0;
}

.user-dropdown a#logoutBtn:hover {
    background: rgba(239,68,68,0.1);
    color: #f87171;
}

/* ===== GAME TABS (progress/history) ===== */
.game-tabs-container {
    margin-bottom: 20px;
}

.game-tabs {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: var(--bg-card);
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.05);
    overflow-x: auto;
}

.game-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    font-family: inherit;
}

.game-tab img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
}

.game-tab span {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.game-tab:hover {
    background: rgba(139,92,246,0.08);
    border-color: rgba(139,92,246,0.15);
}

.game-tab:hover span { color: var(--text-primary); }

.game-tab.active {
    background: rgba(139,92,246,0.12);
    border-color: rgba(139,92,246,0.3);
}

.game-tab.active span { color: #8b5cf6; }

.premium-badge {
    font-size: 0.6rem;
    padding: 2px 7px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-radius: 20px;
    color: white;
    font-weight: 700;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.82rem;
    color: #fff;
    animation: slideIn .3s;
}

.toast.info { background: rgba(99,102,241,0.9); }
.toast.error { background: rgba(239,68,68,0.9); }
.toast.success { background: rgba(34,197,94,0.9); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== MODAL OVERLAY ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

/* ===== SHARED CARD PATTERN ===== */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-header h3 i { color: #8b5cf6; }

.card-link {
    font-size: 0.78rem;
    color: #8b5cf6;
    text-decoration: none;
}

.card-link:hover { text-decoration: underline; }

.card-badge {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(139,92,246,0.12);
    color: #8b5cf6;
    font-weight: 600;
}

/* ===== STATS ROW ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-icon.purple { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.stat-icon.cyan { background: rgba(6,182,212,0.12); color: #06b6d4; }
.stat-icon.green { background: rgba(34,197,94,0.12); color: #22c55e; }
.stat-icon.orange { background: rgba(249,115,22,0.12); color: #f97316; }

.stat-value {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-primary);
    display: block;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.stat-trend {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 0.75rem;
    font-weight: 600;
}

.stat-trend.up { color: #22c55e; }
.stat-trend.down { color: #ef4444; }
.stat-trend.neutral { color: var(--text-muted); }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2rem;
    display: block;
    margin-bottom: 8px;
    opacity: 0.4;
}

.empty-state p { font-size: 0.8rem; }

/* ===== LOADING SPINNER ===== */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(139,92,246,0.5); }

/* ===== GLOBAL POLISHING ===== */
/* Smooth page transitions */
.dashboard-content, .settings-content, .videos-page, .history-page, .training-page {
    animation: fadeInUp .4s ease;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Unified card hover improvements */
.h-card, .vid-card, .settings-card, .sum-item, .stat-card, .tr-card {
    transition: border-color .25s ease, box-shadow .25s ease, transform .2s ease;
}
.h-card:hover, .vid-card:hover, .stat-card:hover, .tr-card:hover {
    border-color: rgba(139,92,246,.18);
    box-shadow: 0 4px 20px rgba(0,0,0,.2), 0 0 30px rgba(139,92,246,.04);
    transform: translateY(-2px);
}

/* Better nav hover */
.nav-item {
    transition: all .2s ease;
}
.nav-item:hover {
    transform: translateX(3px);
}
.nav-item.active {
    transform: translateX(3px);
    position: relative;
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    border-radius: 0 3px 3px 0;
    background: linear-gradient(180deg, #8b5cf6, #6366f1);
}

/* Game pill press effect */
.game-pill:active, .game-tab:active {
    transform: scale(0.96);
}

/* Button press effect */
.btn:active {
    transform: scale(0.97);
}

/* Badge/tag hover */
.hist-tag:hover, .video-tag:hover, .w-tag:hover {
    filter: brightness(1.2);
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid rgba(139,92,246,.6);
    outline-offset: 2px;
}

/* Selection color */
::selection {
    background: rgba(139,92,246,.3);
    color: #fff;
}

/* Smooth images */
img {
    image-rendering: auto;
}

/* ── Staggered Stat Cards ── */
.stats-row .stat-card:nth-child(1) { animation: fadeInUp .4s ease .05s both; }
.stats-row .stat-card:nth-child(2) { animation: fadeInUp .4s ease .1s both; }
.stats-row .stat-card:nth-child(3) { animation: fadeInUp .4s ease .15s both; }
.stats-row .stat-card:nth-child(4) { animation: fadeInUp .4s ease .2s both; }

/* ── Stat Icon Bounce on Hover ── */
.stat-card:hover .stat-icon {
    animation: iconBounce .5s ease;
}
@keyframes iconBounce {
    0%, 100% { transform: scale(1); }
    40% { transform: scale(1.2) rotate(-5deg); }
    70% { transform: scale(0.95) rotate(2deg); }
}

/* ── Stat Value Count-up Glow ── */
.stat-card:hover .stat-value {
    text-shadow: 0 0 20px rgba(139,92,246,0.3);
}

/* ── Better Header Backdrop ── */
.content-header {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(3,0,20,0.85) !important;
}

/* ── Sidebar Logo Animation ── */
.logo-icon {
    transition: transform .3s ease, box-shadow .3s ease;
}
.logo:hover .logo-icon {
    transform: rotate(-8deg) scale(1.08);
    box-shadow: 0 0 16px rgba(139,92,246,0.4);
}

/* ── Nav Section Labels ── */
.nav-label {
    position: relative;
    overflow: hidden;
}
.nav-label::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 12px;
    right: 12px;
    height: 1px;
    background: linear-gradient(90deg, rgba(139,92,246,0.15), transparent);
}

/* ── Upgrade Card Shimmer ── */
.upgrade-card {
    transition: border-color .3s, transform .2s, box-shadow .3s;
}
.upgrade-card:hover {
    box-shadow: 0 4px 20px rgba(139,92,246,0.12);
}

/* ── Header Title Icon ── */
.header-title h1 i {
    transition: transform .3s ease;
}
.header-title h1:hover i {
    transform: rotate(-10deg) scale(1.1);
}

/* ── Sidebar Transition Polish ── */
.sidebar {
    transition: width .3s cubic-bezier(.4,0,.2,1), transform .3s cubic-bezier(.4,0,.2,1);
}

/* ── Card Section Reveal ── */
.dashboard-content > * {
    opacity: 0;
    animation: sectionReveal .5s ease forwards;
}
.dashboard-content > *:nth-child(1) { animation-delay: .05s; }
.dashboard-content > *:nth-child(2) { animation-delay: .1s; }
.dashboard-content > *:nth-child(3) { animation-delay: .15s; }
.dashboard-content > *:nth-child(4) { animation-delay: .2s; }
.dashboard-content > *:nth-child(5) { animation-delay: .25s; }
.dashboard-content > *:nth-child(6) { animation-delay: .3s; }
@keyframes sectionReveal {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Link Card Hover Glow ── */
.link-card {
    transition: all .25s ease;
}
.link-card:hover {
    box-shadow: 0 4px 20px rgba(139,92,246,.1);
    transform: translateY(-2px);
}
.link-card:hover i {
    transform: scale(1.15) rotate(-5deg);
    transition: transform .3s ease;
}

/* ── Game Tab Switching Animation ── */
.game-tab {
    transition: all .25s cubic-bezier(.4,0,.2,1);
}
.game-tab.active {
    box-shadow: 0 0 15px rgba(139,92,246,0.1);
}

/* ── Toast Slide & Glow ── */
.toast {
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.toast.success {
    box-shadow: 0 8px 30px rgba(34,197,94,0.15);
}
.toast.error {
    box-shadow: 0 8px 30px rgba(239,68,68,0.15);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
    }

    .sidebar.mobile-open,
    .sidebar.open {
        transform: translateX(0);
    }

    .main-content { margin-left: 0 !important; }
    .mobile-menu-btn { display: block; }
    .stats-row { grid-template-columns: 1fr 1fr; }

    .game-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .game-tab span:not(.premium-badge) {
        display: none;
    }

    .dashboard-content {
        padding: 16px;
    }

    .content-header {
        padding: 16px;
    }
}
