
/* --- THEME VARIABLES --- */
:root {
    /* --- Light Theme Defaults --- */
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.5);
    
    /* Backgrounds */
    --bg-body: #f8fafc;
    --bg-sidebar: rgba(255, 255, 255, 0.85);
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-input: rgba(255, 255, 255, 0.5);
    
    /* Borders & Text */
    --border: #e2e8f0;
    --border-highlight: transparent;
    --text-main: #0f172a;
    --text-muted: #64748b;
    
    /* Effects */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --glass-blur: blur(12px);
    
    /* Streak Colors */
    --streak-fire: #f59e0b;
    --streak-green: #10b981;
    
    /* Heatmap */
    --heat-low: #dbeafe;
    --heat-med: #93c5fd;
    --heat-high: #3b82f6;
    --heat-max: #1e40af;
}

/* --- Dark Theme Overrides --- */
[data-theme="dark"] {
    --primary: #818cf8;
    --primary-glow: rgba(129, 140, 248, 0.4);
    
    --bg-body: linear-gradient(135deg, #020617 0%, #0f172a 50%, #172554 100%);
    
    --bg-sidebar: rgba(15, 23, 42, 0.6);
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-hover: rgba(51, 65, 85, 0.8);
    --bg-input: rgba(15, 23, 42, 0.6);
    
    --border: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --glass-blur: blur(20px); 

    --heat-low: rgba(255,255,255,0.05);
    --heat-med: #1e3a8a;
    --heat-high: #3b82f6;
    --heat-max: #60a5fa;
}

/* --- RESET & BASE --- */
* {
    margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    transition: background 0.4s ease, color 0.2s ease, border-color 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
}

body {
    height: 100vh;
    display: flex;
    background: var(--bg-body);
    background-size: 200% 200%;
    color: var(--text-main);
    overflow: hidden;
}

[data-theme="dark"] body { animation: gradientShift 20s ease infinite; }
@keyframes gradientShift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }

/* --- SIDEBAR --- */
.sidebar {
    width: 270px; background: var(--bg-sidebar); backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--border); padding: 24px 16px;
    display: flex; flex-direction: column; z-index: 20; flex-shrink: 0; overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.logo-container { display: flex; align-items: center; gap: 12px; padding: 0 12px 20px; }
.logo-icon {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 15px var(--primary-glow); overflow: hidden;
}
.logo-img { width: 100%; height: 100%; object-fit: cover; }
.logo-text { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text-main); }
.sidebar-divider { height: 1px; background: var(--border); margin: 8px 8px 20px; }
.section-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.05em; margin: 20px 12px 10px; }

/* MENU ITEMS */
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px;
    color: var(--text-muted); text-decoration: none; font-size: 0.95rem; font-weight: 500;
    margin-bottom: 4px; cursor: pointer; position: relative; overflow: hidden; z-index: 1;
}
.nav-item::before {
    content: ''; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
    background: var(--bg-hover); z-index: -1; border-radius: 12px;
    transform: scaleX(0); transform-origin: left; transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-item.active::before { transform: scaleX(1); background: var(--bg-hover); opacity: 0.5; }
.nav-item:hover { color: var(--text-main); transform: translateX(6px); }
.nav-item:hover::before { transform: scaleX(1); }
.nav-item i { width: 24px; text-align: center; transition: transform 0.3s; }
.nav-item:hover i { transform: scale(1.15) rotate(5deg); color: var(--primary); }

/* --- MAIN LAYOUT --- */
.main-layout { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }

/* HEADER */
.top-bar {
    height: 72px; padding: 0 32px; display: flex; align-items: center; justify-content: space-between;
    background: var(--bg-sidebar); backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border); z-index: 10;
}
.search-wrapper { position: relative; width: 400px; }
.search-input {
    width: 100%; padding: 11px 16px 11px 44px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text-main); font-size: 0.9rem;
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); background: var(--bg-card); }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 16px; }
.action-btn {
    width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--bg-card); color: var(--text-muted); display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s;
}
.action-btn:hover { background: var(--bg-hover); color: var(--text-main); border-color: var(--primary); transform: translateY(-2px); }
.profile-avatar {
    width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #d946ef);
    display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; cursor: pointer;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}
.mobile-menu-btn { display: none; margin-right: 15px; background: transparent; border: none; font-size: 1.4rem; color: var(--text-muted); cursor: pointer; }

/* --- DASHBOARD GRID --- */
.dashboard-content {
    flex: 1; padding: 32px; padding-bottom: 120px; overflow-y: auto;
    display: grid; grid-template-areas: "header header" "left right";
    grid-template-columns: 2fr 1fr; grid-template-rows: auto 1fr; gap: 28px;
}
.dashboard-card {
    background: var(--bg-card); border: 1px solid var(--border); border-top: 1px solid var(--border-highlight);
    border-radius: 24px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; position: relative; overflow: hidden; height: 100%;
    transition: transform 0.3s, border-color 0.3s;
}
.dashboard-card:hover { border-color: var(--primary); transform: translateY(-2px); }

.area-header { grid-area: header; min-height: 200px; }
.area-left { grid-area: left; min-height: 300px; }
.area-right { grid-area: right; min-height: 300px; }

/* --- REALISTIC 3D GYROSCOPE --- */
.streak-inner { padding: 30px; display: flex; align-items: center; justify-content: space-between; height: 100%; position: relative; z-index: 2; }
.streak-info { max-width: 50%; }
.streak-info h2 { font-size: 2rem; font-weight: 700; margin-bottom: 8px; background: linear-gradient(to right, var(--text-main), var(--primary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.streak-info p { color: var(--text-muted); font-size: 1rem; line-height: 1.5; }

/* Physics Container */
.gyro-container {
    width: 140px; height: 140px; position: relative;
    perspective: 800px; /* 3D Depth */
    transform-style: preserve-3d;
    animation: gyro-float 8s ease-in-out infinite;
}

.gyro-ring {
    position: absolute; top: 50%; left: 50%;
    border-radius: 50%; transform-style: preserve-3d;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.1);
}

/* Outer Ring */
.ring-1 {
    width: 100%; height: 100%;
    border: 3px solid var(--streak-fire);
    border-left-color: transparent; border-right-color: transparent;
    animation: spin-3d-1 12s linear infinite;
}

/* Middle Ring */
.ring-2 {
    width: 75%; height: 75%;
    border: 3px solid var(--primary);
    border-top-color: transparent; border-bottom-color: transparent;
    animation: spin-3d-2 9s linear infinite reverse;
}

/* Inner Ring */
.ring-3 {
    width: 50%; height: 50%;
    border: 3px solid var(--streak-green);
    border-left-color: transparent;
    animation: spin-3d-3 6s linear infinite;
}

/* Core */
.gyro-core {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 16px; height: 16px; background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 25px var(--primary), 0 0 50px var(--primary);
    animation: core-pulse 3s ease-in-out infinite;
}

/* Proper 3D Physics Keyframes */
@keyframes spin-3d-1 {
    0% { transform: translate(-50%, -50%) rotateX(0deg) rotateY(15deg); }
    100% { transform: translate(-50%, -50%) rotateX(360deg) rotateY(15deg); }
}
@keyframes spin-3d-2 {
    0% { transform: translate(-50%, -50%) rotateY(0deg) rotateZ(30deg); }
    100% { transform: translate(-50%, -50%) rotateY(360deg) rotateZ(30deg); }
}
@keyframes spin-3d-3 {
    0% { transform: translate(-50%, -50%) rotateX(90deg) rotateZ(0deg); }
    100% { transform: translate(-50%, -50%) rotateX(90deg) rotateZ(360deg); }
}
@keyframes gyro-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}
@keyframes core-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.3); opacity: 0.8; }
}

/* Stats */
.streak-stats { text-align: right; }
.stat-number { font-size: 3rem; font-weight: 800; color: var(--text-main); display: block; line-height: 1; }
.stat-label { font-size: 0.85rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }

/* --- ACTIVITY CARD --- */
.recent-inner { padding: 24px; display: flex; flex-direction: column; gap: 20px; height: 100%; }
.section-title { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.activity-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.activity-card {
    background: var(--bg-hover); border: 1px solid var(--border);
    padding: 18px; border-radius: 16px; cursor: pointer;
    display: flex; flex-direction: column; justify-content: space-between; height: 150px;
    transition: all 0.3s;
}
.activity-card:hover { transform: translateY(-5px); border-color: var(--primary); background: var(--bg-card); box-shadow: 0 10px 20px -5px rgba(0,0,0,0.1); }
.card-icon { width: 48px; height: 48px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; margin-bottom: 10px; }
.icon-pdf { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.icon-chat { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }

/* --- TOOLS CARD --- */
.tools-inner { padding: 24px; display: flex; flex-direction: column; height: 100%; justify-content: space-between; }
.tool-list { display: flex; flex-direction: column; gap: 10px; }
.tool-item { padding: 14px 16px; background: var(--bg-hover); border-radius: 12px; display: flex; align-items: center; gap: 14px; color: var(--text-muted); font-weight: 600; cursor: pointer; border: 1px solid transparent; }
.tool-item:hover { background: var(--bg-card); border-color: var(--border); color: var(--primary); transform: translateX(5px); }
.heatmap-container { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 20px; }
.heatmap-grid { display: flex; gap: 6px; height: 40px; align-items: flex-end; }
.heat-bar { flex: 1; border-radius: 4px 4px 0 0; min-height: 4px; transition: height 0.4s ease; }

/* --- PROFESSIONAL ENTRY GATEWAY --- */
.gateway-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.95); /* Deep dark background */
    backdrop-filter: blur(20px);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.6s ease;
}
.gateway-overlay.active { opacity: 1; pointer-events: auto; }

.gateway-card {
    width: 480px; padding: 50px; text-align: center;
    background: rgba(30, 41, 59, 0.6); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 32px; box-shadow: 0 0 100px rgba(59, 130, 246, 0.2);
    transform: translateY(30px); transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.gateway-overlay.active .gateway-card { transform: translateY(0); }

.gateway-icon {
    width: 90px; height: 90px; margin: 0 auto 30px;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    border-radius: 24px; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 30px var(--primary-glow);
}
.gateway-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 24px; }

.gateway-title { font-size: 2.2rem; font-weight: 800; color: #fff; margin-bottom: 12px; letter-spacing: -0.02em; }
.gateway-text { color: #94a3b8; font-size: 1.05rem; line-height: 1.6; margin-bottom: 40px; }

.gateway-btn {
    background: #fff; color: #0f172a; border: none;
    padding: 16px 40px; border-radius: 50px; font-size: 1rem; font-weight: 700;
    cursor: pointer; transition: all 0.3s;
    box-shadow: 0 10px 20px rgba(255, 255, 255, 0.1);
    display: flex; align-items: center; justify-content: center; margin: 0 auto;
}
.gateway-btn:hover { transform: scale(1.05); box-shadow: 0 0 30px rgba(255, 255, 255, 0.4); }
.gateway-btn i { margin-left: 10px; }
.btn-loading i { animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- AI WIDGET --- */
.ai-widget { position: absolute; bottom: 30px; right: 30px; z-index: 999; }
.ai-minimized { background: var(--bg-card); backdrop-filter: blur(16px); border: 1px solid var(--border); border-radius: 50px; padding: 12px 24px; box-shadow: var(--shadow); color: var(--text-main); font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 10px; transition: transform 0.3s; }
.ai-minimized:hover { transform: translateY(-3px) scale(1.02); }
.widget-status { width: 8px; height: 8px; background: #10b981; border-radius: 50%; box-shadow: 0 0 10px #10b981; }
.chat-interface { position: absolute; bottom: 0; right: 0; width: 380px; height: 550px; background: var(--bg-card); backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; overflow: hidden; opacity: 0; pointer-events: none; transform: translateY(20px) scale(0.95); transition: all 0.4s; }
.ai-widget.expanded .chat-interface { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }
.ai-widget.expanded .ai-minimized { opacity: 0; pointer-events: none; display: none; }
.chat-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; background: rgba(255, 255, 255, 0.05); }
.ai-profile { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.ai-avatar-small { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #10b981, #059669); display: flex; align-items: center; justify-content: center; color: white; }
.close-chat { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.chat-body { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.msg { padding: 12px 16px; font-size: 0.9rem; line-height: 1.5; max-width: 85%; border-radius: 12px; white-space: pre-wrap; /* Preserves formatting */ }
.msg-user { align-self: flex-end; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white; border-radius: 18px 18px 0 18px; }
.msg-ai { align-self: flex-start; background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-main); border-radius: 18px 18px 18px 0; }
.chat-footer { padding: 16px; }
.chat-input-container { background: var(--bg-card); border: 1px solid var(--border); border-radius: 50px; padding: 6px 6px 6px 16px; display: flex; align-items: center; }
.chat-input { flex: 1; border: none; background: transparent; outline: none; color: var(--text-main); }
.send-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: white; border: none; cursor: pointer; }
.typing-indicator { display: flex; gap: 4px; padding: 12px 16px; align-self: flex-start; background: var(--bg-hover); border-radius: 18px; border: 1px solid var(--border); width: fit-content; }
.dot { width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

/* Mobile */
@media (max-width: 1024px) {
    .dashboard-content { grid-template-areas: "header" "left" "right"; grid-template-columns: 1fr; }
    .sidebar { position: fixed; transform: translateX(-100%); transition: transform 0.3s; z-index: 50; height: 100%; box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu-btn { display: block; }
    .chat-interface { width: 90vw; bottom: 80px; right: 5vw; height: 60vh; }
    .gateway-card { width: 90%; padding: 30px; }
}

/* --- Responsive fixes (small screens) --- */
@media (max-width: 600px) {
    .top-bar { padding: 0 16px; gap: 10px; }
    .search-wrapper { width: auto; flex: 1; min-width: 0; }
    .header-actions { gap: 8px; flex-shrink: 0; }
    .action-btn { width: 38px; height: 38px; }
    .mobile-menu-btn { margin-right: 4px; }
}
