:root {
    --primary: #6366f1;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --accent: #10b981;
    --bg-base: #f8fafc;
    --bg-sidebar: rgba(255, 255, 255, 0.45);
    --bg-surface: rgba(255, 255, 255, 0.75);
    --bg-glass: rgba(255, 255, 255, 0.55);
    --text-main: #0f172a;
    --text-sub: #475569;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.5);
    --border-heavy: rgba(255, 255, 255, 0.7);
    --shadow-soft: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --shadow-hard: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    --glass-blur: blur(20px);
    --glass-border: 1px solid rgba(255, 255, 255, 0.25);
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --radius-full: 9999px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-elastic: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

        /* --- Keyframes --- */
        @keyframes float {
            0% {
                transform: translateY(0px);
            }

            50% {
                transform: translateY(-10px);
            }

            100% {
                transform: translateY(0px);
            }
        }

        @keyframes fadeInScale {
            from {
                opacity: 0;
                transform: scale(0.95);
            }

            to {
                opacity: 1;
                transform: scale(1);
            }
        }

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.skeleton {
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0) 0%, 
        rgba(255, 255, 255, 0.4) 50%, 
        rgba(255, 255, 255, 0) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 4px;
    height: 1em;
    width: 100%;
    display: block;
    margin-bottom: 0.5rem;
}

.dark-theme .skeleton {
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0) 0%, 
        rgba(255, 255, 255, 0.05) 50%, 
        rgba(255, 255, 255, 0) 100%);
    background-size: 200% 100%;
}

@keyframes pulse-soft {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.85; transform: scale(0.99); }
}

.thinking-state {
    animation: pulse-soft 2s infinite ease-in-out;
}

        @keyframes slideInRight {
            from {
                transform: translateX(30px);
                opacity: 0;
            }

            to {
                transform: translateX(0);
                opacity: 1;
            }
        }

        @keyframes slideInLeft {
            from {
                transform: translateX(-30px);
                opacity: 0;
            }

            to {
                transform: translateX(0);
                opacity: 1;
            }
        }

        @keyframes glow {
            0% {
                box-shadow: 0 0 5px rgba(139, 92, 246, 0.2);
            }

            50% {
                box-shadow: 0 0 25px rgba(139, 92, 246, 0.5);
            }

            100% {
                box-shadow: 0 0 5px rgba(139, 92, 246, 0.2);
            }
        }

        @keyframes springIn {
            0% {
                transform: scale(0.8) translateY(20px);
                opacity: 0;
            }

            60% {
                transform: scale(1.05) translateY(-5px);
            }

            100% {
                transform: scale(1) translateY(0);
                opacity: 1;
            }
        }

        @keyframes slideUp {
            from {
                transform: translateY(20px);
                opacity: 0;
            }

            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        body.dark-theme {
            --bg-base: #1e293b;
            --bg-sidebar: rgba(15, 23, 42, 0.4);
            --bg-surface: rgba(30, 41, 59, 0.7);
            --bg-glass: rgba(30, 41, 59, 0.6);
            --text-main: #f8fafc;
            --text-sub: #cbd5e1;
            --text-muted: #94a3b8;
            --border: rgba(255, 255, 255, 0.1);
            --border-heavy: rgba(255, 255, 255, 0.15);
            --shadow-soft: 0 10px 40px 0 rgba(0, 0, 0, 0.5);
            --shadow-hard: 0 12px 48px 0 rgba(0, 0, 0, 0.7);
            --glass-border: 1px solid rgba(255, 255, 255, 0.12);
        }

        @keyframes spin {
            from {
                transform: rotate(0deg);
            }

            to {
                transform: rotate(360deg);
            }
        }

        .spinning {
            animation: spin 1.5s linear infinite;
        }

        .mic-active {
            color: #ef4444 !important;
            animation: pulse 1.5s infinite;
        }

        .memory-tag {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: var(--border);
            padding: 4px 10px;
            border-radius: 8px;
            font-size: 0.85rem;
            margin: 4px;
        }

        .memory-tag span:last-child {
            cursor: pointer;
            opacity: 0.6;
            transition: opacity 0.2s;
        }

        .memory-tag span:last-child:hover {
            opacity: 1;
            color: #ef4444;
        }

        .citation-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 18px;
            height: 18px;
            background: var(--primary);
            color: white;
            border-radius: 4px;
            font-size: 0.65rem;
            font-weight: 800;
            margin: 0 2px;
            vertical-align: super;
            cursor: pointer;
            transition: var(--transition);
        }

        .citation-btn:hover {
            transform: scale(1.2);
            box-shadow: 0 0 10px var(--primary);
        }

        .bottom-options-menu {
            position: absolute;
            bottom: calc(100% + 15px);
            left: 0;
            background: var(--bg-glass);
            backdrop-filter: var(--glass-blur);
            -webkit-backdrop-filter: var(--glass-blur);
            border: var(--glass-border);
            border-radius: var(--radius-lg);
            padding: 1rem;
            display: none;
            flex-direction: column;
            gap: 10px;
            min-width: 260px;
            box-shadow: var(--shadow-hard);
            z-index: 2000;
            animation: springIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }

        .edit-textarea {
            width: 100%;
            background: rgba(0, 0, 0, 0.1);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-main);
            padding: 8px;
            font-family: inherit;
            font-size: 0.95rem;
            resize: none;
            margin-top: 5px;
        }

        .dark-theme .edit-textarea {
            background: rgba(255, 255, 255, 0.05);
        }

        .message-row.user .edit-msg-btn:hover {
            color: var(--primary);
            opacity: 1 !important;
        }

        .btn-secondary {
            background: var(--bg-base);
            border: 1px solid var(--border);
            color: var(--text-muted);
            padding: 8px 16px;
            border-radius: 12px;
            cursor: pointer;
            transition: var(--transition);
        }

        .btn-secondary:hover {
            background: var(--border);
            color: var(--text-main);
        }

        .option-toggle {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 8px;
            border-radius: 8px;
            transition: var(--transition);
            cursor: pointer;
        }

        .option-toggle:hover {
            background: var(--bg-base);
        }

        .option-toggle.active {
            color: var(--primary);
        }

        @keyframes drift {
            0% {
                background-position: 0% 50%;
            }

            50% {
                background-position: 100% 50%;
            }

            100% {
                background-position: 0% 50%;
            }
        }

        @keyframes orbFloat {
            0% {
                transform: translate(0, 0) scale(1);
            }

            33% {
                transform: translate(15vw, 15vh) scale(1.1);
            }

            66% {
                transform: translate(-5vw, 25vh) scale(0.9);
            }

            100% {
                transform: translate(0, 0) scale(1);
            }
        }

        @keyframes orbFloatReverse {
            0% {
                transform: translate(0, 0) scale(1);
            }

            50% {
                transform: translate(-20vw, -15vh) scale(1.2);
            }

            100% {
                transform: translate(0, 0) scale(1);
            }
        }

        /* --- Global Reset & Basics --- */
        *,
        *::before,
        *::after {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            -webkit-tap-highlight-color: transparent;
        }

        body {
            font-family: 'Inter', sans-serif;
            background-color: var(--bg-base);
            color: var(--text-main);
            height: 100vh;
            height: 100dvh;
            overflow: hidden;
            display: flex;
            transition: var(--transition);
        }

        /* Ambient Orbs */
        body::before,
        body::after {
            content: "";
            position: absolute;
            width: 700px;
            height: 700px;
            border-radius: 50%;
            filter: blur(100px);
            opacity: 0.12;
            z-index: -1;
            pointer-events: none;
            transition: opacity 0.5s ease;
        }

        body::before {
            background: var(--primary);
            top: -250px;
            left: -250px;
            animation: orbFloat 35s ease-in-out infinite;
        }

        body::after {
            background: var(--accent);
            bottom: -250px;
            right: -250px;
            animation: orbFloatReverse 40s ease-in-out infinite;
        }

        .dark-theme::before {
            opacity: 0.15;
            filter: blur(120px);
        }

        .dark-theme::after {
            opacity: 0.12;
            filter: blur(120px);
        }

        h1,
        h2,
        h3,
        h4 {
            font-family: 'Outfit', sans-serif;
            font-weight: 700;
        }

        button {
            font-family: inherit;
            cursor: pointer;
            border: none;
            background: none;
            transition: var(--transition-elastic);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        button:active {
            transform: scale(0.92);
        }

        /* --- Root Layout --- */
        #appContainer {
            display: flex;
            width: 100%;
            height: 100vh;
            position: relative;
            overflow: hidden;
            background: transparent;
        }

        /* --- Sidebar Redesign --- */
        .sidebar {
            position: relative;
            width: 300px;
            background: var(--bg-sidebar);
            backdrop-filter: var(--glass-blur);
            -webkit-backdrop-filter: var(--glass-blur);
            border-right: var(--glass-border);
            display: flex;
            flex-direction: column;
            transition: var(--transition);
            z-index: 2000;
            overflow: hidden;
        }

        .sidebar::before {
            content: "";
            position: absolute;
            inset: 0;
            background-image: var(--noise);
            opacity: 0.03;
            pointer-events: none;
            z-index: 0;
        }

        .sidebar-content {
            position: relative;
            z-index: 1;
            display: flex;
            flex-direction: column;
            height: 100%;
            padding-top: env(safe-area-inset-top);
        }

        body.sidebar-closed .sidebar {
            margin-left: -300px;
        }

        .sidebar-backdrop {
            display: none;
        }

        @media (max-width: 768px) {
            .sidebar-backdrop {
                position: fixed;
                inset: 0;
                background: rgba(0, 0, 0, 0.4);
                backdrop-filter: blur(4px);
                z-index: 1001;
                /* Lower than mobile sidebar */
                display: block;
                opacity: 1;
                transition: opacity 0.4s ease, visibility 0.4s;
                visibility: visible;
            }

            body.sidebar-closed .sidebar-backdrop {
                opacity: 0;
                visibility: hidden;
                pointer-events: none;
            }
        }

        .sidebar-header {
            padding: 1.25rem 1.5rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: var(--glass-border);
            margin-bottom: 0.5rem;
        }

        .brand {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            font-size: 1.5rem;
            color: var(--primary);
            font-weight: 800;
            letter-spacing: -0.05em;
            filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3));
        }

        .brand span:last-child {
            background: var(--primary-gradient);
            background-clip: text;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Outfit', sans-serif;
        }

        .new-chat-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 12px;
            margin: 0.75rem 1rem;
            padding: 1rem;
            background: linear-gradient(135deg, var(--primary), #8b5cf6);
            color: #fff;
            border-radius: 16px;
            font-weight: 700;
            font-size: 0.95rem;
            box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
            border: 1px solid rgba(255, 255, 255, 0.1);
            transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
            position: sticky;
            top: 0;
            overflow: hidden;
            cursor: pointer;
            z-index: 100;
            backdrop-filter: blur(10px);
        }

        .new-chat-btn::after {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
            opacity: 0;
            transition: opacity 0.3s;
            pointer-events: none;
        }

        .new-chat-btn:hover {
            transform: translateY(-2px) scale(1.02);
            box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5);
            filter: brightness(1.1);
        }

        .new-chat-btn:hover::after {
            opacity: 1;
        }

        .new-chat-btn:active {
            transform: translateY(1px) scale(0.98);
        }

        .new-chat-btn .material-symbols-outlined {
            font-size: 22px;
            font-variation-settings: 'FILL' 1;
        }

        /* Sidebar Header and Button polish */
        .chat-list-scroll {
            flex: 1;
            overflow-y: auto;
            padding: 0 1rem;
        }

        ::-webkit-scrollbar {
            width: 6px;
        }

        ::-webkit-scrollbar-track {
            background: transparent;
        }

        ::-webkit-scrollbar-thumb {
            background: var(--border-heavy);
            border-radius: 10px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: var(--text-muted);
        }

        .chat-item {
            padding: 0.875rem 1rem;
            border-radius: var(--radius-md);
            margin-bottom: 0.5rem;
            display: flex;
            align-items: center;
            gap: 0.75rem;
            color: var(--text-sub);
            transition: var(--transition);
            animation: slideInLeft 0.5s ease-out backwards;
        }

        .chat-item:nth-child(n) {
            animation-delay: calc(0.05s * n);
        }

        .chat-item:hover {
            background: var(--border);
            color: var(--text-main);
        }

        .chat-item.active {
            background: rgba(99, 102, 241, 0.15);
            backdrop-filter: blur(4px);
            border: 1px solid rgba(99, 102, 241, 0.2);
            color: var(--primary);
            font-weight: 600;
        }

        .chat-item .title {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .sidebar-footer {
            padding: 1.25rem;
            border-top: var(--glass-border);
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        /* --- Main Content Area --- */
        .main-wrapper {
            width: 100%;
            height: 100vh;
            height: 100dvh;
            display: flex;
            flex-direction: column;
            min-width: 0;
            position: relative;
            background: var(--bg-base);
        }

        .top-nav {
            padding: calc(0.75rem + env(safe-area-inset-top)) 1.5rem 0.75rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: var(--bg-glass);
            backdrop-filter: var(--glass-blur);
            -webkit-backdrop-filter: var(--glass-blur);
            border-bottom: var(--glass-border);
            z-index: 900;
            margin: 1rem;
            margin-top: calc(1rem + env(safe-area-inset-top));
            border-radius: var(--radius-lg);
            box-shadow: var(--shadow-soft);
        }

        .nav-actions {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .icon-btn {
            width: 40px;
            height: 40px;
            border-radius: var(--radius-md);
            color: var(--text-sub);
            transition: var(--transition-elastic);
        }

        .icon-btn:hover {
            background: var(--border);
            color: var(--text-main);
            transform: scale(1.1);
        }

        .icon-btn:active {
            transform: scale(0.9);
        }

        .icon-btn.active {
            color: var(--primary);
            background: rgba(99, 102, 241, 0.1);
        }

        /* --- Chat Messages Space --- */
        .chat-scroller {
            flex: 1;
            overflow-y: auto;
            padding: 2rem 5% 2rem;
            display: flex;
            flex-direction: column;
            gap: 2rem;
        }

        .message-row {
            display: flex;
            width: 100%;
            animation: slideUp 0.4s ease-out backwards;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(10px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .message-row.user {
            justify-content: flex-end;
        }

        .message-row.ai {
            justify-content: flex-start;
        }

        /* Sidebar Tabs */
        .sidebar-tabs {
            display: flex;
            padding: 0.5rem;
            gap: 0.5rem;
            border-bottom: 1px solid var(--border);
        }

        .tab-btn {
            flex: 1;
            padding: 0.5rem;
            border-radius: var(--radius-md);
            border: none;
            background: transparent;
            color: var(--text-sub);
            font-size: 0.8rem;
            font-weight: 600;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 5px;
            transition: var(--transition);
        }

        .tab-btn.active {
            background: rgba(var(--primary-rgb), 0.1);
            color: var(--primary);
        }

        .file-item {
            padding: 0.75rem 1rem;
            border-radius: var(--radius-md);
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 10px;
            transition: var(--transition);
            font-size: 0.85rem;
            color: var(--text-sub);
        }

        .file-item:hover {
            background: var(--bg-surface);
            color: var(--text-main);
        }

        .memory-editor-item {
            display: flex;
            align-items: center;
            gap: 10px;
            background: var(--bg-base);
            padding: 8px 12px;
            border-radius: var(--radius-md);
            margin-bottom: 8px;
            border: 1px solid var(--border);
        }

        .memory-editor-item input {
            flex: 1;
            background: transparent;
            border: none;
            color: var(--text-main);
            outline: none;
            font-size: 0.85rem;
        }

        .message-bubble {
            max-width: 85%;
            padding: 1.25rem 1.5rem;
            border-radius: var(--radius-md);
            line-height: 1.6;
            font-size: 1rem;
            position: relative;
        }

        .user .message-bubble {
            background: var(--primary-gradient);
            color: white;
            box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.2);
            border-bottom-right-radius: 4px;
        }

        .ai .message-bubble {
            background: var(--bg-surface);
            backdrop-filter: var(--glass-blur);
            -webkit-backdrop-filter: var(--glass-blur);
            color: var(--text-main);
            box-shadow: var(--shadow-soft);
            border-bottom-left-radius: 4px;
            border: var(--glass-border);
        }

        .bubble-meta {
            font-size: 0.7rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 0.5rem;
            opacity: 0.8;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .source-pill {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            background: rgba(16, 185, 129, 0.1);
            color: var(--accent);
            padding: 4px 10px;
            border-radius: 20px;
            font-size: 0.75rem;
            margin: 4px 4px 0 0;
            border: 1px solid rgba(16, 185, 129, 0.1);
        }

        .input-dock {
            align-self: center;
            margin-bottom: 30px;
            flex-shrink: 0;
            width: calc(100% - 2rem);
            max-width: 800px;
            z-index: 100;
        }

        .input-card {
            background: var(--bg-glass);
            backdrop-filter: var(--glass-blur);
            -webkit-backdrop-filter: var(--glass-blur);
            border: var(--glass-border);
            border-radius: 24px;
            padding: 16px 20px 12px;
            box-shadow: var(--shadow-hard);
            transition: var(--transition);
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .input-card:focus-within {
            border-color: rgba(99, 102, 241, 0.5);
            box-shadow: 0 8px 40px -10px rgba(99, 102, 241, 0.4);
            background: var(--bg-surface);
        }

        #userInput {
            width: 100%;
            border: none;
            background: transparent;
            color: var(--text-main);
            font-size: 1.15rem;
            max-height: 240px;
            resize: none;
            outline: none;
            line-height: 1.6;
            padding: 4px 0;
            font-weight: 400;
        }

        #userInput::placeholder {
            color: var(--text-muted);
            opacity: 0.8;
        }

        .input-actions-bar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;
        }

        .action-group {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .btn-tool {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 6px 12px;
            border-radius: 12px;
            color: var(--text-sub);
            font-size: 0.9rem;
            font-weight: 500;
            transition: var(--transition);
            cursor: pointer;
            background: transparent;
        }

        .btn-tool:hover {
            background: var(--border);
            color: var(--text-main);
        }

        .btn-tool .material-symbols-outlined {
            font-size: 20px;
        }

        .send-btn-modern {
            width: 42px;
            height: 42px;
            background: var(--primary);
            color: white;
            border-radius: 14px;
            transition: var(--transition-elastic);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .send-btn-modern:disabled {
            background: var(--border);
            opacity: 0.6;
            cursor: not-allowed;
            transform: scale(0.95);
        }

        .send-btn-modern:not(:disabled):hover {
            transform: scale(1.05);
            box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
        }

        /* --- Welcome Screen --- */
        .welcome-hero {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            text-align: center;
            padding: 2rem;
        }

        .welcome-hero h1 {
            font-size: 4rem;
            margin-bottom: 1rem;
            background: var(--primary-gradient);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Outfit', sans-serif;
            font-weight: 800;
            filter: drop-shadow(0 10px 20px rgba(99, 102, 241, 0.2));
            letter-spacing: -0.04em;
        }

        .suggested-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 1.5rem;
            max-width: 900px;
            width: 100%;
            margin-top: 3rem;
        }

        .suggested-card {
            padding: 1.5rem;
            background: var(--bg-glass);
            backdrop-filter: var(--glass-blur);
            -webkit-backdrop-filter: var(--glass-blur);
            border: var(--glass-border);
            border-radius: var(--radius-md);
            transition: var(--transition-elastic);
            text-align: left;
            cursor: pointer;
            box-shadow: var(--shadow-soft);
            animation: fadeInScale 0.6s ease-out backwards;
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }

        .suggested-card:hover {
            transform: translateY(-8px) scale(1.03);
            border-color: var(--primary);
            box-shadow: var(--shadow-hard);
            background: var(--bg-surface);
        }

        /* --- Canvas Panel Enhanced --- */
        .preview-panel {
            width: 0;
            height: 100%;
            background: var(--bg-glass);
            backdrop-filter: blur(25px);
            -webkit-backdrop-filter: blur(25px);
            border-left: var(--glass-border);
            transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
            display: flex;
            flex-direction: column;
            overflow: hidden;
            z-index: 1100;
            box-shadow: -20px 0 50px rgba(0, 0, 0, 0.1);
        }

        body.preview-open .preview-panel {
            width: 55%;
        }

        @media (max-width: 1024px) {
            body.preview-open .preview-panel {
                width: 70%;
            }
        }

        @media (max-width: 768px) {
            body.preview-open .preview-panel {
                width: 100%;
                z-index: 3000;
            }
        }

        .preview-header {
            padding: 0.6rem 1rem;
            background: #0b1222;
            border-bottom: 1px solid rgba(255, 255, 255, 0.08);
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: white;
            z-index: 100;
        }

        .header-left, .header-right {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .canvas-title {
            font-size: 0.85rem;
            font-weight: 500;
            color: #f1f5f9;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 180px;
        }

        .header-btn {
            background: transparent;
            color: #94a3b8;
            padding: 6px;
            border-radius: 6px;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .header-btn i, .header-btn .material-symbols-outlined {
            font-size: 18px !important;
        }

        .header-btn:hover {
            color: white;
            background: rgba(255, 255, 255, 0.08);
        }

        .canvas-tabs {
            display: flex;
            background: #1e293b;
            padding: 2px;
            border-radius: 8px;
            gap: 0;
            margin: 0 0.5rem;
        }

        .canvas-tab-btn {
            padding: 4px 14px;
            border-radius: 6px;
            font-size: 0.8rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
            color: #94a3b8;
        }

        .canvas-tab-btn.active {
            background: #2563eb;
            color: white;
            box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
        }

        .share-btn {
            background: #2563eb;
            color: white;
            padding: 5px 14px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 0.8rem;
            font-weight: 600;
            transition: var(--transition);
        }

        .share-btn:hover {
            background: #1d4ed8;
            box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
            transform: translateY(-1px);
        }

        .preview-content-container {
            flex: 1;
            position: relative;
            overflow: hidden;
            background: #0f172a;
        }

        .dark-theme .preview-content-container {
            background: #0f172a;
        }

        #canvasCodeView {
            position: absolute;
            inset: 0;
            padding: 0;
            overflow: auto;
            display: none;
            background: #0d1117;
            color: #c9d1d9;
            animation: fadeIn 0.3s ease;
        }

        .code-with-lines {
            display: flex;
            min-height: 100%;
        }

        .line-numbers {
            padding: 2rem 1rem;
            background: rgba(255, 255, 255, 0.03);
            color: #484f58;
            text-align: right;
            user-select: none;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.85rem;
            line-height: 1.7;
            border-right: 1px solid rgba(255, 255, 255, 0.05);
            min-width: 3.5rem;
        }

        #codeDisplay {
            flex: 1;
            padding: 2rem;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.95rem;
            line-height: 1.7;
            tab-size: 4;
            margin: 0;
            overflow: visible;
        }

        #canvasFrame {
            width: 100%;
            height: 100%;
            border: none;
            display: block;
            background: transparent;
            animation: fadeIn 0.3s ease;
        }

        /* --- Mobile Navigation --- */
        .mobile-nav {
            display: none;
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 70px;
            background: var(--bg-glass);
            backdrop-filter: var(--glass-blur);
            border-top: 1px solid var(--border);
            padding: 0 2rem;
            justify-content: space-between;
            align-items: center;
            z-index: 1000;
        }

        @media (max-width: 768px) {
            .sidebar {
                position: fixed;
                height: 100vh;
                height: 100dvh;
                top: 0;
                left: 0;
                width: 300px;
                margin-left: 0 !important;
                transform: translateX(0);
                z-index: 2005;
            }

            body.sidebar-closed .sidebar {
                transform: translateX(-100%);
            }

            .mobile-nav {
                display: flex;
                position: fixed;
                bottom: calc(1rem + env(safe-area-inset-bottom));
                left: 1rem;
                right: 1rem;
                height: 70px;
                padding-bottom: env(safe-area-inset-bottom);
                background: var(--bg-glass);
                backdrop-filter: var(--glass-blur);
                -webkit-backdrop-filter: var(--glass-blur);
                border: var(--glass-border);
                border-radius: var(--radius-lg);
                align-items: center;
                justify-content: space-around;
                z-index: 1000;
                box-shadow: var(--shadow-hard);
            }

            .chat-scroller {
                padding-bottom: 1rem;
            }

            .input-dock {
                width: calc(100% - 2rem);
                margin-bottom: calc(100px + env(safe-area-inset-bottom));
            }

            .welcome-hero h1 {
                font-size: 2.5rem;
            }

            .message-bubble {
                max-width: 92%;
            }
        }

        /* --- Code & Formatting --- */
        pre {
            background: #1a1b26;
            padding: 1.25rem;
            border-radius: 12px;
            margin: 1.5rem 0;
            overflow-x: auto;
            position: relative;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        code {
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.85rem;
        }

        .copy-code-btn {
            position: absolute;
            top: 10px;
            right: 10px;
            padding: 6px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            color: #94a3b8;
            cursor: pointer;
            transition: var(--transition);
        }

        .copy-code-btn:hover {
            background: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .typing-indicator {
            display: inline-flex;
            gap: 4px;
        }

        .dot {
            width: 6px;
            height: 6px;
            background: var(--text-muted);
            border-radius: 50%;
            animation: pulse 1s infinite;
        }

        .dot:nth-child(2) {
            animation-delay: 0.2s;
        }

        .dot:nth-child(3) {
            animation-delay: 0.4s;
        }

        .top-chat-title {
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            font-family: 'Outfit', sans-serif;
            font-weight: 700;
            font-size: 1rem;
            color: var(--text-main);
            letter-spacing: -0.02em;
            max-width: 40%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            pointer-events: none;
            animation: fadeIn 0.4s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translate(-50%, -5px);
            }

            to {
                opacity: 1;
                transform: translate(-50%, 0);
            }
        }

        @keyframes pulse {
            0% {
                opacity: 0.3;
            }

            50% {
                opacity: 1;
            }

            100% {
                opacity: 0.3;
            }
        }

        /* --- Modals --- */
        .modal-container {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(4px);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 2000;
            padding: 1rem;
        }

        .modal-card {
            background: var(--bg-glass);
            backdrop-filter: var(--glass-blur);
            -webkit-backdrop-filter: var(--glass-blur);
            border: var(--glass-border);
            border-radius: var(--radius-xl);
            width: 100%;
            max-width: 500px;
            padding: 2.5rem;
            box-shadow: var(--shadow-hard);
            animation: modalIn 0.3s ease;
        }

        @keyframes modalIn {
            from {
                transform: scale(0.95);
                opacity: 0;
            }

            to {
                transform: scale(1);
                opacity: 1;
            }
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-group label {
            display: block;
            font-size: 0.875rem;
            font-weight: 600;
            margin-bottom: 0.5rem;
            color: var(--text-sub);
        }

        .form-group input,
        .form-group textarea {
            width: 100%;
            background: var(--bg-base);
            border: 1px solid var(--border);
            border-radius: var(--radius-md);
            padding: 0.75rem 1rem;
            color: var(--text-main);
            outline: none;
            transition: var(--transition);
        }

        .form-group input:focus {
            border-color: var(--primary);
            background: var(--bg-surface);
        }

/* --- Reasoning Display --- */
.reasoning-block {
    margin-top: 10px;
    margin-bottom: 10px;
    background: rgba(0, 0, 0, 0.05);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    overflow: hidden;
}

.dark-theme .reasoning-block {
    background: rgba(255, 255, 255, 0.05);
}

.reasoning-header {
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    transition: background 0.2s;
}

.reasoning-header:hover {
    background: rgba(0, 0, 0, 0.05);
}

.dark-theme .reasoning-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.reasoning-content {
    padding: 0 12px 12px 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    white-space: pre-wrap;
    display: none;
}

.reasoning-block.expanded .reasoning-content {
    display: block;
}

.reasoning-block.expanded .reasoning-header .material-symbols-outlined {
    transform: rotate(90deg);
}

.reasoning-header .material-symbols-outlined {
    font-size: 16px;
    transition: transform 0.2s;
}
