:root {
    color-scheme: light;
    --ink: #1e2925;
    --muted: #68756f;
    --line: #dbe2de;
    --soft-line: #edf1ef;
    --green: #146144;
    --green-dark: #0d4d35;
    --paper: #ffffff;
    --danger: #a34234;
    --blue: #0865d5;
    --bubble: #eef0f3;
}
* { box-sizing: border-box; letter-spacing: 0; }
html, body { width: 100%; height: 100%; }
body { margin: 0; overflow: hidden; color: var(--ink); background: var(--paper); font: 15px/1.5 "Avenir Next", "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
button img { width: 18px; height: 18px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); }
.app-shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); height: 100dvh; }
.history-panel { min-width: 0; border-right: 1px solid var(--line); background: linear-gradient(155deg, #f0f2f5, #f8f9fa); display: flex; flex-direction: column; z-index: 20; }
.rail-heading { min-height: 64px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; }
.brand { width: 76px; height: 38px; overflow: hidden; display: block; border-radius: 6px; background: #202724; color: var(--ink); text-decoration: none; }
.brand img { width: 72px; height: 72px; transform: translateY(-17px); object-fit: contain; }
.icon { width: 40px; height: 40px; min-width: 40px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); display: inline-flex; align-items: center; justify-content: center; }
.icon:hover:not(:disabled) { background: #edf3ef; }
.rail-close { display: none; }
.history-toggle { display: none; }
.new-chat { margin: 8px 14px 20px; height: 42px; padding: 0 14px; border: 1px solid #cbd6d0; border-radius: 6px; background: var(--paper); display: flex; align-items: center; justify-content: flex-start; gap: 10px; font-weight: 650; }
.new-chat:hover:not(:disabled) { border-color: var(--green); background: #f9fcfa; }
.section-label { margin: 0; color: var(--muted); font-size: 10px; font-weight: 750; }
.history-panel > .section-label { padding: 0 20px 9px; }
.chat-history { flex: 1; min-height: 0; overflow: auto; padding: 0 10px 16px; }
.history-empty { margin: 10px; color: var(--muted); font-size: 12px; }
.history-item { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 34px; align-items: center; border-radius: 6px; }
.history-item + .history-item { margin-top: 2px; }
.history-item.active { background: #e0e9f7; }
.history-open, .history-delete { border: 0; background: transparent; }
.history-open { min-width: 0; height: 42px; padding: 0 8px; display: flex; align-items: center; gap: 9px; text-align: left; }
.history-open img { width: 16px; height: 16px; flex: 0 0 16px; opacity: .6; }
.history-open span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.history-delete { width: 32px; height: 32px; padding: 8px; border-radius: 5px; opacity: 0; }
.history-item:hover .history-delete, .history-delete:focus-visible { opacity: .68; }
.history-delete:hover { color: var(--danger); background: #f4e9e6; opacity: 1; }
.rail-footer { padding: 14px; border-top: 1px solid var(--line); }
.repo-link { display: inline-flex; align-items: center; min-height: 28px; margin: 4px 8px 0; color: var(--muted); font-size: 11px; text-underline-offset: 3px; }
.repo-link:hover { color: var(--ink); }
.runtime-button { width: 100%; min-width: 0; padding: 9px 8px; border: 0; border-radius: 6px; background: transparent; display: grid; grid-template-columns: 10px minmax(0, 1fr) 18px; gap: 10px; align-items: center; text-align: left; }
.runtime-button:hover { background: #e9efeb; }
.runtime-button > img { opacity: .62; }
.runtime-copy { min-width: 0; display: flex; flex-direction: column; }
.runtime-copy strong, .runtime-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runtime-copy strong { font-size: 12px; font-weight: 650; }
.runtime-copy small { color: var(--muted); font-size: 10px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ba5a0; box-shadow: 0 0 0 3px #e8ecea; }
.status-dot.loading { background: #c69524; box-shadow: 0 0 0 3px #f7edcf; }
.status-dot.ready { background: #24a16d; box-shadow: 0 0 0 3px #d7efe5; }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px #f2dfda; }
.workspace { min-width: 0; height: 100dvh; display: grid; grid-template-rows: 64px minmax(0, 1fr) auto; background: linear-gradient(180deg, #f8f9fb, #fff 220px); }
.chat-header { padding: 0 24px; border-bottom: 1px solid var(--soft-line); display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 20px; align-items: center; background: rgba(255, 255, 255, .9); z-index: 2; }
.title-block { min-width: 0; }
.title-block h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 700; }
.title-block p { margin: 1px 0 0; color: var(--muted); font-size: 10px; }
.runtime-chip { height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; background: rgba(255, 255, 255, .85); display: flex; align-items: center; gap: 8px; font-size: 11px; }
.runtime-chip img { width: 15px; height: 15px; opacity: .62; }
.header-metrics { display: flex; gap: 12px; align-items: center; white-space: nowrap; }
.live-generation { display: flex; align-items: center; gap: 6px; font-size: 10px; font-variant-numeric: tabular-nums; }
.live-generation strong { color: var(--blue); font-size: 10px; font-weight: 650; }
.live-generation span { color: var(--muted); }
.memory-stats { position: relative; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.memory-stats > span:not([role]) { display: flex; gap: 4px; }
.memory-stats strong { color: var(--ink); font-weight: 600; }
.memory-stats.tight #heap-headroom { color: var(--danger); }
#memory-description { display: none; position: absolute; top: calc(100% + 10px); right: 0; width: 260px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); box-shadow: 0 4px 18px #1e29251a; color: var(--ink); font-size: 11px; white-space: normal; z-index: 5; }
.memory-stats:hover #memory-description, .memory-stats:focus #memory-description { display: block; }
.messages { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 20px 24px; }
.message { width: min(880px, 100%); margin: 0 auto 16px; display: flex; animation: appear .18s ease-out; }
.message.user { justify-content: flex-end; }
.message-inner { min-width: 0; max-width: 86%; display: flex; flex-direction: column; align-items: flex-start; }
.message.user .message-inner { max-width: 76%; align-items: flex-end; }
.message .role { margin: 0 10px 4px; color: var(--muted); font-size: 10px; font-weight: 600; }
.message-stats { margin: 4px 10px 0; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.message .content { min-width: 32px; max-width: 100%; padding: 10px 14px; border-radius: 8px 8px 8px 2px; background: var(--bubble); color: #20242b; overflow-wrap: anywhere; line-height: 1.55; font-size: 14px; }
.message.user .content { background: var(--blue); color: #fff; border-radius: 8px 8px 2px 8px; }
.message.assistant .markdown-body:empty::after { content: '...'; color: var(--muted); }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body.collapsed { max-height: 320px; overflow: hidden; mask-image: linear-gradient(#000 calc(100% - 28px), transparent); }
.message-expand { display: block; margin: 8px 0 0; padding: 4px 0; min-height: 28px; border: 0; background: transparent; color: #075cbf; font-size: 12px; font-weight: 600; }
.message.user .message-expand { color: white; }
.content p, .content ul, .content ol, .content blockquote { margin: 0 0 10px; }
.content ul, .content ol { padding-left: 22px; }
.content li + li { margin-top: 3px; }
.content li > p { margin: 0; }
.content h1, .content h2, .content h3, .content h4, .content h5, .content h6 { margin: 16px 0 7px; font-size: 15px; line-height: 1.4; font-weight: 700; }
.content h1 { font-size: 18px; }
.content h2 { font-size: 16px; }
.content a { color: #075cbf; text-decoration: underline; text-underline-offset: 2px; }
.message.user .content a { color: white; }
.content code { font: 12px/1.6 'SFMono-Regular', Consolas, monospace; background: #00000009; padding: 1px 4px; border-radius: 3px; }
.content pre { margin: 0; padding: 10px 12px; white-space: pre; }
.content pre code { padding: 0; background: none; }
.content .hljs-keyword, .content .hljs-selector-tag, .content .hljs-literal { color: #a32642; }
.content .hljs-string, .content .hljs-regexp, .content .hljs-addition { color: #23683d; }
.content .hljs-title, .content .hljs-function, .content .hljs-built_in { color: #075cbf; }
.content .hljs-number, .content .hljs-attr, .content .hljs-symbol { color: #855010; }
.content .hljs-comment, .content .hljs-quote { color: #62716c; font-style: italic; }
.message.user .markdown-scroll { color: var(--ink); background: #f5f7fa; }
.mermaid-diagram { display: block; width: 100%; min-height: 120px; max-height: 600px; height: auto; border: 0; border-radius: 5px; background: #fff; margin: 10px 0; }
.diagram-source { margin: 8px 0; font-size: 11px; }
.diagram-source summary { cursor: pointer; padding: 4px 0; }
.content .markdown-scroll { max-width: 100%; overflow-x: auto; margin: 10px 0; border: 1px solid #00000012; border-radius: 5px; background: #ffffff80; }
.message.user .markdown-scroll { border-color: #ffffff40; }
.content table { border-collapse: collapse; font-size: 12px; min-width: 100%; }
.content th, .content td { padding: 6px 10px; border: 1px solid #00000014; text-align: left; }
.content th { font-weight: 650; background: #00000006; }
.content blockquote { border-left: 3px solid #889cb4; padding-left: 10px; }
.message.user blockquote { border-color: #ffffff80; }
.content hr { border: 0; border-top: 1px solid #00000020; margin: 12px 0; }
#empty { height: 100%; min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px; text-align: center; }
.empty-logo { width: 140px; height: 72px; overflow: hidden; border-radius: 8px; background: #202724; }
.empty-logo img { width: 160px; height: 160px; transform: translate(-10px, -42px); object-fit: contain; }
#empty h2 { margin: 18px 0 5px; font-size: 20px; line-height: 1.3; font-weight: 600; }
#empty p { margin: 0; color: var(--muted); font-size: 12px; }
.composer-region { padding: 10px 24px 12px; background: linear-gradient(180deg, #ffffff00, #fff 12px); }
#compose { width: min(880px, 100%); margin: 0 auto; border: 1px solid #cdd3dd; border-radius: 8px; background: #fff; display: flex; align-items: flex-end; }
#compose:focus-within { border-color: #6497d8; box-shadow: 0 0 0 2px #0865d512; }
textarea { width: 100%; min-height: 54px; max-height: 170px; padding: 15px 16px 8px; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink); line-height: 1.5; }
#prompt { min-width: 0; min-height: 44px; padding: 11px 12px; font-size: 14px; }
.compose-actions { flex: 0 0 auto; padding: 5px; display: flex; align-items: center; gap: 5px; }
.compose-actions .icon { width: 34px; height: 34px; min-width: 34px; padding: 8px; }
#send { background: var(--blue); border-color: var(--blue); }
#send:disabled { opacity: 1; background: #e3e7ed; border-color: #e3e7ed; }
#send:disabled img { filter: none; opacity: .45; }
.composer-footer { width: min(880px, 100%); margin: 5px auto 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; color: var(--muted); font-size: 10px; }
#generation-stats { min-height: 15px; margin: 0 0 0 auto; overflow-wrap: anywhere; text-align: right; font-variant-numeric: tabular-nums; }
.primary { border-color: var(--green); background: var(--green); color: white; }
.primary:hover:not(:disabled) { border-color: var(--green-dark); background: var(--green-dark); }
.primary img { filter: invert(1); }
.stop { color: var(--danger); }
.stop img { width: 15px; height: 15px; }
.history-backdrop { display: none; }
dialog { width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid #cdd6d1; border-radius: 8px; background: var(--paper); color: var(--ink); box-shadow: 0 24px 80px rgba(20, 37, 29, .24); }
dialog::backdrop { background: rgba(22, 31, 27, .42); backdrop-filter: blur(2px); }
.dialog-shell { padding: 16px 18px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-heading h2 { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 650; }
.dialog-heading .icon { width: 32px; height: 32px; min-width: 32px; padding: 7px; border-color: transparent; }
.model-summary { margin: 12px 0; padding: 0 0 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.model-logo { width: 40px; height: 32px; overflow: hidden; flex: 0 0 40px; border-radius: 5px; background: #202724; }
.model-logo img { width: 50px; height: 50px; transform: translate(-5px, -9px); object-fit: contain; }
.model-summary div { min-width: 0; display: flex; flex-direction: column; }
.model-summary strong { font-size: 13px; }
.model-summary small { color: var(--muted); font-size: 11px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.settings-grid .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 11px; }
input, select { width: 100%; min-width: 0; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink); }
.settings-grid label { min-width: 0; }
.settings-grid .numeric-setting { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
.numeric-setting input { flex: 0 0 64px; width: 64px; min-height: 32px; height: 32px; padding: 4px 7px; font-size: 12px; font-variant-numeric: tabular-nums; }
#manifest { min-height: 88px; height: 88px; max-height: 200px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--paper); font-size: 12px; line-height: 18px; overflow-wrap: anywhere; white-space: pre-wrap; resize: vertical; }
#manifest:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.load-model { flex: 0 0 auto; height: 32px; padding: 0 10px; border: 1px solid var(--green); border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 600; }
.load-model img { width: 15px; height: 15px; }
.runtime { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.runtime-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.runtime-heading { min-width: 0; display: flex; align-items: center; gap: 8px; }
.runtime-heading .status-dot { flex: 0 0 8px; }
#status { margin: 0; font-size: 11px; font-weight: 650; overflow-wrap: anywhere; }
progress { width: 100%; height: 6px; margin-top: 12px; accent-color: var(--green); }
dl { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 6px 12px; margin: 12px 0 8px; font-size: 10px; }
dt { color: var(--muted); }
dd { margin: 0; font-variant-numeric: tabular-nums; }
#warning { margin: 10px 0; color: var(--danger); font-size: 11px; overflow-wrap: anywhere; }
#warning:empty { display: none; }
.subtle { min-height: 28px; padding: 4px 0; border: 0; background: transparent; color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 11px; }
.subtle img { width: 14px; height: 14px; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .message { animation: none; } .messages { scroll-behavior: auto; } }
@media (max-width: 1100px) {
    .live-generation span { display: none; }
}
@media (max-width: 760px) {
    .app-shell { grid-template-columns: minmax(0, 1fr); }
    .history-panel { position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); transform: translateX(-101%); transition: transform .2s ease; box-shadow: 18px 0 45px rgba(20, 37, 29, .18); }
    body.history-visible .history-panel { transform: translateX(0); }
    .rail-close { display: inline-flex; }
    .history-toggle { display: inline-flex; }
    .history-backdrop { position: fixed; inset: 0; z-index: 15; width: 100%; height: 100%; border: 0; background: rgba(22, 31, 27, .35); }
    body.history-visible .history-backdrop { display: block; }
    .workspace { grid-template-rows: 80px minmax(0, 1fr) auto; }
    .chat-header { padding: 8px 12px 6px; grid-template-columns: 36px minmax(0, 1fr) 36px; grid-template-rows: 40px 18px; gap: 4px 10px; }
    .chat-header .icon { width: 36px; height: 36px; min-width: 36px; padding: 8px; }
    .header-metrics { grid-row: 2; grid-column: 1 / -1; justify-content: flex-end; gap: 8px; }
    .live-generation { margin-right: auto; text-align: left; min-width: 0; }
    #header-settings { grid-row: 1; grid-column: 3; }
    .runtime-chip { width: 36px; padding: 0; justify-content: center; position: relative; }
    .runtime-chip #runtime-badge { display: none; }
    .runtime-chip .status-dot { position: absolute; width: 5px; height: 5px; right: 4px; bottom: 4px; box-shadow: none; }
    .messages { padding: 14px 12px; }
    .message { margin-bottom: 13px; }
    .message-inner { max-width: 94%; }
    .message.user .message-inner { max-width: 86%; }
    .message .content { padding: 9px 12px; }
    .composer-region { padding: 8px 12px max(10px, env(safe-area-inset-bottom)); }
    #compose { width: 100%; }
}
@media (max-width: 420px) {
    .dialog-shell { padding: 14px; }
    .settings-grid { gap: 12px; }
    .settings-grid .numeric-setting { flex-direction: column; align-items: flex-start; gap: 5px; }
    .numeric-setting input { flex-basis: auto; }
    #manifest { min-height: 106px; height: 106px; }
    dl { grid-template-columns: minmax(0, 1fr) auto; }
}