/* KocCoach — chat surface. Extends style.css. Dark monochrome + cream accent.
   Patterns lifted: composer grammar (universal), hero-above-empty-composer
   (Claude.ai/ChatGPT/v0), suggestion chips below in empty state (Claude.ai/v0),
   sticky composer with chips above in active state (STARTER §6 intent),
   collapsible tool cards (Claude.ai Artifacts), follow-up chips (Perplexity),
   inline structured-input cards (Cal.com booking flow). */

/* ---- Reset/baseline overrides for full-viewport chat ---- */

.chat-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  padding-bottom: 0;
}
.chat-page main { padding: 0; max-width: none; }

/* ---- Top bar (replaces site-header on chat surface) ---- */

.chat-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(10, 10, 10, 0.72);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  border-bottom: 1px solid var(--line);
}
.chat-topbar .logo {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.chat-topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Credit balance pill */
.balance-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.balance-pill:hover { background: var(--surface-strong); border-color: var(--line-strong); }
.balance-pill .balance-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.balance-pill .balance-unit { color: var(--ink-muted); font-size: 0.78rem; }

/* ---- Chat shell ---- */

.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  min-height: 0;
}

/* Empty state — composer centered, hero above */

.chat-shell.is-empty {
  justify-content: center;
  padding-bottom: max(80px, env(safe-area-inset-bottom));
  /* vh fallback for iOS 15 and older */
  min-height: calc(100vh - 60px);
  /* dvh handles iOS Safari URL bar + keyboard properly */
  min-height: calc(100dvh - 60px);
}
.chat-empty-hero {
  text-align: center;
  margin-bottom: 28px;
}
.chat-empty-hero h1 {
  font-size: clamp(1.6rem, 3.6vw, 2.2rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}
.chat-empty-hero p {
  color: var(--ink-muted);
  font-size: 0.92rem;
  margin: 10px 0 0;
}

/* Empty-state chips row — BELOW the composer (Claude.ai / v0 pattern) */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
}

/* Active-conversation chip row — ABOVE the sticky composer */
.chat-shell.is-active .chip-row.active-chips {
  position: sticky;
  bottom: 88px;
  background: linear-gradient(to bottom, transparent, rgba(10,10,10,0.6) 30%, var(--paper) 70%);
  padding: 18px 0 10px;
  z-index: 5;
  justify-content: flex-start;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: none;
}
.chat-shell.is-active .chip-row.active-chips::-webkit-scrollbar { display: none; }

/* Tool chip — pill with icon + name + cost */
.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
  font-family: inherit;
}
.tool-chip:hover {
  background: var(--surface-strong);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}
.tool-chip:active { transform: translateY(0); }
.tool-chip.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
/* Monochrome SVG line icons (chip_icons.py) — currentColor, sized box.
   Replaces the multicolor emoji (ui-audit P1-3 / Wp ruling 2026-05-22). */
.tool-chip .chip-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; flex-shrink: 0;
  color: var(--ink-dim); opacity: 0.9;
}
.tool-chip .chip-icon svg { width: 100%; height: 100%; display: block; }
.tool-chip:hover .chip-icon { color: var(--ink); }
.tool-chip .chip-name { color: var(--ink); }
.tool-chip .chip-cost {
  color: var(--ink-muted);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.tool-chip .chip-cost.free { color: var(--good); }

/* ---- Conversation stream ---- */

.chat-stream {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 0 32px;
  overflow-y: auto;
  min-height: 0;
}

/* Message base */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}
.msg-user {
  align-self: flex-end;
  max-width: 78%;
}
.msg-user .msg-body {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 12px 16px;
  border-radius: 14px 14px 4px 14px;
  font-size: 0.96rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-assistant {
  align-self: flex-start;
  max-width: 100%;
}
.msg-assistant .msg-body {
  color: var(--ink);
  font-size: 0.96rem;
  line-height: 1.65;
  padding: 4px 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Assistant byline (Claude.ai-ish — subtle, with the spark) */
.msg-byline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.msg-byline .spark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

/* Markdown-ish content inside message body */
.msg-body p { margin: 0 0 12px; }
.msg-body p:last-child { margin: 0; }
.msg-body strong { color: var(--ink); font-weight: 600; }
.msg-body em { color: var(--ink); font-style: italic; }
.msg-body ul, .msg-body ol { margin: 0 0 12px; padding-left: 20px; }
.msg-body li { margin-bottom: 4px; }
.msg-body h2 { font-size: 1.1rem; font-weight: 600; margin: 20px 0 8px; }
.msg-body h3 { font-size: 1rem; font-weight: 600; margin: 16px 0 6px; }
.msg-body code {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}
.msg-body pre code { background: transparent; border: 0; padding: 0; }

/* File chip — attached upload in user turn */
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  margin: 0 6px 6px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.84rem;
  color: var(--ink-dim);
}
.file-chip .file-icon { font-size: 0.95em; opacity: 0.7; }
.file-chip .file-size { color: var(--ink-muted); font-size: 0.78rem; }

/* Tool card — Claude.ai artifacts pattern, collapsible */
.tool-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: 12px;
  overflow: hidden;
}
.tool-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.tool-card-head:hover { background: var(--surface-strong); }
.tool-card-head .tool-card-icon { font-size: 1rem; opacity: 0.75; }
.tool-card-head .tool-card-name {
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.tool-card-head .tool-card-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tool-card-head .tool-card-status .state-chip { font-size: 0.7rem; padding: 3px 9px; }
.tool-card-head .tool-card-chevron {
  font-size: 0.85em;
  color: var(--ink-muted);
  transition: transform 0.15s;
}
.tool-card.open .tool-card-chevron { transform: rotate(180deg); }
.tool-card-body {
  padding: 0 16px 14px;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink-dim);
  display: none;
}
.tool-card.open .tool-card-body { display: block; padding-top: 14px; }
.tool-card-body p { margin: 0 0 10px; color: var(--ink); }
.tool-card-body .summary { color: var(--ink-dim); font-size: 0.88rem; margin-bottom: 8px; }
.tool-card-body pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
}

/* Follow-up chip row (Perplexity pattern) — chips below an assistant turn */
.followup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.followup-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-style 0.15s;
}
.followup-chip:hover {
  background: var(--surface);
  border-style: solid;
}
.followup-chip::before { content: "→"; color: var(--ink-muted); font-size: 0.9em; }

/* Inline credit deduction notice */
.credit-notice {
  align-self: center;
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  padding: 4px 0;
}
.credit-notice .delta { color: var(--ink-dim); font-weight: 500; }

/* Inline structured-input cards (course picker, consent, etc.) */
.input-card {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-top: 12px;
}
.input-card .input-card-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 8px;
}
.input-card .input-card-body { font-size: 0.92rem; color: var(--ink); }
.input-card .input-card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Streaming caret */
.streaming-caret {
  display: inline-block;
  width: 7px;
  height: 1.1em;
  vertical-align: text-bottom;
  margin-left: 2px;
  background: var(--accent);
  animation: caret-blink 1s steps(2) infinite;
}
@keyframes caret-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ---- Composer ---- */

.composer-wrap {
  position: relative;
  margin-top: 8px;
}
.chat-shell.is-active .composer-wrap {
  position: sticky;
  bottom: 0;
  padding: 12px 0 max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--paper) 30%, var(--paper));
  z-index: 10;
  /* --keyboard-inset set by chat.js VisualViewport listener; defaults to 0 */
  transform: translateY(calc(-1 * var(--keyboard-inset, 0px)));
  transition: transform 0.15s ease-out;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 14px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s;
}
.composer:focus-within {
  border-color: var(--accent);
}
.composer-input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  min-height: 28px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 2px;
}
.composer-input::placeholder { color: var(--ink-muted); }

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.composer-left, .composer-right { display: flex; align-items: center; gap: 6px; }

/* Composer icon button (attach, mic) */
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-size: 1.05rem;
  font-family: inherit;
}
.icon-btn:hover { background: var(--surface-strong); color: var(--ink); }
.icon-btn.attach { font-weight: 600; }

/* Composer tier badge (right) */
.composer-tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--ink-dim);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.composer-tier-badge:hover { border-color: var(--line-strong); color: var(--ink); }
.composer-tier-badge .tier-name { font-weight: 600; color: var(--ink); }

/* Send button */
.send-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: filter 0.15s, transform 0.12s, opacity 0.15s;
  font-family: inherit;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.05); }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Attached-file chips inside composer (before send) */
.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.composer-attachments:empty { display: none; }
.composer-attachments .file-chip {
  margin: 0;
  background: var(--surface-strong);
}
.composer-attachments .file-chip .remove-btn {
  margin-left: 4px;
  color: var(--ink-muted);
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
  font-size: 0.95em;
}
.composer-attachments .file-chip .remove-btn:hover { color: var(--bad); }

/* ---- Drag-drop overlay ---- */

.dropzone-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.85);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.dropzone-overlay.active { display: flex; }
.dropzone-overlay .dropzone-card {
  background: var(--surface-strong);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  padding: 40px 60px;
  color: var(--ink);
  font-size: 1.1rem;
  text-align: center;
}

/* ---- Mobile ---- */

@media (max-width: 600px) {
  .chat-shell { padding: 0 12px; }
  .chat-topbar { padding: 12px 16px; }
  .balance-pill { padding: 6px 12px; font-size: 0.78rem; min-height: 36px; }
  .chat-empty-hero h1 { font-size: 1.5rem; }
  .composer-wrap { padding: 10px 0 max(14px, env(safe-area-inset-bottom)); }
  .composer { padding: 12px 14px 8px; border-radius: var(--radius); }
  .composer-input { font-size: 16px; }  /* prevent iOS auto-zoom */
  .msg-user { max-width: 88%; }

  /* Apple HIG 44pt floor for tap targets */
  .send-btn, .icon-btn { width: 44px; height: 44px; font-size: 1.15rem; }
  .tool-chip { padding: 10px 14px; min-height: 44px; }
  .followup-chip { padding: 8px 14px; min-height: 40px; }
}
