:root {
  color-scheme: light;
  --glacial: #0098a8;
  --glacial-dark: #007c8a;
  --wet-sand: #e1d7c8;
  --beach: #fdf5ea;
  --black: #000000;

  --chat-width: 340px;
  --chat-height: 580px;
  --radius-lg: 20px;
  --radius-md: 20px;
  --radius-sm: 16px;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 20px;

  font-family: "Figtree", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f6f1e7;
  min-height: 100vh;
  font-family: inherit;
}

/* ---- Contracted launcher (chat bubble with dots) ---- */
#chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 57px;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  display: block;
  cursor: pointer;
  z-index: 20;
  outline: none;
}

#chat-launcher .launcher-box,
#chat-launcher .launcher-dots {
  position: absolute;
  display: block;
}

#chat-launcher .launcher-box {
  inset: 0;
  width: 100%;
  height: 100%;
}

#chat-launcher .launcher-dots {
  left: 50%;
  top: 50%;
  width: 30px;
  height: 9px;
  transform: translate(-50%, -58%);
}

#chat-launcher.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---- Expanded window ---- */
#chat-overlay {
  position: fixed;
  bottom: 25px;
  right: 25px;
  z-index: 30;
}
#chat-overlay[hidden] {
  display: none;
}

.chat-window {
  background: var(--glacial);
  color: var(--beach);
  width: var(--chat-width);
  height: var(--chat-height);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(9, 40, 44, 0.3);
  overflow: hidden;
}

.chat-header {
  position: relative;
  padding: 46px var(--spacing-xl) 0;
  text-align: center;
}

.chat-header h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 500;
  line-height: 37px;
  letter-spacing: -0.6px;
  color: var(--beach);
  word-break: break-word;
}

.chat-subtitle {
  margin: 5px 0 0;
  color: var(--beach);
  font-size: 12px;
  line-height: 14px;
}

.chat-subtitle a {
  color: var(--beach);
  text-decoration: underline;
  text-underline-offset: 2px;
}

#chat-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 25px;
  height: 25px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  display: block;
}

#chat-close img {
  display: block;
  width: 100%;
  height: 100%;
}

#chat-close:hover,
#chat-close:focus-visible {
  opacity: 0.85;
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px var(--spacing-xl);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--wet-sand) transparent;
}

#chat-log::-webkit-scrollbar {
  width: 6px;
}

#chat-log::-webkit-scrollbar-track {
  background: transparent;
}

#chat-log::-webkit-scrollbar-thumb {
  background: var(--wet-sand);
  border-radius: 3px;
}

.history {
  align-items: center;
}

.history-button {
  border: none;
  background: rgba(0, 124, 138, 0.18);
  color: var(--beach);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.history-button:hover,
.history-button:focus-visible {
  background: rgba(0, 124, 138, 0.3);
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

.chat-message.assistant {
  align-items: flex-start;
}

.chat-message.user {
  align-items: flex-end;
}

.message-meta {
  font-size: 12px;
  font-weight: 600;
  line-height: 18.75px;
  color: var(--beach);
  padding: 0 20px;
}

.message-bubble {
  padding: 20px;
  border-radius: 20px;
  max-width: 280px;
  width: fit-content;
}

.chat-message.assistant .message-bubble {
  background: var(--glacial-dark);
}

.chat-message.user .message-bubble {
  background: var(--wet-sand);
}

.message-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
  line-height: 18.75px;
  font-weight: 400;
}

.chat-message.assistant .message-text {
  color: var(--beach);
}

.chat-message.user .message-text {
  color: var(--black);
}

.message-text a {
  color: var(--beach);
  text-decoration: underline;
}

.chat-message.user .message-text a {
  color: var(--glacial-dark);
}

.message-text code {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  padding: 0 6px;
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: 0.85em;
}

.bubble-tip {
  display: block;
  width: 57px;
  height: 11px;
  margin-top: -6px;
  flex-shrink: 0;
}

#chat-form {
  padding: var(--spacing-xl);
  background: var(--beach);
}

.chat-field {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#chat-input {
  flex: 1;
  resize: none;
  border: none;
  background: var(--wet-sand);
  border-radius: 20px;
  padding: 15px 20px;
  font-size: 15px;
  font-family: inherit;
  line-height: 18.75px;
  min-height: 90px;
  box-sizing: border-box;
  color: var(--black);
}

#chat-input::placeholder {
  color: rgba(0, 0, 0, 0.55);
}

#chat-input:focus {
  outline: 2px solid var(--glacial);
  outline-offset: 1px;
}

#chat-send {
  border: none;
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border-radius: 25px;
  background: var(--glacial);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s ease;
}

#chat-send img {
  display: block;
  width: 18px;
  height: 13px;
}

#chat-send[disabled] {
  opacity: 0.6;
  cursor: wait;
}

#chat-send:not([disabled]):hover,
#chat-send:not([disabled]):focus-visible {
  background: var(--glacial-dark);
}

.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--beach);
  animation: dot 1s ease-in-out infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.15s; }
.loading-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot {
  0%, 80%, 100% { opacity: 0.4; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

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

@media (max-width: 600px) {
  #chat-overlay {
    padding: 12px;
  }

  .chat-window {
    width: calc(100% - 50px);
    box-sizing: border-box;
    height: min(calc(100vh - 50px), 540px);
  }
}
