/* chat.css — Chat bubble + panel.
   Inherits CSS custom properties from warm.css / dark.css automatically. */

/* ── Bubble ────────────────────────────────────────────────── */
.chat-bubble {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--chat-bubble-color, var(--dark-accent, #c48b6e));
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  z-index: 9000;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.chat-bubble:hover { transform: scale(1.07); }
.chat-bubble:focus-visible {
  outline: 3px solid var(--dark-accent, #c48b6e);
  outline-offset: 3px;
}
.chat-bubble.chat-thinking {
  animation: chat-pulse 1.4s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(0,0,0,0.18); }
  50%       { box-shadow: 0 4px 24px rgba(0,0,0,0.28),
                          0 0 0 6px rgba(255,255,255,0.15); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-bubble.chat-thinking { animation: none; }
}

/* Unread badge */
.chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #e05252;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  padding: 0 4px;
  pointer-events: none;
}
.chat-unread[hidden] { display: none !important; }

/* ── Panel ─────────────────────────────────────────────────── */
.chat-panel {
  position: fixed;
  bottom: calc(1.5rem + 3.25rem + 0.75rem);
  right: 1.5rem;
  width: min(320px, calc(100vw - 24px));
  max-height: min(60vh, 480px);
  background: var(--dark-surface, #24212a);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
  display: flex;
  flex-direction: column;
  z-index: 9001;
  overflow: hidden;
}
.chat-panel[hidden] { display: none !important; }

/* ── Header ────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  flex-shrink: 0;
}
.chat-header-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--dark-text, #e2ddd8);
}
.chat-header-mood {
  font-size: 0.8rem;
  color: var(--dark-muted, #968e96);
  flex: 1;
}
.chat-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  color: var(--dark-muted, #968e96);
  border-radius: 4px;
}
.chat-close:hover { color: var(--dark-text, #e2ddd8); }
.chat-close:focus-visible {
  outline: 2px solid var(--dark-accent, #c48b6e);
  outline-offset: 2px;
}

/* ── Messages ──────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.chat-msg {
  max-width: 85%;
  font-size: 0.88rem;
  line-height: 1.45;
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  word-break: break-word;
}
.chat-msg--spark {
  align-self: flex-start;
  background: var(--dark-surface, #24212a);
  border-left: 3px solid var(--chat-bubble-color, var(--dark-accent, #c48b6e));
  color: var(--dark-text, #e2ddd8);
}
/* SPARK-initiated messages: slightly warmer background to stand out */
.chat-msg--spark-init {
  align-self: flex-start;
  background: color-mix(in srgb, var(--chat-bubble-color, var(--dark-accent, #c48b6e)) 12%, var(--dark-surface, #24212a));
  border-left: 3px solid var(--chat-bubble-color, var(--dark-accent, #c48b6e));
  color: var(--dark-text, #e2ddd8);
}
@supports not (color: color-mix(in srgb, red 10%, blue)) {
  .chat-msg--spark-init { background: var(--dark-surface, #24212a); }
}
.chat-msg--user {
  align-self: flex-end;
  background: rgba(0,0,0,0.06);
  color: var(--dark-text, #e2ddd8);
}

/* ── PIN auth form ─────────────────────────────────────────── */
.chat-pin-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  flex: 1;
}
.chat-pin-label {
  font-size: 0.88rem;
  color: var(--dark-muted, #968e96);
  text-align: center;
}
.chat-pin-input {
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--dark-surface, #24212a);
  color: var(--dark-text, #e2ddd8);
  text-align: center;
  letter-spacing: 0.25em;
}
.chat-pin-input:focus {
  outline: 2px solid var(--dark-accent, #c48b6e);
  outline-offset: 1px;
  border-color: transparent;
}
.chat-pin-submit {
  background: var(--chat-bubble-color, var(--dark-accent, #c48b6e));
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}
.chat-pin-submit:hover { opacity: 0.85; }
.chat-pin-error {
  font-size: 0.8rem;
  color: #e05252;
  text-align: center;
  min-height: 1.1rem;
}

/* Thinking dots */
.chat-thinking-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.chat-thinking-dots span {
  display: inline-block;
  font-size: 1.2rem;
  animation: chat-dot-bounce 1.2s ease-in-out infinite;
  color: var(--dark-muted, #968e96);
}
.chat-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%            { transform: translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-thinking-dots span { animation: none; }
}

/* ── Input row ─────────────────────────────────────────────── */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid rgba(0,0,0,0.06);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
  font-family: inherit;
  background: var(--dark-surface, #24212a);
  color: var(--dark-text, #e2ddd8);
  line-height: 1.4;
  max-height: 6rem;
  overflow-y: auto;
}
.chat-input:focus {
  outline: 2px solid var(--dark-accent, #c48b6e);
  outline-offset: 1px;
  border-color: transparent;
}
.chat-input:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-send {
  background: var(--chat-bubble-color, var(--dark-accent, #c48b6e));
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 2.25rem;
  height: 2.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.chat-send:hover { opacity: 0.85; }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-send:focus-visible {
  outline: 2px solid var(--dark-accent, #c48b6e);
  outline-offset: 2px;
}
