:root {
    --bg: #0f0f0f;
    --sidebar-bg: #161616;
    --surface: #1e1e1e;
    --surface-hover: #252525;
    --border: #2a2a2a;
    --text: #e4e4e4;
    --text-muted: #888;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --user-bg: #1a3a5c;
    --assistant-bg: #1e1e1e;
    --input-bg: #1a1a1a;
    --error: #dc2626;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono: 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    overflow: hidden;
}

/* Layout */
.layout { display: flex; height: 100vh; }

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

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
}

.brand-icon { color: var(--accent); font-size: 22px; }

.sidebar-body { flex: 1; padding: 12px; overflow-y: auto; }

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.new-chat-btn:hover { background: var(--surface-hover); }

/* Session list */
.session-list {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}

.session-item:hover { background: var(--surface-hover); color: var(--text); }
.session-item.active { background: var(--surface); color: var(--text); }

.session-item-title {
    flex: 1;
    min-width: 0;
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item-actions {
    display: none;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.session-item:hover .session-item-actions { display: flex; }

.session-item-action {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 5px;
    color: var(--text-muted);
    cursor: pointer;
}

.session-item-action:hover { background: var(--border); color: var(--text); }

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

.model-badge {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface);
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    font-family: var(--mono);
}

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

/* Welcome */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    gap: 12px;
}

.welcome-icon { font-size: 42px; color: var(--accent); margin-bottom: 4px; }
.welcome h1 { font-size: 24px; font-weight: 600; }
.welcome p { color: var(--text-muted); font-size: 14px; }

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 24px 8px;
    display: none;
    flex-direction: column;
    gap: 20px;
}

.messages.visible { display: flex; }

.message {
    display: flex;
    gap: 12px;
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
}

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

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar { background: var(--accent); color: white; }
.message.assistant .message-avatar { background: #3a1d6e; color: #c4b5fd; font-size: 15px; }

.message-content {
    padding: 10px 14px;
    border-radius: 12px;
    max-width: calc(100% - 42px);
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 0;
}

.message.user .message-content {
    background: var(--user-bg);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.message.assistant .message-content {
    background: var(--assistant-bg);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

/* Markdown */
.message.assistant .message-content p { margin: 0 0 10px; }
.message.assistant .message-content p:last-child { margin-bottom: 0; }
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3,
.message.assistant .message-content h4 { margin: 16px 0 8px; font-weight: 600; }
.message.assistant .message-content h1 { font-size: 1.3em; }
.message.assistant .message-content h2 { font-size: 1.15em; }
.message.assistant .message-content h3 { font-size: 1.05em; }
.message.assistant .message-content ul,
.message.assistant .message-content ol { padding-left: 22px; margin: 8px 0; }
.message.assistant .message-content li { margin: 4px 0; }
.message.assistant .message-content code {
    font-family: var(--mono);
    background: #2d2d2d;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
}
.message.assistant .message-content pre {
    background: #161616;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    overflow-x: auto;
    margin: 10px 0;
}
.message.assistant .message-content pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.55;
}
.message.assistant .message-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    color: var(--text-muted);
    margin: 10px 0;
}
.message.assistant .message-content a { color: #60a5fa; text-decoration: underline; }
.message.assistant .message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 14px;
    overflow-x: auto;
    display: block;
}
.message.assistant .message-content th,
.message.assistant .message-content td {
    border: 1px solid var(--border);
    padding: 7px 12px;
    text-align: left;
}
.message.assistant .message-content th { background: var(--surface); font-weight: 600; }
.message.assistant .message-content hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.message.assistant .message-content strong { font-weight: 600; }
.message.assistant .message-content em { font-style: italic; color: #c0c0c0; }

/* Typing cursor */
.typing-cursor::after {
    content: '▋';
    display: inline;
    animation: blink 0.7s steps(1) infinite;
    margin-left: 1px;
    color: var(--accent);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Error */
.message-error {
    color: #fca5a5;
    font-size: 13px;
    padding: 10px 14px;
    background: rgba(220, 38, 38, 0.12);
    border-radius: 8px;
    border: 1px solid rgba(220, 38, 38, 0.25);
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
}

/* Attachments */
.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 760px;
    margin: 0 auto 8px;
}

.attachment-preview:empty { display: none; }

.attachment-thumb {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.attachment-thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    padding: 0;
}

.attachment-thumb-remove:hover { background: rgba(220, 38, 38, 0.9); }

.attach-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.attach-btn:hover { background: var(--surface-hover); color: var(--text); }

/* Message images */
.message-content .message-image {
    max-width: 320px;
    max-height: 320px;
    border-radius: 8px;
    display: block;
    margin-bottom: 8px;
    cursor: zoom-in;
}

.message-content .message-image:last-child { margin-bottom: 0; }

/* Copy buttons */
.message {
    position: relative;
}

.message-copy-btn {
    width: 26px;
    height: 26px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 2px;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.message:hover .message-copy-btn { opacity: 1; }
.message-copy-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.message-copy-btn.copied { opacity: 1; color: #4ade80; }

.code-block-wrapper { position: relative; }

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 9px;
    font-size: 11.5px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.code-block-wrapper:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: var(--text); }
.code-copy-btn.copied { color: #4ade80; opacity: 1; }

/* Input */
.input-wrapper {
    padding: 12px 24px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 8px 8px 16px;
    max-width: 760px;
    margin: 0 auto;
    transition: border-color 0.15s;
}

.input-container:focus-within { border-color: #3f3f3f; }

.message-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 0;
}

.message-input::placeholder { color: #555; }

.send-btn {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.disclaimer {
    text-align: center;
    font-size: 11px;
    color: #444;
    margin-top: 8px;
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #303030; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #404040; }

/* Mobile */
@media (max-width: 640px) {
    .sidebar { display: none; }
    .input-wrapper { padding: 10px 14px 16px; }
    .messages { padding: 16px 14px 8px; }
}
