:root {
    --bg: #0f172a;
    --bg2: #1e293b;
    --bg3: #334155;
    --accent: #6366f1;
    --accent2: #818cf8;
    --text: #f1f5f9;
    --text2: #94a3b8;
    --border: #334155;
    --user-bubble: #6366f1;
    --ai-bubble: #1e293b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --sidebar-w: 260px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
}

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

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    margin-bottom: 12px;
}

.sidebar-logo svg { color: var(--accent2); }

.btn-new-chat {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}
.btn-new-chat:hover { background: var(--accent2); }

.sidebar-nav {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text2);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    background: var(--bg3);
    color: var(--text);
}

.sessions-label {
    padding: 10px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12.5px;
    color: var(--text2);
    transition: all 0.15s;
    position: relative;
    group: true;
}
.session-item:hover { background: var(--bg3); color: var(--text); }
.session-item.active { background: var(--bg3); color: var(--text); }

.session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-del {
    display: none;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 13px;
}
.session-item:hover .session-del { display: block; }

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

.topbar {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
    gap: 12px;
}

.topbar-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-select {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    outline: none;
}

/* MESSAGES */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.msg {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: fadeIn 0.2s ease;
}

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

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    font-weight: 700;
}
.msg.user .msg-avatar { background: var(--user-bubble); }
.msg.assistant .msg-avatar { background: var(--bg3); }

.msg-bubble {
    max-width: 72%;
    background: var(--ai-bubble);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.65;
    border: 1px solid var(--border);
}
.msg.user .msg-bubble {
    background: var(--user-bubble);
    border-color: var(--user-bubble);
    color: #fff;
}

.msg-bubble pre {
    background: #0f172a;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
    border: 1px solid var(--border);
}
.msg-bubble code { font-family: 'Fira Code', monospace; font-size: 13px; }
.msg-bubble p { margin-bottom: 6px; }
.msg-bubble p:last-child { margin-bottom: 0; }

.typing-dot {
    display: inline-flex;
    gap: 4px;
    padding: 2px 0;
}
.typing-dot span {
    width: 6px; height: 6px;
    background: var(--text2);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}
.typing-dot span:nth-child(2) { animation-delay: 0.2s; }
.typing-dot span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}

/* INPUT */
.input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg2);
}

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

#messageInput {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    resize: none;
    max-height: 160px;
    min-height: 22px;
    font-family: inherit;
    line-height: 1.5;
}
#messageInput::placeholder { color: var(--text2); }

.btn-send {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.btn-send:hover { background: var(--accent2); }
.btn-send:disabled { background: var(--bg3); cursor: not-allowed; }

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

/* WELCOME */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
    color: var(--text2);
}
.welcome h2 { font-size: 22px; color: var(--text); }
.welcome p { font-size: 14px; text-align: center; max-width: 400px; }
.welcome-icon { font-size: 48px; }

/* MODAL */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 480px;
}
.modal h3 { margin-bottom: 16px; font-size: 16px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    font-family: inherit;
}
.form-group textarea { resize: vertical; min-height: 80px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.btn { padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: var(--bg3); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }

/* TOAST */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 13px;
    z-index: 9999;
    animation: slideUp 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* RESPONSIVE */
@media (max-width: 640px) {
    .sidebar { display: none; }
    .sidebar.open { display: flex; position: fixed; z-index: 100; }
}
