/* Ishmael — floating chat field + expandable panel.
   Loaded alongside the site's own styles.css, which already defines every
   bg, text, space, and radius token this file uses — only the chat-specific
   ones below (no existing site equivalent) are new here, per Lance: "ok to
   bring these over as new tokens" since this UI doesn't exist elsewhere on
   the site yet. */

:root {
  --chat-z-scrim: 400;
  --chat-z-dock:  410;
  --chat-panel-height: 62vh;
  --chat-panel-max-height: 640px;
  --chat-gutter: 15px;
  --chat-content-width: 800px;
  --chat-ease: cubic-bezier(.65, 0, .35, 1);
}

/* Reserve room above the footer so the docked input never overlaps it */
body { padding-bottom: 130px; }

@keyframes raft-chat-dot {
  0%, 60%, 100% { opacity: .25; }
  30% { opacity: 1; }
}

@keyframes raft-chat-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Scrim */
.raft-chat-scrim {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s var(--chat-ease);
  z-index: var(--chat-z-scrim);
}

.raft-chat-scrim[data-active="focus"] { opacity: .3; pointer-events: auto; }
.raft-chat-scrim[data-active="open"] { opacity: .55; pointer-events: auto; }

/* Dock — always-present fixed bar at the bottom of the viewport */
.raft-chat-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--chat-z-dock);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font-sans);
}

/* Expandable message panel */
.raft-chat-panel {
  width: 100%;
  background: var(--bg-canvas);
  border-top: 0 solid var(--border-rule);
  overflow: hidden;
  height: 0;
  transition: height .45s var(--chat-ease), border-top-width .2s var(--chat-ease);
}

.raft-chat-dock[data-mode="open"] .raft-chat-panel {
  border-top-width: 1px;
}

.raft-chat-dock[data-mode="open"] .raft-chat-panel {
  height: min(var(--chat-panel-height), var(--chat-panel-max-height));
}

.raft-chat-panel-inner {
  max-width: var(--chat-content-width);
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 var(--chat-gutter);
  box-sizing: border-box;
}

.raft-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 1px;
  border-bottom: 1px solid var(--border-rule);
  flex-shrink: 0;
}

.raft-chat-header-id {
  display: flex;
  align-items: center;
  gap: 12px;
}

.raft-chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: block;
}

.raft-chat-label {
  margin: 0;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--text-muted);
}

.raft-chat-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background .2s;
}

.raft-chat-close:hover { background: var(--border-rule); }

.raft-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 11px 20px 1px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.raft-chat-msg--user {
  display: flex;
  justify-content: flex-end;
}

/* Applied only on a message's first render — see the enteredIds tracking
   in raft-chat.js. Re-render (e.g. every word-reveal tick) must NOT carry
   this, or the fade-in restarts from opacity:0 every tick and the text
   never reaches full opacity while "typing." */
.raft-chat-msg--enter {
  animation: raft-chat-rise .3s ease-out;
}

.raft-chat-bubble--user {
  max-width: 560px;
  margin: 0;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 16px;
  line-height: 1.45;
}

.raft-chat-msg--bot {
  display: flex;
  gap: 16px;
  max-width: 820px;
}

.raft-chat-bot-arrow {
  flex-shrink: 0;
  color: var(--text-accent);
  font-size: 16px;
  font-weight: 900;
  line-height: 1.5;
}

.raft-chat-bot-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.raft-chat-bot-text {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  text-wrap: pretty;
  white-space: pre-wrap;
}

.raft-chat-projects {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.raft-chat-project-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 300px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-rule);
  border-radius: var(--radius-md);
  padding: 16px;
  color: var(--text-primary);
  text-decoration: none;
  box-sizing: border-box;
  transition: border-color .2s;
}

.raft-chat-project-card:hover { border-color: var(--border-button); }

.raft-chat-project-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-sm);
  background-color: var(--bg-sunken);
  background-size: cover;
  background-position: center;
}

.raft-chat-project-name {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.raft-chat-project-sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.raft-chat-project-go {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  color: var(--text-accent);
}

/* Compact, no thumbnail — distinct from project cards since a Journal
   citation is a "read more" pointer, not a concrete work example, and
   always leaves the site (Substack), unlike same-tab project links. */
.raft-chat-journal-card {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-rule);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  text-decoration: none;
  transition: border-color .2s;
}

.raft-chat-journal-card:hover { border-color: var(--border-button); }

.raft-chat-journal-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.52px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.raft-chat-journal-title {
  font-size: 13px;
  font-weight: 700;
}

.raft-chat-journal-go {
  font-size: 13px;
  font-weight: 900;
  color: var(--text-accent);
}

.raft-chat-cta {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px 22px;
  border: 1px solid var(--border-button);
  border-radius: var(--radius-pill);
  background: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background .2s, color .2s;
}

.raft-chat-cta:hover {
  background: var(--bg-brand);
  color: var(--accent-ink);
}

.raft-chat-thinking {
  display: flex;
  gap: 16px;
  align-items: center;
  animation: raft-chat-rise .3s ease-out;
}

.raft-chat-thinking-arrow {
  color: var(--text-accent);
  font-size: 16px;
  font-weight: 900;
}

.raft-chat-thinking-dots {
  display: flex;
  gap: 6px;
}

.raft-chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-accent);
  animation: raft-chat-dot 1.2s infinite;
}

.raft-chat-dot:nth-child(2) { animation-delay: .2s; }
.raft-chat-dot:nth-child(3) { animation-delay: .4s; }

/* Input area — always visible, transparent until the panel opens */
.raft-chat-input-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  background: transparent;
  transition: background .4s var(--chat-ease);
}

.raft-chat-dock[data-mode="open"] .raft-chat-input-wrap {
  background: var(--bg-canvas);
}

.raft-chat-input-inner {
  width: 100%;
  max-width: var(--chat-content-width);
  padding: 0 var(--chat-gutter) 30px;
  box-sizing: border-box;
}

.raft-chat-chips-wrap {
  overflow: hidden;
  height: 0;
  transition: height .35s var(--chat-ease);
}

.raft-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 4px;
}

.raft-chat-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border-rule);
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color .2s, color .2s;
}

.raft-chat-chip:hover {
  border-color: var(--border-button);
  color: var(--text-accent);
}

.raft-chat-form {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-pill);
  padding: 10px 10px 10px 24px;
  box-sizing: border-box;
}

.raft-chat-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
  padding: 8px 0;
}

.raft-chat-input::placeholder { color: var(--text-muted); }

.raft-chat-mic,
.raft-chat-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.raft-chat-mic {
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: background .2s;
}

.raft-chat-mic:hover { background: var(--border-rule); }

.raft-chat-mic--listening {
  background: var(--bg-brand);
  color: var(--accent-ink);
  animation: raft-chat-dot 1.2s infinite;
}

.raft-chat-send {
  background: var(--bg-brand);
  color: var(--accent-ink);
  transition: opacity .2s;
}

.raft-chat-send:hover { opacity: .85; }

@media (max-width: 768px) {
  .raft-chat-dock[data-mode="open"] .raft-chat-panel {
    height: min(78vh, var(--chat-panel-max-height));
  }
  .raft-chat-project-card { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .raft-chat-scrim,
  .raft-chat-panel,
  .raft-chat-input-wrap,
  .raft-chat-chips-wrap {
    transition: none;
  }
  .raft-chat-msg--user,
  .raft-chat-msg--bot,
  .raft-chat-thinking {
    animation: none;
  }
  .raft-chat-dot { animation: none; opacity: 1; }
  .raft-chat-mic--listening { animation: none; }
}
