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

:root {
    --bg-primary: #212121;
    --bg-secondary: #171717;
    --bg-tertiary: #2f2f2f;
    --bg-input: #2f2f2f;
    --bg-hover: #383838;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --text-tertiary: #8e8e8e;
    --border-color: #424242;
    --accent: #10a37f;
    --accent-hover: #1a7f64;
    --user-bg: #2f2f2f;
    --assistant-bg: transparent;
    --sidebar-width: 260px;
    --header-height: 48px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Söhne', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    transition: margin-left 0.3s ease;
    flex-shrink: 0;
    z-index: 10;
}

.sidebar.closed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    height: var(--header-height);
}

.sidebar-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-btn:hover {
    background: var(--bg-hover);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: background 0.2s;
}

.sidebar-item:hover {
    background: var(--bg-hover);
}

.sidebar-item.active {
    background: var(--bg-hover);
}

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

.credits-display {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 4px;
    font-size: 13px;
}

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

.credits-info {
    display: flex;
    align-items: center;
    gap: 4px;
}

#credits-remaining {
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    border-bottom: 1px dashed var(--text-tertiary);
}

.credits-label {
    color: var(--text-secondary);
    font-size: 12px;
}

.credits-consumed {
    font-size: 11px;
    color: #f59e0b;
    opacity: 0;
    transition: opacity 0.3s;
    margin-left: 4px;
}

.credits-consumed.active {
    opacity: 1;
}

.settings-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
}

.settings-btn:hover {
    background: var(--bg-hover);
}

/* Main Content */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header */
.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.header-left, .header-right {
    width: 80px;
    display: flex;
    align-items: center;
}

.header-right {
    justify-content: flex-end;
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn:hover {
    background: var(--bg-hover);
}

.header-center {
    display: flex;
    align-items: center;
}

.model-select {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    appearance: none;
    -webkit-appearance: none;
}

.model-select:hover {
    background: var(--bg-hover);
}

.model-select:focus {
    outline: none;
}

.model-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Welcome Screen */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 20px;
}

.welcome h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.quick-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 600px;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.quick-action:hover {
    background: var(--bg-hover);
}

.quick-action-icon {
    font-size: 18px;
}

/* Messages */
.messages {
    display: flex;
    flex-direction: column;
    padding: 0 0 20px 0;
}

.message {
    padding: 16px 0;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #5865f2;
}

.message.assistant .message-avatar {
    background: var(--accent);
}

.message-content {
    max-width: 85%;
    line-height: 1.7;
    font-size: 15px;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.user .message-content {
    background: var(--user-bg);
    padding: 12px 16px;
    border-radius: 18px;
}

.message-content code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Söhne Mono', 'Monaco', 'Menlo', monospace;
    font-size: 13px;
}

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

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

/* Typing indicator */
.typing-indicator {
    display: none;
    padding: 16px 0;
}

.typing-indicator.active {
    display: block;
}

.typing-indicator .message-inner {
    max-width: 768px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 16px;
}

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

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

/* Input Area */
.input-area {
    padding: 0 24px 24px;
    flex-shrink: 0;
}

.input-container {
    max-width: 768px;
    margin: 0 auto;
    background: var(--bg-input);
    border-radius: 24px;
    border: 1px solid var(--border-color);
    padding: 4px;
    transition: border-color 0.2s;
}

.input-container:focus-within {
    border-color: var(--text-tertiary);
}

.attachments-preview {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0 8px;
}

.attachment-item {
    background: var(--bg-tertiary);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.attachment-remove {
    cursor: pointer;
    opacity: 0.7;
}

.attachment-remove:hover {
    opacity: 1;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

.input-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.input-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 200px;
    padding: 10px 0;
    font-family: inherit;
    line-height: 1.5;
}

textarea::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    background: var(--accent);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, opacity 0.2s;
}

.send-btn:hover {
    background: var(--accent-hover);
}

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

.input-footer {
    text-align: center;
    padding-top: 8px;
    font-size: 12px;
    color: var(--text-tertiary);
    max-width: 768px;
    margin: 0 auto;
}

/* Settings Panel */
.settings-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
}

.settings-overlay.active {
    display: block;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -360px;
    width: 360px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    z-index: 101;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.settings-panel.active {
    right: 0;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.settings-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.settings-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.settings-close:hover {
    background: var(--bg-hover);
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

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

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.setting-group input[type="text"],
.setting-group input[type="password"] {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
}

.setting-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 14px;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle.active {
    background: var(--accent);
}

.toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

.toggle.active::after {
    transform: translateX(20px);
}

.btn-new-conversation {
    width: 100%;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.btn-new-conversation:hover {
    background: var(--bg-hover);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--error, #ef4444);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    display: none;
    z-index: 1000;
}

.toast.active {
    display: block;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateX(-50%) translateY(20px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* File input hidden */
#file-input {
    display: none;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

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

    .sidebar.closed {
        margin-left: calc(-1 * var(--sidebar-width));
    }

    .quick-actions {
        flex-direction: column;
        align-items: center;
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }
}
