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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f7f7f8;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.logo-icon {
    font-size: 2rem;
}

.logo h1 {
    color: #667eea;
    font-size: 1.8rem;
    font-weight: 700;
}

.nav {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.nav-link {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: #666;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.nav-link:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.nav-link.active {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.btn {
    padding: 0.5rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.btn-outline {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-outline:hover {
    background: #667eea;
    color: white;
}

.btn-ghost {
    background: transparent;
    color: #666;
    border: 2px solid rgba(0, 0, 0, 0.05);
    padding: 0.6rem 0.9rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-ghost:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

/* Chat Container Layout */
.chat-container {
    display: flex;
    height: calc(100vh - 70px);
    background: #f7f7f8;
    overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
    width: 260px;
    background: #202123;
    color: #ececf1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .btn-primary {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ececf1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
}

.sidebar-header .btn-primary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
    font-size: 14px;
    color: #ececf1;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.history-item.active {
    background: rgba(255, 255, 255, 0.15);
}

.history-icon {
    font-size: 16px;
}

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

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer .btn-ghost {
    width: 100%;
    justify-content: flex-start;
    color: #ececf1;
    border-color: rgba(255, 255, 255, 0.1);
}

.sidebar-footer .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
}

.api-config-btn {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: #ececf1;
    transition: background 0.2s;
}

.api-config-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    position: relative;
}

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

/* Welcome Message */
.welcome-message {
    max-width: 768px;
    margin: 0 auto;
    text-align: center;
    padding: 48px 24px;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 24px;
}

.welcome-message h2 {
    font-size: 32px;
    margin-bottom: 16px;
    color: #202123;
}

.welcome-message p {
    font-size: 16px;
    color: #6e6e80;
    margin-bottom: 16px;
    line-height: 1.6;
}

.welcome-message ul {
    text-align: left;
    display: inline-block;
    margin: 16px 0;
    color: #6e6e80;
}

.welcome-message li {
    margin: 8px 0;
    font-size: 15px;
}

.suggestions-title {
    margin-top: 32px !important;
    font-weight: 600;
    color: #202123 !important;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

.suggestion-chip {
    padding: 10px 16px;
    background: #f7f7f8;
    border: 1px solid #e5e5e6;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    color: #202123;
    transition: all 0.2s;
}

.suggestion-chip:hover {
    background: #ececf1;
    border-color: #d1d1d6;
}

/* Message Bubbles */
.message-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    gap: 16px;
    padding: 16px;
    border-radius: 8px;
}

.message.user {
    background: transparent;
    justify-content: flex-end;
}

.message.assistant {
    background: #f7f7f8;
}

.message-content {
    flex: 1;
    max-width: 85%;
}

.message.user .message-content {
    text-align: right;
}

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    order: 2;
}

.message.assistant .message-avatar {
    background: #19c37d;
    color: white;
}

.message.user .message-avatar {
    background: #ab68ff;
    color: white;
}

.message-text {
    line-height: 1.6;
    color: #202123;
    font-size: 15px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-text {
    color: #202123;
}

.message.assistant .message-text {
    color: #374151;
}

.message-text code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

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

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

.message-time {
    font-size: 12px;
    color: #8e8ea0;
    margin-top: 4px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px;
    background: #f7f7f8;
    border-radius: 8px;
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8e8ea0;
    animation: typing 1.4s infinite;
}

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

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Container */
.chat-input-container {
    padding: 24px;
    background: #ffffff;
    border-top: 1px solid #e5e5e6;
}

.input-wrapper {
    max-width: 768px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #ffffff;
    border: 1px solid #d1d1d6;
    border-radius: 24px;
    padding: 12px 16px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: #10a37f;
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 15px;
    line-height: 1.5;
    color: #202123;
    background: transparent;
    max-height: 200px;
    overflow-y: auto;
    font-family: inherit;
}

.chat-input::placeholder {
    color: #8e8ea0;
}

.send-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6e6e80;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: rgba(16, 163, 127, 0.1);
    color: #10a37f;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-footer {
    max-width: 768px;
    margin: 8px auto 0;
    text-align: center;
}

.input-hint {
    font-size: 12px;
    color: #8e8ea0;
}

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

.modal.show {
    display: flex;
}

.modal-content {
    background: #ffffff;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e5e6;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    color: #202123;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #8e8ea0;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #f7f7f8;
    color: #202123;
}

.modal-body {
    padding: 24px;
}

.modal-body p {
    color: #6e6e80;
    margin-bottom: 20px;
    line-height: 1.6;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #202123;
    font-weight: 600;
    font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d1d6;
    border-radius: 6px;
    font-size: 14px;
    color: #202123;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #10a37f;
}

.form-group small {
    display: block;
    margin-top: 6px;
    color: #8e8ea0;
    font-size: 12px;
}

.form-group input[type="checkbox"] {
    margin-right: 8px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Dark Theme Support */
.theme-dark .chat-container {
    background: #0f172a;
}

.theme-dark .chat-main {
    background: #0f172a;
}

.theme-dark .chat-messages {
    background: #0f172a;
}

.theme-dark .welcome-message h2 {
    color: #e2e8f0;
}

.theme-dark .welcome-message p,
.theme-dark .welcome-message li {
    color: #94a3b8;
}

.theme-dark .suggestions-title {
    color: #e2e8f0 !important;
}

.theme-dark .suggestion-chip {
    background: #1f2937;
    border-color: #374151;
    color: #e2e8f0;
}

.theme-dark .suggestion-chip:hover {
    background: #374151;
    border-color: #4b5563;
}

.theme-dark .message.assistant {
    background: #1f2937;
}

.theme-dark .message.user {
    background: transparent;
}

.theme-dark .message-text {
    color: #e2e8f0;
}

.theme-dark .message.user .message-text {
    color: #e2e8f0;
}

.theme-dark .message.assistant .message-text {
    color: #cbd5e1;
}

.theme-dark .message-text code {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

.theme-dark .message-text pre {
    background: rgba(0, 0, 0, 0.2);
}

.theme-dark .message-text pre code {
    background: none;
    color: #e2e8f0;
}

.theme-dark .typing-indicator {
    background: #1f2937;
}

.theme-dark .typing-indicator span {
    background: #64748b;
}

.theme-dark .chat-input-container {
    background: #0f172a;
    border-top-color: #1f2937;
}

.theme-dark .input-wrapper {
    background: #1f2937;
    border-color: #374151;
}

.theme-dark .input-wrapper:focus-within {
    border-color: #10a37f;
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.2);
}

.theme-dark .chat-input {
    color: #e2e8f0;
}

.theme-dark .chat-input::placeholder {
    color: #64748b;
}

.theme-dark .send-btn {
    color: #94a3b8;
}

.theme-dark .send-btn:hover:not(:disabled) {
    background: rgba(16, 163, 127, 0.15);
    color: #10a37f;
}

.theme-dark .input-hint {
    color: #64748b;
}

.theme-dark .message-time {
    color: #64748b;
}

.theme-dark .chat-sidebar {
    background: #111827;
    border-right-color: #1f2937;
}

.theme-dark .sidebar-header {
    border-bottom-color: #1f2937;
}

.theme-dark .sidebar-header .btn-primary {
    color: #e2e8f0;
    border-color: #374151;
}

.theme-dark .sidebar-header .btn-primary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #4b5563;
}

.theme-dark .history-item {
    color: #cbd5e1;
}

.theme-dark .history-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.theme-dark .history-item.active {
    background: rgba(165, 180, 252, 0.12);
    color: #a5b4fc;
}

.theme-dark .sidebar-footer {
    border-top-color: #1f2937;
}

.theme-dark .sidebar-footer .btn-ghost {
    color: #cbd5e1;
    border-color: #374151;
}

.theme-dark .sidebar-footer .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #a5b4fc;
}

.theme-dark .api-config-btn {
    color: #cbd5e1;
}

.theme-dark .api-config-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.theme-dark .modal {
    background: rgba(0, 0, 0, 0.7);
}

.theme-dark .modal-content {
    background: #1f2937;
    color: #e2e8f0;
    border: 1px solid #374151;
}

.theme-dark .modal-header {
    border-bottom-color: #374151;
}

.theme-dark .modal-header h3 {
    color: #e2e8f0;
}

.theme-dark .modal-close {
    color: #94a3b8;
}

.theme-dark .modal-close:hover {
    background: #374151;
    color: #e2e8f0;
}

.theme-dark .modal-body {
    color: #cbd5e1;
}

.theme-dark .form-group label {
    color: #e2e8f0;
}

.theme-dark .form-group input[type="text"],
.theme-dark .form-group input[type="password"] {
    background: #0f172a;
    border-color: #374151;
    color: #e2e8f0;
}

.theme-dark .form-group input[type="text"]:focus,
.theme-dark .form-group input[type="password"]:focus {
    border-color: #10a37f;
    outline: none;
}

.theme-dark .form-group input[type="text"]::placeholder,
.theme-dark .form-group input[type="password"]::placeholder {
    color: #64748b;
}

.theme-dark .form-group input[type="checkbox"] {
    accent-color: #10a37f;
}

.theme-dark .form-group small {
    color: #94a3b8;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        left: -260px;
        top: 70px;
        height: calc(100vh - 70px);
        z-index: 100;
        transition: left 0.3s;
    }

    .chat-sidebar.open {
        left: 0;
    }

    .chat-main {
        width: 100%;
    }

    .chat-messages {
        padding: 16px;
    }

    .welcome-message {
        padding: 24px 16px;
    }

    .welcome-message h2 {
        font-size: 24px;
    }

    .chat-input-container {
        padding: 16px;
    }
}

