:root {
  color: #202320;
  background: #f4f5f2;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", Arial, sans-serif;
  font-synthesis: none;
  --line: #d9ddd7;
  --muted: #697069;
  --surface: #ffffff;
  --surface-soft: #f0f2ee;
  --accent: #166534;
  --accent-hover: #14532d;
  --danger: #b42318;
  --warning: #a15c08;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body { min-height: 100vh; min-height: 100dvh; }

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand-block, .topbar-actions, .composer-actions, .connection-state {
  display: flex;
  align-items: center;
}

.brand-block { gap: 11px; min-width: 0; }

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 7px;
  background: #202320;
  color: white;
  font-weight: 800;
}

h1, h2, p { margin: 0; }

h1 { font-size: 16px; line-height: 1.25; }

.brand-block p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(52vw, 520px);
}

.topbar-actions { gap: 10px; }

.connection-state {
  gap: 7px;
  min-width: 0;
  max-width: min(48vw, 420px);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.connection-state > span:last-child { overflow: hidden; text-overflow: ellipsis; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa19a; }
.connection-state[data-state="ok"] .status-dot { background: #16803c; }
.connection-state[data-state="busy"] .status-dot { background: var(--warning); }
.connection-state[data-state="error"] .status-dot { background: var(--danger); }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.settings-panel {
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #fafbf9;
}

.settings-section { padding: 20px; border-bottom: 1px solid var(--line); }
.settings-section h2 { margin-bottom: 16px; font-size: 13px; text-transform: uppercase; color: #464c46; }

.field, .range-field { display: grid; gap: 7px; margin-bottom: 15px; }
.field > span, .range-field > span { color: #4b524b; font-size: 13px; font-weight: 650; }
.range-field > span { display: flex; justify-content: space-between; }

input, select, textarea {
  width: 100%;
  border: 1px solid #cbd0ca;
  border-radius: 6px;
  background: var(--surface);
  color: #202320;
  outline: none;
}

input, select { height: 38px; padding: 0 10px; }
textarea { padding: 10px 11px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(22, 101, 52, .12); }
input[type="range"] { height: 24px; padding: 0; accent-color: var(--accent); box-shadow: none; border: 0; }

.button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
}

.button:disabled { opacity: .55; cursor: not-allowed; }
.button.primary { background: var(--accent); color: white; }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); }
.button.secondary { background: var(--surface); color: #343934; border-color: #cbd0ca; }
.button.danger { background: #fff5f3; color: var(--danger); border-color: #efc4bd; }
.full-width { width: 100%; }

.runtime-section { padding: 18px 20px; }
.runtime-section dl { margin: 0; display: grid; gap: 9px; font-size: 12px; }
.runtime-section dl div { display: flex; justify-content: space-between; gap: 12px; }
.runtime-section dt { color: var(--muted); }
.runtime-section dd { margin: 0; font-weight: 650; text-align: right; }

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: var(--surface);
}

.messages {
  overflow-y: auto;
  padding: 28px max(24px, calc((100% - 860px) / 2));
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  gap: 7px;
  color: var(--muted);
  text-align: center;
}
.empty-state strong { color: #2f352f; font-size: 18px; }

.message { margin-bottom: 24px; }
.message-header { margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 750; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.message.user { margin-left: auto; max-width: 82%; }
.message.user .message-content { padding: 12px 14px; border-radius: 7px; background: var(--surface-soft); }
.message.assistant { padding-left: 14px; border-left: 3px solid #55a36d; }
.message.error { padding-left: 14px; border-left: 3px solid var(--danger); color: #8b1e16; }
.cursor::after { content: ""; display: inline-block; width: 7px; height: 15px; margin-left: 3px; vertical-align: -2px; background: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer {
  padding: 14px max(24px, calc((100% - 860px) / 2)) 18px;
  border-top: 1px solid var(--line);
  background: #fafbf9;
}
.composer textarea { min-height: 74px; max-height: 220px; background: white; }
.composer-actions { min-height: 44px; justify-content: space-between; gap: 12px; }
.composer-actions > span { color: var(--muted); font-size: 12px; }
.composer-actions > div { display: flex; gap: 8px; }

@media (max-width: 760px) {
  .app-shell { min-height: 0; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { min-height: 60px; padding: 10px 14px; }
  .connection-state { display: none; }
  .workspace { display: grid; grid-template-rows: minmax(180px, 36dvh) minmax(0, 1fr); }
  .settings-panel { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .settings-section { padding: 14px; }
  .runtime-section { display: none; }
  .chat-panel { height: auto; min-height: 0; }
  .messages, .composer { padding-left: 14px; padding-right: 14px; }
  .message.user { max-width: 94%; }
}
