*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #0d0d0d;
    --sidebar:   #171717;
    --surface:   #1e1e1e;
    --border:    #2a2a2a;
    --text:      #ececec;
    --muted:     #8e8ea0;
    --accent:    #10a37f;
    --user-bg:   #2a2a2a;
    --bot-bg:    transparent;
    --radius:    12px;
    --font:      'Segoe UI', system-ui, sans-serif;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); height: 100vh; overflow: hidden; }

.app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar { width: 260px; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px; gap: 12px; }
.sidebar-header h2 { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 10px; }
.btn-new-chat { width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; font-size: 14px; font-weight: 600; transition: opacity .2s; }
.btn-new-chat:hover { opacity: .85; }
.chat-history { flex: 1; overflow-y: auto; }
.history-item { padding: 8px 10px; border-radius: 8px; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .2s; }
.history-item:hover { background: var(--surface); color: var(--text); }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 24px 0; display: flex; flex-direction: column; gap: 8px; }
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.welcome { text-align: center; padding: 60px 20px; color: var(--muted); }
.welcome h1 { font-size: 28px; color: var(--text); margin-bottom: 8px; }
.welcome p { font-size: 15px; margin-bottom: 24px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 640px; margin: 0 auto; }
.suggest-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 10px 14px; border-radius: var(--radius); cursor: pointer; font-size: 13px; transition: background .2s; }
.suggest-btn:hover { background: var(--border); }

.message { padding: 12px 0; max-width: 780px; width: 100%; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
.message.user .bubble { background: var(--user-bg); padding: 12px 16px; border-radius: var(--radius); display: inline-block; max-width: 75%; float: right; clear: both; }
.message.bot .bubble { background: var(--bot-bg); padding: 12px 0; display: block; clear: both; line-height: 1.7; }

/* Markdown rendering */
.bubble h1,.bubble h2,.bubble h3 { margin: 16px 0 8px; color: var(--text); }
.bubble p { margin-bottom: 12px; }
.bubble ul,.bubble ol { padding-left: 20px; margin-bottom: 12px; }
.bubble li { margin-bottom: 4px; }
.bubble code:not([class]) { background: var(--surface); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; color: #f8f8f2; }
.bubble pre { background: #161b22; border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; margin: 12px 0; }
.bubble pre code { padding: 16px; display: block; font-size: 13px; }
.code-header { display: flex; justify-content: space-between; align-items: center; background: #21262d; padding: 6px 16px; border-radius: var(--radius) var(--radius) 0 0; font-size: 12px; color: var(--muted); }
.copy-btn { background: none; border: 1px solid var(--border); color: var(--muted); padding: 2px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; }
.copy-btn:hover { color: var(--text); }
.bubble strong { color: #fff; }
.bubble a { color: var(--accent); }
.bubble table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.bubble th,.bubble td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.bubble th { background: var(--surface); }

/* Typing indicator */
.typing-indicator { display: flex; gap: 4px; padding: 6px 0; align-items: center; }
.typing-indicator span { width: 8px; height: 8px; background: var(--muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Input */
.input-area { padding: 16px 24px 20px; border-top: 1px solid var(--border); background: var(--bg); }
.input-wrapper { max-width: 780px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; transition: border-color .2s; }
.input-wrapper:focus-within { border-color: var(--accent); }
textarea { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-size: 15px; resize: none; font-family: var(--font); max-height: 200px; line-height: 1.5; }
#sendBtn { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: opacity .2s; flex-shrink: 0; }
#sendBtn:hover:not(:disabled) { opacity: .85; }
#sendBtn:disabled { opacity: .4; cursor: not-allowed; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; max-width: 780px; margin-left: auto; margin-right: auto; }

/* Mobile */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .message { padding-left: 16px; padding-right: 16px; }
}
/* Attach button */
#attachBtn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color .2s;
    flex-shrink: 0;
}
#attachBtn:hover { color: var(--text); }
#attachBtn.has-file { color: var(--accent); }

/* File preview pill */
.file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--accent);
    max-width: 780px;
    margin: 6px auto 0;
}
.file-preview button {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}
.file-preview button:hover { color: var(--text); }
/* Edit button on user messages */
.message.user:hover .msg-actions { opacity: 1; }
.msg-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity .2s;
    margin-top: 4px;
}
.msg-action-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: color .2s, border-color .2s;
}
.msg-action-btn:hover { color: var(--text); border-color: var(--muted); }

/* Inline edit box */
.edit-box {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--accent);
    color: var(--text);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: 14px;
    font-family: var(--font);
    resize: vertical;
    min-height: 60px;
    outline: none;
}
.edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 6px;
}
.btn-save {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 5px 14px;
    font-size: 12px;
    cursor: pointer;
}
.btn-cancel {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 6px;
    padding: 5px 14px;
    font-size: 12px;
    cursor: pointer;
}
.btn-cancel:hover { color: var(--text); }

/* Code block copy button */
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #21262d;
    padding: 6px 16px;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 12px;
    color: var(--muted);
}
.copy-btn { 
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 2px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: color .2s;
}
.copy-btn:hover { color: var(--text); }
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }

