/* components.css — chat widget styles for the Complex Frequency story.
   Matches the tokens defined in design.css :root (glass panel, accent, etc.).
   Placed bottom-LEFT so it never collides with the right-side #narrative panel.
   We reuse design.css variables (--panel, --accent, --line, …) directly. */

/* ---- floating launcher button (bottom-left) ----------------------------- */
.cf-chat-launcher {
  position: fixed;
  left: 26px;
  bottom: 76px;                 /* sits above #counter (bottom:30px) on the left */
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  transition: border-color .2s, transform .2s var(--ease), box-shadow .2s;
}
.cf-chat-launcher:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}
.cf-chat-launcher-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 0 12px rgba(189, 178, 255, .5);
}

/* ---- chat panel --------------------------------------------------------- */
.cf-chat-panel {
  position: fixed;
  left: 26px;
  bottom: 76px;
  z-index: 60;
  width: min(360px, calc(100vw - 52px));
  max-height: min(540px, calc(100vh - 120px));
  display: none;                /* hidden until .cf-chat-open is added */
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  font-family: var(--font);
  /* enter animation */
  transform: translateY(12px) scale(.98);
  opacity: 0;
  transition: opacity .26s var(--ease), transform .26s var(--ease);
}
.cf-chat-panel.cf-chat-open {
  display: flex;
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ---- header ------------------------------------------------------------- */
.cf-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.cf-chat-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
.cf-chat-close {
  background: transparent;
  border: none;
  color: var(--mute);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  transition: color .2s;
}
.cf-chat-close:hover { color: var(--text); }

/* ---- message list ------------------------------------------------------- */
.cf-chat-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.cf-chat-list::-webkit-scrollbar { width: 8px; }
.cf-chat-list::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

/* message bubbles */
.cf-chat-msg {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: var(--r-md);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;        /* preserve newlines from multi-line replies */
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.cf-chat-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--bg);
  border-bottom-right-radius: 4px;
}
.cf-chat-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
/* system / status / error notes — quieter, centered, italic */
.cf-chat-system {
  align-self: center;
  max-width: 100%;
  text-align: center;
  background: transparent;
  color: var(--mute);
  font-size: 13px;
  font-style: italic;
}
/* the transient "Thinking…" bubble gets a gentle pulse */
.cf-chat-thinking { opacity: .7; animation: cf-chat-pulse 1.2s ease-in-out infinite; }
@keyframes cf-chat-pulse { 0%, 100% { opacity: .45; } 50% { opacity: .85; } }

/* ---- input row ---------------------------------------------------------- */
.cf-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.cf-chat-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 110px;
  padding: 9px 11px;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  background: #1c2430;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color .2s;
}
.cf-chat-input:focus { border-color: var(--accent); }
.cf-chat-input::placeholder { color: var(--mute); }
.cf-chat-input:disabled { opacity: .6; }

.cf-chat-send {
  flex: 0 0 auto;
  padding: 9px 16px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s, opacity .2s;
}
.cf-chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 12px rgba(189, 178, 255, .5);
}
.cf-chat-send:disabled { opacity: .5; cursor: default; }

/* ---- responsive: on narrow screens the #narrative panel docks to the
   bottom (see design.css @max-width:820px), so lift the chat clear of it
   and let it span the width. ---------------------------------------------- */
@media (max-width: 820px) {
  .cf-chat-launcher { bottom: 96px; }
  .cf-chat-panel {
    left: 12px;
    right: 12px;
    bottom: 96px;
    width: auto;
    max-height: min(60vh, 480px);
  }
}
