/* =========================================================================
   Almo v2 — Chat
   ========================================================================= */

.chat {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 0;
}
.chat .page-head { margin-bottom: 0; }

/* ---- Character ---- */
.almo-character {
  position: relative;
  width: 52px; height: 52px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}
.almo-character__video,
.almo-character__img { width: 100%; height: 100%; object-fit: cover; display: block; }
.almo-character__ring {
  position: absolute; inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 55%, transparent);
  opacity: 0; transition: opacity var(--dur);
  pointer-events: none;
}
.almo-character[data-state="thinking"] .almo-character__ring,
.almo-character[data-state="talking"] .almo-character__ring { opacity: 1; animation: ring-pulse 1.4s var(--ease) infinite; }
@keyframes ring-pulse { 50% { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--primary) 75%, transparent); } }

/* ---- Stream ---- */
.chat__stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-4) 2px;
  scroll-behavior: smooth;
}

.chat-empty {
  margin: auto;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-5);
  padding: var(--sp-8) var(--sp-4);
}
.chat-empty__title { font-size: var(--text-xl); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.chat-suggestion {
  border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: var(--radius-pill); padding: 8px var(--sp-4);
  font-size: var(--text-sm); color: var(--text-muted); font-weight: var(--fw-medium);
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
@media (hover: hover) { .chat-suggestion:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); } }

/* ---- Messages ---- */
.msg { display: flex; }
.msg--user { justify-content: flex-end; }
.msg--almo, .msg--file { justify-content: flex-start; }
.msg__bubble {
  position: relative;
  max-width: min(76%, 640px);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  line-height: 1.55;
}
.msg--user .msg__bubble {
  background: var(--primary); color: var(--text-on-primary);
  border-bottom-right-radius: var(--radius-xs);
}
.msg--almo .msg__bubble {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: var(--radius-xs);
  padding-bottom: var(--sp-5);
}
.msg--almo.is-error .msg__bubble { border-color: var(--danger-soft); color: var(--danger); }
.msg__content p { margin: 0; }
.msg__content p + p { margin-top: var(--sp-2); }
.msg__content ul, .msg__content ol { margin: var(--sp-2) 0; padding-left: var(--sp-5); }
.msg__content a { text-decoration: underline; }
.msg__content code {
  font-family: var(--font-mono); font-size: 0.85em;
  background: var(--surface-inset); padding: 1px 5px; border-radius: 5px;
}
.msg__tts {
  position: absolute; bottom: 6px; right: 8px;
  border: none; background: transparent; color: var(--text-subtle);
  width: 24px; height: 24px; border-radius: 6px;
  display: grid; place-items: center;
  opacity: 0; transition: opacity var(--dur-fast), color var(--dur-fast);
}
@media (hover: hover) { .msg--almo .msg__bubble:hover .msg__tts { opacity: 1; } }
@media (hover: hover) { .msg__tts:hover { color: var(--primary); } }

.msg__actions { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-3); }
.msg__actions--standalone { margin-top: 0; max-width: min(78%, 640px); }

/* ---- File chip ---- */
.file-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-muted);
}
.file-chip .spinner { width: 14px; height: 14px; }
.file-chip .icon:last-child { color: var(--success); }

/* ---- Action cards ---- */
.action-card {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-md); padding: var(--sp-3);
}
.action-card.is-delete { border-left-color: var(--danger); }
.action-card.is-update { border-left-color: var(--info); }
.action-card.is-save { border-left-color: var(--success); }
.action-card.is-call { border-left-color: var(--accent); }
.action-card__icon {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 8px; display: grid; place-items: center;
  background: var(--surface); color: var(--text-muted);
}
.action-card.is-delete .action-card__icon { color: var(--danger); }
.action-card.is-save .action-card__icon { color: var(--success); }
.action-card.is-update .action-card__icon { color: var(--info); }
.action-card__label { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-subtle); font-weight: var(--fw-semibold); }
.action-card__title { font-weight: var(--fw-semibold); font-size: var(--text-base); }
.action-card__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.action-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--text-xs); color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: var(--radius-pill);
}
.action-chip .icon { color: var(--text-subtle); }

/* ---- Typing indicator ---- */
.chat-typing { display: inline-flex; gap: 5px; padding: var(--sp-3) var(--sp-4); align-self: flex-start; }
.chat-typing span {
  width: 7px; height: 7px; border-radius: 999px; background: var(--text-subtle);
  animation: typing 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---- Composer ---- */
.chat__composer {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.chat__input {
  flex: 1; min-width: 0;
  border: none; background: transparent; outline: none;
  font-size: var(--text-base); color: var(--text);
  padding: 0 var(--sp-2); height: 40px;
}
.chat__input::placeholder { color: var(--text-subtle); }
.chat__composer .iconbtn.is-recording { background: var(--danger); color: #fff; animation: rec-pulse 1.2s infinite; }
@keyframes rec-pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 25%, transparent); } }

/* ---- Call control (top bar, right of the Almo title) ----
   The whole call UI is this one button — no pop-up bar. It is right-aligned and
   does not float over page content. While a call is running the icon itself
   shows the live state (a pulsing colour), and clicking it ends the call. */
.call-btn {
  margin-left: auto; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary-soft-text);
}
@media (hover: hover) { .call-btn:hover { background: color-mix(in srgb, var(--primary) 20%, transparent); color: var(--primary-soft-text); } }

/* Call in progress: the button glows so it's clear a call is live. */
.call-btn--live { color: #fff; }
.call-btn--live.is-active { background: var(--success); animation: call-live-pulse 1.4s infinite; }
@media (hover: hover) { .call-btn--live.is-active:hover { background: var(--success); color: #fff; } }
.call-btn--live.is-connecting { background: var(--warning); animation: call-connect-pulse 1s infinite; }
@media (hover: hover) { .call-btn--live.is-connecting:hover { background: var(--warning); color: #fff; } }
@keyframes call-live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent); }
  50% { box-shadow: 0 0 0 7px transparent; }
}
@keyframes call-connect-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--warning) 55%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .call-btn--live.is-active, .call-btn--live.is-connecting { animation: none; }
}

@media (max-width: 560px) {
  .msg__bubble { max-width: 86%; }
}
