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

:root {
    --bg: #0a0a0a;
    --bg-card: #141414;
    --bg-input: #1a1a1a;
    --text: #f0f0f0;
    --text-muted: #888;
    --border: #2a2a2a;
    --accent: #ff6b35;
    --accent-hover: #ff7b4a;
    --sidebar-w: 260px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'PingFang SC', 'Noto Sans SC', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 12px;
}

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

.new-chat-btn:hover {
    border-color: var(--accent);
}

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

.chat-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chat-item.active {
    background: var(--bg-input);
    color: var(--text);
}

.chat-item .delete-btn {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    flex-shrink: 0;
}

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

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

.clear-btn {
    width: 100%;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    padding: 8px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.clear-btn:hover {
    border-color: #ff4444;
    color: #ff4444;
}

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

.header {
    height: 52px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
}

.menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: none;
}

.logo {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.logo-icon {
    color: var(--accent);
    font-size: 18px;
}

.model-select {
    margin-left: auto;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    outline: none;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.welcome-icon {
    font-size: 48px;
    color: var(--accent);
    margin-bottom: 16px;
}

.welcome h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.welcome p {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 32px;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-width: 400px;
}

.suggestion {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    font-family: inherit;
    line-height: 1.4;
}

.suggestion:hover {
    border-color: var(--accent);
    background: var(--bg-input);
}

/* Message Bubbles */
.message {
    max-width: 720px;
    margin: 0 auto 20px;
    display: flex;
    gap: 12px;
}

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

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

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

.message.user .message-avatar {
    background: #3a3a3a;
    color: var(--text);
}

.message-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.7;
    max-width: 85%;
    overflow-wrap: break-word;
}

.message.user .message-content {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.message-content p {
    margin-bottom: 8px;
}

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

.message-content pre {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}

.message-content code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
}

.message-content :not(pre) > code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

.message-content ul, .message-content ol {
    padding-left: 20px;
    margin: 8px 0;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content h1, .message-content h2, .message-content h3 {
    margin: 12px 0 8px;
    font-weight: 600;
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 15px; }

.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-muted);
}

.message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.message-content th, .message-content td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    font-size: 13px;
}

.message-content th {
    background: var(--bg-input);
}

/* Typing indicator */
.typing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    margin: 0 2px;
    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% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* Input Area */
.input-area {
    padding: 16px 20px 12px;
    border-top: 1px solid var(--border);
    max-width: 780px;
    margin: 0 auto;
    width: 100%;
}

.input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px 8px 8px 16px;
    transition: border-color 0.2s;
}

.input-wrap:focus-within {
    border-color: var(--accent);
}

textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 150px;
    padding: 4px 0;
}

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

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

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

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

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    opacity: 0.6;
}

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

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

    .menu-btn {
        display: block;
    }

    .suggestions {
        grid-template-columns: 1fr;
    }

    .message-content {
        max-width: 95%;
    }
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #3a3a3a;
}
