:root {
  /* Match the shared surfaces and typography in Agent Portal. */
  --font-ui: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  --text-2xs: .8rem;
  --text-xs: .85rem;
  --text-sm: .9rem;
  --text-base: 1rem;
  --ink: #2c2c2c;
  --message-ink: #434343;
  --action: #4e4e4e;
  --muted: #6a6a6a;
  --secondary: #848484;
  --placeholder: #979797;
  --border: #d8d8d8;
  --divider: #cdcdcd;
  --scroll-thumb: #b9b9b9;
  --canvas: #f0f0f0;
  --panel: #f2f2f2;
  --paper: #f6f6f6;
  --raised: #f9f9f9;
  --white: #fff;
  --selection: #e6e6e6;
  --selection-strong: #ddd;
  --header: #e8e8e8;
  --danger: #904a3b;
  --focus-ring: 0 0 0 3px rgb(60 60 60 / 8%);
  color-scheme: light;
}

* { box-sizing: border-box; scrollbar-color: var(--scroll-thumb) transparent; scrollbar-width: thin; }
[hidden] { display: none !important; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--canvas);
  font: var(--text-sm)/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; }
button, input, textarea { border: 1px solid var(--border); border-radius: 8px; }
button {
  padding: 8px 12px;
  min-height: 36px;
  color: inherit;
  background: var(--raised);
  cursor: pointer;
  white-space: nowrap;
}
button:hover:enabled { background: var(--selection); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.primary { border-color: var(--action); background: var(--action); color: var(--white); font-weight: 600; }
.primary:hover:enabled { background: var(--ink); }
.danger { color: var(--danger); }
.container { width: min(calc(100% - 40px), 880px); margin-inline: auto; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 37px 0 20px; }
h1 { margin: 0; font-size: 1.5rem; font-weight: 600; }
h2 { margin: 0 0 16px; font-size: 1.125rem; font-weight: 600; }
.panel { margin-bottom: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--raised); }
.list { overflow: hidden; }
.list > p { margin: 0; padding: 28px 20px; text-align: center; color: var(--muted); }
.list > button { display: block; margin: 0 auto 18px; }
ul { list-style: none; margin: 0; padding: 0; }
li { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 20px; }
li + li { border-top: 1px solid var(--border); }
.project-info { min-width: 0; }
.project-id { font-size: var(--text-base); font-weight: 500; overflow-wrap: anywhere; }
.project-root { margin: 4px 0 0; color: var(--muted); font-size: var(--text-sm); overflow-wrap: anywhere; }
.row-actions, .form-actions { display: flex; gap: 8px; }
.editor { padding: 20px; }
form { display: grid; gap: 7px; }
label { font-size: 14px; font-weight: 650; }
label:not(:first-child) { margin-top: 8px; }
input, textarea { padding: 8px 12px; width: 100%; color: inherit; background: var(--raised); }
textarea { resize: vertical; }
small, label span { color: var(--muted); font-size: var(--text-2xs); font-weight: 400; line-height: 1.5; }
.form-actions { justify-content: flex-end; margin-top: 8px; }
.error { margin-block: 4px 12px; color: var(--danger); font-size: var(--text-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.workbench {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}
#workbench.chat-maximized { grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
.project-sidebar { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--panel); }
.project-picker { position: relative; flex: 0 0 auto; margin-bottom: 8px; padding: 4px 44px 4px 4px; background: var(--canvas); }
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
}
.workbench svg { display: block; width: 20px; height: 20px; flex: 0 0 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
#project-setup { position: absolute; z-index: 1; top: 4px; right: 8px; }
#project-setup[aria-expanded="true"] { background: var(--selection-strong); }
#project-list-status { margin: 0; padding: 7px 8px; color: var(--muted); font-size: var(--text-2xs); }
#project-switcher { max-height: 40vh; min-height: 32px; overflow: auto; padding-block: 2px; }
#project-switcher:empty { display: none; }
#project-switcher li { display: block; border: 0; padding: 0; }
#project-switcher button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 26px;
  padding: 2px 8px;
  text-align: left;
  border: 0;
  border-radius: 6px;
  color: var(--message-ink);
  background: transparent;
  font-size: var(--text-2xs);
  font-weight: 500;
  line-height: 1.35;
}
#project-switcher button:focus-visible { outline-offset: -2px; }
#project-switcher button:hover:enabled { background: var(--selection); }
#project-switcher button[aria-current="true"] { background: var(--selection-strong); }
.project-slot { display: grid; place-items: center; width: 18px; height: 18px; flex: 0 0 18px; border-radius: 50%; background: var(--white); color: var(--action); line-height: 1; }
.project-slot:empty { background: transparent; }
.project-label { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#open-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  margin: 0 8px 8px;
  padding: 4px 8px;
  border: 0;
  background: var(--raised);
  color: var(--action);
  font-size: var(--text-2xs);
  font-weight: 600;
}
#open-chat:hover:enabled { background: var(--header); }
.workspace { min-width: 0; min-height: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); background: var(--divider); padding: 1px; }
#chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: var(--raised); outline: 1px solid var(--secondary); }
.chat-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 8px 4px 12px;
  background: var(--header);
}
.chat-heading > span { flex: none; color: var(--secondary); font-size: var(--text-2xs); font-weight: 800; letter-spacing: .1em; }
.chat-heading h1 { min-width: 0; flex: 1; color: var(--action); font-size: var(--text-2xs); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-heading button:hover:enabled { background: var(--selection-strong); }
.chat-window-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; }
.chat-window-actions .icon-button { border-radius: 4px; }
.chat-window-actions .icon-button:disabled { color: var(--muted); opacity: .5; }
.chat-scroll { overflow: auto; overscroll-behavior: contain; min-height: 0; padding: 16px 16px 8px; }
.chat-scroll:focus-visible { outline-offset: -3px; }
.chat-empty { display: grid; min-height: 100%; place-content: center; justify-items: center; gap: 8px; padding: 32px; color: var(--secondary); text-align: center; }
.chat-empty svg { color: var(--ink); }
#chat-empty { max-width: 440px; margin: 0; font-size: var(--text-xs); line-height: 1.7; }
#chat-messages { margin: 0; padding: 0; list-style: none; }
#chat-messages:empty { display: none; }
#chat-messages li { display: block; min-width: 0; padding: 0; border: 0; }
.chat-message { width: 100%; min-width: 0; }
.chat-message.user { margin-bottom: 16px; padding: 12px 16px; border-radius: 8px; background: var(--selection); text-align: right; }
.chat-message.assistant { margin-bottom: 8px; padding-bottom: 16px; }
.chat-message-body { margin: 0; color: var(--message-ink); font-size: var(--text-base); line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-waiting { color: var(--secondary); font-size: var(--text-sm); }
#chat-form { position: relative; padding: 12px 16px 16px; background: var(--raised); }
#chat-form .error { margin: 0; overflow-wrap: anywhere; }
.chat-compose-field { position: relative; display: grid; }
.chat-routing { display: grid; flex: 0 1 112px; min-width: 0; }
.chat-routing-track { position: relative; justify-self: start; width: min(100%, 112px); }
#chat-routing-model { min-width: 0; margin-top: -5px; padding-inline-start: 6px; overflow: hidden; color: var(--muted); font-size: .7rem; line-height: 1.2; text-align: start; text-overflow: ellipsis; white-space: nowrap; }
.chat-routing-stops { position: absolute; inset: 0 6px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.chat-routing-stops::before { content: ""; position: absolute; inset-inline: 0; height: 2px; background: var(--divider); }
.chat-routing-stops i { z-index: 0; width: 5px; height: 5px; margin-inline: -2.5px; border-radius: 50%; background: var(--secondary); }
#chat-reasoning { position: relative; display: block; height: 24px; margin: 0; padding: 0; border: 0; appearance: none; background: transparent; cursor: pointer; }
#chat-reasoning::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; border: 1px solid var(--raised); border-radius: 50%; background: var(--action); }
#chat-reasoning::-moz-range-thumb { box-sizing: border-box; width: 12px; height: 12px; border: 1px solid var(--raised); border-radius: 50%; background: var(--action); }
#chat-input {
  min-height: 46px;
  max-height: min(20rem, 30vh);
  field-sizing: content;
  resize: none;
  overflow-y: auto;
  padding: 12px 48px 12px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  outline: 0;
  background: var(--canvas);
  font: var(--text-sm)/1.55 var(--font-ui);
}
#chat-input:focus { border-color: var(--placeholder); box-shadow: var(--focus-ring); }
#chat-input::placeholder { color: var(--placeholder); }
#chat-send { position: absolute; right: 8px; bottom: 7px; color: var(--action); }
.settings { overflow: auto; background: var(--paper); }

.model-settings { padding: 16px 20px; }
.model-settings fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.model-settings h3 { margin: 0; overflow-wrap: anywhere; font-size: var(--text-base); font-weight: 600; }
#models-status, .model-note { margin: 8px 0; color: var(--muted); }
.model-toolbar, .provider-heading, .model-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.model-toolbar + .model-toolbar { margin-top: 8px; }
.model-toolbar select, [data-manual-model] { min-width: 0; flex: 1 1 180px; }
.model-toolbar select { min-height: 36px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; color: inherit; background: var(--raised); font: inherit; }
.provider-card { margin-top: 12px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--paper); }
.provider-heading { justify-content: space-between; margin-bottom: 8px; }
.provider-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); align-items: end; gap: 8px; }
.provider-fields label { display: grid; gap: 4px; margin: 0; }
.provider-fields .provider-check, .provider-check { display: flex; align-items: center; gap: 4px; margin: 0; font-weight: 400; }
.provider-check input { width: auto; }
.model-list { margin-top: 8px; }
.model-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.model-row:last-child { border-bottom: 0; }
.model-row input[type="number"] { width: 88px; }
.model-id { flex: 1 1 180px; min-width: 0; overflow-wrap: anywhere; }

.folder-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
dialog {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: inherit;
  background: var(--raised);
}
dialog::backdrop { background: rgb(0 0 0 / 52%); }
.folder-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.folder-location, .folder-empty { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.folder-form { margin-block: 12px; }
.folder-list { max-height: min(32vh, 240px); overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.folder-list:empty { display: none; }
.folder-list li { display: block; padding: 0; }
.folder-list button {
  width: 100%;
  border: 0;
  border-radius: 0;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}
.folder-list button:focus-visible { outline-offset: -2px; }

@media (max-width: 900px) {
  .workbench { grid-template-columns: 200px minmax(0, 1fr); }
}

@media (max-width: 680px) {
  .chat-heading { flex-wrap: wrap; }
  .chat-routing { order: 1; flex: 0 0 min(100%, 112px); margin-left: auto; }
}

@media (max-width: 480px) {
  .container { width: calc(100% - 24px); }
  .page-heading { margin-top: 24px; }
  li { align-items: flex-start; flex-direction: column; gap: 10px; padding: 14px; }
  .editor { padding: 14px; }
  .workbench { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .project-picker { margin-bottom: 0; }
  #project-switcher { display: flex; gap: 4px; overflow: auto; }
  #project-switcher button { width: max-content; max-width: 160px; min-height: 28px; }
  #open-chat { display: none; }
  .chat-scroll, #chat-form { padding-inline: 12px; }
  .page-heading { flex-wrap: wrap; }
}
