/* ===== OFA AI Chat Widget ===== */

.ofa-chat-launcher {

  position: fixed;

  bottom: 24px;

  right: 24px;

  z-index: 9999;

  display: flex;

  align-items: center;

  gap: 8px;

  background: var(--primary);

  color: #fff;

  border: none;

  border-radius: 24px;

  padding: 10px 16px 10px 12px;

  font-family: var(--sans);

  font-size: 14px;

  font-weight: 600;

  cursor: pointer;

  box-shadow: 0 4px 16px rgba(242, 101, 34, 0.4);

  transition: transform .15s, box-shadow .15s;

}

.ofa-chat-launcher:hover {

  transform: translateY(-2px);

  box-shadow: 0 6px 20px rgba(242, 101, 34, 0.5);

}

.ofa-chat-launcher.open {

  background: var(--black);

  box-shadow: 0 4px 16px rgba(0,0,0,0.3);

}

.ofa-chat-label {

  white-space: nowrap;

}

.ofa-chat-launcher svg {

  flex: none;

}



.ofa-chat-window {

  position: fixed;

  bottom: 88px;

  right: 24px;

  z-index: 9998;

  width: 360px;

  max-width: calc(100vw - 32px);

  height: 480px;

  max-height: calc(100vh - 120px);

  background: var(--card);

  border: 1px solid var(--line);

  border-radius: 12px;

  box-shadow: 0 8px 32px rgba(0,0,0,0.15);

  display: flex;

  flex-direction: column;

  overflow: hidden;

  transform: translateY(20px);

  opacity: 0;

  transition: transform .2s, opacity .2s;

  pointer-events: none;

}

.ofa-chat-window.open {

  transform: translateY(0);

  opacity: 1;

  pointer-events: auto;

}



.ofa-chat-header {

  display: flex;

  align-items: center;

  justify-content: space-between;

  padding: 12px 16px;

  background: var(--black);

  color: #fff;

}

.ofa-chat-title {

  display: flex;

  align-items: center;

  gap: 8px;

  font-size: 14px;

  font-weight: 600;

}

.ofa-chat-title svg {

  color: var(--primary);

}

.ofa-chat-close {

  background: none;

  border: none;

  color: #a1a1aa;

  font-size: 20px;

  cursor: pointer;

  padding: 0;

  line-height: 1;

}

.ofa-chat-close:hover { color: #fff; }



.ofa-chat-messages {

  flex: 1;

  overflow-y: auto;

  padding: 14px;

  display: flex;

  flex-direction: column;

  gap: 10px;

  background: var(--bg);

}



.ofa-chat-bubble {

  max-width: 85%;

  padding: 9px 13px;

  border-radius: 14px;

  font-size: 14px;

  line-height: 1.55;

  word-wrap: break-word;

}

.ofa-chat-bot {

  background: var(--card);

  border: 1px solid var(--line);

  color: var(--fg);

  border-bottom-left-radius: 4px;

}

.ofa-chat-user {

  background: var(--primary);

  color: #fff;

  align-self: flex-end;

  border-bottom-right-radius: 4px;

}



.ofa-chat-typing {

  display: flex;

  gap: 4px;

  padding: 12px;

}

.typing-dot {

  width: 7px;

  height: 7px;

  border-radius: 50%;

  background: var(--fg-dim);

  animation: typing-bounce 1.2s infinite ease-in-out;

}

.typing-dot:nth-child(2) { animation-delay: .2s; }

.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typing-bounce {

  0%, 60%, 100% { transform: translateY(0); opacity: .4; }

  30% { transform: translateY(-5px); opacity: 1; }

}



.ofa-chat-input-row {

  display: flex;

  align-items: flex-end;

  gap: 8px;

  padding: 10px;

  border-top: 1px solid var(--line);

  background: var(--card);

}

.ofa-chat-input {
  flex: 1;
  border: 1px solid var(--line-2);
  border-radius: 18px;
  padding: 9px 14px;
  font-size: 14px;
  line-height: 1.45;
  font-family: var(--sans);
  outline: none;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.ofa-chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
.ofa-chat-input:disabled {
  background: var(--bg);
  opacity: .7;
  cursor: not-allowed;
}
.ofa-chat-send-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, opacity .15s;
}
.ofa-chat-send-btn:hover { background: var(--primary-hover); }
.ofa-chat-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* 发送中 spinner：覆盖图标 */
.ofa-chat-send-btn.loading,
.btn-accent.loading { position: relative; }
.ofa-chat-send-btn.loading svg,
.btn-accent.loading svg { visibility: hidden; }
.ofa-chat-send-btn.loading::after,
.btn-accent.loading::after {
  content: "";
  position: absolute;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ofa-spin .7s linear infinite;
}
.btn-accent.loading .send-label { display: none; }
@keyframes ofa-spin { to { transform: rotate(360deg); } }



/* Mobile adjustments */

@media (max-width: 480px) {

  .ofa-chat-window {

    bottom: 76px;

    right: 8px;

    left: 8px;

    width: auto;

    height: 420px;

  }

  .ofa-chat-launcher {

    bottom: 16px;

    right: 16px;

  }

}

/* ===== Chain-of-Thought Thinking Block ===== */

.ofa-chat-thinking {

  background: #fefce8;

  border: 1px solid #fde68a;

  border-radius: 14px;

  margin: 4px 0;

  max-width: 90%;

  overflow: hidden;

}

.ofa-chat-thinking .thinking-header {

  display: flex;

  align-items: center;

  gap: 6px;

  padding: 8px 12px;

  cursor: pointer;

  font-size: 12px;

  font-weight: 600;

  color: #b45309;

  background: #fef3c7;

  user-select: none;

}

.ofa-chat-thinking .thinking-header:hover {

  background: #fde68a;

}

.ofa-chat-thinking .thinking-header svg {

  flex: none;

}

.ofa-chat-thinking .thinking-header .thinking-arrow {

  margin-left: auto;

  transition: transform .15s;

}

.ofa-chat-thinking:not(.expanded) .thinking-arrow {

  transform: rotate(-90deg);

}

.ofa-chat-thinking .thinking-body {

  max-height: 0;

  overflow: hidden;

  transition: max-height .25s ease;

}

.ofa-chat-thinking.expanded .thinking-body {

  max-height: 400px;

}

.ofa-chat-thinking .thinking-body pre {

  margin: 0;

  padding: 10px 12px;

  font-family: var(--mono);

  font-size: 12px;

  line-height: 1.55;

  color: var(--fg-dim);

  white-space: pre-wrap;

  word-break: break-word;

  background: transparent;

  border: none;

}

/* ===== Markdown content in chat bubbles ===== */

.ofa-chat-md { line-height: 1.6; word-wrap: break-word; }

.ofa-chat-md > :first-child { margin-top: 0; }

.ofa-chat-md > :last-child { margin-bottom: 0; }

.ofa-chat-md p { margin: 0 0 8px; }

.ofa-chat-md ul, .ofa-chat-md ol { margin: 0 0 8px; padding-left: 20px; }

.ofa-chat-md li { margin: 2px 0; }

.ofa-chat-md h1, .ofa-chat-md h2, .ofa-chat-md h3 { margin: 6px 0; font-size: 1.05em; }

.ofa-chat-md a { color: var(--primary); text-decoration: underline; }

.ofa-chat-md code {

  background: rgba(127,127,127,0.16);

  padding: 1px 5px; border-radius: 4px;

  font-family: var(--mono); font-size: 0.92em;

}

.ofa-chat-md pre {

  background: rgba(127,127,127,0.14);

  padding: 10px 12px; border-radius: 8px; overflow-x: auto;

  margin: 0 0 8px;

}

.ofa-chat-md pre code { background: transparent; padding: 0; }

.ofa-chat-md blockquote {

  border-left: 3px solid var(--primary);

  margin: 0 0 8px; padding: 2px 12px; color: var(--fg-dim);

}

.ofa-chat-md hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }



/* ===== Crisis help card ===== */

.ofa-chat-crisis {

  background: linear-gradient(180deg, #fff7ed, #ffedd5);

  border: 1px solid #fdba74;

  border-radius: 14px;

  padding: 14px 16px;

  max-width: 92%;

  color: #7c2d12;

}

.ofa-chat-crisis .crisis-head {

  display: flex; align-items: center; gap: 8px;

  font-weight: 700; color: #c2410c; margin-bottom: 6px;

}

.ofa-chat-crisis .crisis-head svg { color: #ef4444; flex: none; }

.ofa-chat-crisis .crisis-msg { margin: 0 0 8px; line-height: 1.6; }

.ofa-chat-crisis .crisis-tip { font-size: 12px; margin-bottom: 6px; color: #9a3412; }

.ofa-chat-crisis .crisis-list { list-style: none; margin: 0; padding: 0; }

.ofa-chat-crisis .crisis-list li {

  display: flex; justify-content: space-between; gap: 12px;

  padding: 6px 0; border-top: 1px dashed #fdba74;

}

.ofa-chat-crisis .crisis-list .cl-name { font-size: 13px; }

.ofa-chat-crisis .crisis-list .cl-phone {

  font-family: var(--mono); font-weight: 700; color: #c2410c; white-space: nowrap;

}

