/* =========================================================
   Chat widget — uses design tokens defined in style.css (:root)
   Ink/paper/accent/signal, Sora/Inter/Plex Mono
   ========================================================= */

#chat-widget { font-family: var(--font-body); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ===== Launcher ===== */
#chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(21, 16, 31, 0.25);
  transition: background 0.15s ease, transform 0.15s ease;
}
#chat-launcher:hover { background: var(--accent-dark); transform: translateY(-2px); }
#chat-launcher-icon { width: 26px; height: 26px; }
#chat-launcher-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--signal);
  border: 2px solid var(--ink);
}
#chat-launcher-badge:empty { display: none; }
#chat-widget.chat-is-open #chat-launcher { display: none; }

/* ===== Panel ===== */
#chat-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 48px);
  background: var(--paper);
  border: 1px solid var(--border-on-paper);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(21, 16, 31, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1001;
  transform-origin: bottom right;
  animation: chat-panel-in 0.18s ease;
}
@keyframes chat-panel-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  #chat-panel { animation: none; }
}

#chat-panel[hidden] { display: none; }

/* Expanded (fullscreen) state */
#chat-panel.chat-is-expanded {
  right: 0;
  bottom: 0;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  border: none;
}
#chat-panel.chat-is-expanded #chat-messages { max-width: 720px; margin-inline: auto; width: 100%; }
#chat-panel.chat-is-expanded #chat-form { max-width: 720px; margin-inline: auto; width: 100%; }

/* ===== Header ===== */
#chat-panel-header {
  background: var(--ink);
  color: var(--ink-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-on-ink);
  flex-shrink: 0;
}
#chat-header-identity { display: flex; align-items: center; gap: 12px; }
#chat-header-text h2 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}
#chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-text-muted);
  margin-top: 2px;
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-pass { background: var(--signal); }

#chat-header-actions { display: flex; gap: 4px; }
#chat-header-actions button {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--ink-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
#chat-header-actions button:hover { background: var(--border-on-ink); color: var(--ink-text); }
#chat-header-actions svg { width: 18px; height: 18px; }

/* ===== Messages ===== */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-message {
  max-width: 82%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.55;
}
.chat-message p { max-width: none; }
.chat-message-time {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  opacity: 0.6;
}

.chat-message-bot {
  align-self: flex-start;
  background: var(--paper-raised);
  color: var(--paper-text);
  border-bottom-left-radius: 4px;
}
.chat-message-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

#chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 2px;
}
.chat-quick-reply {
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-on-paper);
  background: transparent;
  color: var(--accent);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chat-quick-reply:hover { background: var(--paper-raised); border-color: var(--accent); }

/* ===== Typing indicator ===== */
#chat-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0 18px 12px;
  flex-shrink: 0;
}
#chat-typing-indicator[hidden] { display: none; }
#chat-typing-indicator span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--paper-text-muted);
  animation: chat-typing 1.1s infinite ease-in-out;
}
#chat-typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
#chat-typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  #chat-typing-indicator span { animation: none; opacity: 0.6; }
}

/* ===== Input form ===== */
#chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-on-paper);
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 11px 14px;
  border: 1px solid var(--border-on-paper);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--paper-text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  line-height: 1.4;
}
#chat-input:focus { border-color: var(--accent); }

#chat-send {
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
#chat-send:hover { background: var(--accent-dark); }
#chat-send:disabled { background: var(--border-on-paper); color: var(--paper-text-muted); cursor: not-allowed; }
#chat-send svg { width: 18px; height: 18px; }

#chat-disclaimer {
  font-size: 0.72rem;
  color: var(--paper-text-muted);
  text-align: center;
  padding: 0 18px 14px;
  flex-shrink: 0;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  #chat-launcher { right: 16px; bottom: 16px; }
  #chat-panel {
    right: 0;
    bottom: 0;
    left: 0;
    top: auto;
    width: 100%;
    height: 88vh;
    max-height: 88vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  #chat-panel.chat-is-expanded {
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    top: 0;
  }
}