/* S-Lab AI Brain — Stanford branded */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,300;8..60,400;8..60,600;8..60,700&family=Source+Sans+3:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg: hsl(0 0% 100%);
    --fg: hsl(0 0% 13%);
    --muted: hsl(0 0% 96.5%);
    --muted-fg: hsl(0 0% 44%);
    --border: hsl(0 0% 88%);
    --input: hsl(0 0% 90%);
    --cardinal: hsl(0 83% 27%);
    --cardinal-dark: hsl(0 83% 20%);
    --cardinal-light: hsl(0 60% 95%);
    --primary: var(--cardinal);
    --primary-fg: hsl(0 0% 100%);
    --accent: hsl(0 0% 96%);
    --card: hsl(0 0% 100%);
    --ring: var(--cardinal);
    --success: hsl(142 71% 45%);
    --danger: hsl(0 84% 60%);
    --radius: 0.5rem;
    --font: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Source Serif 4', Georgia, serif;
    --mono: 'JetBrains Mono', ui-monospace, monospace;
    --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--fg);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────── */
.top-bar {
    height: 52px;
    background: var(--cardinal);
    border-bottom: none;
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 50;
}
.top-bar-inner { display: flex; align-items: center; gap: 12px; }
.logo {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 600;
    color: white;
    text-decoration: none;
    letter-spacing: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}
.tagline {
    font-family: var(--font);
    font-size: 12px;
    font-weight: 400;
    color: hsla(0, 0%, 100%, 0.7);
    padding-left: 12px;
    border-left: 1px solid hsla(0, 0%, 100%, 0.25);
}

/* ── Layout ──────────────────────────────────── */
.app-container {
    display: flex;
    height: calc(100vh - 52px);
    margin-top: 52px;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--muted);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.sidebar-header { padding: 12px; }
.new-chat-btn {
    display: block;
    width: 100%;
    padding: 8px 0;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font);
    color: white;
    background: var(--cardinal);
    border: none;
    border-radius: var(--radius);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}
.new-chat-btn:hover { background: var(--cardinal-dark); }
.session-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.session-item-row {
    display: flex;
    align-items: center;
    border-radius: calc(var(--radius) - 4px);
    transition: background 0.1s;
}
.session-item-row:hover { background: var(--bg); }
.session-item-row.active { background: var(--bg); font-weight: 500; }
.session-item-link {
    flex: 1;
    min-width: 0;
    display: block;
    padding: 8px 10px;
    text-decoration: none;
    color: var(--fg);
    font-size: 13px;
}
.session-delete {
    visibility: hidden;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 6px;
    padding: 0;
    background: none;
    border: none;
    color: var(--muted-fg);
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
    transition: opacity 0.15s, color 0.15s;
}
.session-delete:hover { color: var(--danger); background: hsl(0 84% 60% / 0.1); }
.session-item-row:hover .session-delete { visibility: visible; opacity: 1; }
.session-title {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-date { font-size: 11px; color: var(--muted-fg); }

.sidebar-footer {
    padding: 8px;
    border-top: 1px solid var(--border);
}
.delete-all-btn, .kill-server-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 4px);
    color: var(--muted-fg);
    font-size: 12px;
    font-family: var(--font);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.delete-all-btn:hover, .kill-server-btn:hover { color: var(--danger); border-color: var(--danger); }
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; }

/* ── Main ────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
}
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

/* ── Welcome ─────────────────────────────────── */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0 40px;
}
.welcome-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cardinal-light);
    border-radius: 50%;
    color: var(--cardinal);
    margin-bottom: 16px;
}
.welcome h2 {
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--fg);
}
.welcome p {
    font-size: 14px;
    color: var(--muted-fg);
    margin: 4px 0 32px;
}
.suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    max-width: 560px;
}
.suggestion {
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.4;
    font-family: var(--font);
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.suggestion:hover {
    background: var(--cardinal-light);
    border-color: hsl(0 40% 80%);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ── Messages ────────────────────────────────── */
.message { margin-bottom: 24px; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.message-user {
    display: flex;
    justify-content: flex-end;
}
.message-user .message-content {
    background: var(--cardinal);
    color: white;
    padding: 10px 16px;
    border-radius: 20px 20px 4px 20px;
    max-width: 70%;
    font-size: 14px;
    line-height: 1.5;
}
.message-user .message-content p { color: white; margin: 0; }

.message-assistant .message-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--fg);
    overflow: hidden;
    max-width: 100%;
}

.message-meta {
    font-size: 11px;
    color: var(--muted-fg);
    font-family: var(--mono);
    margin-top: 8px;
}
.message-user .message-meta { text-align: right; }

/* ── Prose inside assistant messages ─────────── */
.message-assistant .message-content p { margin: 6px 0; }
.message-assistant .message-content h1,
.message-assistant .message-content h2,
.message-assistant .message-content h3 {
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 20px 0 6px;
}
.message-assistant .message-content h1 { font-size: 18px; }
.message-assistant .message-content h2 { font-size: 16px; }
.message-assistant .message-content h3 { font-size: 14px; }
.message-assistant .message-content ul,
.message-assistant .message-content ol { padding-left: 20px; margin: 6px 0; }
.message-assistant .message-content li { margin: 2px 0; }
.message-assistant .message-content strong { font-weight: 600; }
.message-assistant .message-content a { color: var(--fg); text-decoration: underline; text-underline-offset: 2px; }
.message-assistant .message-content code {
    font-family: var(--mono);
    font-size: 12.5px;
    background: var(--muted);
    padding: 1px 5px;
    border-radius: 4px;
}
.message-assistant .message-content pre {
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    overflow-x: auto;
}
.message-assistant .message-content pre code {
    display: block;
    padding: 14px 16px;
    background: hsl(240 10% 4%);
    color: hsl(0 0% 95%);
    border: none;
    border-radius: calc(var(--radius) - 2px);
    font-size: 13px;
    line-height: 1.6;
}

/* ── Tables ──────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    padding: 8px 14px;
    text-align: left;
    font-weight: 500;
    font-size: 12px;
    color: var(--muted-fg);
    background: var(--muted);
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 12.5px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--muted); }

/* ── Artifacts ───────────────────────────────── */
.artifact-container { margin: 14px 0; }
.message-content img,
.artifact-image {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
}
.artifact-video {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
}
.artifact-actions {
    font-size: 12px;
    color: var(--muted-fg);
    margin-top: 6px;
}
.artifact-actions a {
    color: var(--fg);
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ── Tool blocks (collapsible) ───────────────── */
.tool-block {
    margin: 8px 0;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    overflow: hidden;
    font-size: 13px;
}
.tool-block[open] { background: var(--muted); }
.tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted-fg);
    list-style: none;
    user-select: none;
}
.tool-header::-webkit-details-marker { display: none; }
.tool-header::before {
    content: '>';
    font-size: 10px;
    color: var(--muted-fg);
    transition: transform 0.1s;
}
.tool-block[open] .tool-header::before { transform: rotate(90deg); }
.tool-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tool-output {
    border-top: 1px solid var(--border);
}
.tool-output-pre {
    margin: 0;
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--fg);
    background: var(--bg);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}
.tool-spinner {
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--border);
    border-top-color: var(--fg);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}
.tool-spinner.done {
    animation: none;
    border-color: transparent;
    background: var(--success);
    width: 10px;
    height: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-text {
    color: var(--danger);
    font-weight: 500;
    margin: 8px 0;
}

/* ── Streaming text ──────────────────────────── */
.streaming-text {
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.7;
    color: var(--fg);
}

/* ── Input area ──────────────────────────────── */
.chat-input-container { padding: 8px 0 20px; }

.input-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    padding: 0 2px;
}

.model-select {
    appearance: none;
    -webkit-appearance: none;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted-fg);
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 4px);
    padding: 4px 24px 4px 8px;
    cursor: pointer;
    flex-shrink: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    transition: border-color 0.1s;
}
.model-select:hover { border-color: var(--ring); }
.model-select:focus { outline: none; border-color: var(--ring); }

/* ── Toggle switch ───────────────────────────── */
.light-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    flex-shrink: 0;
}
.light-toggle input[type="checkbox"] {
    display: none;
}
.toggle-track {
    width: 28px;
    height: 16px;
    background: var(--border);
    border-radius: 8px;
    position: relative;
    transition: background 0.2s;
}
.toggle-thumb {
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.light-toggle input:checked ~ .toggle-track {
    background: var(--cardinal);
}
.light-toggle input:checked ~ .toggle-track .toggle-thumb {
    transform: translateX(12px);
}
.light-label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted-fg);
    user-select: none;
}

/* ── Input row ───────────────────────────────── */
.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px 8px 14px;
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input-row:focus-within {
    border-color: var(--ring);
    box-shadow: 0 0 0 1px var(--ring);
}
#message-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    max-height: 150px;
    color: var(--fg);
    background: transparent;
}
#message-input::placeholder { color: var(--muted-fg); }
.send-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cardinal);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.send-btn:hover { background: var(--cardinal-dark); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; }

.stop-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--danger);
    color: var(--primary-fg);
    border: none;
    border-radius: calc(var(--radius) - 4px);
    cursor: pointer;
    flex-shrink: 0;
}
.stop-btn:hover { opacity: 0.85; }
.stop-btn svg { width: 16px; height: 16px; }

.status-bar {
    font-size: 12px;
    color: var(--muted-fg);
    text-align: center;
    margin-top: 6px;
    min-height: 16px;
    font-family: var(--mono);
}

/* ── Highlight ───────────────────────────────── */
.highlight { border-radius: calc(var(--radius) - 2px); margin: 10px 0; }
.highlight pre { padding: 14px 16px; margin: 0; overflow-x: auto; }

/* ── Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .suggestions { grid-template-columns: 1fr; }
    .chat-container { padding: 0 16px; }
}
