:root {
    --bg: #0f1115;
    --bg-2: #161922;
    --bg-3: #1d212c;
    --border: #262a36;
    --text: #ececf1;
    --text-dim: #a0a3b1;
    --accent: #10a37f;
    --accent-hover: #0e8c6c;
    --user-bubble: #2b3140;
    --assistant-bubble: transparent;
    --danger: #ef4444;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow: hidden;
}
.new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.new-chat:hover { background: var(--bg-3); border-color: #333949; }
.new-chat .plus { font-size: 18px; line-height: 1; opacity: 0.85; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    text-decoration: none;
    margin-top: 8px;
    transition: background 0.15s, border-color 0.15s;
}
.sidebar-link:hover { background: var(--bg-3); border-color: #333949; }
.sidebar-link .plus { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; opacity: 0.85; }

.sessions { flex: 1; overflow-y: auto; margin-top: 14px; }
.session-item {
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s, color 0.15s;
}
.session-item:hover { background: var(--bg-3); color: var(--text); }
.session-item.active { background: var(--bg-3); color: var(--text); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 10px; }
.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; }
.dot.ready { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot.loading { background: #f59e0b; animation: pulse 1.4s infinite; }
.dot.error { background: var(--danger); }
.model { font-size: 11px; color: var(--text-dim); margin-top: 4px; word-break: break-all; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Main */
.main { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
    color: white;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 15px;
}
.title { font-weight: 600; font-size: 15px; }
.topbar-actions .ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
}
.topbar-actions .ghost:hover { color: var(--text); background: var(--bg-3); }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 20px 0; scroll-behavior: smooth; }
.empty { display: grid; place-items: center; min-height: 100%; }
.hero { text-align: center; max-width: 720px; padding: 40px 20px; }
.hero-logo {
    width: 56px; height: 56px; margin: 0 auto 18px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
    color: white; display: grid; place-items: center;
    font-weight: 700; font-size: 26px;
}
.hero h1 { font-weight: 600; font-size: 28px; margin: 0 0 8px; }
.hero p { color: var(--text-dim); margin: 0 0 28px; }
.prompts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.prompt-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text);
    text-align: left;
    padding: 14px 16px;
    border-radius: 12px;
    cursor: pointer;
    display: flex; flex-direction: column; gap: 2px;
    transition: background 0.15s, border-color 0.15s;
}
.prompt-card:hover { background: var(--bg-3); border-color: #333949; }
.prompt-card strong { font-weight: 600; font-size: 14px; }
.prompt-card span { font-size: 13px; color: var(--text-dim); }

.message-row {
    display: flex;
    gap: 14px;
    padding: 18px 24px;
    max-width: 820px;
    margin: 0 auto;
}
.avatar {
    flex-shrink: 0;
    width: 32px; height: 32px;
    border-radius: 8px;
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px;
    color: white;
}
.avatar.user { background: #4f46e5; }
.avatar.assistant { background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%); }
.bubble { flex: 1; min-width: 0; }
.role { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; font-weight: 600; }
.content { white-space: pre-wrap; word-wrap: break-word; }
.content pre {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    font-size: 13px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
}
.content code {
    background: var(--bg-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: "SF Mono", Menlo, Consolas, monospace;
}
.content pre code { background: transparent; padding: 0; }

.actions {
    margin-top: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s;
}
.message-row:hover .actions { opacity: 1; }
.actions button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
}
.actions button:hover { color: var(--text); background: var(--bg-3); }

.cursor {
    display: inline-block;
    width: 7px;
    height: 14px;
    background: var(--text);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Composer */
.composer { padding: 12px 24px 18px; background: var(--bg); border-top: 1px solid var(--border); }
.composer form { max-width: 820px; margin: 0 auto; }
.input-wrap {
    position: relative;
    display: flex;
    align-items: flex-end;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 12px;
    box-shadow: var(--shadow);
    transition: border-color 0.15s;
}
.input-wrap:focus-within { border-color: #3a4054; }
.input-wrap textarea {
    flex: 1;
    background: transparent;
    color: var(--text);
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    max-height: 180px;
    padding: 4px 6px;
}
.send, .stop {
    flex-shrink: 0;
    width: 32px; height: 32px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    margin-left: 6px;
}
.send {
    background: var(--accent);
    color: white;
}
.send:hover { background: var(--accent-hover); }
.send:disabled { background: #2b3140; color: var(--text-dim); cursor: not-allowed; }
.stop { background: var(--danger); color: white; }
.stop:hover { filter: brightness(1.1); }
.hidden { display: none !important; }

.hint { color: var(--text-dim); font-size: 12px; text-align: center; margin-top: 8px; }
.hint kbd {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: inherit;
    font-size: 11px;
}

@media (max-width: 760px) {
    .app { grid-template-columns: 0 1fr; }
    .sidebar { display: none; }
    .prompts { grid-template-columns: 1fr; }
    .message-row { padding: 14px 16px; }
    .composer { padding: 10px 12px 14px; }
}

/* Scrollbar */
.messages::-webkit-scrollbar, .sessions::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track, .sessions::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb, .sessions::-webkit-scrollbar-thumb { background: #2b3140; border-radius: 4px; }
.messages::-webkit-scrollbar-thumb:hover, .sessions::-webkit-scrollbar-thumb:hover { background: #3a4054; }
