:root {
  --canvas: #ffffff;
  --surface: #fffdf8;
  --sidebar: #ffffff;
  --soft: #eeeae0;
  --ink: #211f19;
  --muted: #716d62;
  --faint: #999386;
  --line: #ddd7ca;
  --line-dark: #c8c0b0;
  --accent: #c97500;
  --accent-soft: #fff0d2;
  --success: #397054;
  --danger: #b74a3b;
  --danger-soft: #f9e8e3;
  --thought: #865d1b;
  --thought-soft: #fff4df;
  --radius: 5px;
  --font: Inter, "Segoe UI Variable", "Noto Sans SC", "Microsoft YaHei UI", sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; min-height: 100%; overflow: hidden; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 14px/1.55 var(--font); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell { height: 100dvh; min-height: 0; overflow: hidden; display: grid; grid-template-columns: 204px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100dvh; z-index: 3;
  border-right: 1px solid var(--line-dark); background: var(--sidebar);
  padding: 24px 14px 16px; display: flex; flex-direction: column;
}
.brand-row { display: flex; align-items: center; gap: 11px; padding: 0 8px 38px; }
.brand-row strong { display: block; font-size: 18px; letter-spacing: -.05em; }
.brand-row span { display: block; margin-top: 1px; color: var(--muted); font: 10px/1.4 var(--mono); }
.brand-mark { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 4px; display: block; border: 1px solid var(--line-dark); background: #fff; object-fit: cover; }
.nav { display: grid; gap: 1px; }
.nav-item, .item-button { border: 0; background: transparent; text-align: left; cursor: pointer; }
.nav-item {
  width: 100%; min-height: 43px; padding: 0 10px; border-radius: 3px;
  color: #656c67; display: flex; align-items: center; gap: 10px;
}
.nav-icon { width: 20px; text-align: center; color: #818883; font: 16px var(--mono); }
.nav-item:hover { color: var(--ink); background: var(--soft); }
.nav-item.active { color: var(--ink); background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }
.nav-item.active .nav-icon { color: var(--accent); }
.sidebar-bottom { margin-top: auto; display: grid; gap: 5px; }
.status-line { margin: 0 10px 7px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #a8ada9; box-shadow: 0 0 0 3px rgba(120,126,121,.09); }
.status-dot.running { background: var(--success); box-shadow: 0 0 0 3px rgba(36,134,91,.1); }
.status-dot.busy { background: #d49e31; box-shadow: 0 0 0 3px rgba(212,158,49,.11); }
.status-dot.error { background: var(--danger); }
.settings-link { border-top: 1px solid var(--line); border-radius: 0; padding-top: 4px; margin-top: 2px; }
.quiet-action { border: 0; background: none; padding: 6px 11px; color: var(--muted); cursor: pointer; text-align: left; font-size: 11px; }

.workspace { min-width: 0; min-height: 0; height: 100dvh; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--canvas); }
.topbar {
  min-height: 82px; border-bottom: 1px solid var(--line-dark); padding: 14px clamp(20px, 3vw, 48px);
  display: flex; align-items: center; justify-content: space-between; gap: 20px; background: rgba(255,253,248,.96);
}
.topbar h1 { margin: 3px 0 0; font-size: 21px; line-height: 1.2; letter-spacing: -.045em; }
.eyebrow { margin: 0; color: var(--faint); font: 600 9px/1.4 var(--mono); letter-spacing: .12em; }
.button-row { display: flex; gap: 8px; }
button.primary, button.secondary, button.agent-action {
  min-height: 38px; padding: 0 15px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}
button.agent-action { font-weight: 650; }
button.agent-action.start { border: 1px solid #9f5d00; background: var(--accent); color: #fff; }
button.agent-action.start:hover { background: #a86100; }
button.agent-action.stop { border: 1px solid #aa3e38; background: var(--danger); color: #fff; }
button.agent-action.stop:hover { background: #aa403a; }
button.primary { border: 1px solid #9f5d00; background: var(--accent); color: #fff; font-weight: 650; }
button.primary:hover { background: #a86100; }
button.secondary { border: 1px solid var(--line-dark); background: #fff; color: var(--ink); }
button.secondary:hover { background: var(--soft); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid #dd9a32; outline-offset: 2px;
}

.view { display: none; min-height: 0; overflow: hidden; }
.view.active { display: block; height: 100%; }
#view-chat.active { display: grid; grid-template-rows: auto auto minmax(0, 1fr) max-content max-content; height: 100%; min-height: 0; overflow: hidden; }
.agent-error {
  grid-row: 1; margin: 14px clamp(24px, 8vw, 132px) 0; padding: 14px 16px;
  border: 1px solid #dfaaa1; border-left: 3px solid var(--danger); border-radius: 4px;
  background: #fff5f2; color: #75342c; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: start;
}
.agent-error h2 { margin: 3px 0 2px; color: var(--ink); font-size: 15px; }
.agent-error p:not(.eyebrow) { margin: 0; overflow-wrap: anywhere; font-size: 12px; }
.agent-error details { max-width: min(560px, 48vw); }
.agent-error summary { cursor: pointer; font-size: 12px; font-weight: 650; }
.agent-error pre { max-height: 180px; margin: 9px 0 0; padding: 10px; overflow: auto; border: 1px solid #e9c9c3; background: #fff; color: #5f3a35; font: 10px/1.55 var(--mono); white-space: pre-wrap; }
.extension-widget {
  grid-row: 2;
  margin: 12px clamp(22px, 7vw, 112px) 0; border: 1px solid #d8d0e5; border-radius: 8px;
  padding: 9px 12px; background: var(--thought-soft); color: var(--thought); white-space: pre-wrap; font-size: 12px;
}
.messages {
  grid-row: 3; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-gutter: stable; padding: 38px clamp(24px, 8vw, 132px) 54px; background: var(--canvas);
}
.message { max-width: 900px; margin: 0 auto 30px; }
.message-label { margin-bottom: 7px; color: var(--faint); font: 650 10px var(--mono); letter-spacing: .08em; }
.message-body { overflow-wrap: anywhere; font-size: 15px; line-height: 1.72; }
.text-content { white-space: pre-wrap; }
.text-content + .text-content { margin-top: 12px; }
.message.user { display: grid; justify-items: end; }
.message.user .message-label { width: min(84%, 700px); }
.message.user .message-body {
  width: min(84%, 700px); border: 1px solid var(--line); border-radius: 12px 12px 3px 12px;
  padding: 13px 16px; background: var(--surface);
}
.message.tool { margin-top: -12px; }
.message.tool .message-label { margin-left: 12px; }
.message-meta { margin-top: 7px; color: var(--faint); font: 10px var(--mono); }
.thinking-block, .tool-call, .tool-result {
  margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fafaf9;
}
.thinking-block { border-color: #ead2a6; background: var(--thought-soft); color: var(--thought); }
.thinking-block summary, .tool-call summary, .tool-result summary {
  cursor: pointer; list-style: none; padding: 8px 11px; font: 600 11px/1.5 var(--mono);
}
.thinking-block summary::before, .tool-call summary::before, .tool-result summary::before { content: "›"; display: inline-block; margin-right: 8px; transition: transform 120ms; }
details[open] > summary::before { transform: rotate(90deg); }
.thinking-content { border-top: 1px solid #ead2a6; padding: 11px 13px; white-space: pre-wrap; font-size: 13px; line-height: 1.65; }
.tool-call { border-color: #ead2a6; background: #fff8ea; color: #805510; }
.tool-call pre, .tool-result pre, .unknown-content {
  margin: 0; border-top: 1px solid var(--line); padding: 10px 12px; overflow: auto;
  color: #4f5651; background: rgba(255,255,255,.7); font: 11px/1.6 var(--mono); white-space: pre-wrap;
}
.tool-result.failed { border-color: #edc8c4; background: var(--danger-soft); }
.working-line { color: var(--muted); font-style: italic; }
.media-note { color: var(--muted); font-size: 12px; }
.model-api-error {
  margin: 8px 0; padding: 12px 14px; border: 1px solid #dfaaa1; border-left: 3px solid var(--danger);
  border-radius: 4px; background: #fff5f2; color: #75342c; overflow-wrap: anywhere; white-space: pre-wrap;
}
.model-api-error strong { display: block; margin-bottom: 4px; color: #9a392e; font-size: 12px; }
.model-api-error div { font: 12px/1.6 var(--mono); }
.composer {
  grid-row: 4;
  position: relative;
  margin: 0 clamp(24px, 8vw, 132px); border: 1px solid var(--line-dark); border-top: 3px solid var(--accent); border-radius: 4px;
  background: var(--surface); padding: 8px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px;
  box-shadow: 0 12px 34px rgba(52,42,23,.09);
}
.composer textarea { height: 52px; min-height: 52px; max-height: 190px; resize: none; overflow-y: auto; border: 0; padding: 10px 11px; background: transparent; }
.composer textarea:focus { outline: none; }
.composer .send-button { align-self: end; min-height: 42px; }
.send-button span { margin-left: 5px; }
.command-menu {
  position: absolute; z-index: 12; inset: auto -1px calc(100% + 8px);
  max-height: min(420px, 48dvh); overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--line-dark); border-radius: 11px; padding: 5px;
  background: rgba(255,255,255,.98); box-shadow: 0 18px 50px rgba(28,35,31,.16);
}
.command-option {
  width: 100%; min-height: 44px; border: 0; border-radius: 7px; padding: 7px 9px;
  display: grid; grid-template-columns: minmax(120px, .7fr) minmax(180px, 1.5fr) auto;
  align-items: center; gap: 12px; color: var(--ink); background: transparent; text-align: left; cursor: pointer;
}
.command-option.active { background: var(--accent-soft); box-shadow: inset 2px 0 var(--accent); }
.command-name { color: var(--accent); font: 650 12px/1.4 var(--mono); overflow-wrap: anywhere; }
.command-description { color: #555d58; font-size: 12px; overflow-wrap: anywhere; }
.command-source { color: var(--faint); font: 600 9px/1.4 var(--mono); letter-spacing: .08em; }
.session-bar {
  grid-row: 5;
  min-height: 36px; padding: 7px clamp(25px, 7vw, 115px) 11px; display: flex; justify-content: flex-end;
  align-items: center; gap: 18px; color: var(--faint); font: 10px/1.4 var(--mono); white-space: nowrap; overflow-x: auto;
}
.session-bar span + span::before { content: "·"; margin-right: 18px; color: var(--line-dark); }

textarea, input, select { width: 100%; border: 1px solid var(--line-dark); border-radius: 8px; background: #fff; color: var(--ink); }
textarea { resize: vertical; padding: 11px 12px; }
input, select { min-height: 40px; padding: 7px 10px; }
textarea::placeholder, input::placeholder { color: #9a9f9b; }

.split-view.active { display: grid; grid-template-columns: minmax(230px, 300px) minmax(0, 1fr); height: 100%; min-height: 0; }
.index-pane { min-height: 0; overflow: auto; border-right: 1px solid var(--line); background: var(--surface); }
.pane-heading { padding: 27px 22px 20px; border-bottom: 1px solid var(--line); }
.pane-heading h2, .editor-heading h2 { margin: 4px 0 5px; font-size: 18px; letter-spacing: -.03em; }
.pane-heading p:not(.eyebrow), .editor-heading p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 12px; }
.item-list { padding: 9px; }
.item-button { width: 100%; border-radius: 8px; padding: 11px 12px; color: var(--muted); }
.item-button:hover, .item-button.active { background: var(--accent-soft); color: var(--ink); }
.item-button.active { box-shadow: inset 2px 0 var(--accent); }
.item-button strong { display: block; font-size: 13px; font-weight: 650; }
.item-button span { display: block; margin-top: 2px; font-size: 11px; }
.editor-pane { min-width: 0; padding: 30px clamp(20px, 4vw, 58px) 56px; overflow: auto; }
.editor-heading { max-width: 920px; margin: 0 auto 27px; display: flex; justify-content: space-between; gap: 24px; align-items: start; }
.config-form, .memory-form { max-width: 920px; margin: 0 auto; }
.field-group { border: 1px solid var(--line); border-radius: 10px; padding: 17px; margin: 0 0 13px; background: #fbfbfa; }
.field-group legend { padding: 0 7px; color: var(--ink); font-weight: 650; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label { display: block; margin-bottom: 6px; color: #4d554f; font-size: 12px; font-weight: 600; }
.field-help { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.config-form .field-grid { grid-template-columns: minmax(0, 1fr); gap: 11px; }
.config-form .field {
  display: grid; grid-template-columns: clamp(96px, 28%, 168px) minmax(0, 1fr);
  align-items: start; column-gap: 18px; row-gap: 6px;
}
.config-form .field.full { grid-column: auto; }
.config-form .field > label { margin: 0; padding-top: 10px; }
.config-form .field.boolean-field { align-items: center; }
.config-form .field.boolean-field > label { padding-top: 0; }
.config-form .field > input,
.config-form .field > textarea,
.config-form .field > select,
.config-form .field > .sensitive-clear,
.config-form .field > .field-help { grid-column: 2; }
.config-form .field > input[type="checkbox"] {
  width: 16px; min-height: 16px; justify-self: start; accent-color: var(--accent);
}
.disabled-field { opacity: .5; }
.check-row { min-height: 38px; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.check-row input { width: 16px; min-height: 16px; accent-color: var(--accent); }
.editor-actions {
  position: sticky; bottom: 12px; margin-top: 21px; padding: 9px; border: 1px solid var(--line);
  border-radius: 10px; background: rgba(250,250,248,.95); display: flex; justify-content: flex-end; gap: 8px;
  box-shadow: 0 8px 25px rgba(35,42,37,.08); backdrop-filter: blur(10px);
}
.memory-text { min-height: min(64dvh, 700px); font: 13px/1.68 var(--mono); tab-size: 2; }
.module-view.active { display: block; height: 100%; overflow: hidden; }
.module-view .editor-pane { height: 100%; }
.empty-state { min-height: 300px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); padding: 40px; }
.empty-glyph { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; margin-bottom: 14px; color: var(--accent); font: 19px var(--mono); }
.empty-state h2 { margin: 0 0 7px; color: var(--ink); font-size: 17px; letter-spacing: -.02em; }
.empty-state p { margin: 0; max-width: 48ch; }

.settings-view.active { display: block; height: 100%; padding: 42px clamp(20px, 7vw, 92px) 76px; overflow: auto; }
.settings-form { max-width: 980px; }
.settings-heading { margin-bottom: 25px; }
.settings-heading h2 { margin: 4px 0 5px; font-size: 25px; letter-spacing: -.04em; }
.settings-heading p:not(.eyebrow) { margin: 0; color: var(--muted); }
.setting-card { margin: 0 0 14px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 4px; padding: 21px; background: var(--surface); }
.model-card { padding: 26px; }
.model-grid { margin-top: 25px; }
.setting-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 25px; margin-bottom: 17px; }
.setting-card-head h3 { margin: 0 0 3px; font-size: 15px; }
.setting-card-head p { margin: 0; color: var(--muted); font-size: 12px; }
.setting-card-head code { padding: 4px 7px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font: 11px var(--mono); }
.switch { flex: 0 0 auto; position: relative; width: 38px; height: 22px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #c9cdc9; transition: background 150ms; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 150ms; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.settings-actions { display: flex; justify-content: flex-end; padding-top: 7px; }

.login-shell { height: 100dvh; min-height: 0; overflow: auto; display: grid; place-items: center; padding: 24px; background: var(--canvas); }
.login-panel { width: min(100%, 390px); border: 1px solid var(--line-dark); border-top: 4px solid var(--accent); border-radius: 4px; background: var(--surface); padding: 34px; box-shadow: 0 24px 70px rgba(52,42,23,.12); }
.login-panel .brand-mark { margin-bottom: 25px; }
.login-panel h1 { margin: 5px 0 4px; font-size: 25px; letter-spacing: -.04em; }
.login-panel label { display: block; margin: 24px 0 7px; font-size: 12px; font-weight: 600; }
.login-panel button { width: 100%; margin-top: 10px; }
.muted { color: var(--muted); }
.inline-error { min-height: 20px; margin: 6px 0 0; color: var(--danger); font-size: 12px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(450px, calc(100vw - 40px)); border: 1px solid #bed4c8; border-radius: 10px; background: #f3faf6; color: #285740; padding: 11px 14px; box-shadow: 0 16px 44px rgba(32,38,34,.15); }
.toast.error { border-color: #e3b7b3; background: #fff2f0; color: #9e3933; }
.rpc-dialog { width: min(520px, calc(100vw - 32px)); border: 1px solid var(--line-dark); border-radius: 14px; padding: 0; color: var(--ink); box-shadow: 0 30px 90px rgba(20,26,22,.23); }
.rpc-dialog::backdrop { background: rgba(20,24,21,.32); backdrop-filter: blur(2px); }
.rpc-dialog form { padding: 24px; }
.rpc-dialog h2 { margin: 5px 0 4px; font-size: 20px; }
#rpc-dialog-control { margin-top: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 21px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .workspace { min-height: calc(100dvh - 62px); height: calc(100dvh - 62px); }
  .sidebar {
    position: fixed; inset: auto 0 0; width: auto; height: 62px; border: 0; border-top: 1px solid var(--line);
    padding: 7px 5px; display: grid; grid-template-columns: repeat(6, 1fr); background: rgba(255,253,248,.97); backdrop-filter: blur(12px);
  }
  .brand-row, .status-line, .quiet-action { display: none; }
  .nav, .sidebar-bottom { display: contents; }
  .nav-item, .settings-link { min-height: 47px; margin: 0; padding: 3px 4px; border: 0; border-radius: 7px; display: grid; place-content: center; justify-items: center; gap: 0; text-align: center; font-size: 10px; }
  .nav-icon { height: 21px; font-size: 15px; }
  .topbar { min-height: 66px; padding: 10px 14px; }
  .topbar h1 { font-size: 17px; }
  .topbar .eyebrow { display: none; }
  #view-chat.active { min-height: 0; height: 100%; }
  .messages { padding: 20px 14px 30px; }
  .message.user .message-label, .message.user .message-body { width: 91%; }
  .composer { margin: 0 10px; }
  .command-option { grid-template-columns: minmax(105px, .8fr) minmax(0, 1.4fr); gap: 4px 10px; }
  .command-source { grid-column: 2; }
  .session-bar { padding: 7px 13px 8px; justify-content: flex-start; }
  .split-view.active { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
  .index-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .pane-heading { padding: 20px 16px 14px; }
  .item-list { display: flex; overflow-x: auto; }
  .item-button { flex: 0 0 auto; width: auto; }
  .editor-pane { padding: 22px 15px 38px; }
  .editor-heading { display: block; }
  .field-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .settings-view.active { padding: 24px 14px 44px; }
  .setting-card { padding: 16px; }
  .extension-widget { margin: 10px 14px 0; }
  .agent-error { margin: 10px 14px 0; grid-template-columns: 1fr; }
  .agent-error details { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition-duration: 0s !important; }
}
