/* ChemChat 聊天页样式：独立于官网 style.css，深色「数字实验室」主题。 */

.chat-page {
  --bg: #070d18;
  --panel: rgba(13, 24, 41, 0.72);
  --panel-strong: rgba(15, 27, 46, 0.94);
  --line: rgba(126, 178, 230, 0.14);
  --line-strong: rgba(126, 178, 230, 0.3);
  --text: #e7eef8;
  --muted: #8ea3bf;
  --dim: #5f748f;
  --cyan: #f89d2e;
  --teal: #2ee6c5;
  --blue: #eb642a;
  --danger: #ff6b7a;
  --accent-grad: linear-gradient(135deg, #f89d2e, #eb642a);
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: "Inter", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body.chat-page {
  height: 100%;
  margin: 0;
}

body.chat-page {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(900px 620px at 80% -12%, rgba(248, 157, 46, 0.16), transparent 62%),
    radial-gradient(720px 520px at -6% 104%, rgba(235, 100, 42, 0.12), transparent 62%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='97' viewBox='0 0 56 97'%3E%3Cpath d='M28 0L56 16.17L56 48.5L28 64.67L0 48.5L0 16.17Z M28 64.67L28 97' fill='none' stroke='rgba(125,196,255,0.075)' stroke-width='1'/%3E%3C/svg%3E") repeat,
    linear-gradient(180deg, #081020 0%, #060b14 100%);
}

button {
  font-family: inherit;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: rgba(126, 178, 230, 0.18);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(126, 178, 230, 0.32);
}

/* ---------- 侧栏 ---------- */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 18px 14px 16px;
  border-right: 1px solid var(--line);
  background: rgba(8, 15, 28, 0.74);
  backdrop-filter: blur(16px);
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.chat-brand img {
  width: 40px;
  height: 40px;
  padding: 4px;
  border-radius: 12px;
  background: #fff;
}

.chat-brand strong {
  display: block;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.chat-brand small {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--accent-grad);
  color: #04121c;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(248, 157, 46, 0.18);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.new-chat-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.chat-history-label {
  padding: 6px 8px 0;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.chat-history {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.history-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.history-item.active {
  background: rgba(248, 157, 46, 0.1);
  border-color: rgba(248, 157, 46, 0.22);
  color: var(--text);
}

.history-item > i {
  font-size: 0.9rem;
}

.history-item span {
  overflow: hidden;
  font-size: 0.92rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.history-item:hover .history-delete,
.history-item.active .history-delete {
  opacity: 1;
}

.history-delete:hover,
.history-delete.is-confirm {
  opacity: 1;
  color: var(--danger);
  background: rgba(255, 107, 122, 0.14);
}

.chat-history-empty {
  padding: 10px;
  font-size: 0.85rem;
  color: var(--dim);
}

.chat-sidebar-footer {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.status-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
}

.chat-status[data-state="online"] .status-dot {
  background: var(--teal);
  box-shadow: 0 0 12px rgba(46, 230, 197, 0.85);
  animation: statusPulse 2.2s ease-in-out infinite;
}

.chat-status[data-state="offline"] .status-dot {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(255, 107, 122, 0.6);
}

.chat-status[data-state="offline"] {
  border-color: rgba(255, 107, 122, 0.3);
}

.status-model {
  margin-left: auto;
  overflow: hidden;
  max-width: 45%;
  color: var(--cyan);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}

.chat-sidebar-footer a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.sidebar-backdrop {
  display: none;
}

/* ---------- 主区 ---------- */
.chat-main {
  position: relative;
  display: grid;
  /* 列必须显式 minmax(0, 1fr)：隐式 auto 列会被顶栏不换行的长标题撑开，导致整页横向溢出。 */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
}

.chat-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 13, 24, 0.5);
  backdrop-filter: blur(12px);
}

.chat-topbar h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-meta {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.topbar-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-chip.is-live {
  border-color: rgba(235, 100, 42, 0.3);
  color: var(--teal);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--line-strong);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.menu-btn {
  display: none;
}

/* ---------- 会话流 ---------- */
.chat-thread {
  min-height: 0;
  overflow-y: auto;
  padding: 28px 24px 12px;
}

.chat-thread-inner {
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 860px;
  margin: 0 auto;
}

/* 欢迎态 */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 12px 8px;
  text-align: center;
}

.molecule {
  width: 176px;
  height: 176px;
  margin-bottom: 4px;
}

.molecule .orbit {
  fill: none;
  stroke: rgba(248, 157, 46, 0.22);
  stroke-width: 1;
  stroke-dasharray: 4 7;
  transform-origin: 100px 100px;
  animation: orbitSpin 40s linear infinite;
}

.molecule .bond {
  fill: none;
  stroke: rgba(248, 157, 46, 0.6);
  stroke-width: 2;
  stroke-linecap: round;
}

.molecule .bond-inner {
  stroke: rgba(235, 100, 42, 0.45);
  stroke-width: 1.5;
}

.molecule .atom {
  fill: url(#atomGradient);
  filter: drop-shadow(0 0 8px rgba(248, 157, 46, 0.75));
  animation: atomPulse 3.2s ease-in-out infinite;
}

.molecule .atom-hub {
  fill: url(#hubGradient);
  filter: drop-shadow(0 0 14px rgba(235, 100, 42, 0.9));
}

.molecule .atom:nth-of-type(2n) {
  animation-delay: -1.1s;
}

.molecule .atom:nth-of-type(3n) {
  animation-delay: -2.2s;
}

.chat-welcome .kicker {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cyan);
}

.chat-welcome h2 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 750;
  letter-spacing: -0.01em;
}

.chat-welcome h2 .accent {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* 窄屏换行时让"对话助手"整体下移，避免单字孤行。 */
.chat-welcome h2 .nobr {
  white-space: nowrap;
}

.chat-welcome p {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 720px;
  margin-top: 8px;
}

.prompt-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.prompt-chip i {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(248, 157, 46, 0.1);
  color: var(--cyan);
  font-size: 1rem;
}

.prompt-chip span {
  font-size: 0.92rem;
  line-height: 1.4;
}

.prompt-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(248, 157, 46, 0.42);
  background: rgba(248, 157, 46, 0.07);
}

.capability-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

.capability-tags span {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  color: var(--dim);
}

/* 消息 */
.message-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.message-row.user {
  grid-template-columns: minmax(0, 1fr) 36px;
}

.message-row.user .message-avatar {
  grid-column: 2;
  grid-row: 1;
}

.message-row.user .message-body {
  grid-column: 1;
  grid-row: 1;
  align-items: flex-end;
}

.message-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-top: 2px;
  background: var(--accent-grad);
  color: #04121c;
  font-size: 1rem;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.message-row.user .message-avatar {
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  clip-path: none;
}

.message-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.message-meta {
  padding: 0 2px;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

.message-bubble {
  padding: 13px 18px;
  border-radius: 16px;
  font-size: 0.96rem;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.message-row.assistant .message-bubble {
  border: 1px solid var(--line);
  border-top-left-radius: 6px;
  background: var(--panel);
}

.message-row.user .message-bubble {
  max-width: 78%;
  border-top-right-radius: 6px;
  background: linear-gradient(135deg, rgba(235, 100, 42, 0.88), rgba(248, 157, 46, 0.58));
  color: #f4fbff;
  white-space: pre-wrap;
}

.message-bubble.is-error {
  border-color: rgba(255, 107, 122, 0.4);
  background: rgba(255, 107, 122, 0.08);
  color: #ffd3d8;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.message-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.message-row:hover .message-actions,
.message-actions.is-visible {
  opacity: 1;
}

.message-actions button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.message-actions button:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

/* Markdown 渲染 */
.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 10px;
}

.md h3,
.md h4,
.md h5,
.md h6 {
  margin: 14px 0 8px;
  font-size: 1.02rem;
  font-weight: 700;
  color: #fff;
}

.md ul,
.md ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.md li {
  margin: 4px 0;
}

.md strong {
  color: #fff;
}

.md del {
  color: var(--dim);
}

.md a {
  color: var(--cyan);
}

.md code {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(248, 157, 46, 0.1);
  color: #9fe7ff;
  font-family: var(--mono);
  font-size: 0.86em;
}

.md pre {
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #050a13;
  overflow-x: auto;
}

.md pre code {
  padding: 0;
  background: transparent;
  color: #dbe7f5;
  font-size: 0.84rem;
  line-height: 1.6;
}

.md table {
  display: block;
  width: 100%;
  margin: 10px 0;
  border-collapse: collapse;
  overflow-x: auto;
  font-size: 0.9rem;
}

.md th,
.md td {
  padding: 7px 10px;
  border: 1px solid var(--line);
  text-align: left;
}

.md th {
  background: rgba(248, 157, 46, 0.08);
  color: #fff;
  font-weight: 600;
}

.md blockquote {
  margin: 8px 0;
  padding: 6px 14px;
  border-left: 3px solid var(--cyan);
  color: var(--muted);
}

.md hr {
  margin: 12px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.cursor {
  display: inline-block;
  width: 8px;
  height: 1em;
  margin-left: 3px;
  border-radius: 2px;
  background: var(--cyan);
  vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 1.4em;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  animation: typingPulse 1.1s ease-in-out infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

/* ---------- 输入区 ---------- */
.chat-composer {
  padding: 10px 24px 16px;
}

.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  max-width: 860px;
  margin: 0 auto;
  padding: 8px 8px 8px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--panel-strong);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.38);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer-box:focus-within {
  border-color: rgba(248, 157, 46, 0.55);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.38), 0 0 0 3px rgba(248, 157, 46, 0.12);
}

.composer-box textarea {
  width: 100%;
  min-height: 44px;
  max-height: 180px;
  padding: 11px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.96rem;
  line-height: 1.6;
}

.composer-box textarea::placeholder {
  color: var(--dim);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.send-btn,
.stop-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.send-btn {
  background: var(--accent-grad);
  color: #04121c;
  box-shadow: 0 8px 20px rgba(248, 157, 46, 0.25);
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.send-btn:disabled {
  opacity: 0.35;
  box-shadow: none;
  cursor: not-allowed;
}

.stop-btn {
  display: none;
  border: 1px solid rgba(255, 107, 122, 0.4);
  background: rgba(255, 107, 122, 0.14);
  color: var(--danger);
}

.chat-page.is-generating .stop-btn {
  display: grid;
}

.chat-page.is-generating .send-btn {
  display: none;
}

.composer-hint {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  max-width: 860px;
  margin: 8px auto 0;
  padding: 0 8px;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  color: var(--dim);
}

.composer-hint #charCount {
  flex: none;
}

.composer-hint .is-over {
  color: var(--danger);
}

/* ---------- 动画 ---------- */
@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 230, 197, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(46, 230, 197, 0); }
}

@keyframes atomPulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

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

@keyframes blink {
  to { opacity: 0; }
}

@keyframes typingPulse {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .molecule .orbit,
  .molecule .atom,
  .status-dot,
  .cursor,
  .typing span {
    animation: none;
  }
}

/* ---------- 移动端 ---------- */
@media (max-width: 900px) {
  body.chat-page {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(300px, 84vw);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.5);
  }

  .chat-page.sidebar-open .chat-sidebar {
    transform: none;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.55);
  }

  .chat-page.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .menu-btn {
    display: grid;
  }

  .chat-topbar {
    padding: 10px 14px;
  }

  .topbar-chip {
    display: none;
  }

  .chat-thread {
    padding: 18px 14px 8px;
  }

  /* 小屏上压缩欢迎区高度，保证首屏能看到示例问题。 */
  .chat-welcome {
    gap: 10px;
    padding-top: 6px;
  }

  .molecule {
    width: 108px;
    height: 108px;
  }

  .chat-welcome h2 {
    font-size: 1.45rem;
  }

  .chat-welcome p {
    font-size: 0.9rem;
    line-height: 1.6;
  }

  .prompt-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .prompt-chip {
    padding: 11px 14px;
  }

  .message-row {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
  }

  .message-row.user {
    grid-template-columns: minmax(0, 1fr) 30px;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.88rem;
  }

  .message-bubble {
    padding: 11px 14px;
  }

  .message-row.user .message-bubble {
    max-width: 92%;
  }

  .message-actions {
    opacity: 1;
  }

  .chat-composer {
    padding: 8px 12px 12px;
  }

  .composer-box {
    padding-left: 14px;
  }

  .hint-keys {
    display: none;
  }
}
