:root {
  color-scheme: light;
  --ink: #17241f;
  --muted: #68756f;
  --paper: #f4f1e8;
  --surface: #fffdf8;
  --line: #dcd7ca;
  --jade: #315f50;
  --jade-dark: #21483d;
  --jade-soft: #e4eee9;
  --cinnabar: #a34b38;
  --shadow: 0 24px 70px rgba(38, 48, 42, 0.12);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 6%, rgba(163, 75, 56, 0.08), transparent 28rem),
    radial-gradient(circle at 90% 92%, rgba(49, 95, 80, 0.12), transparent 32rem),
    var(--paper);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(1540px, calc(100% - 24px));
  height: min(880px, calc(100vh - 32px));
  min-height: 660px;
  margin: 16px auto;
  overflow: hidden;
  border: 1px solid rgba(49, 95, 80, 0.18);
  border-radius: 24px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark, .avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: var(--jade);
  font-family: "STKaiti", "KaiTi", serif;
}
.brand-mark { width: 42px; height: 42px; border-radius: 13px; font-size: 23px; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .03em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.connection {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b6a998;
  box-shadow: 0 0 0 4px rgba(182, 169, 152, .16);
}
.connection.ready .connection-dot { background: #4d8b6c; box-shadow: 0 0 0 4px rgba(77,139,108,.14); }
.connection.error .connection-dot { background: var(--cinnabar); box-shadow: 0 0 0 4px rgba(163,75,56,.14); }

.workspace { display: grid; grid-template-columns: 286px minmax(400px, 1fr) 390px; height: calc(100% - 82px); }

.settings {
  overflow-y: auto;
  padding: 28px 24px;
  border-right: 1px solid var(--line);
  background: rgba(244, 241, 232, 0.56);
}

.debug-panel {
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  border-left: 1px solid var(--line);
  background: #18221e;
  color: #dae6df;
}
.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 18px 14px;
}
.debug-header h2 { margin: 3px 0 0; color: #f6f2e8; font-size: 16px; }
.debug-header .eyebrow { color: #d78a75; }
.debug-actions { display: flex; gap: 6px; }
.debug-actions button {
  padding: 5px 8px;
  color: #aebdb6;
  border: 1px solid #3a4a43;
  border-radius: 7px;
  background: #23302a;
  font-size: 11px;
}
.debug-actions button:hover { color: #fff; border-color: #60746a; }
.debug-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 0 18px 15px;
}
.debug-summary > div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #33423b;
  border-radius: 9px;
  background: #202d27;
}
.debug-summary .trace-card { grid-column: 1 / -1; }
.debug-summary span { display: block; margin-bottom: 4px; color: #84968d; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.debug-summary strong { display: block; overflow: hidden; color: #eef4f0; font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.debug-tabs { display: grid; grid-template-columns: repeat(5, 1fr); padding: 0 12px; border-bottom: 1px solid #33423b; }
.debug-tabs button {
  padding: 10px 4px 9px;
  color: #82948b;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-size: 11px;
}
.debug-tabs button.active { color: #f1f6f3; border-bottom-color: #65a386; }
.debug-content { min-height: 0; overflow: auto; }
.debug-view { min-height: 100%; padding: 12px; }
.debug-view[hidden] { display: none; }
.empty-debug { padding: 24px 12px; color: #70837a; text-align: center; font-size: 11px; line-height: 1.6; }
.timings-list { display: grid; gap: 10px; }
.timing-entry { display: grid; gap: 5px; }
.timing-header { display: flex; justify-content: space-between; gap: 12px; color: #9eb0a7; font: 10px/1.3 "Cascadia Code", Consolas, monospace; }
.timing-header strong { color: #d8e4de; font-weight: 500; }
.timing-track { height: 4px; overflow: hidden; border-radius: 3px; background: #26352e; }
.timing-track span { display: block; height: 100%; border-radius: inherit; background: #65a386; }
.timing-entry.total .timing-header { color: #f0b28f; }
.timing-entry.total .timing-track span { background: #d78a75; }
.debug-view pre {
  margin: 0;
  color: #c9d9d1;
  font: 10px/1.65 "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}
.event-log { display: grid; gap: 7px; }
.event-entry { border: 1px solid #314039; border-radius: 8px; background: #1d2924; }
.event-entry summary {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 8px 9px;
  cursor: pointer;
  list-style: none;
}
.event-entry summary::-webkit-details-marker { display: none; }
.event-entry .event-time { color: #6f8b7d; font: 9px "Cascadia Code", Consolas, monospace; }
.event-entry .event-name { color: #dbe9e2; font: 11px "Cascadia Code", Consolas, monospace; }
.event-entry .event-size { color: #61776c; font-size: 9px; }
.event-entry[data-event="error"] { border-color: #7e473e; }
.event-entry[data-event="complete"] { border-color: #3f6c58; }
.event-entry pre { padding: 9px; border-top: 1px solid #314039; background: #15201b; }
.stages-list { display: grid; gap: 7px; }
.stage-entry { border: 1px solid #314039; border-radius: 8px; background: #1d2924; }
.stage-entry summary { display: grid; grid-template-columns: 25px 1fr auto; gap: 7px; padding: 9px; cursor: pointer; list-style: none; }
.stage-entry summary::-webkit-details-marker { display: none; }
.stage-index { color: #65a386; font: 10px "Cascadia Code", Consolas, monospace; }
.stage-name { min-width: 0; overflow: hidden; color: #dbe9e2; font: 10px "Cascadia Code", Consolas, monospace; text-overflow: ellipsis; }
.stage-confidence { color: #a8b8b0; font-size: 9px; }
.stage-entry pre { padding: 9px; border-top: 1px solid #314039; background: #15201b; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; }
.section-heading.compact { margin-bottom: 16px; }
.eyebrow { color: var(--cinnabar); font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.section-heading h2 { margin: 4px 0 0; font-family: "STKaiti", "KaiTi", serif; font-size: 20px; font-weight: 600; }
.text-button { padding: 4px 0; color: var(--jade); border: 0; background: none; font-size: 12px; }
.text-button:hover { color: var(--cinnabar); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 10px; }
.field { display: grid; gap: 7px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field span { color: var(--muted); font-size: 12px; }
.field input, .field select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  transition: border-color .18s, box-shadow .18s;
}
.field input:focus, .field select:focus, .composer textarea:focus {
  border-color: var(--jade);
  box-shadow: 0 0 0 3px rgba(49, 95, 80, .1);
}
.divider { height: 1px; margin: 25px 0; background: var(--line); }
.api-key-field { margin-top: 2px; }
.privacy-note {
  margin-top: 22px;
  padding: 13px 14px;
  color: var(--muted);
  border: 1px solid rgba(49, 95, 80, .16);
  border-radius: 12px;
  background: var(--jade-soft);
  font-size: 11px;
  line-height: 1.65;
}

.chat { min-width: 0; min-height: 0; display: grid; grid-template-rows: 1fr auto auto; background: var(--surface); }
.messages { overflow-y: auto; padding: 34px clamp(20px, 5vw, 62px) 26px; scroll-behavior: smooth; }
.message { display: flex; gap: 11px; max-width: 780px; margin: 0 auto 24px; }
.message.user { justify-content: flex-end; }
.avatar { width: 34px; height: 34px; margin-top: 2px; border-radius: 11px; font-size: 16px; }
.bubble { max-width: min(680px, calc(100% - 45px)); color: #27332e; }
.assistant .bubble {
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 4px 17px 17px 17px;
  background: #fff;
}
.user .bubble {
  padding: 13px 16px;
  color: #fff;
  border-radius: 17px 17px 4px 17px;
  background: var(--jade);
}
.bubble p { margin: 0; white-space: pre-wrap; line-height: 1.78; }
.message-label { margin-bottom: 7px !important; color: var(--jade); font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.message-meta { margin-top: 10px !important; color: var(--muted); font-size: 11px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.suggestions button {
  padding: 7px 10px;
  color: var(--jade);
  border: 1px solid rgba(49, 95, 80, .22);
  border-radius: 999px;
  background: var(--jade-soft);
  font-size: 12px;
}
.suggestions button:hover { border-color: var(--jade); background: #dbe9e2; }
.chart-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chart-strip span { padding: 5px 8px; color: var(--jade-dark); border-radius: 7px; background: var(--jade-soft); font-size: 12px; }

.progress {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px clamp(20px, 5vw, 62px);
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.progress[hidden] { display: none; }
.spinner { width: 13px; height: 13px; border: 2px solid #cfdbd5; border-top-color: var(--jade); border-radius: 50%; animation: spin .8s linear infinite; }
.stage-count { margin-left: auto; color: var(--jade); }
@keyframes spin { to { transform: rotate(360deg); } }

.composer { margin: 0 clamp(18px, 4vw, 48px) 26px; padding: 12px 13px 10px; border: 1px solid var(--line); border-radius: 17px; background: #fff; box-shadow: 0 10px 32px rgba(49, 63, 56, .08); }
.composer:focus-within { border-color: rgba(49, 95, 80, .58); }
.composer textarea { display: block; width: 100%; max-height: 150px; resize: none; padding: 3px 3px 9px; color: var(--ink); border: 0; outline: 0; background: transparent; line-height: 1.6; }
.composer-actions { display: flex; align-items: center; gap: 9px; }
.hint { margin-right: auto; color: #929b96; font-size: 10px; }
.send-button, .stop-button { min-height: 34px; padding: 7px 13px; border-radius: 10px; }
.send-button { display: flex; align-items: center; gap: 8px; color: #fff; border: 1px solid var(--jade); background: var(--jade); }
.send-button:hover { background: var(--jade-dark); }
.send-button:disabled { cursor: not-allowed; opacity: .5; }
.stop-button { color: var(--cinnabar); border: 1px solid rgba(163,75,56,.3); background: #fff7f4; }
.stop-button[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 820px) {
  .shell { width: 100%; height: 100vh; min-height: 600px; margin: 0; border: 0; border-radius: 0; }
  .topbar { height: 70px; padding: 0 18px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand p { display: none; }
  .workspace { display: block; height: calc(100% - 70px); overflow-y: auto; }
  .settings { max-height: 255px; padding: 18px; border-right: 0; border-bottom: 1px solid var(--line); }
  .settings .divider, .settings .compact, .settings .api-key-field, .settings .privacy-note { display: none; }
  .section-heading { margin-bottom: 12px; }
  .field-grid { grid-template-columns: repeat(4, minmax(118px, 1fr)); overflow-x: auto; padding-bottom: 4px; }
  .field.full { grid-column: auto; }
  .chat { height: 620px; min-height: 0; }
  .debug-panel { height: 560px; border-top: 1px solid var(--line); border-left: 0; }
  .messages { padding-top: 22px; }
  .composer { margin-bottom: 14px; }
}

@media (max-width: 520px) {
  .connection span:last-child { display: none; }
  .messages { padding-inline: 14px; }
  .composer { margin-inline: 12px; }
  .hint { display: none; }
  .bubble { max-width: calc(100% - 42px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
