:root {
    --bg: #f5f5f2;
    --card: #ffffff;
    --text: #1d1d1b;
    --muted: #6b6b66;
    --line: #d9d9d3;
    --accent: #2f5fb3;
    --accent-text: #ffffff;
    --error-bg: #fbe9e7;
    --error: #a0281b;
    --ok-bg: #e6f3e8;
    --ok: #1d6a2e;
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #161615;
        --card: #222220;
        --text: #ececea;
        --muted: #a2a29c;
        --line: #3a3a37;
        --accent: #7aa2e8;
        --accent-text: #10131a;
        --error-bg: #3a1d19;
        --error: #f2a196;
        --ok-bg: #18301d;
        --ok: #93d3a0;
    }
}
* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; }
.who { color: var(--muted); }
main { padding: 48px 16px; }
.card {
    max-width: 400px;
    margin: 0 auto;
    padding: 28px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
}
h1 { margin: 0 0 16px; font-size: 1.5rem; font-weight: 600; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 4px; font-weight: 500; }
small { color: var(--muted); font-weight: 400; }
input {
    font: inherit;
    padding: 9px 11px;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .button {
    font: inherit;
    font-weight: 500;
    padding: 9px 16px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}
.button.secondary { background: transparent; color: var(--accent); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; align-items: center; margin-top: 8px; }
.actions form { display: block; }
.msg { padding: 10px 12px; border-radius: 6px; margin: 0 0 16px; }
.msg.error { background: var(--error-bg); color: var(--error); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.hint { color: var(--muted); font-size: 0.875rem; margin: 18px 0 0; }
a { color: var(--accent); }

/* ---- shared header pieces ---- */
a.brand { color: var(--text); text-decoration: none; }

/* ---- avatar menu ---- */
.user-menu { position: relative; }
.user-menu > summary { list-style: none; }
.user-menu > summary::-webkit-details-marker { display: none; }
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 50%;
    font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em;
    color: #fff; user-select: none;
}
.avatar.large { width: 40px; height: 40px; font-size: 0.9375rem; }
summary.avatar { cursor: pointer; }
summary.avatar:hover, .user-menu[open] > summary.avatar { box-shadow: 0 0 0 3px var(--line); }
summary.avatar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-c0 { background: #2f5fb3; } .avatar-c1 { background: #1d7a5c; }
.avatar-c2 { background: #a2482a; } .avatar-c3 { background: #7a4bb0; }
.avatar-c4 { background: #b0306a; } .avatar-c5 { background: #2c7d94; }
.avatar-c6 { background: #7a6a1d; } .avatar-c7 { background: #5a6170; }
.menu {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 10;
    min-width: 220px; padding: 6px;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
    display: grid; gap: 2px;
}
.menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head .who { font-weight: 600; color: var(--text); }
.menu form { display: block; }
.menu a, .menu button {
    display: block; width: 100%; text-align: left;
    padding: 8px 10px; border-radius: 6px; border: none; background: none;
    font: inherit; font-size: 0.9375rem; font-weight: 400; color: var(--text); text-decoration: none; cursor: pointer;
}
.menu a:hover, .menu button:hover, .menu a:focus-visible, .menu button:focus-visible { background: var(--bg); outline: none; }

/* ---- documents list ---- */
.docs { max-width: 720px; margin: 0 auto; }
.docs-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.docs-head h1 { margin: 0; }
.doc-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; }
.doc-list li + li { border-top: 1px solid var(--line); }
.doc-list a { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); text-decoration: none; }
.doc-list a:hover { background: var(--bg); }
.doc-list .doc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.doc-list time { color: var(--muted); font-size: 0.875rem; white-space: nowrap; }
.doc-icon { width: 16px; height: 20px; flex: none; border: 1.5px solid var(--accent); border-radius: 2px; position: relative; }
.doc-icon::after { content: ""; position: absolute; left: 3px; right: 3px; top: 5px; height: 6px; border-top: 1.5px solid var(--accent); border-bottom: 1.5px solid var(--accent); }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

/* ---- document page ---- */
body.doc-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body.doc-page main { flex: 1; min-height: 0; padding: 0; }
.doc-bar { gap: 12px; justify-content: flex-start; padding: 8px 16px; }
.doc-bar .spacer { flex: 1; }
.doc-name-input {
    font-size: 1.125rem; font-weight: 500;
    padding: 3px 6px; border: 1px solid transparent; border-radius: 4px; background: transparent;
    field-sizing: content; min-width: 8ch; max-width: 45vw; width: 30ch;
    text-overflow: ellipsis;
}
@supports (field-sizing: content) { .doc-name-input { width: auto; } }
.doc-name-input:hover { border-color: var(--line); }
.doc-name-input:focus { border-color: var(--accent); outline: none; background: var(--card); }
.save-status { color: var(--muted); font-size: 0.8125rem; white-space: nowrap; }
.save-status.error { color: var(--error); }
.doc-bar .button { padding: 5px 12px; font-size: 0.875rem; }

.split {
    --chat: 35%;
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 7px var(--chat);
}
.pane { min-width: 0; min-height: 0; overflow: auto; }
.doc-pane { background: var(--bg); display: flex; flex-direction: column; overflow: hidden; position: relative; }
.page {
    max-width: 816px; min-height: calc(100% - 8px); margin: 0 auto; padding: 56px 64px;
    background: var(--card); border: 1px solid var(--line); border-radius: 4px;
}
.divider {
    cursor: col-resize; background: var(--line); position: relative; touch-action: none;
    border-left: 3px solid var(--bg); border-right: 3px solid var(--bg); background-clip: padding-box;
}
.divider:hover, .divider:focus-visible, body.resizing .divider { background-color: var(--accent); outline: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .pane { pointer-events: none; }
@media (max-width: 700px) {
    .split { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 55%); }
    .divider { display: none; }
    .page { padding: 24px; }
    .tab-panel { padding: 12px; }
    .doc-tab span { display: none; }
    .doc-tab[aria-selected="true"] span { display: inline; }
    .doc-name-input { max-width: 40vw; }
}

/* =====================================================================
   Document view and chat (chat.js)
   ===================================================================== */
:root {
    --clay: #d4704a;            /* Claude's accent, for the assistant */
    --clay-soft: #f8e6dd;
    --user-from: #3a6fd8;
    --user-to: #5b4fd6;
    --chat-bg: #fbfaf8;
    --code-bg: #f1f0ec;
    --add-bg: #e3f4e6; --add: #1d6a2e;
    --del-bg: #fbe7e4; --del: #a0281b;
    --changed: #fff3c4;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.06), 0 1px 1px rgb(0 0 0 / 0.04);
    --shadow-md: 0 6px 24px rgb(0 0 0 / 0.10), 0 2px 6px rgb(0 0 0 / 0.06);
}
@media (prefers-color-scheme: dark) {
    :root {
        --clay: #e08a66;
        --clay-soft: #3a2820;
        --user-from: #4a7be0;
        --user-to: #6a5fe0;
        --chat-bg: #1c1c1a;
        --code-bg: #2b2b28;
        --add-bg: #17301c; --add: #93d3a0;
        --del-bg: #3a1d19; --del: #f2a196;
        --changed: #4a3f12;
        --shadow-md: 0 6px 24px rgb(0 0 0 / 0.45), 0 2px 6px rgb(0 0 0 / 0.3);
    }
}

/* ---- the rendered document ---- */
.markdown-body { line-height: 1.65; overflow-wrap: anywhere; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { line-height: 1.25; margin: 1.4em 0 0.5em; font-weight: 650; }
.markdown-body h1 { font-size: 1.9rem; letter-spacing: -0.01em; }
.markdown-body h2 { font-size: 1.45rem; }
.markdown-body h3 { font-size: 1.2rem; }
.markdown-body p, .markdown-body ul, .markdown-body ol, .markdown-body dl, .markdown-body blockquote, .markdown-body pre, .markdown-body table { margin: 0 0 0.9em; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5em; }
.markdown-body li + li { margin-top: 0.2em; }
.markdown-body blockquote { margin-left: 0; padding: 0.2em 1em; border-left: 3px solid var(--line); color: var(--muted); }
.markdown-body code { font: 0.88em/1.4 ui-monospace, "SF Mono", Menlo, monospace; background: var(--code-bg); padding: 0.12em 0.35em; border-radius: 4px; }
.markdown-body pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow: auto; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body table { border-collapse: collapse; display: block; overflow-x: auto; }
.markdown-body th, .markdown-body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.markdown-body th { background: var(--code-bg); font-weight: 600; }
.markdown-body dt { font-weight: 600; }
.markdown-body dd { margin: 0 0 0.6em 1.2em; }
.markdown-body mark { background: #fbe38e; color: inherit; padding: 0 0.15em; border-radius: 3px; }
.markdown-body hr { border: none; border-top: 1px solid var(--line); margin: 1.6em 0; }
.markdown-body .footnotes { font-size: 0.88em; color: var(--muted); }
.markdown-body .footnotes-sep { margin-top: 2em; }
.markdown-body img { max-width: 100%; }

.page.markdown-body { font-size: 1.02rem; }
.doc-page .page > .changed { animation: changed 2.6s ease-out; border-radius: 4px; }
@keyframes changed {
    0%, 35% { background: var(--changed); box-shadow: 0 0 0 6px var(--changed); }
    100% { background: transparent; box-shadow: 0 0 0 6px transparent; }
}
.doc-empty { text-align: center; color: var(--muted); padding: 18vh 12px 0; }
.doc-empty h2 { color: var(--text); margin: 14px 0 6px; font-size: 1.25rem; }
.doc-empty p { max-width: 340px; margin: 0 auto; }
.doc-empty-mark, .chat-empty-mark {
    width: 52px; height: 52px; margin: 0 auto; border-radius: 16px; color: #fff;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #e48a62, #c95f3d);
    box-shadow: 0 6px 18px rgb(201 95 61 / 0.35);
}
.doc-empty-mark svg, .chat-empty-mark svg { width: 28px; height: 28px; }
.split.chat-running .page { box-shadow: 0 0 0 1px var(--clay-soft), 0 0 0 4px color-mix(in srgb, var(--clay) 12%, transparent); transition: box-shadow 0.3s; }

/* ---- chat pane ---- */
.chat-pane { display: flex; flex-direction: column; background: var(--chat-bg); }
.chat-head {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card);
}
.chat-switch { position: relative; flex: 1; min-width: 0; }
.chat-switch-button {
    display: flex; align-items: center; gap: 8px; max-width: 100%;
    padding: 6px 10px 6px 6px; border-radius: 8px;
    background: transparent; border: 1px solid transparent; color: var(--text); font-weight: 600;
}
.chat-switch-button:hover, .chat-switch-button[aria-expanded="true"] { background: var(--bg); border-color: var(--line); }
.chat-mark { width: 26px; height: 26px; flex: none; border-radius: 8px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #e48a62, #c95f3d); }
.chat-mark svg { width: 16px; height: 16px; }
.chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev svg { width: 16px; height: 16px; color: var(--muted); display: block; }
.icon-button {
    width: 34px; height: 34px; padding: 0; flex: none; display: grid; place-items: center;
    border-radius: 8px; background: transparent; border: 1px solid var(--line); color: var(--text);
}
.icon-button svg { width: 18px; height: 18px; }
.icon-button:hover:not(:disabled) { background: var(--bg); }
.icon-button:disabled { opacity: 0.4; cursor: default; }

.chat-list {
    position: absolute; left: 0; top: calc(100% + 6px); z-index: 20;
    width: min(360px, 90vw); max-height: 60vh; overflow: auto; padding: 6px;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-md);
}
.chat-item { display: flex; align-items: center; border-radius: 8px; }
.chat-item:hover, .chat-item.current { background: var(--bg); }
.chat-item.current .chat-item-title { color: var(--accent); }
.chat-item-open, .chat-item.new {
    flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; text-align: left;
    padding: 9px 10px; background: none; border: none; color: var(--text); font-weight: 400; border-radius: 8px;
}
.chat-item.new { width: 100%; font-weight: 600; color: var(--accent); border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; margin-bottom: 4px; }
.chat-item.new:hover { background: var(--bg); }
.chat-item .plus { font-size: 1.1em; margin-right: 2px; }
.chat-item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-when { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.chat-item-delete {
    width: 28px; height: 28px; margin-right: 4px; padding: 0; border-radius: 6px;
    background: none; border: none; color: var(--muted); font-size: 1.15rem; line-height: 1; opacity: 0;
}
.chat-item:hover .chat-item-delete, .chat-item-delete:focus-visible { opacity: 1; }
.chat-item-delete:hover { background: var(--del-bg); color: var(--del); }
.chat-list-empty { color: var(--muted); font-size: 0.875rem; padding: 10px; }

.chat-log { flex: 1; overflow-y: auto; padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; }

/* empty state */
.chat-empty { margin: auto 0; text-align: center; padding: 24px 8px; }
.chat-empty h2 { margin: 16px 0 6px; font-size: 1.2rem; }
.chat-empty p { color: var(--muted); margin: 0 auto 18px; max-width: 320px; font-size: 0.94rem; }
.suggestions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; max-width: 360px; margin: 0 auto; }
.suggestion {
    text-align: left; font-weight: 400; font-size: 0.92rem; color: var(--text);
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
    box-shadow: var(--shadow-sm); transition: border-color 0.15s, transform 0.15s;
}
.suggestion:hover { border-color: var(--clay); transform: translateY(-1px); }

/* messages */
.msg-row { display: flex; gap: 10px; animation: rise 0.22s ease-out; }
.msg-row.user { justify-content: flex-end; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bubble.user {
    max-width: 85%; padding: 10px 14px; border-radius: 18px 18px 4px 18px;
    background: linear-gradient(135deg, var(--user-from), var(--user-to)); color: #fff;
    white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 2px 8px rgb(74 90 216 / 0.25);
}
.avatar-claude {
    width: 30px; height: 30px; flex: none; border-radius: 10px; margin-top: 2px;
    display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, #e48a62, #c95f3d);
}
.avatar-claude svg { width: 18px; height: 18px; }
.answer { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.answer-text {
    background: var(--card); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px;
    padding: 10px 14px; box-shadow: var(--shadow-sm); font-size: 0.95rem;
}
.answer-text:empty { display: none; }
.answer-text h1 { font-size: 1.3rem; } .answer-text h2 { font-size: 1.15rem; } .answer-text h3 { font-size: 1.05rem; }
.answer-meta { color: var(--muted); font-size: 0.75rem; padding-left: 4px; }

/* tool rows */
.tool-row { border-radius: 10px; font-size: 0.86rem; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.tool-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; list-style: none; }
.tool-row.edit > summary { cursor: pointer; }
.tool-row.edit > summary::-webkit-details-marker { display: none; }
.tool-row.edit > summary:hover { background: var(--bg); }
.tool-icon { width: 22px; height: 22px; flex: none; border-radius: 6px; display: grid; place-items: center; }
.tool-icon svg { width: 14px; height: 14px; }
.tool-row.edit .tool-icon { background: var(--clay-soft); color: var(--clay); }
.tool-row.read .tool-icon { background: var(--bg); color: var(--muted); }
.tool-row.read { background: transparent; border-style: dashed; color: var(--muted); }
.tool-verb { flex: 1; font-weight: 500; }
.delta { font: 600 0.78rem ui-monospace, Menlo, monospace; padding: 1px 6px; border-radius: 999px; }
.delta.add { background: var(--add-bg); color: var(--add); }
.delta.del { background: var(--del-bg); color: var(--del); }
.tool-state { width: 14px; height: 14px; flex: none; border-radius: 50%; }
.tool-row:not(.pending):not(.failed) .tool-state { background: var(--add); mask: url("/static/check.svg") center/contain no-repeat; }
.tool-row.pending .tool-state { border: 2px solid var(--line); border-top-color: var(--clay); animation: spin 0.8s linear infinite; }
.tool-row.failed .tool-state { background: var(--del); border-radius: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-diff { border-top: 1px solid var(--line); max-height: 260px; overflow: auto; }
.tool-diff pre { margin: 0; padding: 8px 12px; font: 0.8rem/1.45 ui-monospace, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff-del { background: var(--del-bg); color: var(--del); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--del) 40%, transparent); }
.diff-add { background: var(--add-bg); color: var(--add); }

/* waiting indicators */
.typing { display: inline-flex; gap: 5px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px; width: fit-content; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--clay); animation: bounce 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-5px); opacity: 1; } }
.thinking { font-size: 0.88rem; padding: 4px 2px; }
.shimmer {
    background: linear-gradient(90deg, var(--muted) 0%, var(--clay) 50%, var(--muted) 100%);
    background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
    animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.notice { font-size: 0.86rem; padding: 8px 12px; border-radius: 10px; }
.notice.error { background: var(--error-bg); color: var(--error); }
.notice.muted { color: var(--muted); padding: 2px 4px; }

/* composer */
.composer { padding: 10px 12px 8px; background: var(--chat-bg); display: block; }
.composer-box {
    background: var(--card); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: var(--shadow-sm); padding: 10px 10px 8px 14px; transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within { border-color: color-mix(in srgb, var(--clay) 60%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--clay) 14%, transparent); }
.composer textarea {
    width: 100%; resize: none; border: none; outline: none; background: transparent; padding: 2px 0;
    font: inherit; font-size: 0.95rem; line-height: 1.45; color: var(--text); max-height: 220px;
}
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.model-tag { flex: 1; display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; color: var(--muted); }
.model-tag svg { width: 13px; height: 13px; color: var(--clay); }
.send-button {
    width: 34px; height: 34px; padding: 0; border-radius: 50%; display: grid; place-items: center;
    border: none; background: var(--clay); color: #fff; transition: transform 0.12s, opacity 0.12s;
}
.send-button svg { width: 18px; height: 18px; }
.send-button:hover:not(:disabled) { transform: scale(1.06); }
.send-button:disabled { opacity: 0.35; cursor: default; }
.send-button.stop { background: var(--text); color: var(--card); }
.send-button[hidden] { display: none; }
.composer-hint { margin: 6px 4px 0; font-size: 0.72rem; color: var(--muted); text-align: center; }

/* =====================================================================
   Left-side tabs: Document · Agent Instructions · Data Sources (panes.js)
   ===================================================================== */
.doc-tabs {
    display: flex; gap: 2px; padding: 8px 16px 0; flex: none;
    border-bottom: 1px solid var(--line); background: var(--bg);
    overflow-x: auto; scrollbar-width: none;
}
.doc-tab {
    display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
    padding: 8px 14px 9px; margin-bottom: -1px; border-radius: 8px 8px 0 0;
    background: transparent; color: var(--muted); font-weight: 500; font-size: 0.9rem;
    border: 1px solid transparent; border-bottom: none;
}
.doc-tab svg { width: 16px; height: 16px; flex: none; }
.doc-tab:hover { color: var(--text); background: color-mix(in srgb, var(--card) 60%, transparent); }
.doc-tab[aria-selected="true"] { color: var(--text); background: var(--card); border-color: var(--line); box-shadow: 0 -2px 0 var(--accent) inset; }
.doc-tab[aria-selected="true"] svg { color: var(--accent); }
.doc-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-count {
    min-width: 20px; padding: 1px 6px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; text-align: center;
    background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.tab-count.bump { animation: bump 0.6s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 30% { transform: scale(1.35); } 100% { transform: scale(1); } }
.tab-panel { flex: 1; min-height: 0; overflow: auto; padding: 24px; }
.tab-panel[hidden] { display: none; }

/* a "sheet": the card that holds the instructions and the sources */
.sheet {
    max-width: 816px; margin: 0 auto; padding: 28px 32px;
    background: var(--card); border: 1px solid var(--line); border-radius: 4px;
    display: flex; flex-direction: column; gap: 16px; min-height: calc(100% - 8px);
}
.sheet-head { display: flex; align-items: flex-start; gap: 16px; }
.sheet-head > div { flex: 1; }
.sheet-head h2 { margin: 0 0 4px; font-size: 1.3rem; }
.sheet-head p { margin: 0; color: var(--muted); font-size: 0.92rem; max-width: 560px; }
.sheet-head code, .sheet-foot code { font-size: 0.85em; background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; }
.sheet-foot { margin: 0; color: var(--muted); font-size: 0.8rem; }

.instructions-editor {
    flex: 1; min-height: 320px; resize: none; width: 100%;
    font: 0.92rem/1.6 ui-monospace, "SF Mono", Menlo, monospace; color: var(--text);
    background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px;
}
.instructions-editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }

.file-button { cursor: pointer; white-space: nowrap; padding: 7px 14px; font-size: 0.9rem; }
.file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* the list of data sources */
.sources-list { display: flex; flex-direction: column; gap: 10px; }
.sources-empty {
    border: 2px dashed var(--line); border-radius: 12px; padding: 48px 24px; text-align: center; color: var(--muted);
}
.sources-empty svg { width: 40px; height: 40px; color: var(--accent); opacity: 0.7; }
.sources-empty strong { display: block; color: var(--text); margin: 10px 0 4px; font-size: 1.05rem; }
.source {
    display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
    padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.source:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); box-shadow: var(--shadow-sm); }
.source-badge {
    width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
    font: 700 0.72rem ui-monospace, Menlo, monospace; letter-spacing: 0.04em; color: #fff;
}
.source-badge.nt { background: linear-gradient(135deg, #3a8f6e, #23714f); }
.source-badge.nq { background: linear-gradient(135deg, #6a5fd6, #4a3fb3); }
.source-main { min-width: 0; }
.source-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-name-input { font: inherit; font-weight: 600; width: 100%; padding: 2px 6px; margin: -3px -7px; border: 1px solid var(--accent); border-radius: 6px; background: var(--card); color: var(--text); }
.source-meta { color: var(--muted); font-size: 0.82rem; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.source-actions { display: flex; gap: 4px; }
.source-actions button {
    width: 32px; height: 32px; padding: 0; display: grid; place-items: center; border-radius: 8px;
    background: transparent; border: 1px solid transparent; color: var(--muted);
}
.source-actions button svg { width: 16px; height: 16px; }
.source-actions button:hover { background: var(--bg); border-color: var(--line); color: var(--text); }
.source-actions button.danger:hover { background: var(--del-bg); border-color: transparent; color: var(--del); }
.source.uploading .source-meta { color: var(--accent); }
.source.failed { border-color: var(--del); }
.source.failed .source-meta { color: var(--del); }
.progress { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* drag and drop */
.drop-overlay {
    position: absolute; inset: 0; z-index: 30; display: grid; place-items: center;
    background: color-mix(in srgb, var(--accent) 12%, transparent); backdrop-filter: blur(2px);
    border: 3px dashed var(--accent); border-radius: 6px; pointer-events: none;
}
.drop-overlay[hidden] { display: none; }
.drop-card {
    display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 36px;
    background: var(--card); border-radius: 16px; box-shadow: var(--shadow-md); color: var(--muted);
}
.drop-card svg { width: 44px; height: 44px; color: var(--accent); }
.drop-card strong { color: var(--text); font-size: 1.1rem; }
.toast {
    position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 31;
    padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--card); font-size: 0.9rem;
    box-shadow: var(--shadow-md); animation: rise 0.2s ease-out;
}
.toast.error { background: var(--del); color: #fff; }
