.chat-page {
  margin: 0;
  color: #17202f;
  background: #fff;
  font: 15px/1.65 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.chat-root {
  --ink: #17202f;
  --muted: #7c8798;
  --line: #e8ebf0;
  --soft: #f7f8fa;
  --blue: #376df5;
  --blue-soft: #eef3ff;
  --blue-line: #b7c9ff;
  --thinking: #687386;
  --panel: #fff;
  --composer-space: 220px;
  min-height: 100vh;
}

.chat-root, .chat-root * { box-sizing: border-box; }
.chat-root button, .chat-root textarea { font: inherit; }
.chat-root button, .chat-root a { -webkit-tap-highlight-color: transparent; }
.chat-root button { cursor: pointer; }
.chat-root a { color: inherit; text-decoration: none; }

.chat-root .chat-app { min-height: 100vh; display: flex; flex-direction: column; }
.chat-root .chat-header {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 72px; padding: 14px 28px; border-bottom: 1px solid #f0f1f4;
}
.chat-root .brand-lockup { display: flex; align-items: center; gap: 10px; }
.chat-root .brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; background: var(--blue); font-size: 17px; font-weight: 800;
}
.chat-root .brand-lockup strong { display: block; font-size: 14px; line-height: 1.2; }
.chat-root .brand-lockup span:not(.brand-mark) { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.chat-root .header-actions { display: flex; gap: 8px; }
.chat-root .icon-button {
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px;
  display: grid; place-items: center; background: #fff; color: #687386; font-size: 18px;
}
.chat-root .icon-button:hover { border-color: var(--blue-line); color: var(--blue); background: var(--blue-soft); }

.chat-root .chat-main { flex: 1; display: flex; min-height: 0; }
.chat-root .chat-column {
  width: min(920px, calc(100% - 40px)); min-height: calc(100vh - 72px);
  margin: 0 auto; display: flex; flex-direction: column; position: relative;
}
.chat-root .empty-state {
  display: flex; flex: 1; align-items: center; justify-content: center;
  flex-direction: column; padding: 90px 20px 170px; text-align: center;
}
.chat-root .empty-mark {
  width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 16px;
  border: 1px solid #c8d5ff; border-radius: 14px; color: var(--blue);
  background: var(--blue-soft); font-size: 24px;
}
.chat-root .empty-state h1 { margin: 0; font-size: clamp(26px, 4vw, 38px); line-height: 1.2; letter-spacing: 0; }
.chat-root .empty-state p { max-width: 500px; margin: 12px 0 0; color: var(--muted); font-size: 14px; }
.chat-root .empty-state[hidden] { display: none; }

.chat-root .chat-log { display: flex; flex-direction: column; gap: 30px; padding: 50px 0 var(--composer-space); scroll-padding-bottom: var(--composer-space); }
.chat-root .chat-log:empty { display: none; }
.chat-root .message { display: flex; flex-direction: column; gap: 12px; }
.chat-root .message.user { align-items: flex-end; }
.chat-root .user-bubble {
  max-width: min(700px, 88%); padding: 12px 18px; border-radius: 18px 18px 4px 18px;
  color: #19316e; background: var(--blue-soft); white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-root .assistant-message { max-width: 820px; }
.chat-root .thinking-panel {
  color: var(--thinking); overflow: hidden;
}
.chat-root .thinking-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 28px; padding: 0;
  border: 0; background: transparent; color: var(--thinking); font-size: 14px;
}
.chat-root .thinking-toggle:hover { color: var(--blue); }
.chat-root .thinking-icon { color: var(--blue); font-size: 16px; }
.chat-root .thinking-chevron { font-size: 15px; transition: transform .2s ease; }
.chat-root .thinking-toggle[aria-expanded="true"] .thinking-chevron { transform: rotate(90deg); }
.chat-root .thinking-body {
  max-width: 760px; padding: 9px 0 3px; color: #7e8998; font-size: 13px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-root .thinking-body[hidden] { display: none; }
.chat-root .answer-body {
  padding-left: 20px; color: #1d2634; overflow-wrap: anywhere; min-height: 24px;
}
.chat-root .answer-body > :first-child { margin-top: 0; }
.chat-root .answer-body > :last-child { margin-bottom: 0; }
.chat-root .answer-body p { margin: 0 0 14px; }
.chat-root .answer-body h1,
.chat-root .answer-body h2,
.chat-root .answer-body h3,
.chat-root .answer-body h4,
.chat-root .answer-body h5,
.chat-root .answer-body h6 {
  margin: 22px 0 10px; color: #17202f; line-height: 1.35; font-weight: 700;
}
.chat-root .answer-body h1 { font-size: 22px; }
.chat-root .answer-body h2 { font-size: 19px; }
.chat-root .answer-body h3 { font-size: 17px; }
.chat-root .answer-body h4,
.chat-root .answer-body h5,
.chat-root .answer-body h6 { font-size: 15px; }
.chat-root .answer-body ul,
.chat-root .answer-body ol { margin: 0 0 14px; padding-left: 24px; }
.chat-root .answer-body li + li { margin-top: 5px; }
.chat-root .answer-body blockquote {
  margin: 0 0 14px; padding: 8px 14px; border-left: 3px solid #cbd3e1;
  color: var(--thinking); background: var(--soft);
}
.chat-root .answer-body hr { margin: 20px 0; border: 0; border-top: 1px solid var(--line); }
.chat-root .answer-body a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.chat-root .answer-body code {
  padding: 2px 5px; border-radius: 4px; color: #334155; background: #f1f3f6;
  font: 0.9em/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.chat-root .answer-body pre {
  margin: 0 0 14px; padding: 13px 14px; overflow-x: auto; border: 1px solid #e3e7ed;
  border-radius: 8px; background: #f7f8fa; white-space: pre;
}
.chat-root .answer-body pre code {
  padding: 0; color: #263241; background: transparent; font-size: 13px; white-space: pre;
}
.chat-root .answer-body table {
  display: block; width: 100%; margin: 0 0 16px; overflow-x: auto;
  border-collapse: collapse; white-space: nowrap;
}
.chat-root .answer-body th,
.chat-root .answer-body td { padding: 8px 12px; border: 1px solid #dfe4ec; text-align: left; }
.chat-root .answer-body th { color: #17202f; background: #f4f6fa; font-weight: 700; }
.chat-root .answer-body tr:nth-child(even) td { background: #fbfcfd; }
.chat-root .answer-body img { max-width: 100%; height: auto; }
.chat-root .answer-body.streaming::after {
  content: ""; display: inline-block; width: 6px; height: 17px; margin-left: 4px;
  vertical-align: -3px; background: var(--blue); animation: chat-blink 1s steps(2, jump-none) infinite;
}
@keyframes chat-blink { 50% { opacity: 0; } }
.chat-root .message-meta { padding-left: 20px; color: var(--muted); font-size: 12px; }
.chat-root .message.error .answer-body { color: #b54751; }
.chat-root .action-confirmation { margin-left: 20px; padding: 12px 14px; border-left: 2px solid #c77b12; background: #fff7e6; }
.chat-root .action-confirmation[hidden] { display: none; }
.chat-root .confirmation-title { display: block; font-size: 13px; overflow-wrap: anywhere; }
.chat-root .confirmation-detail { margin: 8px 0 12px; max-height: 200px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 13px; }
.chat-root .confirmation-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.chat-root .confirmation-actions button { min-height: 32px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fff; font-size: 12px; }
.chat-root .confirmation-actions button[data-confirm="approve"] { border-color: var(--blue); color: #fff; background: var(--blue); }
.chat-root .confirmation-actions button:disabled { cursor: default; opacity: .5; }

.chat-root .composer-wrap {
  position: fixed; left: 50%; bottom: 20px; z-index: 4; width: min(920px, calc(100% - 40px));
  transform: translateX(-50%);
}
.chat-root .composer {
  position: relative; padding: 17px 17px 12px; border: 1px solid #dfe4ec; border-radius: 20px;
  background: rgba(255, 255, 255, .97); box-shadow: 0 12px 32px rgba(32, 48, 80, .09);
}
.chat-root .composer:focus-within { border-color: var(--blue-line); box-shadow: 0 12px 32px rgba(55, 109, 245, .12); }
.chat-root .composer textarea {
  display: block; width: 100%; min-height: 42px; max-height: 180px; padding: 0; resize: none;
  border: 0; outline: 0; color: var(--ink); background: transparent; line-height: 1.55;
}
.chat-root .composer textarea::placeholder { color: #a9b1bd; }
.chat-root .composer-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 13px; }
.chat-root .composer-left, .chat-root .composer-right { display: flex; align-items: center; gap: 9px; min-width: 0; }
.chat-root .composer-icon-button {
  width: 32px; height: 32px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 9px;
  display: grid; place-items: center; background: #fff; color: var(--muted); font-size: 16px;
}
.chat-root .composer-icon-button:hover { border-color: var(--blue-line); color: var(--blue); background: var(--blue-soft); }
.chat-root .embedded-only { display: none; }
.chat-root .tool-chip, .chat-root .selected-skill {
  min-height: 32px; padding: 0 11px; border: 1px solid var(--blue-line); border-radius: 999px;
  display: inline-flex; align-items: center; gap: 7px; background: var(--blue-soft); color: var(--blue);
  font-size: 13px;
}
.chat-root .tool-chip:hover { background: #e5edff; }
.chat-root .selected-skill { max-width: 280px; }
.chat-root .selected-skill[hidden] { display: none; }
.chat-root .selected-skill > span:not(.selected-dot) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-root .selected-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--blue); }
.chat-root .selected-skill button {
  width: 17px; height: 17px; padding: 0; border: 0; border-radius: 50%;
  color: var(--blue); background: transparent; line-height: 1;
}
.chat-root .selected-skill button:hover { background: #d8e3ff; }
.chat-root .send-button {
  width: 38px; height: 38px; flex: 0 0 auto; border: 0; border-radius: 50%;
  display: grid; place-items: center; color: #fff; background: #a9bfff; font-size: 23px; line-height: 1;
}
.chat-root .send-button.ready { background: var(--blue); }
.chat-root .send-button.stop { background: #687386; font-size: 15px; }
.chat-root .send-button:disabled { cursor: default; opacity: .55; }
.chat-root .composer-note { margin: 7px 0 0; color: #a2aab6; text-align: center; font-size: 11px; }

.chat-view {
  height: 100vh;
  min-height: 0;
  margin: -26px -24px -42px;
}

.chat-root .skill-popover {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 12px); z-index: 2;
  padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: #fff;
  box-shadow: 0 18px 45px rgba(32, 48, 80, .14);
}
.chat-root .skill-popover[hidden] { display: none; }
.chat-root .popover-head { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid #f0f1f4; }
.chat-root .popover-head strong { display: block; font-size: 14px; }
.chat-root .popover-head span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.chat-root .popover-close { width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 20px; }
.chat-root .popover-close:hover { background: var(--soft); color: var(--ink); }
.chat-root .skill-options { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; max-height: 420px; overflow: auto; padding-top: 12px; }
.chat-root .skill-option {
  display: flex; flex-direction: row; align-items: center; gap: 8px; min-width: 0; height: 38px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; text-align: left;
  background: #fff; color: var(--ink);
}
.chat-root .skill-option:hover, .chat-root .skill-option.selected { border-color: var(--blue-line); background: var(--blue-soft); }
.chat-root .skill-option-top { display: contents; }
.chat-root .skill-option-name { flex: none; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; font-size: 13px; }
.chat-root .skill-option-desc { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.chat-root .skill-option-badge { flex: none; color: var(--blue); font-size: 11px; }
.chat-root .skill-option-badge.risk { color: #b7791f; }
.chat-root .empty-skills { padding: 18px 4px; color: var(--muted); font-size: 13px; }
.chat-root .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; }

.chat-root.embedded-chat {
  --embedded-sidebar-width: 188px;
  height: 100%; min-height: 0;
}
.chat-root.embedded-chat .chat-app {
  height: 100%;
  min-height: 0;
  border: 0; border-radius: 0; overflow: hidden; background: #fff;
}
.chat-root.embedded-chat .chat-header { display: none; }
.chat-root.embedded-chat .chat-main { flex: 1; min-height: 0; }
.chat-root.embedded-chat .chat-column {
  width: min(920px, calc(100% - 40px));
  min-height: 0;
  height: 100%;
}
.chat-root.embedded-chat .empty-state { padding: 48px 20px 24px; }
.chat-root.embedded-chat .chat-log {
  flex: 1; min-height: 0; overflow-y: auto; padding: 28px 0 var(--composer-space);
  scroll-padding-bottom: var(--composer-space);
  scrollbar-gutter: stable;
}
.chat-root.embedded-chat .composer-wrap {
  position: fixed; left: var(--embedded-sidebar-width); right: 0; bottom: 0; z-index: 4;
  width: auto; transform: none; margin: 0; padding: 10px 24px 12px;
  /* border-top: 1px solid #f0f2f5; */ background: #fff;
}
.chat-root.embedded-chat .composer {
  width: min(920px, 100%); margin: 0 auto;
  padding: 13px 14px 10px; border-radius: 14px;
  box-shadow: 0 4px 16px rgba(32, 48, 80, .07);
}
.chat-root.embedded-chat .composer-note { display: none; }
.chat-root.embedded-chat .composer-toolbar { margin-top: 10px; }
.chat-root.embedded-chat .composer-icon-button { width: 30px; height: 30px; }
.chat-root.embedded-chat .send-button { width: 36px; height: 36px; }

@media (max-width: 680px) {
  .chat-root .chat-header { min-height: 62px; padding: 12px 16px; }
  .chat-root .chat-column, .chat-root .composer-wrap { width: calc(100% - 24px); }
  .chat-root .chat-column { min-height: calc(100vh - 62px); }
  .chat-root .empty-state { padding: 60px 12px 150px; }
  .chat-root .empty-state h1 { font-size: 28px; }
  .chat-root .chat-log { padding-top: 28px; gap: 24px; }
  .chat-root .composer-wrap { bottom: 12px; }
  .chat-root .composer { padding: 14px 13px 10px; border-radius: 17px; }
  .chat-root .composer-hint { display: none; }
  .chat-root .skill-options { max-height: 270px; }
  .chat-root .selected-skill { max-width: 190px; }
  .chat-root.embedded-chat .chat-app,
  .chat-root.embedded-chat .chat-main,
  .chat-root.embedded-chat .chat-column { min-height: 0; }
  .chat-root.embedded-chat .chat-column { width: calc(100% - 24px); }
  .chat-root.embedded-chat .empty-state { padding: 34px 12px 18px; }
  .chat-root.embedded-chat .chat-log { padding: 22px 0 var(--composer-space); }
  .chat-root.embedded-chat .composer-wrap { left: 72px; padding: 8px 12px 10px; }
}

@media (max-width: 900px) {
  .chat-view { height: 100vh; min-height: 0; margin: -22px -18px -40px; }
  .chat-root.embedded-chat { --embedded-sidebar-width: 72px; }
}
.chat-context { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px; border-bottom: 1px solid #e4e7ec; }
.chat-context[hidden] { display: none; }
.chat-context span { min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
