:root {
  color-scheme: light;
  --primary: #2468f2;
  --primary-hover: #1554d1;
  --primary-soft: #e8f3ff;
  --success: #168c46;
  --success-soft: #e8f7ed;
  --error: #d92d20;
  --error-soft: #fff0ee;
  --ink: #1f2329;
  --ink-soft: #4e5969;
  --muted: #6b7785;
  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-tinted: #f7f8fa;
  --surface-subtle: #f2f3f5;
  --border: #e5e6eb;
  --focus: #1554d1;
  --z-sticky: 20;
  --z-modal: 80;
  --z-toast: 100;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.6;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { font: inherit; }

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 72%, white);
  outline-offset: 3px;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: var(--z-toast);
  padding: 10px 14px;
  border-radius: 8px;
  color: white;
  background: var(--primary-hover);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.app-shell {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  width: min(1280px, calc(100% - 32px));
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  margin: 16px auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.category-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 20px 16px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface-tinted);
}

.brand {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark,
.agent-avatar,
.message-avatar,
.welcome-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  background: var(--surface);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  box-shadow: 0 1px 4px rgb(31 35 41 / 10%);
}

.brand-mark img,
.agent-avatar img,
.message-avatar img,
.welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.brand-copy strong {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-copy span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 14px;
}

.category-heading {
  margin-top: 30px;
  padding: 0 8px;
}

.category-heading h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.4;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.category-heading p {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.75;
  text-wrap: pretty;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 18px;
}

.category-button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: border-color 180ms cubic-bezier(0.22, 1, 0.36, 1), background-color 180ms cubic-bezier(0.22, 1, 0.36, 1), transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.category-button:hover { background: var(--surface); }
.category-button:active { transform: scale(0.985); }

.category-button[aria-current="true"] {
  border-color: #b7d4ff;
  color: #1549a8;
  background: var(--primary-soft);
}

.category-icon {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  margin-right: 11px;
  place-items: center;
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface-subtle);
}

.category-button[aria-current="true"] .category-icon {
  color: var(--primary-hover);
  background: #d7e8ff;
}

.category-icon svg {
  width: 20px;
  height: 20px;
}

.category-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
}

.category-copy strong {
  font-size: 16px;
  line-height: 1.45;
}

.category-copy small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-chevron {
  width: 17px;
  height: 17px;
  margin-left: 7px;
  color: var(--muted);
  opacity: 0.62;
}

.category-button[aria-current="true"] .category-chevron {
  color: var(--primary);
  opacity: 1;
}

.sidebar-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: auto;
  padding: 14px 12px;
  border-top: 1px solid var(--border);
}

.note-mark {
  display: grid;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  color: var(--primary-hover);
  background: var(--primary-soft);
}

.note-mark svg {
  width: 17px;
  height: 17px;
}

.sidebar-note p {
  display: flex;
  margin: 0;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.55;
}

.sidebar-note strong { font-size: 14px; }
.sidebar-note span { margin-top: 2px; color: var(--muted); }

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

.chat-header {
  position: relative;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
}

.agent,
.agent small,
.chat-actions,
.quiet-button {
  display: flex;
  align-items: center;
}

.agent { gap: 11px; }

.agent-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgb(31 35 41 / 10%);
}

.agent > span:last-child {
  display: flex;
  flex-direction: column;
}

.agent strong {
  font-size: 17px;
  line-height: 1.35;
}

.agent small {
  gap: 7px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.agent small > span:first-child {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.chat-actions { gap: 4px; }

.quiet-button {
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  gap: 7px;
  padding: 0 11px;
  border: 0;
  border-radius: 9px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: color 180ms ease-out, background-color 180ms ease-out, opacity 180ms ease-out;
}

.quiet-button svg {
  width: 18px;
  height: 18px;
}

.quiet-button:hover:not(:disabled) {
  color: var(--primary-hover);
  background: var(--primary-soft);
}

.quiet-button:active:not(:disabled) { background: #d7e8ff; }

.quiet-button:disabled {
  cursor: not-allowed;
  opacity: 0.32;
}

.mobile-categories { display: none; }

.chat-messages {
  min-height: 0;
  padding: 28px clamp(28px, 5vw, 64px) 40px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

.welcome-state {
  display: flex;
  width: min(560px, 100%);
  min-height: 100%;
  margin: 0 auto;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding-bottom: 7vh;
}

.welcome-avatar {
  width: 66px;
  height: 66px;
  margin-bottom: 23px;
  border-radius: 16px;
  background: var(--surface-subtle);
}

.welcome-state h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.35;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.welcome-state > p {
  max-width: 42ch;
  margin: 11px 0 0;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1.85;
  text-wrap: pretty;
}

.welcome-guide {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 26px;
  padding: 10px 13px;
  border-radius: 10px;
  color: var(--primary-hover);
  background: var(--primary-soft);
  font-size: 15px;
  font-weight: 700;
}

.welcome-guide svg {
  width: 18px;
  height: 18px;
}

.message-row {
  display: flex;
  width: 100%;
  max-width: 760px;
  margin: 0 auto 22px;
  gap: 13px;
}

.message-row.is-entering,
.option-list.is-entering {
  animation: message-in 180ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.message-row:last-child { margin-bottom: 0; }

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgb(31 35 41 / 9%);
}

.message-bubble {
  min-width: 0;
  max-width: min(680px, calc(100% - 47px));
}

.agent-bubble {
  position: relative;
  padding: 13px 16px 14px;
  border-radius: 4px 10px 10px 10px;
  background: var(--surface-subtle);
}

.agent-bubble::before {
  position: absolute;
  top: 0;
  left: -7px;
  width: 12px;
  height: 12px;
  border-radius: 0 0 0 10px;
  background: var(--surface-subtle);
  content: "";
}

.agent-bubble h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.55;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.agent-bubble h2 + .message-content { margin-top: 7px; }

.message-content {
  max-width: 70ch;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1.75;
  white-space: pre-line;
  text-wrap: pretty;
}

.message-image-link {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  color: var(--primary-hover);
  background: var(--surface);
  cursor: zoom-in;
}

.image-bubble {
  width: fit-content;
  padding: 0;
  overflow: hidden;
  background: transparent;
}

.image-bubble::before { display: none; }

.agent-bubble h2 + .message-image-link { margin-top: 0; }

.message-image {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: min(520px, 56vh);
  object-fit: contain;
}

.message-image-caption {
  margin: 0;
  padding: 10px 12px 11px;
  color: var(--ink-soft);
  background: var(--surface-subtle);
  font-size: 15px;
  line-height: 1.6;
}

.image-load-error {
  display: block;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
}

.user-row {
  justify-content: flex-end;
  padding-left: 47px;
}

.user-bubble {
  max-width: 78%;
  padding: 11px 16px;
  border-radius: 10px 4px 10px 10px;
  color: white;
  background: var(--primary);
  font-size: 16px;
  font-weight: 700;
}

.option-list {
  display: flex;
  max-width: 680px;
  margin: 10px auto 22px;
  padding-left: 47px;
  flex-direction: column;
  gap: 9px;
}

.option-button,
.retry-button,
.inline-action {
  cursor: pointer;
  transition: color 180ms ease-out, background-color 180ms ease-out, border-color 180ms ease-out, transform 180ms cubic-bezier(0.22, 1, 0.36, 1), opacity 180ms ease-out;
}

.option-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  min-height: 56px;
  padding: 9px 13px 9px 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  text-align: left;
}

.option-button:hover {
  border-color: #91baff;
  background: #f5f9ff;
}

.option-button:active { transform: scale(0.99); }

.option-button:disabled,
.retry-button:disabled {
  cursor: wait;
  opacity: 0.48;
}

.option-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.option-copy strong {
  font-size: 16px;
  line-height: 1.5;
}

.option-copy small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.option-button svg {
  width: 18px;
  height: 18px;
  margin-left: 13px;
  color: var(--primary);
}

.error-panel,
.completion-panel {
  max-width: 680px;
  margin: 12px auto 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.error-panel p,
.completion-panel p {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.retry-button,
.inline-action {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 700;
}

.retry-button {
  border: 1px solid var(--primary);
  color: white;
  background: var(--primary);
}

.retry-button:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.inline-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  border: 1px solid var(--primary);
  color: var(--primary-hover);
  background: var(--surface);
  text-decoration: none;
}

.inline-action:hover { background: var(--primary-soft); }

.error-panel {
  border-color: #f1b4ae;
  background: var(--error-soft);
}

.error-panel p + p,
.completion-panel p + p {
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 400;
}

.completion-panel {
  border-color: #b7dfc4;
  background: var(--success-soft);
}

.completion-panel p:first-child { color: var(--success); }

.skeleton {
  position: relative;
  display: block;
  overflow: hidden;
  background: #e5e6eb;
}

.skeleton::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 75%), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}

.skeleton-bubble {
  width: min(520px, calc(100% - 47px));
  padding: 9px 0;
}

.skeleton.line-wide,
.skeleton.line-short {
  height: 12px;
  border-radius: 4px;
}

.skeleton.line-wide { width: 82%; }

.skeleton.line-short {
  width: 48%;
  margin-top: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--z-toast);
  max-width: min(360px, calc(100vw - 32px));
  padding: 11px 15px;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  box-shadow: 0 4px 12px rgb(31 35 41 / 18%);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}

.image-preview {
  width: auto;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  margin: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 10px;
  color: white;
  background: #111318;
}

.image-preview::backdrop {
  background: rgb(10 12 16 / 86%);
}

.image-preview-figure {
  display: flex;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  margin: 0;
  flex-direction: column;
}

.image-preview-figure img {
  display: block;
  min-width: 0;
  max-width: 100%;
  max-height: calc(100vh - 112px);
  max-height: calc(100dvh - 112px);
  object-fit: contain;
}

.image-preview-figure figcaption {
  padding: 12px 16px 14px;
  color: #f2f3f5;
  font-size: 16px;
  line-height: 1.6;
}

.image-preview-close {
  position: absolute;
  top: -18px;
  right: -18px;
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 2px solid rgb(255 255 255 / 86%);
  border-radius: 50%;
  color: white;
  background: #20242c;
  cursor: pointer;
}

.image-preview-close:hover { background: #353b47; }

.image-preview-close svg {
  width: 22px;
  height: 22px;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(7px); }
}

@keyframes shimmer {
  to { transform: translateX(100%); }
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
    background: var(--surface);
  }

  .app-shell {
    display: block;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .category-panel { display: none; }
  .chat-panel { height: 100%; }

  .chat-header {
    min-height: 64px;
    padding: 9px 14px;
  }

  .agent-avatar { width: 38px; height: 38px; }
  .agent strong { font-size: 16px; }
  .agent small { margin-top: 1px; }
  .quiet-button { padding: 0 8px; }
  .quiet-button span { display: none; }

  .mobile-categories {
    display: flex;
    gap: 8px;
    padding: 10px 14px 11px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    background: var(--surface-tinted);
    scrollbar-width: none;
  }

  .mobile-categories::-webkit-scrollbar { display: none; }

  .mobile-categories .category-button {
    width: auto;
    min-width: max-content;
    min-height: 44px;
    padding: 7px 12px;
    border-color: var(--border);
    border-radius: 9px;
    background: var(--surface);
  }

  .mobile-categories .category-button[aria-current="true"] {
    border-color: #91baff;
    color: #1549a8;
    background: var(--primary-soft);
  }

  .mobile-categories .category-icon,
  .mobile-categories .category-copy small,
  .mobile-categories .category-chevron { display: none; }

  .mobile-categories .category-copy strong { font-size: 15px; }

  .chat-messages {
    padding: 28px 16px 36px;
    scrollbar-gutter: auto;
  }

  .welcome-state {
    min-height: calc(100% - 10px);
    padding: 0 12px 11vh;
  }

  .welcome-avatar {
    width: 58px;
    height: 58px;
    margin-bottom: 19px;
    border-radius: 14px;
  }

  .welcome-state h2 { font-size: 24px; }
  .welcome-state > p { font-size: 16px; }
  .welcome-guide { margin-top: 22px; }

  .message-row {
    margin-bottom: 20px;
    gap: 10px;
  }

  .message-avatar { width: 30px; height: 30px; }
  .message-bubble { max-width: calc(100% - 40px); }
  .agent-bubble h2 { font-size: 19px; }

  .agent-bubble {
    padding: 14px 15px 15px;
  }

  .image-bubble { padding: 0; }

  .message-content {
    font-size: 16px;
    line-height: 1.75;
  }

  .user-row { padding-left: 40px; }

  .option-list {
    margin-top: 8px;
    padding-left: 40px;
  }

  .error-panel,
  .completion-panel { margin-left: 40px; }
  .option-button { min-height: 58px; }

  .toast {
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
  }

  .image-preview,
  .image-preview-figure {
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 40px);
  }

  .image-preview-close {
    top: 8px;
    right: 8px;
  }

  .image-preview-figure img { max-height: calc(100dvh - 96px); }
}

@media (max-width: 390px) {
  .chat-header { padding-right: 8px; }
  .agent { gap: 8px; }
  .mobile-categories { padding-right: 12px; padding-left: 12px; }
  .chat-messages { padding-right: 12px; padding-left: 12px; }
  .user-bubble { max-width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
