@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #1a1825;
    --bg-panel: #211f2e;
    --bg-raised: #2a2738;
    --border: #3a3650;
    --text: #c4c0d4;
    --text-dim: #8b85a8;
    --text-bright: #ece9f5;
    --accent: #7aa2f7;
    --accent-dim: #4d6aa8;
    --logo-block: #9d97c4;
}

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

body {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}

.container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 28px 18px;
    display: flex;
    flex-direction: column;
}

#logo {
    font-weight: 800;
    font-size: 22px;
    letter-spacing: 2px;
    color: var(--logo-block);
    margin-bottom: 36px;
    text-transform: uppercase;
    background: linear-gradient(180deg, var(--text-bright) 0%, var(--logo-block) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.menu-item {
    margin-bottom: 2px;
}

.menu-item a {
    display: block;
    color: var(--text-dim);
    text-decoration: none;
    padding: 9px 10px;
    border-radius: 6px;
    font-size: 13px;
    transition: background 0.15s, color 0.15s;
}

.menu-item a::before {
    content: "/";
    color: var(--accent-dim);
    margin-right: 6px;
}

.menu-item a:hover {
    background: var(--bg-raised);
    color: var(--text-bright);
}

/* Main area */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 32px 40px;
    overflow-y: auto;
}

.main h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 24px;
}

/* Dashboard cards */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
}

.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px 20px;
}

.card h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent);
    margin-bottom: 10px;
    font-weight: 600;
}

.card p {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 5px;
    line-height: 1.5;
}

/* Chat / Study shared layout */
.chat-container, #study-chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-box, #studyBox {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0 20px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 720px;
    font-size: 14px;
    line-height: 1.65;
}

.message strong {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 6px;
    font-weight: 600;
}

.user-message {
    align-self: flex-end;
    text-align: right;
}

.user-message strong {
    color: var(--text-dim);
}

.ai-message {
    align-self: flex-start;
    border-left: 2px solid var(--accent-dim);
    padding-left: 14px;
}

.ai-message strong {
    color: var(--accent);
}

.ai-message code {
    background: var(--bg-raised);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.ai-message pre {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 8px 0;
}

/* Input bar - the signature element */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    margin-top: 16px;
}

#userInput, #studyInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-bright);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    padding: 4px 0;
}

#userInput::placeholder, #studyInput::placeholder {
    color: var(--text-dim);
}

#userInput:focus, #studyInput:focus {
    outline: none;
}

.chat-input-area button:not(#codeModeBtn):not(#stopBtn) {
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 6px;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

.chat-input-area button:not(#codeModeBtn):not(#stopBtn):hover {
    background: var(--text-bright);
}

#codeModeBtn {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 12px;
    cursor: pointer;
    font-family: monospace;
    font-size: 13px;
}

#codeModeBtn:hover, #codeModeBtn.active {
    color: var(--accent);
    border-color: var(--accent-dim);
}

#stopBtn {
    background: transparent;
    color: #d97777;
    border: 1px solid #5a3a3a;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
}

#stopBtn:hover {
    background: #2a1a1a;
}

/* Status bar - bottom, signature element */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 2px 0 2px;
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.3px;
}

.status-bar span.hint {
    color: var(--accent-dim);
}

/* Topic select screen */
#topic-select h1 {
    font-size: 22px;
    margin-bottom: 20px;
}

.topic-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.topic-buttons button {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.topic-buttons button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

#session-title {
    font-size: 16px;
    color: var(--text-bright);
    font-weight: 600;
    margin-bottom: 18px;
}

/* Code modal */
.code-modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(10, 9, 15, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.code-modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 70%;
    max-width: 800px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    overflow: hidden;
}

.code-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: var(--bg-raised);
    color: var(--text-bright);
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.code-modal-header button {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
}

.code-modal-header button:hover {
    color: var(--text-bright);
}

#editorContainer {
    min-height: 0;
    border: none;
}

.CodeMirror {
    height: 400px !important;
    width: 100% !important;
    font-size: 14px;
}

.code-modal-footer {
    padding: 12px 18px;
    background: var(--bg-raised);
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--border);
}

.code-modal-footer button {
    padding: 9px 18px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
}

.code-modal-footer button:hover {
    background: var(--text-bright);
}

@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 16px;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        overflow-x: auto;
    }

    #logo {
        font-size: 16px;
        margin-bottom: 0;
        white-space: nowrap;
    }

    .menu-item {
        margin-bottom: 0;
        white-space: nowrap;
    }

    .main {
        padding: 16px;
    }

    .chat-input-area {
        flex-wrap: wrap;
    }

    .message {
        max-width: 100%;
    }
}