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

:root
{
    --bg:          #0e0f11;
    --surface:     #16181c;
    --surface2:    #1e2026;
    --border:      #2a2d35;
    --accent:      #c8a96e;
    --accent-dim:  #7a6440;
    --text:        #d4cfc8;
    --text-dim:    #6b6760;
    --text-bright: #f0ebe3;
    --user-bubble: #1a2235;
    --ai-bubble:   #1a1f18;
    --danger:      #8b3a3a;
    --success:     #3a6b4a;
    --font-mono:   'Geist Mono', monospace;
    --font-serif:  'Instrument Serif', serif;
    --chat-font:   'Geist Mono', monospace;
    --chat-size:   13px;
    --radius:      6px;
    --header-h:    48px;
    --tab-h:       38px;
}

html, body
{
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    overflow: hidden;
}

/* ── Layout ─────────────────────────────────────── */

#app
{
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#header
{
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    flex-shrink: 0;
}

#header .logo
{
    font-family: var(--font-serif);
    font-size: 18px;
    color: var(--accent);
    letter-spacing: 0.02em;
    font-style: italic;
}

#header .project-name
{
    color: var(--text-dim);
    font-size: 12px;
}

#header .spacer { flex: 1; }

#main
{
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Left Pane ───────────────────────────────────── */

#left-pane
{
    display: flex;
    flex-direction: column;
    width: 55%;
    min-width: 300px;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

#file-tabs
{
    height: var(--tab-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    padding: 0 8px;
    gap: 2px;
    overflow-x: auto;
    flex-shrink: 0;
}

#file-tabs::-webkit-scrollbar { height: 3px; }
#file-tabs::-webkit-scrollbar-thumb { background: var(--border); }

.tab
{
    padding: 6px 14px;
    font-size: 11px;
    color: var(--text-dim);
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s;
    background: transparent;
    font-family: var(--font-mono);
}

.tab:hover { color: var(--text); }

.tab.active
{
    color: var(--accent);
    background: var(--bg);
    border-color: var(--border);
}

.tab .tab-close
{
    margin-left: 6px;
    color: var(--text-dim);
    font-size: 10px;
}

.tab .tab-close:hover { color: var(--danger); }

#add-context-tab
{
    padding: 6px 10px;
    font-size: 16px;
    color: var(--text-dim);
    cursor: pointer;
    line-height: 1;
    align-self: center;
    transition: color 0.15s;
    background: none;
    border: none;
    font-family: var(--font-mono);
}

#add-context-tab:hover { color: var(--accent); }

#editor-container
{
    flex: 1;
    overflow: hidden;
}

#left-toolbar
{
    height: 40px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Right Pane ──────────────────────────────────── */

#right-pane
{
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
}

#chat-toolbar
{
    height: 40px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    flex-shrink: 0;
}

#chat-history
{
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#chat-history::-webkit-scrollbar { width: 4px; }
#chat-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message
{
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-header
{
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-role
{
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.message-actions
{
    display: none;
    gap: 4px;
    margin-left: auto;
}

.message:hover .message-actions,
.message.active .message-actions { display: flex; }

.message-bubble
{
    padding: 10px 14px;
    border-radius: var(--radius);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--chat-font);
    font-size: var(--chat-size);
}

.message.user .message-bubble
{
    background: var(--user-bubble);
    border: 1px solid #253050;
    color: var(--text-bright);
}

.message.assistant .message-bubble
{
    background: var(--ai-bubble);
    border: 1px solid #252e20;
    color: var(--text);
}

#chat-input-area
{
    padding: 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

#chat-input
{
    width: 100%;
    min-height: 72px;
    max-height: 200px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-bright);
    font-family: var(--chat-font);
    font-size: var(--chat-size);
    padding: 10px 14px;
    resize: vertical;
    outline: none;
    line-height: 1.6;
    transition: border-color 0.15s;
}

#chat-input:focus { border-color: var(--accent-dim); }

#chat-input-row
{
    display: flex;
    align-items: center;
    gap: 8px;
}

#chat-input-row .spacer { flex: 1; }

/* ── Buttons ─────────────────────────────────────── */

.btn
{
    padding: 6px 14px;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:hover
{
    border-color: var(--accent-dim);
    color: var(--accent);
}

.btn.primary
{
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.btn.primary:hover
{
    background: var(--accent);
    color: var(--bg);
}

.btn.danger
{
    border-color: var(--danger);
    color: #c06060;
}

.btn.danger:hover
{
    background: var(--danger);
    color: var(--text-bright);
}

.btn.small
{
    padding: 3px 9px;
    font-size: 11px;
}

.btn:disabled
{
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Modals ──────────────────────────────────────── */

.modal-overlay
{
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal
{
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 400px;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal h2
{
    font-family: var(--font-serif);
    font-size: 18px;
    color: var(--accent);
    font-style: italic;
}

.modal label
{
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.modal input, .modal select
{
    padding: 8px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.modal input:focus, .modal select:focus { border-color: var(--accent-dim); }

.modal-actions
{
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Status bar ──────────────────────────────────── */

#status-bar
{
    height: 24px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 16px;
    font-size: 11px;
    color: var(--text-dim);
    flex-shrink: 0;
}

#status-bar .status-msg { color: var(--accent); }

/* ── Git log panel ───────────────────────────────── */

#git-panel
{
    display: none;
    position: fixed;
    right: 0;
    top: var(--header-h);
    bottom: 24px;
    width: 340px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    flex-direction: column;
    z-index: 100;
}

#git-panel.open { display: flex; }

#git-panel-header
{
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

#git-panel-header .spacer { flex: 1; }

#git-log
{
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

#git-log::-webkit-scrollbar { width: 4px; }
#git-log::-webkit-scrollbar-thumb { background: var(--border); }

.git-commit
{
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.12s;
    margin-bottom: 4px;
}

.git-commit:hover
{
    background: var(--surface2);
    border-color: var(--border);
}

.git-commit .commit-hash
{
    font-size: 10px;
    color: var(--accent-dim);
    font-family: var(--font-mono);
}

.git-commit .commit-msg
{
    font-size: 12px;
    color: var(--text);
    margin-top: 2px;
}

.git-commit .commit-date
{
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* ── Splitter ─────────────────────────────────────── */

#splitter
{
    width: 4px;
    background: var(--border);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.15s;
}

#splitter:hover { background: var(--accent-dim); }

/* ── Sticky message header ───────────────────────── */

.message-header
{
    display: flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: -17px;
    z-index: 10;
    padding: 3px 0;
    /* Solid background matching the chat pane so content scrolling behind is hidden */
    background: var(--bg);
    /* Bleed the background edge-to-edge to cover the padding gap */
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
}

#message-editor-pane
{
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#message-editor-pane.active { display: flex; }

#message-editor-toolbar
{
    height: 40px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    flex-shrink: 0;
}

#message-editor-toolbar .role-label
{
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

#message-editor-textarea
{
    flex: 1;
    background: var(--bg);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 16px;
    resize: none;
    outline: none;
    line-height: 1.7;
    overflow-y: auto;
}

#message-editor-footer
{
    height: 40px;
    background: var(--surface);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    flex-shrink: 0;
}

#message-editor-footer .spacer { flex: 1; }

.spinner
{
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Markdown in bubbles and preview ────────────── */

.message-bubble,
.markdown-content                { line-height: 1.7; }

.message-bubble p,
.markdown-content p              { margin: 0 0 0.7em 0; }
.message-bubble p:last-child,
.markdown-content p:last-child   { margin-bottom: 0; }

.message-bubble h1,
.markdown-content h1,
.message-bubble h2,
.markdown-content h2,
.message-bubble h3,
.markdown-content h3             { font-family: var(--font-serif); color: var(--accent); margin: 1em 0 0.4em 0; font-style: italic; }
.message-bubble h1,
.markdown-content h1             { font-size: 1.4em; }
.message-bubble h2,
.markdown-content h2             { font-size: 1.2em; }
.message-bubble h3,
.markdown-content h3             { font-size: 1.05em; }

.message-bubble ul,
.markdown-content ul,
.message-bubble ol,
.markdown-content ol             { padding-left: 1.4em; margin: 0.4em 0; }
.message-bubble li,
.markdown-content li             { margin: 0.25em 0; }

.message-bubble code,
.markdown-content code           { background: var(--surface2); padding: 1px 5px; border-radius: 3px; font-family: var(--font-mono); font-size: 0.88em; }
.message-bubble pre,
.markdown-content pre            { background: var(--surface2); padding: 10px 14px; border-radius: var(--radius); overflow-x: auto; margin: 0.6em 0; }
.message-bubble pre code,
.markdown-content pre code       { background: none; padding: 0; }

.message-bubble blockquote,
.markdown-content blockquote     { border-left: 2px solid var(--accent-dim); margin: 0.4em 0; padding: 2px 10px; color: var(--text-dim); font-size: 0.9em; }
.message-bubble blockquote p,
.markdown-content blockquote p   { margin: 0; }

.message-bubble em,
.markdown-content em             { color: var(--text-dim); font-style: italic; }
.message-bubble strong,
.markdown-content strong         { color: var(--text-bright); font-style: normal; }

.message-bubble hr,
.markdown-content hr             { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }
.message-bubble a,
.markdown-content a              { color: var(--accent); text-decoration: underline; }

/* Preview gets more breathing room than chat bubbles */
.markdown-content                { font-size: 13px; color: var(--text); }

#welcome
{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
    color: var(--text-dim);
}

#welcome h1
{
    font-family: var(--font-serif);
    font-size: 32px;
    color: var(--accent);
    font-style: italic;
}

#welcome p { font-size: 12px; max-width: 320px; text-align: center; line-height: 1.7; }


/* ── User input syntax highlighting ─────────────── */

/* Ensure user bubble em (private thoughts) stays dimmed even with markdown rules */
.message.user .message-bubble em { color: var(--text-dim); font-style: italic; }


/* ── Markdown spacing variants ───────────────────── */

/* Tight: minimal spacing, dense reading */
#chat-history.md-tight .message-bubble   { line-height: 1.3; }
#chat-history.md-tight .message-bubble p { margin: 0; }
#chat-history.md-tight .message-bubble h1,
#chat-history.md-tight .message-bubble h2,
#chat-history.md-tight .message-bubble h3 { margin: 0.25em 0 0.1em 0; }
#chat-history.md-tight .message-bubble ul,
#chat-history.md-tight .message-bubble ol { margin: 0; }
#chat-history.md-tight .message-bubble li { margin: 0; }
#chat-history.md-tight .message-bubble blockquote { margin: 0.1em 0; }
#chat-history.md-tight .message-bubble hr { margin: 0.2em 0; }

/* Comfortable: current default — no overrides needed */

/* Spacious: generous spacing, airy reading */
#chat-history.md-spacious .message-bubble   { line-height: 1.9; }
#chat-history.md-spacious .message-bubble p { margin: 0 0 1.1em 0; }
#chat-history.md-spacious .message-bubble h1,
#chat-history.md-spacious .message-bubble h2,
#chat-history.md-spacious .message-bubble h3 { margin: 1.4em 0 0.6em 0; }
#chat-history.md-spacious .message-bubble ul,
#chat-history.md-spacious .message-bubble ol { margin: 0.6em 0; }
#chat-history.md-spacious .message-bubble li { margin: 0.4em 0; }
#chat-history.md-spacious .message-bubble blockquote { margin: 0.7em 0; padding: 4px 14px; }
#chat-history.md-spacious .message-bubble hr { margin: 1.2em 0; }

/* ── Driver.js tour popover styling ─────────────── */

.studio-tour-popover.driver-popover
{
    background:    var(--surface);
    border:        1px solid var(--accent-dim);
    border-radius: var(--radius);
    color:         var(--text);
    font-family:   var(--font-mono);
    font-size:     13px;
    max-width:     380px;
}

.studio-tour-popover .driver-popover-title
{
    font-family: var(--font-serif);
    font-style:  italic;
    font-size:   17px;
    color:       var(--accent);
    margin-bottom: 8px;
}

.studio-tour-popover .driver-popover-description
{
    color:       var(--text);
    line-height: 1.6;
}

.studio-tour-popover .driver-popover-description code
{
    background:    var(--surface2);
    padding:       1px 5px;
    border-radius: 3px;
    font-family:   var(--font-mono);
    font-size:     0.88em;
    color:         var(--accent);
}

.studio-tour-popover .driver-popover-footer
{
    margin-top:  12px;
    border-top:  1px solid var(--border);
    padding-top: 10px;
}

.studio-tour-popover .driver-popover-progress-text
{
    color:     var(--text-dim);
    font-size: 11px;
}

.studio-tour-popover button.driver-popover-next-btn,
.studio-tour-popover button.driver-popover-prev-btn,
.studio-tour-popover button.driver-popover-close-btn
{
    background:    var(--surface2);
    border:        1px solid var(--border);
    color:         var(--text);
    border-radius: var(--radius);
    font-family:   var(--font-mono);
    font-size:     12px;
    padding:       4px 12px;
    cursor:        pointer;
    transition:    border-color 0.15s, color 0.15s;
}

.studio-tour-popover button.driver-popover-next-btn
{
    background:  var(--accent);
    border-color: var(--accent);
    color:       var(--bg);
}

.studio-tour-popover button.driver-popover-next-btn:hover
{
    background:  var(--text-bright);
    border-color: var(--text-bright);
}

.studio-tour-popover button.driver-popover-prev-btn:hover,
.studio-tour-popover button.driver-popover-close-btn:hover
{
    border-color: var(--accent);
    color:        var(--accent);
}

/* ── Model browser ───────────────────────────────── */

#models-list table
{
    width:           100%;
    border-collapse: collapse;
    font-size:       12px;
}

#models-list th
{
    text-align:    left;
    padding:       6px 10px;
    border-bottom: 1px solid var(--border);
    color:         var(--text-dim);
    font-size:     10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space:   nowrap;
    position:      sticky;
    top:           0;
    background:    var(--surface);
}

#models-list td
{
    padding:       8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    color:         var(--text);
}

#models-list tr:hover td  { background: var(--surface2); cursor: pointer; }
#models-list tr.selected td { background: var(--accent-dim); }

#models-list .model-id    { color: var(--text-bright); font-weight: 500; }
#models-list .model-ctx   { color: var(--text-dim); white-space: nowrap; }
#models-list .model-price { color: var(--accent); white-space: nowrap; }
#models-list .model-type  { font-size: 10px; color: var(--text-dim); }
