/* ════════════════════════════════════════════════════════════════
   BTB Helper — chat widget
   Self-contained, scoped under .btbchat-*. Reuses the site palette
   vars (--gold, --panel, --paper, --line, --mono …) defined in
   portal.css / wiki.css, so it matches both pages automatically.
   ════════════════════════════════════════════════════════════════ */

.btbchat-root {
  --bc-radius: 14px;
  position: fixed;
  z-index: 9000;
  bottom: 22px;
  right: 22px;
  font-family: var(--body, system-ui, sans-serif);
}

/* ── Floating button ─────────────────────────────────────────────── */
.btbchat-fab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1px solid var(--gold-deep, #b07d22);
  background: linear-gradient(180deg, var(--gold-2, #f3cd72), var(--gold, #e0a93e));
  color: #2a1c06;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--gold-deep, #b07d22), 0 10px 26px rgba(224, 169, 62, 0.4);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.btbchat-fab:hover { transform: translateY(-2px); box-shadow: 0 4px 0 var(--gold-deep, #b07d22), 0 14px 32px rgba(224, 169, 62, 0.5); }
.btbchat-fab:active { transform: translateY(0); }
.btbchat-fab svg { width: 28px; height: 28px; }
.btbchat-fab .bc-x { display: none; }
.btbchat-root.bc-open .btbchat-fab .bc-bubble { display: none; }
.btbchat-root.bc-open .btbchat-fab .bc-x { display: block; }

/* ── Panel ───────────────────────────────────────────────────────── */
.btbchat-panel {
  display: none;
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(620px, 78vh);
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--bc-radius);
  border: 1px solid var(--line-2, #4d3a20);
  background: var(--panel, #1a140c);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.btbchat-root.bc-open .btbchat-panel {
  display: flex;
  animation: bc-rise 0.18s ease both;
}
@keyframes bc-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Header ──────────────────────────────────────────────────────── */
.btbchat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line, #3a2c18);
  background: linear-gradient(180deg, var(--panel-2, #221a10), var(--panel, #1a140c));
}
.btbchat-head .bc-avatar {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--gold-2, #f3cd72), var(--gold-deep, #b07d22));
  color: #2a1c06;
}
.btbchat-head .bc-avatar svg { width: 19px; height: 19px; }
.btbchat-head .bc-title { font-family: var(--display, serif); font-weight: 700; font-size: 16px; color: var(--paper, #f3e7cc); line-height: 1.1; }
.btbchat-head .bc-sub { font-size: 11px; color: var(--paper-faint, #8d7c5b); margin-top: 2px; }
.btbchat-head .bc-status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--emerald, #6fae4e); margin-right: 5px; vertical-align: middle; }
.btbchat-head .bc-close {
  margin-left: auto; flex: none;
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: transparent; border: 1px solid transparent; color: var(--paper-dim, #c9b78f); cursor: pointer;
}
.btbchat-head .bc-close:hover { background: rgba(255,255,255,0.06); color: var(--paper, #f3e7cc); }
.btbchat-head .bc-close svg { width: 17px; height: 17px; }

/* ── Message log ─────────────────────────────────────────────────── */
.btbchat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2, #4d3a20) transparent;
}
.btbchat-log::-webkit-scrollbar { width: 8px; }
.btbchat-log::-webkit-scrollbar-thumb { background: var(--line-2, #4d3a20); border-radius: 8px; }

.btbchat-msg { max-width: 86%; font-size: 14px; line-height: 1.5; border-radius: 12px; padding: 9px 12px; word-wrap: break-word; overflow-wrap: anywhere; }
.btbchat-msg.bot { align-self: flex-start; background: var(--panel-2, #221a10); border: 1px solid var(--line, #3a2c18); color: var(--paper, #f3e7cc); border-bottom-left-radius: 4px; }
.btbchat-msg.user { align-self: flex-end; background: linear-gradient(180deg, var(--gold-2, #f3cd72), var(--gold, #e0a93e)); color: #2a1c06; font-weight: 500; border-bottom-right-radius: 4px; }
.btbchat-msg.err { background: rgba(210, 80, 42, 0.12); border-color: var(--crimson, #d2502a); }
.btbchat-msg p { margin: 0 0 7px; }
.btbchat-msg p:last-child { margin-bottom: 0; }
.btbchat-msg ul { margin: 4px 0; padding-left: 18px; }
.btbchat-msg li { margin: 2px 0; }
.btbchat-msg code { font-family: var(--mono, monospace); font-size: 12.5px; background: rgba(0,0,0,0.32); border: 1px solid var(--line, #3a2c18); border-radius: 5px; padding: 1px 5px; color: var(--gold-2, #f3cd72); }
.btbchat-msg.user code { background: rgba(0,0,0,0.16); border-color: rgba(0,0,0,0.2); color: #3a2606; }
.btbchat-msg a { color: var(--sky, #5aa6d0); text-decoration: underline; }
.btbchat-msg.user a { color: #3a2606; }

.btbchat-src { align-self: flex-start; font-size: 10.5px; color: var(--paper-faint, #8d7c5b); margin: -6px 0 0 4px; font-family: var(--mono, monospace); letter-spacing: 0.02em; }

/* typing dots */
.btbchat-typing { align-self: flex-start; display: flex; gap: 5px; padding: 11px 14px; background: var(--panel-2, #221a10); border: 1px solid var(--line, #3a2c18); border-radius: 12px; border-bottom-left-radius: 4px; }
.btbchat-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--paper-faint, #8d7c5b); animation: bc-blink 1.3s infinite ease-in-out both; }
.btbchat-typing span:nth-child(2) { animation-delay: 0.18s; }
.btbchat-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bc-blink { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* starter suggestion chips */
.btbchat-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 2px; }
.btbchat-chip {
  font-size: 12px; color: var(--gold-2, #f3cd72);
  background: rgba(224, 169, 62, 0.08); border: 1px solid var(--line-2, #4d3a20);
  border-radius: 999px; padding: 6px 11px; cursor: pointer; transition: background 0.15s ease;
}
.btbchat-chip:hover { background: rgba(224, 169, 62, 0.18); }

/* ── Input row ───────────────────────────────────────────────────── */
.btbchat-input {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px; border-top: 1px solid var(--line, #3a2c18);
  background: var(--panel, #1a140c);
}
.btbchat-input textarea {
  flex: 1; resize: none; max-height: 96px; min-height: 22px;
  font-family: var(--body, sans-serif); font-size: 14px; line-height: 1.4;
  color: var(--paper, #f3e7cc); background: var(--ink-2, #14100a);
  border: 1px solid var(--line-2, #4d3a20); border-radius: 9px; padding: 9px 11px;
}
.btbchat-input textarea::placeholder { color: var(--paper-faint, #8d7c5b); }
.btbchat-input textarea:focus { outline: none; border-color: var(--gold, #e0a93e); box-shadow: 0 0 0 2px rgba(224,169,62,0.18); }
.btbchat-send {
  flex: none; display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 9px; cursor: pointer;
  color: #2a1c06; background: linear-gradient(180deg, var(--gold-2, #f3cd72), var(--gold, #e0a93e));
  border: 1px solid var(--gold-deep, #b07d22);
}
.btbchat-send:hover { filter: brightness(1.05); }
.btbchat-send:disabled { opacity: 0.45; cursor: default; filter: none; }
.btbchat-send svg { width: 18px; height: 18px; }

.btbchat-foot { text-align: center; font-size: 10px; color: var(--paper-faint, #8d7c5b); padding: 0 0 8px; background: var(--panel, #1a140c); }

/* ── Mobile: full-width sheet ────────────────────────────────────── */
@media (max-width: 480px) {
  .btbchat-root { bottom: 16px; right: 16px; }
  .btbchat-panel {
    position: fixed; bottom: 0; right: 0; left: 0;
    width: 100%; max-width: 100%; height: 86vh;
    border-radius: var(--bc-radius) var(--bc-radius) 0 0;
    border-left: none; border-right: none; border-bottom: none;
  }
  .btbchat-root.bc-open .btbchat-fab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .btbchat-root.bc-open .btbchat-panel { animation: none; }
  .btbchat-typing span { animation: none; }
}
