* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #10a37f;
    --primary-hover: #0d8f6e;
    --bg-color: #ffffff;
    --sidebar-bg: #202123;
    --chat-bg: #343541;
    --message-user-bg: #10a37f;
    --message-assistant-bg: #444654;
    --text-primary: #ececf1;
    --text-secondary: #8e8ea0;
    --border-color: #565869;
    --input-bg: #40414f;
    --modal-bg: rgba(0, 0, 0, 0.5);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.new-chat-btn {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: var(--input-bg);
}

.new-chat-btn span {
    font-size: 1.2rem;
}

.sidebar-actions {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
}

.action-btn:hover {
    background: var(--input-bg);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.chat-history h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.history-item {
    padding: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: background 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item:hover {
    background: var(--input-bg);
    color: var(--text-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.welcome-screen {
    text-align: center;
    margin: auto;
    max-width: 600px;
}

.welcome-screen h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.welcome-screen p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.welcome-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.feature {
    padding: 1.5rem;
    background: var(--input-bg);
    border-radius: 8px;
    text-align: center;
}

.feature span {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.5rem;
}

.feature p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.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;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.2rem;
}

.message.user .message-avatar {
    background: var(--message-user-bg);
}

.message.assistant .message-avatar {
    background: var(--message-assistant-bg);
}

.message-content {
    flex: 1;
    padding: 1rem;
    border-radius: 8px;
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--message-user-bg);
    color: white;
}

.message.assistant .message-content {
    background: var(--message-assistant-bg);
    color: var(--text-primary);
}

.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 {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

.message-content h1, .message-content h2, .message-content h3 {
    margin: 1rem 0 0.5rem 0;
}

.message-content ul, .message-content ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin: 0.25rem 0;
}

.message-content strong {
    font-weight: 600;
}

.message.loading .message-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loading-dots {
    display: flex;
    gap: 0.25rem;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.loading-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Input Area */
.input-area {
    padding: 1rem;
    background: var(--chat-bg);
    border-top: 1px solid var(--border-color);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--input-bg);
    border-radius: 12px;
    padding: 0.75rem;
}

.attach-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.attach-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
    font-family: inherit;
}

#messageInput:focus {
    outline: none;
}

.send-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-footer {
    text-align: center;
    margin-top: 0.5rem;
}

.api-status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.api-status.connected {
    color: #10a37f;
}

.api-status.error {
    color: #ef4444;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-bg);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--sidebar-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.25rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}

.close-btn:hover {
    background: var(--input-bg);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    margin-bottom: 1rem;
}

.upload-area:hover {
    border-color: var(--primary-color);
}

.upload-area input {
    display: none;
}

.upload-list {
    margin-bottom: 1rem;
}

.upload-item {
    padding: 0.75rem;
    background: var(--input-bg);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.upload-submit-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.upload-submit-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.upload-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.records-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.records-controls input {
    flex: 1;
    padding: 0.75rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
}

.records-controls input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.records-controls button {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.records-list {
    max-height: 400px;
    overflow-y: auto;
}

.record-item {
    padding: 1rem;
    background: var(--input-bg);
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.record-item h4 {
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.record-item p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0.25rem 0;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        transition: left 0.3s;
        z-index: 100;
    }

    .sidebar.active {
        left: 0;
    }

    .main-content {
        width: 100%;
    }
}

