:root {
    --bg-color: #0f172a;
    --chat-bg: rgba(30, 41, 59, 0.7);
    --sidebar-bg: rgba(15, 23, 42, 0.8);
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --secondary-gradient: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --user-msg-bg: #3b82f6;
    --bot-msg-bg: rgba(51, 65, 85, 0.8);
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
}

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

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

body.generating-response {
    cursor: progress;
}

/* Background Animations */
.background-globes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.globe {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
    animation: float 20s infinite ease-in-out;
}

.globe-1 {
    width: 400px;
    height: 400px;
    background: var(--primary-gradient);
    top: -100px;
    left: -100px;
}

.globe-2 {
    width: 300px;
    height: 300px;
    background: var(--secondary-gradient);
    bottom: -50px;
    right: -50px;
    animation-delay: -10s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(30px, 50px);
    }
}

/* App Container Layout */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 260px;
    height: 100%;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    border-right: var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-logo {
    display: flex;
    justify-content: center;
    padding-bottom: 8px;
}

.sidebar-logo img {
    height: 48px;
    width: auto;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.3));
}

.search-container {
    position: relative;
    width: 100%;
}

#chatSearch {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: var(--glass-border);
    border-radius: 8px;
    padding: 10px 12px 10px 36px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s ease;
}

#chatSearch:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(99, 102, 241, 0.5);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    opacity: 0.6;
}

.new-chat-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: var(--glass-border);
    border-radius: 8px;
    padding: 12px;
    text-align: left;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    margin-top: 10px;
}

.conversation-item {
    padding: 12px 16px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-item span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-chat-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.2s;
    margin-left: 8px;
}

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

.delete-chat-btn:hover {
    color: #ef4444;
}

.conversation-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.conversation-item.active {
    background: rgba(99, 102, 241, 0.2);
    color: white;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.generating-indicator {
    display: flex;
    gap: 3px;
    padding: 0 4px;
}

.generating-indicator span {
    width: 4px;
    height: 4px;
    background: #6366f1;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.generating-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.generating-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

/* Main Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(10px);
    height: 100%;
    width: 100%;
}

/* Header */
.chat-header {
    padding: 16px 24px;
    padding-top: calc(16px + env(safe-area-inset-top));
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: var(--glass-border);
    background: rgba(15, 23, 42, 0.6);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-btn {
    display: none;
    /* Hidden on desktop */
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 1.5rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.status-indicator {
    width: 10px;
    height: 10px;
    background-color: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 10px #22c55e;
    cursor: pointer;
    transition: all 0.3s ease;
}

.status-indicator.offline {
    background-color: #64748b;
    box-shadow: 0 0 5px #64748b;
    opacity: 0.5;
}

.status-indicator.locked {
    cursor: not-allowed;
    opacity: 0.8;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-new-chat-btn {
    display: none;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    max-width: 800px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    flex-shrink: 0;
}

.bot-message .avatar {
    background: var(--primary-gradient);
    color: white;
}

.user-message .avatar {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
}

.message-content {
    background: var(--bot-msg-bg);
    padding: 12px 16px;
    border-radius: 16px;
    border-top-left-radius: 4px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
    border: var(--glass-border);
}

.bot-message[data-streaming="true"] .message-content {
    display: flex;
    flex-direction: column;
}

.bot-message[data-streaming="true"] .message-content .markdown-wrapper {
    display: inline;
}

.bot-message[data-streaming="true"] .message-content .cursor {
    align-self: flex-start;
    margin-top: 4px;
}

.user-message .message-content {
    background: var(--user-msg-bg);
    border-radius: 16px;
    border-top-right-radius: 4px;
    border: none;
}

/* Typing Indicator */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 6px;
}

.typing-dots.inline {
    display: inline-flex;
    padding: 0;
    margin-left: 4px;
    vertical-align: middle;
}

.dot {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.5);
    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;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Input Area */
.chat-input-area {
    padding: 20px 24px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(10px);
    border-top: var(--glass-border);
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    position: relative;
}

input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 14px 16px;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s ease;
    outline: none;
}

input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

button[type="submit"] {
    background: var(--primary-gradient);
    border: none;
    border-radius: 12px;
    width: 54px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s ease;
    color: white;
    flex-shrink: 0;
}

button[type="submit"]:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Stop Button */
.stop-btn {
    background: #ef4444;
    border: none;
    border-radius: 12px;
    width: 54px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    flex-shrink: 0;
}

.stop-btn:hover {
    background: #dc2626;
    transform: translateY(-2px);
}

.stop-btn:active {
    transform: translateY(0);
}

/* Mobile Responsive */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 10px 0 20px rgba(0, 0, 0, 0.3);
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    .menu-btn {
        display: block;
    }

    .chat-container {
        border: none;
        border-radius: 0;
        height: 100%;
    }

    .mobile-new-chat-btn {
        display: flex;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        max-width: none;
        /* Fit the corners */
    }

    input {
        padding: 12px 14px;
    }

    button[type="submit"] {
        width: 48px;
        height: 48px;
    }
}

/* Streaming Cursor */
.cursor {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #ae57ff;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
    box-shadow: 0 0 15px #e382fc;
    animation: blink 0.5s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Markdown Styles */
.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    color: var(--text-primary);
    font-size: 0.9em;
}

.message-content th,
.message-content td {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-align: left;
}

.message-content th {
    background: rgba(255, 255, 255, 0.1);
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    color: #e2e8f0;
}

.message-content p {
    margin-bottom: 8px;
}

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

.message-content ul,
.message-content ol {
    margin: 8px 0 8px 24px;
    padding-left: 0;
}

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

.message-content li::marker {
    color: rgba(255, 255, 255, 0.7);
}