@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --ink: #17211b;
  --paper: #f4f1ea;
  --panel: #fffdf8;
  --line: #d8d5ca;
  --muted: #77786f;
  --moss: #2f6b4f;
  --moss-dark: #214936;
  --amber: #c9852b;
  --red: #b94a3d;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--paper); color: var(--ink); font: 14px/1.45 var(--sans); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.shell { min-height: 100vh; padding: 25px 30px 40px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; max-width: 1640px; margin: 0 auto; }
.brand-kicker, .section-kicker { display: block; color: var(--muted); font: 500 10px/1.2 var(--mono); letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin: 0; }
h1 { margin-top: 8px; font-size: clamp(26px, 3vw, 42px); letter-spacing: -.035em; font-weight: 700; }
h2 { margin-top: 6px; font-size: 23px; letter-spacing: -.025em; }
h3 { margin-top: 4px; font-size: 18px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.user-line { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-right: 10px; }
.button { min-height: 36px; border: 1px solid transparent; border-radius: 4px; padding: 0 14px; font-weight: 600; white-space: nowrap; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button-primary { background: var(--moss); color: #fff; }
.button-primary:hover { background: var(--moss-dark); }
.button-accent { background: var(--amber); color: #fff; }
.button-accent:hover { background: #a96d20; }
.button-outline, .button-quiet { background: transparent; border-color: var(--line); color: var(--ink); }
.button-danger { background: transparent; border-color: #e6bbb5; color: var(--red); }
.button-danger:hover { background: #fff3f1; }
.button-outline:hover, .button-quiet:hover { background: #ebe7dd; }
.status-strip { display: flex; justify-content: space-between; gap: 20px; max-width: 1640px; margin: 22px auto 14px; padding: 9px 12px; background: var(--ink); color: #f7f4ec; font-size: 12px; }
.status-strip.has-error { background: var(--red); }
.status-strip > div, .status-meta { display: flex; align-items: center; gap: 14px; }
.status-dot { width: 7px; height: 7px; display: inline-block; border-radius: 50%; background: #8fc5a2; box-shadow: 0 0 0 3px rgba(143,197,162,.16); }
.status-meta { color: #bbc5bd; font: 11px var(--mono); }
.workspace { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 14px; max-width: 1640px; min-height: calc(100vh - 170px); margin: 0 auto; }
.chat-index, .editor-pane { border: 1px solid var(--line); background: var(--panel); }
.chat-index { padding: 16px 12px 12px; }
.index-heading { padding: 0 5px 13px; border-bottom: 1px solid var(--line); }
.index-heading { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 8px; }
.index-heading input { margin-top: 14px; }
.index-heading input { grid-column: 1 / -1; }
.button-small { min-height: 30px; padding: 0 10px; font-size: 12px; }
input, select { width: 100%; min-height: 36px; padding: 8px 10px; color: var(--ink); background: #fbfaf5; border: 1px solid var(--line); border-radius: 3px; outline: none; }
input:focus, select:focus { border-color: var(--moss); box-shadow: 0 0 0 2px rgba(47,107,79,.12); }
.task-list { display: grid; gap: 2px; padding-top: 10px; }
.model-label { padding: 11px 8px 4px; color: var(--muted); font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.task-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 39px; padding: 0 9px; color: var(--ink); text-align: left; background: transparent; border: 1px solid transparent; border-radius: 3px; }
.task-item small { color: var(--muted); font: 10px var(--mono); }
.task-item:hover { background: #f0eee7; }
.task-item.active { background: #e4eee6; border-color: #c4d8c9; color: var(--moss-dark); font-weight: 600; }
.chat-list { display: grid; gap: 4px; padding-top: 10px; }
.chat-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 56px; padding: 8px 9px; color: var(--ink); text-align: left; background: transparent; border: 1px solid transparent; border-radius: 3px; }
.chat-item span { min-width: 0; }
.chat-item strong, .chat-item code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item code { margin-top: 3px; color: var(--muted); font: 10px var(--mono); }
.chat-item small { color: var(--muted); font: 10px var(--mono); white-space: nowrap; }
.chat-item:hover { background: #f0eee7; }
.chat-item.active { background: #e4eee6; border-color: #c4d8c9; color: var(--moss-dark); }
.editor-pane { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; }
.editor-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; padding: 23px 25px 20px; border-bottom: 1px solid var(--line); }
.editor-heading p { margin-top: 8px; color: var(--muted); }
.chat-meta-form { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(250px, 1.4fr); gap: 10px; margin-top: 16px; max-width: 680px; }
.chat-meta-form label span { display: block; margin-bottom: 5px; color: var(--muted); font: 10px var(--mono); text-transform: uppercase; }
.chat-meta-form input { font-family: var(--mono); font-size: 12px; }
.editor-tools { display: flex; align-items: end; gap: 8px; min-width: 410px; }
.compact-label { color: var(--muted); font-size: 11px; white-space: nowrap; }
.editor-tools select { min-width: 150px; }
.chat-roster { padding: 20px 25px; overflow: auto; }
.roster-heading { display: flex; justify-content: space-between; align-items: end; gap: 14px; margin-bottom: 12px; }
.function-count-note { margin-top: 4px; color: var(--muted); font: 11px var(--mono); }
.roster-actions { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.roster-actions select { min-width: 220px; }
.binding-rows { display: grid; gap: 8px; }
.function-search { max-width: 360px; margin-bottom: 14px; }
.function-rows { display: grid; gap: 8px; }
.function-model { padding: 11px 8px 4px; color: var(--muted); font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.function-row { display: grid; grid-template-columns: minmax(185px, .75fr) 92px minmax(160px, 1fr) minmax(160px, 1fr); align-items: end; gap: 12px; padding: 14px 14px 13px; border: 1px solid var(--line); border-left: 3px solid #b5c9b9; background: #fcfbf7; }
.function-row:hover { border-left-color: var(--moss); background: #fff; }
.function-row.is-disabled { border-left-color: var(--line); background: #f3f1eb; }
.function-row.is-disabled:hover { background: #f3f1eb; }
.function-identity { min-width: 0; padding-bottom: 5px; }
.function-identity strong, .function-identity code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.function-identity code { margin-top: 3px; color: var(--muted); font: 10px var(--mono); }
.status-toggle { display: flex; align-items: center; gap: 7px; min-height: 36px; color: var(--muted); font-size: 12px; cursor: pointer; }
.status-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.switch-track { position: relative; width: 36px; height: 20px; flex: none; border-radius: 12px; background: #c7c5bc; transition: background .15s ease; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fffdf8; box-shadow: 0 1px 2px rgba(23,33,27,.18); transition: transform .15s ease; }
.status-toggle input:checked + .switch-track { background: var(--moss); }
.status-toggle input:checked + .switch-track::after { transform: translateX(16px); }
.status-toggle input:focus-visible + .switch-track { outline: 2px solid var(--moss); outline-offset: 2px; }
.status-label { min-width: 24px; }
.function-row label span { display: block; margin-bottom: 5px; color: var(--muted); font: 10px var(--mono); text-transform: uppercase; }
.function-row input { font-family: var(--mono); font-size: 12px; }
.function-row input:disabled { color: #9d9c92; background: #e8e6df; cursor: not-allowed; }
.remove-function { min-height: 32px; padding: 0 8px; color: var(--red); background: transparent; border: 1px solid transparent; border-radius: 3px; font-size: 12px; }
.remove-function:hover { border-color: #e6bbb5; background: #fff3f1; }
.binding-row { display: grid; grid-template-columns: minmax(185px, .75fr) minmax(160px, 1fr) minmax(160px, 1fr) auto; align-items: end; gap: 12px; padding: 14px 14px 13px; border: 1px solid var(--line); border-left: 3px solid #b5c9b9; background: #fcfbf7; }
.binding-row:hover { border-left-color: var(--moss); background: #fff; }
.chat-identity { display: flex; align-items: center; gap: 9px; min-width: 0; padding-bottom: 5px; }
.chat-mark { width: 8px; height: 8px; flex: none; background: var(--moss); transform: rotate(45deg); }
.chat-identity strong, .chat-identity code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-identity code { margin-top: 3px; color: var(--muted); font: 10px var(--mono); }
.binding-row label span { display: block; margin-bottom: 5px; color: var(--muted); font: 10px var(--mono); text-transform: uppercase; }
.binding-row input { font-family: var(--mono); font-size: 12px; }
.remove-chat { min-height: 32px; padding: 0 8px; color: var(--red); background: transparent; border: 1px solid transparent; border-radius: 3px; font-size: 12px; }
.remove-chat:hover { border-color: #e6bbb5; background: #fff3f1; }
.audit-note { display: flex; gap: 12px; padding: 13px 25px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.audit-note strong { color: var(--amber); white-space: nowrap; }
.empty-copy { padding: 28px 8px; color: var(--muted); }
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); padding: 30px; background: var(--panel); border: 1px solid var(--line); border-top: 5px solid var(--moss); }
.login-panel h1 { font-size: 30px; }
.login-panel p { margin: 10px 0 20px; color: var(--muted); }
.toast { position: fixed; right: 24px; bottom: 22px; max-width: min(520px, calc(100vw - 48px)); padding: 11px 14px; color: #fff; background: var(--ink); border-left: 3px solid var(--amber); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
@media (max-width: 1050px) {
  .shell { padding: 18px 16px 28px; }
  .topbar, .editor-heading { align-items: flex-start; flex-direction: column; }
  .top-actions, .editor-tools { width: 100%; min-width: 0; }
  .chat-meta-form { width: 100%; max-width: none; }
  .workspace { grid-template-columns: 260px minmax(0, 1fr); }
  .function-row { grid-template-columns: 1fr 92px 1fr; }
  .function-identity { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .top-actions { flex-wrap: wrap; }
  .user-line { width: 100%; }
  .workspace { display: block; }
  .chat-index { margin-bottom: 14px; }
  .task-list { max-height: 280px; overflow: auto; }
  .editor-tools { align-items: stretch; flex-direction: column; }
  .chat-meta-form { grid-template-columns: 1fr; }
  .function-row { grid-template-columns: 1fr; }
  .function-identity { grid-column: auto; }
  .status-strip { align-items: flex-start; flex-direction: column; gap: 5px; }
}
