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

:root {
    --bg:        #0f0f10;
    --bg-2:      #131315;
    --bg-3:      #1a1a1e;
    --bg-4:      #1e1e22;
    --border:    #252528;
    --border-2:  #2a2a2e;
    --text:      #d4d4d8;
    --text-2:    #888;
    --text-3:    #555;
    --accent:    #6c6cff;
    --accent-bg: #1e1e40;
    --accent-border: #2e2e60;
    --accent-text:   #c8c8ee;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

#sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--bg-2);
    border-right: 0.5px solid var(--bg-4);
    display: flex;
    flex-direction: column;
    padding: 16px 10px;
    gap: 2px;
}

.sidebar-logo {
    font-size: 16px;
    font-weight: 500;
    color: #e8e8ea;
    padding: 4px 10px 14px;
    border-bottom: 0.5px solid var(--bg-4);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

.sidebar-logo span, .drawer-logo span { color: var(--accent); }

.sidebar-section, .drawer-section {
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
    font-weight: 500;
    padding: 10px 10px 4px;
}

.drawer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-2);
    font-size: 14px;
    font-family: 'DM Sans', sans-serif;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.drawer-item:hover {
    background: var(--bg-3);
    color: var(--text);
}

.drawer-item.active {
    background: var(--accent-bg);
    color: #a0a0ff;
}

.drawer-item i {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 0.5px solid var(--bg-4);
    flex-shrink: 0;
}

#mode-label {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-3);
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--bg-3);
    border: 0.5px solid var(--border-2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-2);
    transition: background 0.15s;
}

.icon-btn:hover { background: var(--bg-4); }
.icon-btn i { width: 15px; height: 15px; }

#menu-btn { display: none; }

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; }

.msg {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-width: 80%;
}

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.msg-role {
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    font-weight: 500;
    padding: 0 4px;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.6;
}

.msg.user .msg-bubble {
    background: var(--accent-bg);
    border: 0.5px solid var(--accent-border);
    color: var(--accent-text);
    border-bottom-right-radius: 4px;
}

.msg.assistant .msg-bubble {
    background: var(--bg-3);
    border: 0.5px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg-bubble p { margin: 0 0 0.5em; }
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble code {
    font-family: 'DM Mono', monospace;
    font-size: 12.5px;
    background: #0a0a0c;
    padding: 2px 6px;
    border-radius: 4px;
    color: #a78bfa;
}

.msg-bubble pre {
    background: #0a0a0c;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    overflow-x: auto;
    margin: 8px 0;
}

.msg-bubble pre code {
    background: none;
    padding: 0;
    font-size: 12.5px;
    color: #c4b5fd;
}

.msg-bubble ul, .msg-bubble ol {
    padding-left: 1.25em;
    margin: 0.4em 0;
}

.msg-bubble li { margin: 0.2em 0; }

.mode-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 20px;
    background: var(--accent-bg);
    color: #8080ee;
    border: 0.5px solid var(--accent-border);
    font-weight: 500;
}

.mode-pill i { width: 10px; height: 10px; }

.thinking-bubble {
    background: var(--bg-3);
    border: 0.5px solid var(--border);
    border-bottom-left-radius: 4px;
    padding: 13px 16px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 5px;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    animation: thinking 1.4s ease-in-out infinite;
}

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

@keyframes thinking {
    0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
    30% { opacity: 1; transform: scale(1.25); }
}

#input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    border-top: 0.5px solid var(--bg-4);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg);
    flex-shrink: 0;
}

#input {
    flex: 1;
    background: var(--bg-3);
    border: 0.5px solid var(--border-2);
    border-radius: var(--radius-md);
    padding: 10px 13px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    resize: none;
    min-height: 42px;
    max-height: 140px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.15s;
}

#input:focus { border-color: var(--accent); }
#input::placeholder { color: var(--text-3); }

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

.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn i { width: 15px; height: 15px; }

#drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
}

#drawer-overlay.hidden { display: none; }

#drawer {
    width: 220px;
    height: 100%;
    background: var(--bg-2);
    border-right: 0.5px solid var(--bg-4);
    display: flex;
    flex-direction: column;
    padding: 16px 10px;
    gap: 2px;
    z-index: 101;
    animation: slideIn 0.2s ease;
}

.drawer-logo {
    font-size: 16px;
    font-weight: 500;
    color: #e8e8ea;
    padding: 4px 10px 14px;
    border-bottom: 0.5px solid var(--bg-4);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

#drawer-backdrop {
    flex: 1;
    background: rgba(0,0,0,0.5);
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to   { transform: translateX(0); }
}

.hidden { display: none !important; }

@media (max-width: 600px) {
    #sidebar { display: none; }
    #menu-btn { display: flex; }
    .msg { max-width: 92%; }
}