/* ================================================================
   ALPS Chat Widget
   ================================================================ */

#alps-chat-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
  font-family: inherit;
}

/* ---- Toggle button ---- */
#alps-chat-toggle {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 45%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  flex-shrink: 0;
}

#alps-chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#alps-chat-toggle svg {
  pointer-events: none;
}

/* ---- Chat window ---- */
#alps-chat-window {
  width: 340px;
  border-radius: 1rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  transition: opacity 0.18s ease, transform 0.18s ease;
  transform-origin: bottom right;
}

#alps-chat-window.alps-chat-hidden {
  display: none;
}

/* Dark mode */
html.dark #alps-chat-window {
  background: #1c1c1e;
  border-color: rgba(255, 255, 255, 0.1);
}

/* ---- Header ---- */
#alps-chat-header {
  background: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 42%);
  color: #fff;
  padding: 0.7rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  flex-shrink: 0;
}

#alps-chat-subtitle {
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.85;
  margin-top: 1px;
}

#alps-chat-header-text {
  display: flex;
  flex-direction: column;
}

#alps-chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  padding: 2px 4px;
  opacity: 0.75;
  border-radius: 4px;
  transition: opacity 0.15s;
}

#alps-chat-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

/* ---- Message area ---- */
#alps-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 340px;
  scroll-behavior: smooth;
}

/* ---- Individual messages ---- */
.alps-msg {
  max-width: 88%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.8rem;
  font-size: 0.85rem;
  line-height: 1.55;
  word-break: break-word;
}

.alps-msg-user {
  background: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 44%);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 0.2rem;
}

.alps-msg-bot {
  background: #f2f2f2;
  color: #1a1a1a;
  align-self: flex-start;
  border-bottom-left-radius: 0.2rem;
}

html.dark .alps-msg-bot {
  background: #2c2c2e;
  color: #e5e5e5;
}

.alps-msg-bot a {
  color: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 38%);
  text-decoration: underline;
  text-underline-offset: 2px;
}

html.dark .alps-msg-bot a {
  color: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 65%);
}

.alps-msg-bot ul {
  margin: 0.35rem 0 0.1rem 1.1rem;
  padding: 0;
}

.alps-msg-bot li {
  margin: 0.2rem 0;
}

/* ---- Input area ---- */
#alps-chat-input-area {
  display: flex;
  border-top: 1px solid rgba(0, 0, 0, 0.09);
  padding: 0.55rem 0.6rem;
  gap: 0.45rem;
  background: #ffffff;
  flex-shrink: 0;
}

html.dark #alps-chat-input-area {
  background: #1c1c1e;
  border-top-color: rgba(255, 255, 255, 0.1);
}

#alps-chat-input {
  flex: 1;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 0.55rem;
  padding: 0.42rem 0.65rem;
  font-size: 0.84rem;
  background: #f8f8f8;
  color: #111;
  outline: none;
  transition: border-color 0.15s;
}

html.dark #alps-chat-input {
  background: #2c2c2e;
  border-color: rgba(255, 255, 255, 0.14);
  color: #e5e5e5;
}

#alps-chat-input:focus {
  border-color: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 44%);
}

#alps-chat-send {
  background: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 44%);
  color: #fff;
  border: none;
  border-radius: 0.55rem;
  padding: 0.42rem 0.85rem;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
}

#alps-chat-send:hover {
  background: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 36%);
}

/* ---- Code blocks inside bot messages ---- */
.alps-code-wrap {
  margin: 0.45rem 0;
  border-radius: 0.45rem;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

html.dark .alps-code-wrap {
  border-color: rgba(255, 255, 255, 0.12);
}

.alps-code-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #555;
}

html.dark .alps-code-bar {
  background: rgba(255, 255, 255, 0.07);
  color: #aaa;
}

.alps-copy-btn {
  background: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 44%);
  color: #fff;
  border: none;
  border-radius: 0.3rem;
  padding: 0.1rem 0.45rem;
  font-size: 0.7rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}

.alps-copy-btn:hover {
  background: hsl(var(--primary-hue, 42deg) var(--primary-saturation, 50%) 36%);
}

.alps-pre {
  margin: 0;
  padding: 0.55rem 0.65rem;
  background: #f7f7f7;
  overflow-x: auto;
  font-size: 0.75rem;
  line-height: 1.5;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  white-space: pre;
  max-height: 260px;
}

html.dark .alps-pre {
  background: #111;
  color: #d4d4d4;
}

/* Widen the chat window when a code block is displayed */
#alps-chat-window:has(.alps-code-wrap) {
  width: 420px;
}

/* ---- Mobile ---- */
@media (max-width: 500px) {
  #alps-chat-widget {
    bottom: 1rem;
    right: 1rem;
  }

  #alps-chat-window,
  #alps-chat-window:has(.alps-code-wrap) {
    width: calc(100vw - 2rem);
    max-height: 80vh;
  }

  #alps-chat-messages {
    max-height: calc(80vh - 130px);
  }
}
