:root {
    --bg-base: #09090b;
    --glass-bg: rgba(18, 18, 20, 0.75);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --secondary: #6366f1;
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Ambient Glowing Background Orbs */
.ambient-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.25;
    animation: floatOrb 20s ease-in-out infinite alternate;
}

.orb-1 {
    width: 400px;
    height: 400px;
    background: #3b82f6;
    top: -100px;
    left: -100px;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: #8b5cf6;
    bottom: -150px;
    right: -150px;
    animation-delay: -5s;
}

.orb-3 {
    width: 300px;
    height: 300px;
    background: #06b6d4;
    top: 40%;
    left: 60%;
    animation-delay: -10s;
}

@keyframes floatOrb {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(40px, 60px) scale(1.1); }
    100% { transform: translate(-30px, -40px) scale(0.95); }
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

/* Login Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
}

.login-box {
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    border: 1px solid var(--glass-border);
    position: relative;
}

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

.login-box h1 {
    font-size: 2.5rem;
    margin-bottom: 6px;
    letter-spacing: -1px;
}

.login-box p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

.login-features {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
    text-align: left;
}

.feature-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
    color: var(--text-main);
}

.google-btn {
    width: 100%;
    background: #ffffff;
    color: #1f2937;
    border: none;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.google-btn:hover {
    background: #f3f4f6;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 280px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--glass-border);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
    background: var(--glass-bg);
}

.sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.sidebar.collapsed * {
    display: none !important;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h2 {
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online {
    background: #22c55e;
    box-shadow: 0 0 8px #22c55e;
}

.sidebar-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.sidebar-content h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 15px;
    letter-spacing: 1px;
}

.capability-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
    color: #e2e8f0;
    font-size: 0.95rem;
}

.capability-list li {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

/* Desktop Top Chat Header & Model Selector */
.chat-header {
    height: 56px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--glass-border);
    z-index: 10;
}

.model-select {
    background: rgba(24, 24, 27, 0.8);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 14px;
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}

.model-select:hover, .model-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}

/* Collapsible Desktop Sidebar */
/* Main Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.chat-history {
    flex: 1;
    min-height: 0;
    padding: 32px 40px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.message {
    max-width: 85%;
    line-height: 1.6;
    font-size: 1rem;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    padding: 16px 24px;
    border-radius: 20px 20px 4px 20px;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.bot-message {
    align-self: flex-start;
    padding: 16px 24px;
    border-radius: 20px 20px 20px 4px;
}

.glass-message {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
}

/* Tool Activity */
.tool-activity {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Input Area */
.input-container {
    margin: 16px 40px 24px 40px;
    padding: 8px 12px;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.input-wrapper {
    flex: 1;
}

/* Pending Attachment Chips */
.pending-attachments {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--glass-border);
    width: 100%;
}

.attachment-chip {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-main);
    animation: fadeIn 0.2s ease-out;
}

.chip-thumb {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    object-fit: cover;
}

.chip-remove {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
}

.chip-remove:hover {
    color: var(--danger);
}

.input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: 100%;
}

textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 16px !important; /* Prevents iOS forced auto-zoom */
    resize: none;
    padding: 12px;
    outline: none;
    max-height: 150px;
}

textarea::placeholder {
    color: var(--text-muted);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Markdown & Code Block Styling */
.message pre {
    background: #0d1117 !important;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
    position: relative;
}

.message code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
}

.message :not(pre) > code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.88rem;
}

.message p {
    margin-bottom: 12px;
}

.message p:last-child {
    margin-bottom: 0;
}

.message ul, .message ol {
    margin: 10px 0 10px 20px;
}

.message li {
    margin-bottom: 4px;
}

.message blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 12px;
    color: var(--text-muted);
    margin: 12px 0;
}

.message table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
}

.message th, .message td {
    border: 1px solid var(--glass-border);
    padding: 8px 12px;
    text-align: left;
}

.message th {
    background: rgba(255, 255, 255, 0.05);
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.copy-code-btn:hover {
    background: var(--primary);
    color: white;
}

/* Header Top & New Chat Button */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.new-chat-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
}

/* Threads List in Sidebar */
.threads-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
}

.thread-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.88rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.thread-item:hover, .thread-item.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.thread-item.active {
    border-left: 3px solid var(--primary);
}

.thread-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-thread-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.thread-item:hover .delete-thread-btn {
    opacity: 1;
}

.delete-thread-btn:hover {
    color: var(--danger);
}

.empty-threads {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-style: italic;
}

.section-divider {
    border-top: 1px solid var(--glass-border);
    padding-top: 15px;
    margin-top: 15px;
}

/* Chat Image Preview */
.chat-image-preview {
    max-width: 100%;
    max-height: 250px;
    border-radius: 12px;
    margin-top: 8px;
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-image-preview:hover {
    transform: scale(1.02);
}

/* Mobile Top Header & Overlay */
.mobile-header {
    display: none;
    height: 60px;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--glass-border);
    z-index: 100;
}

.mobile-logo {
    font-weight: 600;
    font-size: 1.2rem;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 400;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* Responsive Media Queries (< 768px) */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: 100dvh;
        width: 100vw;
        overflow: hidden;
    }

    .mobile-header {
        display: flex;
        height: 54px;
        padding: 0 12px;
    }

    .chat-area {
        height: calc(100dvh - 54px);
        width: 100%;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        z-index: 500;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        left: 0;
    }

    .chat-history {
        padding: 12px 10px !important;
        gap: 12px !important;
    }

    .message {
        max-width: 90% !important;
        font-size: 0.92rem !important;
        padding: 12px 16px !important;
    }

    .input-container {
        margin: 8px 10px 14px 10px !important;
        padding: 6px 10px !important;
        width: calc(100% - 20px) !important;
        border-radius: 20px !important;
    }

    .chat-header {
        display: none;
    }
}
