:root {
  color-scheme: light;
  --color-background: #f7f8fb;
  --color-surface: #ffffff;
  --color-text: #16172a;
  --color-muted: #73778a;
  --color-border: #e2e4ec;
  --color-assistant: #f2f1fb;
  --color-accent: #5946e8;
  --color-accent-dark: #4935d2;
  --color-success: #20b976;
  --color-error: #b4233d;
  --shadow-frame: 0 24px 70px rgb(27 23 76 / 8%);
  --font-ui: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--color-background);
  color: var(--color-text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(24px, 4vw, 64px);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--color-text);
  font-size: 25px;
  font-weight: 760;
  letter-spacing: -0.035em;
  text-decoration: none;
}

.brand-mark,
.assistant-avatar {
  display: grid;
  place-items: center;
  color: var(--color-accent);
}

.brand-mark {
  width: 42px;
  height: 42px;
}

.brand-mark svg,
.assistant-avatar svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.brand-mark path,
.assistant-avatar path {
  fill: none;
  stroke: currentcolor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.6;
}

.brand-mark circle,
.assistant-avatar circle {
  fill: currentcolor;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 34px;
}

.new-chat-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 17px;
  border: 1px solid var(--color-accent);
  border-radius: 11px;
  background: var(--color-surface);
  color: var(--color-accent);
  cursor: pointer;
  font-size: 15px;
  font-weight: 650;
  transition:
    background-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.new-chat-button svg {
  width: 18px;
  fill: none;
  stroke: currentcolor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.new-chat-button:hover {
  background: #f3f1ff;
}

.new-chat-button:active {
  transform: translateY(1px);
}

.online-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #343547;
  font-size: 15px;
  font-weight: 560;
}

.online-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 0 4px rgb(32 185 118 / 11%);
}

.chat-frame {
  display: grid;
  width: min(1390px, calc(100% - 48px));
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
  margin: 28px auto 30px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  box-shadow: var(--shadow-frame);
}

.message-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 26px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: clamp(30px, 5vh, 58px) clamp(28px, 7vw, 92px) 24px;
  scroll-behavior: smooth;
  scrollbar-color: #c9c9d5 transparent;
  scrollbar-width: thin;
}

.message-row {
  display: flex;
  width: 100%;
  align-items: flex-start;
  gap: 14px;
  animation: message-enter 220ms ease-out both;
}

.user-message {
  justify-content: flex-end;
  padding-left: min(24vw, 260px);
}

.assistant-message {
  padding-right: min(18vw, 200px);
}

.assistant-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  padding: 7px;
  border-radius: 50%;
  background: #f0eefe;
}

.message-bubble {
  max-width: 700px;
  padding: 15px 19px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.assistant-bubble {
  border-top-left-radius: 7px;
  background: var(--color-assistant);
  min-width: 0;
  white-space: normal;
}

.answer-text {
  white-space: pre-wrap;
}

.tool-traces {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.tool-traces:empty {
  display: none;
}

.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid #d9d2fb;
  border-radius: 8px;
  color: var(--color-accent-dark);
  background: #faf9ff;
  font-size: 11px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.tool-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: currentcolor;
}

.tool-badge[data-state="running"]::before,
.tool-badge[data-state="retrying"]::before {
  animation: cursor-blink 800ms steps(1, end) infinite;
}

.tool-badge[data-state="succeeded"] {
  color: #187552;
  border-color: #b8dfce;
  background: #f3fcf7;
}

.tool-badge[data-state="failed"] {
  color: var(--color-error);
  border-color: #f0c7cf;
  background: #fff7f8;
}

.reply-error {
  margin-top: 6px;
  color: var(--color-error);
  font-size: 13px;
}

.user-bubble {
  border-bottom-right-radius: 7px;
  background: var(--color-accent);
  color: #fff;
}

.error-bubble {
  border: 1px solid #f0c7cf;
  background: #fff2f4;
  color: var(--color-error);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 27px;
}

.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: dot-bounce 900ms infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dots i:nth-child(3) {
  animation-delay: 240ms;
}

.streaming::after {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 4px;
  background: var(--color-accent);
  content: "";
  vertical-align: -0.13em;
  animation: cursor-blink 800ms steps(1, end) infinite;
}

.composer-area {
  padding: 12px clamp(28px, 7vw, 92px) 22px;
  background: var(--color-surface);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 50px;
  align-items: end;
  gap: 12px;
  padding: 8px 9px 8px 20px;
  border: 1px solid #cfd2de;
  border-radius: 16px;
  background: var(--color-surface);
  box-shadow: 0 6px 26px rgb(32 27 82 / 7%);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: var(--color-accent);
  box-shadow:
    0 0 0 3px rgb(89 70 232 / 12%),
    0 8px 30px rgb(32 27 82 / 8%);
}

.composer textarea {
  width: 100%;
  max-height: 132px;
  min-height: 48px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.55;
  padding: 11px 0;
}

.composer textarea::placeholder {
  color: #9699a9;
}

.composer textarea:disabled {
  color: var(--color-muted);
}

.send-button {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
  transition:
    background-color 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.send-button:hover:not(:disabled) {
  background: var(--color-accent-dark);
  transform: translateY(-1px);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.send-icon {
  width: 23px;
  fill: none;
  stroke: currentcolor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.send-loader {
  display: none;
  width: 19px;
  height: 19px;
  border: 2px solid rgb(255 255 255 / 38%);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.send-button.loading .send-icon {
  display: none;
}

.send-button.loading .send-loader {
  display: block;
}

.disclaimer {
  margin: 12px 0 0;
  color: var(--color-muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.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;
}

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

@keyframes dot-bounce {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes cursor-blink {
  0%,
  48% {
    opacity: 1;
  }
  49%,
  100% {
    opacity: 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-rows: 66px minmax(0, 1fr);
  }

  .app-header {
    padding: 0 16px;
  }

  .brand {
    gap: 8px;
    font-size: 21px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .header-actions {
    gap: 14px;
  }

  .new-chat-button {
    min-width: 42px;
    min-height: 42px;
    justify-content: center;
    padding: 0 11px;
  }

  .new-chat-button span,
  .online-status span:last-child {
    display: none;
  }

  .online-status {
    gap: 0;
  }

  .chat-frame {
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .message-list {
    gap: 20px;
    padding: 26px 16px 18px;
  }

  .assistant-message {
    padding-right: 8vw;
  }

  .user-message {
    padding-left: 18vw;
  }

  .assistant-avatar {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
    padding: 6px;
  }

  .message-row {
    gap: 9px;
  }

  .message-bubble {
    padding: 12px 14px;
    border-radius: 15px;
    font-size: 15px;
    line-height: 1.65;
  }

  .composer-area {
    padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 45px;
    gap: 8px;
    padding: 6px 7px 6px 15px;
    border-radius: 15px;
  }

  .composer textarea {
    min-height: 45px;
    font-size: 16px;
    padding: 10px 0;
  }

  .send-button {
    width: 45px;
    height: 45px;
    border-radius: 11px;
  }

  .disclaimer {
    margin-top: 8px;
    font-size: 11px;
  }
}

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

.citation-button { color: #6d45bf; background: #f0eafa; border: 0; border-radius: 5px; padding: 0 4px; cursor: pointer; font: inherit; }
 .rag-status { color: #776886; font-size: 14px; margin-bottom: 8px; }
.answer-feedback { display: flex; gap: 2px; align-items: center; margin-top: 12px; color: #858093; font-size: 12px; }
.answer-feedback button { display: grid; place-items: center; width: 34px; height: 34px; padding: 7px; color: #8a839c; border: 0; border-radius: 8px; background: transparent; cursor: pointer; transition: color .15s, background .15s; }
.answer-feedback button:hover:not(:disabled) { color: #5946e8; background: #eae5fa; }
.answer-feedback button:focus-visible { outline: 2px solid #5946e8; outline-offset: 2px; }
.answer-feedback button[aria-pressed="true"] { color: #5946e8; background: #e9e3fa; opacity: 1; }
.answer-feedback button:disabled { cursor: default; }
.answer-feedback button:disabled:not([aria-pressed="true"]) { opacity: .35; }
.answer-feedback .feedback-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.answer-feedback .feedback-icon.down { transform: rotate(180deg); }
.answer-feedback [role="status"] { margin-left: 7px; }
.source-popover { position: fixed; z-index: 100; width: min(400px, calc(100vw - 24px)); max-height: min(420px, calc(100dvh - 24px)); overflow: auto; padding: 20px; border: 1px solid #e7e2f0; border-radius: 14px; color: #352f45; background: #fff; box-shadow: 0 10px 40px #2c204526, 0 2px 8px #2c20450d; font-size: 14px; line-height: 1.75; }
.source-popover:focus-visible { outline: 2px solid #b9a9ee; }
.source-eyebrow { color: #8c7ea9; font-size: 11px; letter-spacing: .06em; }
.source-popover h3 { margin: 7px 0; font-size: 15px; }
.source-path { color: #898194; font-size: 12px; margin: 0 0 12px; overflow-wrap: anywhere; }
.source-original { white-space: pre-wrap; overflow-wrap: anywhere; border-top: 1px solid #f0edf5; padding-top: 12px; }
@media (pointer: coarse) { .answer-feedback button { width: 44px; height: 44px; } }

.support-options {display:flex; flex-wrap:wrap; gap:12px; margin-top:16px;}
.support-option {display:flex; flex-direction:column; gap:6px; min-width:110px; max-width:100%;}
.support-option button, .ticket-dialog button {padding:10px 16px; border:1px solid #d8cbed; border-radius:12px; background:#f5efff; color:#60408b; font:inherit; cursor:pointer;}
.support-option button:disabled {opacity:.65; cursor:default;}
.support-action-status {font-size:14px; color:#655873; overflow-wrap:anywhere;}
.ticket-dialog {width:min(480px, calc(100vw - 32px)); box-sizing:border-box; padding:24px; border:1px solid #e5dcef; border-radius:20px; color:#352942; background:#fff; box-shadow:0 20px 70px #32204b26;}
.ticket-dialog::backdrop {background:#22123166;}
.ticket-dialog h2 {margin:0 0 12px; font-size:22px;}
.ticket-dialog p {font-size:15px; line-height:1.6; color:#766b80;}
.ticket-dialog label {display:flex; flex-direction:column; gap:8px; margin-top:16px; font-size:16px;}
.ticket-dialog textarea, .ticket-dialog select {box-sizing:border-box; width:100%; padding:12px; border:1px solid #d9cfe3; border-radius:10px; font:inherit; color:inherit; background:white; resize:vertical;}
.ticket-dialog-actions {display:flex; justify-content:flex-end; gap:12px; margin-top:24px;}
.ticket-dialog .confirm-ticket {color:white; background:#7954a6;}
.support-option button:focus-visible, .ticket-dialog :focus-visible {outline:3px solid #b49ace; outline-offset:3px;}

.refund-section { margin: 12px 0; border-top: 1px solid #e6e0ee; padding-top: 10px; font-size: 15px; }
.refund-section summary { cursor: pointer; color: #675087; font-weight: 600; }
.order-selector { margin-top: 16px; }
.order-selector > p:first-child { font-weight: 650; }
.order-note { font-size: 14px; color: #6b6476; line-height: 1.6; }
.order-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.order-card { display: flex; flex-direction: column; gap: 7px; text-align: left; border: 1px solid #d8cbe8; background: #faf7fe; padding: 14px; border-radius: 12px; cursor: pointer; font: inherit; color: #392b49; min-width: 0; }
.order-card strong { font-size: 16px; }
.order-card span { font-size: 14px; }
.order-card:hover:not(:disabled), .order-card:focus-visible { border-color: #8459b0; background: #f2eafa; }
.order-card:disabled { opacity: .65; cursor: default; }
.refund-form button { font: inherit; cursor: pointer; border: 1px solid #d8cbe8; padding: 9px 16px; background: white; border-radius: 9px; color: #624783; }
.refund-form { display: grid; gap: 12px; padding-top: 12px; }
.refund-form label { display: grid; gap: 6px; font-size: 15px; }
.refund-form select, .refund-form textarea { font: inherit; padding: 10px; border: 1px solid #d8cbe8; border-radius: 8px; width: 100%; box-sizing: border-box; background: white; color: #392b49; }
.refund-form button { background: #765098; color: white; justify-self: start; }
.refund-form button:disabled { opacity: .6; cursor: default; }
.interaction-status { font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
@media (max-width: 560px) { .order-grid { grid-template-columns: 1fr; } }

.chat-workspace { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 0; }
.chat-workspace .chat-frame { width: min(100% - 48px, 1020px); min-width: 0; }
.conversation-sidebar { min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: #fafafe; border-right: 1px solid var(--color-border); }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 26px 22px 16px; }
.sidebar-heading h2 { margin: 0; font-size: 17px; font-weight: 650; }
.conversation-count { color: var(--color-muted); font-size: 14px; }
.conversation-list { overflow-y: auto; min-height: 0; padding: 0 12px 24px; }
.conversation-item { display: block; width: 100%; padding: 14px 12px; margin: 3px 0; border: 1px solid transparent; border-radius: 12px; text-align: left; background: transparent; color: var(--color-text); cursor: pointer; }
.conversation-item:hover { background: #f0eff9; }
.conversation-item[aria-current="true"] { border-color: #ded8ff; background: #eeebff; }
.conversation-preview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; line-height: 1.55; font-size: 15px; }
.conversation-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 9px; color: #707184; font-size: 12px; }
.summary-badge { padding: 2px 7px; border-radius: 5px; color: #645295; background: #e9e4f5; }
.conversation-empty { color: var(--color-muted); padding: 10px; font-size: 14px; line-height: 1.7; }
.conversation-item:disabled, .new-chat-button:disabled { opacity: .55; cursor: wait; }
.conversation-toggle { display: none; }
#conversation-drawer { margin: 0; width: min(320px, 88vw); height: 100dvh; max-height: 100dvh; border: 0; padding: 0; color: var(--color-text); background: #fafafe; }
#conversation-drawer[open] { display: flex; flex-direction: column; }
#conversation-drawer::backdrop { background: rgb(22 23 42 / 35%); }
#close-conversations { border: 0; padding: 10px; color: var(--color-accent); background: transparent; cursor: pointer; }
@media (max-width: 760px) {
  .chat-workspace { display: block; min-height: 0; }
  .conversation-sidebar { display: none; }
  .chat-workspace .chat-frame { width: 100%; height: 100%; margin: 0; }
  .conversation-toggle { display: inline-flex; align-items: center; padding: 9px 11px; border: 1px solid var(--color-border); border-radius: 9px; background: #fff; color: var(--color-text); font-size: 14px; }
  .header-actions { gap: 10px; }
  .online-status { display: none; }
}

.ticket-confirmation { max-width: 560px; }
.ticket-description { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.ticket-confirm-actions { display: flex; gap: 12px; margin-top: 16px; }
.ticket-confirm-actions button { padding: 10px 18px; border-radius: 10px; border: 1px solid var(--color-border); cursor: pointer; font: inherit; }
.ticket-confirm-actions .ticket-submit { background: var(--color-accent); color: white; border-color: var(--color-accent); }
.ticket-confirm-actions .ticket-cancel { background: white; color: var(--color-text); }
.ticket-confirm-actions button:disabled { opacity: .5; cursor: default; }
