/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background-color: #212121;
    color: #ececec;
    height: 100vh;
    overflow: hidden;
}

/* Container layout */
.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: #171717;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #2d2d2d;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid #2d2d2d;
}

.new-chat-btn {
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid #2d2d2d;
    color: #ececec;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
}

.new-chat-btn:hover {
    background-color: #2d2d2d;
}

/* Conversations list */
.conversations-list {
    flex: 1;
    padding: 0 12px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #2d2d2d #171717;
}

.conversations-list::-webkit-scrollbar {
    width: 4px;
}

.conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: #2d2d2d;
    border-radius: 2px;
}

.conversation-item {
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.15s ease;
    font-size: 14px;
    color: #ececec;
    position: relative;
    overflow: hidden;
}

.conversation-item:hover {
    background-color: #2d2d2d;
}

.conversation-item.active {
    background-color: #2d2d2d;
}

.conversation-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.delete-btn {
    opacity: 0;
    background: transparent;
    border: none;
    color: #ececec;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
    font-size: 12px;
}

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

.delete-btn:hover {
    background-color: #dc3545;
    color: white;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid #2d2d2d;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-btn, .export-btn, .import-btn {
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: #ececec;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    transition: all 0.15s ease;
}

.settings-btn:hover, .export-btn:hover, .import-btn:hover {
    background-color: #2d2d2d;
}

/* Main chat area */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #212121;
    position: relative;
}

/* Mobile menu toggle */
.mobile-menu-toggle {
    display: none;
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 50;
    background: transparent;
    border: none;
    color: #ececec;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.mobile-menu-toggle:hover {
    background-color: #2d2d2d;
}

/* Messages container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: #2d2d2d #212121;
}

.messages-container::-webkit-scrollbar {
    width: 4px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #2d2d2d;
    border-radius: 2px;
}

/* Welcome screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 32px;
}

.welcome-content {
    text-align: center;
    max-width: 600px;
}

.welcome-content h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    color: #ececec;
}

.welcome-content p {
    font-size: 18px;
    color: #9b9b9b;
    font-weight: 400;
}

/* Messages */
.message {
    margin: 0;
    border-bottom: 1px solid #2d2d2d;
    animation: messageAppear 0.3s ease-out;
}

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

.message-content-wrapper {
    max-width: 768px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    gap: 16px;
    position: relative;
}

/* User messages */
.message.user .message-content-wrapper {
    justify-content: flex-end;
}

.message.user .message-text {
    background: #2d2d2d;
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 70%;
    color: #ececec;
    font-size: 16px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Assistant messages */
.message.assistant .message-content-wrapper {
    align-items: flex-start;
}

.message.assistant .message-avatar {
    width: 32px;
    height: 32px;
    background: #19c37d;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
}

.message.assistant .message-text {
    flex: 1;
    color: #ececec;
    font-size: 16px;
    line-height: 1.7;
    padding: 0;
    background: transparent;
}

/* Message text styling */
.message-text h1, .message-text h2, .message-text h3 {
    margin: 16px 0 8px 0;
    color: #ececec;
    font-weight: 600;
}

.message-text h1 { font-size: 24px; }
.message-text h2 { font-size: 20px; }
.message-text h3 { font-size: 18px; }

.message-text p {
    margin: 12px 0;
}

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

.message-text li {
    margin: 6px 0;
}

.message-text blockquote {
    border-left: 3px solid #19c37d;
    margin: 16px 0;
    padding-left: 16px;
    color: #b3b3b3;
    font-style: italic;
}

.message-text code {
    background-color: #1e1e1e;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: ui-monospace, 'Monaco', 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 14px;
    color: #e96900;
}

.message-text pre {
    background-color: #1e1e1e;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    overflow-x: auto;
    border: 1px solid #2d2d2d;
}

.message-text pre code {
    background: none;
    padding: 0;
    color: #ececec;
}

/* Search results */
.search-results {
    margin: 12px 0;
    padding: 12px;
    background: #2d2d2d;
    border-radius: 8px;
    border: 1px solid #404040;
}

.search-results-header {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #19c37d;
}

.search-source-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.search-source-card {
    background: #1e1e1e;
    border: 1px solid #404040;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    color: #b3b3b3;
    text-decoration: none;
    transition: all 0.15s ease;
    cursor: pointer;
}

.search-source-card:hover {
    background: #404040;
    color: #ececec;
}

.search-source-title {
    font-weight: 500;
    margin-bottom: 2px;
}

.search-source-domain {
    opacity: 0.7;
}

/* Typing indicator */
.typing-indicator {
    max-width: 768px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    animation: messageAppear 0.3s ease-out;
}

.typing-avatar {
    width: 32px;
    height: 32px;
    background: #19c37d;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background-color: #9b9b9b;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Input section */
.input-section {
    padding: 0 24px 24px;
}

.input-container {
    max-width: 768px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 24px;
    padding: 12px;
    gap: 8px;
    transition: border-color 0.15s ease;
}

.input-wrapper:focus-within {
    border-color: #19c37d;
    box-shadow: 0 0 0 2px rgba(25, 195, 125, 0.1);
}

.search-toggle {
    background: transparent;
    border: none;
    color: #9b9b9b;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.search-toggle:hover {
    color: #ececec;
    background: #404040;
}

.search-toggle.active {
    color: #19c37d;
    background: rgba(25, 195, 125, 0.1);
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: #ececec;
    font-size: 16px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 24px;
    overflow-y: auto;
    font-family: inherit;
}

#messageInput::placeholder {
    color: #9b9b9b;
}

.send-button {
    background: #ececec;
    border: none;
    color: #212121;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: #d4d4d4;
    transform: scale(1.05);
}

.send-button:disabled {
    background: #6b6b6b;
    color: #9b9b9b;
    cursor: not-allowed;
    transform: none;
}

.send-button.stop {
    background: #dc3545;
    color: white;
}

.send-button.stop:hover {
    background: #c82333;
}

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

.modal-content {
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin: 0 0 20px;
    color: #ececec;
    font-size: 20px;
    font-weight: 600;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-group label {
    display: block;
    margin-bottom: 6px;
    color: #b3b3b3;
    font-size: 14px;
    font-weight: 500;
}

.setting-group input,
.setting-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: #1e1e1e;
    border: 1px solid #404040;
    border-radius: 8px;
    color: #ececec;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s ease;
}

.setting-group input:focus,
.setting-group textarea:focus {
    outline: none;
    border-color: #19c37d;
}

.setting-group textarea {
    resize: vertical;
    min-height: 80px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.save-btn, .cancel-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.save-btn {
    background: #19c37d;
    color: white;
}

.save-btn:hover {
    background: #17b377;
}

.cancel-btn {
    background: #404040;
    color: #ececec;
}

.cancel-btn:hover {
    background: #4a4a4a;
}

/* Loading states */
.searching-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #9b9b9b;
    font-size: 14px;
    margin: 12px 0;
}

.searching-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #404040;
    border-top: 2px solid #19c37d;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 200;
        transform: translateX(-100%);
    }

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

    .mobile-menu-toggle {
        display: flex;
    }

    .main {
        width: 100%;
    }

    .message-content-wrapper {
        padding: 16px;
    }

    .message.user .message-text {
        max-width: 85%;
    }

    .input-section {
        padding: 0 16px 16px;
    }

    .welcome-content h1 {
        font-size: 24px;
    }

    .welcome-content p {
        font-size: 16px;
    }
}

/* Dark scrollbar for webkit browsers */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #2d2d2d;
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: #404040;
}

/* Firefox scrollbar */
html {
    scrollbar-width: thin;
    scrollbar-color: #2d2d2d #212121;
}