:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --chat-bg: #0f172a;
    --message-user-bg: #3b82f6;
    --message-model-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --primary: #3b82f6;
    --input-bg: #334155;
    background-clip: padding-box;
    /* Compatibility fix */
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100dvh;
    /* Use dvh for mobile viewport height */
    overflow: hidden;
}

/* Auth Layout */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    /* Allow scrolling on small screens */
    padding: 1rem;
    /* Add padding for mobile */
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    overflow-y: auto;
    /* Enable vertical scroll if needed */
}

.auth-card {
    background: var(--sidebar-bg);
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    text-align: center;
    margin: auto;
    /* Center in flex container */
}

.auth-card h1 {
    margin-bottom: 2rem;
    color: var(--primary);
}

.auth-card .input-group {
    margin-bottom: 1rem;
    position: relative;
}

.auth-card input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: white;
}

.auth-card i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.auth-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-weight: 600;
    margin-top: 1rem;
}

.auth-link {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.auth-link a {
    color: var(--primary);
    text-decoration: none;
}

.alert {
    background: #fee2e2;
    color: #991b1b;
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Chat Layout */
.chat-layout {
    display: flex;
    height: 100dvh;
    /* Dynamic height for mobile browsers */
    overflow: hidden;
    /* Prevent body scroll */
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    padding: 1rem;
}

.new-chat-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--border);
    border: 1px solid var(--border);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
}

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

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.5rem;
}

.history-item {
    padding: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

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

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.footer-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
}

.footer-btn:hover {
    color: white;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
    height: 100%;
    /* Ensure it takes full height */
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
    /* Prevent header from shrinking */
}

.mobile-only {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* Smooth scrolling */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

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

.message .avatar {
    width: 32px;
    height: 32px;
    background: var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .avatar {
    background: var(--primary);
}

.message.model .avatar {
    background: #10b981;
}

.message .content {
    padding: 0.5rem 1rem;
    background: var(--message-model-bg);
    border-radius: 8px;
    line-height: 1.5;
    color: var(--text-main);
    max-width: 80%;
    word-wrap: break-word;
    /* Prevent overflow */
}

.message.user .content {
    background: var(--message-user-bg);
    color: white;
}

.download-action-btn {
    display: inline-block;
    margin-top: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-muted);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: none;
    transition: all 0.2s;
}

.download-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Message Actions */
.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.2rem;
    transition: color 0.2s;
}

.action-btn:hover {
    color: white;
}

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

/* Sidebar Item Actions */
.sidebar-item-actions {
    margin-left: auto;
    display: none;
}

.history-item:hover .sidebar-item-actions {
    display: block;
}

.delete-chat-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

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

.input-area {
    padding: 1rem;
    background: var(--chat-bg);
    /* Ensure solid background */
    flex-shrink: 0;
    /* Prevent input area from shrinking */
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    background: var(--input-bg);
    border-radius: 12px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    position: relative;
    border: 1px solid var(--border);
}

.input-wrapper textarea {
    background: none;
    border: none;
    color: white;
    resize: none;
    max-height: 200px;
    outline: none;
    padding: 0.5rem;
    font-family: inherit;
}

.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}

.input-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
}

.input-actions button:hover {
    color: var(--primary);
}

.file-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.file-tag {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.file-tag i.remove {
    cursor: pointer;
    color: #ef4444;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--sidebar-bg);
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
}

.modal-content .input-group input {
    width: 100%;
    padding: 0.5rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: white;
    margin-top: 0.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}

.secondary-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}

/* Markdown Styles in Chat */
.message .content p {
    margin-bottom: 0.5rem;
}

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

.message .content code {
    font-family: monospace;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}


/* Chat Options Menu */
.chat-options-container {
    margin-left: auto;
    position: relative;
    display: inline-block;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
}

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

.chat-options-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    padding: 0.5rem;
    min-width: 150px;
    z-index: 200;
}

.chat-options-menu.hidden {
    display: none;
}

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 0.5rem;
    color: var(--text-main);
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.menu-item.delete:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: -100%;
        height: 100%;
        width: 85%;
        /* Wider sidebar on mobile */
        max-width: 300px;
        z-index: 100;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 90;
        visibility: hidden;
        opacity: 0;
        transition: opacity 0.3s, visibility 0.3s;
        pointer-events: none;
        display: block;
        /* Ensure it's rendered for transition */
    }

    .mobile-overlay.visible {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-only {
        display: block;
    }

    /* Adjust padding for mobile chat */
    .messages-container {
        padding: 1rem;
    }

    .message {
        max-width: 100%;
        /* Use full width on mobile */
    }

    /* Better touch targets */
    .icon-btn,
    .auth-btn,
    .footer-btn,
    .new-chat-btn {
        min-height: 44px;
    }

    .input-area {
        padding: 0.5rem;
        /* Reduce padding to save space */
    }
}

/* Typing Indicator */
/* Typing Indicator */
.typing-indicator-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.2rem 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

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

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

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--sidebar-bg);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease-out forwards;
    min-width: 250px;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.info {
    border-left: 4px solid #3b82f6;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}