/* ══════════════════════════════════════════════════════════════
   TONALLIX · conversación, prosa y composer
   ══════════════════════════════════════════════════════════════ */

.thread-wrap {
  max-width: 810px;
  margin: 0 auto;
  padding: 24px 0 14px;
  animation: fadeIn 0.35s ease both;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.msg {
  animation: msgIn 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Usuario ───────────────────────────────────────────────── */

.msg-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.user-bubble {
  max-width: 78%;
  padding: 12px 16px;
  border: 1px solid rgba(var(--accent-rgb), 0.17);
  border-radius: 18px 18px 5px 18px;
  background: linear-gradient(160deg, rgba(var(--accent-rgb), 0.11), rgba(var(--accent-rgb), 0.04));
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  color: #f3ecdf;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.user-attach {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.14);
  color: var(--text-soft);
  font: 400 9px var(--font-ui);
}

.user-attach svg {
  width: 11px;
  height: 11px;
  color: var(--accent);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.user-meta {
  margin-top: 6px;
  padding-right: 5px;
  color: var(--faint);
  font: 400 8px var(--font-mono);
  letter-spacing: 0.03em;
}

/* ── Asistente ─────────────────────────────────────────────── */

.msg-ai {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 13px;
}

.ai-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 1px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff6df 0%, #ffd27a 22%, var(--accent) 48%, var(--accent-2) 100%);
  color: #221304;
  box-shadow: 0 0 0 1px rgba(255, 230, 185, 0.16), 0 0 22px rgba(var(--accent-rgb), 0.18);
}

.ai-avatar svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
  stroke: none;
  opacity: 0.9;
}

.ai-main {
  min-width: 0;
}

.ai-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
}

.ai-name {
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.ai-model {
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--faint);
  font: 400 7.5px var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ai-time {
  margin-left: auto;
  color: var(--faint);
  font: 400 8px var(--font-mono);
}

.ai-content {
  margin-top: 7px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.76;
  overflow-wrap: anywhere;
}

.ai-content.streaming {
  white-space: pre-wrap;
}

.ai-content [data-stream] {
  white-space: pre-wrap;
}

/* Prosa */

.prose p {
  margin: 0 0 13px;
}

.prose p:last-child {
  margin-bottom: 0;
}

.prose > :first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3 {
  margin: 21px 0 10px;
  color: #fff3dd;
  font-weight: 600;
  line-height: 1.34;
  letter-spacing: -0.025em;
}

.prose h1 {
  font-size: 20px;
}

.prose h2 {
  font-size: 17px;
}

.prose h3 {
  font-size: 15px;
}

.prose h4 {
  margin: 17px 0 8px;
  color: var(--muted);
  font: 500 9px var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.prose strong {
  color: #fff1d7;
  font-weight: 600;
}

.prose em {
  color: #f7e9d0;
  font-family: var(--font-display);
  font-size: 1.08em;
  font-style: italic;
}

.prose ul,
.prose ol {
  margin: 0 0 13px;
  padding-left: 20px;
}

.prose li {
  margin: 4px 0;
  padding-left: 1px;
}

.prose li::marker {
  color: var(--accent);
  font-size: 0.9em;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(var(--accent-rgb), 0.35);
}

.prose a:hover {
  text-decoration-color: var(--accent);
}

.prose blockquote {
  margin: 14px 0;
  padding: 2px 0 2px 14px;
  border-left: 2px solid rgba(var(--accent-rgb), 0.42);
  color: var(--muted);
  font-style: italic;
}

.prose hr {
  margin: 19px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.prose code {
  padding: 1px 5px;
  border: 1px solid rgba(var(--accent-rgb), 0.12);
  border-radius: 5px;
  background: rgba(var(--accent-rgb), 0.075);
  color: #ffe6bb;
  font: 400 11.5px var(--font-mono);
}

.code-block {
  margin: 15px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #0a0807;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px 7px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  color: var(--faint);
  font: 400 8px var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border: 0;
  background: none;
  color: var(--faint);
  font: 400 8.5px var(--font-mono);
  cursor: pointer;
  transition: color 0.15s;
}

.code-copy:hover {
  color: var(--accent);
}

.code-copy svg {
  width: 10px;
  height: 10px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  color: #d8cdbc;
  font: 400 11.5px/1.7 var(--font-mono);
  tab-size: 2;
}

.code-block pre code {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
}

/* Pensando / streaming */

.thinking {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 30px;
  color: var(--muted);
}

.thinking-ring {
  width: 15px;
  height: 15px;
  flex: none;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg 286deg, var(--accent) 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
  animation: spin 0.95s linear infinite;
}

.thinking-text {
  background: linear-gradient(90deg, var(--muted) 0%, #fff2d9 42%, var(--muted) 68%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font: 400 10px var(--font-mono);
  letter-spacing: 0.035em;
  animation: shimmer 2.4s linear infinite;
}

.thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-dots i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--faint);
  animation: dotBounce 1.2s ease-in-out infinite;
}

.thinking-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.caret {
  display: inline-block;
  width: 6px;
  height: 14px;
  margin-left: 2px;
  border-radius: 1px;
  background: var(--accent);
  vertical-align: -2px;
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.5);
  animation: blink 0.9s steps(1) infinite;
}

/* Acciones del mensaje */

.ai-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.18s;
}

.msg-ai:hover .ai-actions,
.ai-actions:focus-within {
  opacity: 1;
}

.ai-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 25px;
  padding: 0 7px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--faint);
  font: 400 9px var(--font-ui);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.ai-action:hover {
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-soft);
}

.ai-action svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-action.speaking {
  color: var(--accent);
}

/* Error de API */

.api-error {
  padding: 11px 13px;
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: 9px;
  background: rgba(255, 107, 107, 0.05);
  color: #ffc0c0;
  font-size: 12px;
  line-height: 1.6;
}

.api-error strong {
  display: block;
  margin-bottom: 3px;
  color: #ffdada;
  font-weight: 500;
}

/* ── Composer ──────────────────────────────────────────────── */

.composer-wrap {
  position: relative;
  z-index: 12;
  flex: 0 0 auto;
  padding: 8px 30px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(7, 6, 5, 0), rgba(7, 6, 5, 0.55) 26%, rgba(7, 6, 5, 0.84));
}

.composer {
  position: relative;
  max-width: 840px;
  margin: 0 auto;
  padding: 12px 12px 9px;
  border: 1px solid rgba(255, 235, 200, 0.13);
  border-radius: 19px;
  background: rgba(19, 16, 12, 0.82);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.42), inset 0 1px rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(26px) saturate(130%);
  -webkit-backdrop-filter: blur(26px) saturate(130%);
  transition: border-color 0.25s, box-shadow 0.25s;
}

.composer:focus-within {
  border-color: rgba(var(--accent-rgb), 0.3);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(var(--accent-rgb), 0.07), 0 0 60px rgba(var(--accent-rgb), 0.06);
}

.composer::before {
  content: "";
  position: absolute;
  inset: -1px;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(115deg, rgba(var(--accent-rgb), 0.34), transparent 27%, transparent 72%, rgba(var(--accent2-rgb), 0.25));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.25s;
}

.composer:focus-within::before {
  opacity: 1;
}

#prompt {
  display: block;
  width: 100%;
  min-height: 30px;
  max-height: 190px;
  padding: 3px 6px 9px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 400 14px/1.6 var(--font-ui);
  resize: none;
  overflow-y: auto;
}

#prompt::placeholder {
  color: var(--faint);
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 2px;
}

.composer-left,
.composer-right {
  display: flex;
  align-items: center;
  gap: 3px;
}

.composer-left .icon-btn,
.composer-right .icon-btn {
  width: 30px;
  height: 30px;
}

.composer-left .icon-btn svg,
.composer-right .icon-btn svg {
  width: 15px;
  height: 15px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 7px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--faint);
  font: 400 10px var(--font-ui);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tool-btn svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-soft);
}

.composer-divider {
  width: 1px;
  height: 15px;
  margin: 0 4px;
  background: var(--line-2);
}

.composer-mode {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 3px;
  color: var(--faint);
  font: 400 8.5px var(--font-mono);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.mode-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.7);
}

.mic-btn.listening {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent);
  animation: micPulse 1.5s ease-in-out infinite;
}

.send-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(var(--accent-rgb), 0.22);
  color: #1d1306;
  cursor: pointer;
  transition: transform 0.2s, filter 0.2s, box-shadow 0.2s, background 0.2s;
}

.send-btn:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(var(--accent-rgb), 0.3);
}

.send-btn:disabled {
  background: rgba(255, 255, 255, 0.055);
  box-shadow: none;
  color: var(--faint);
  cursor: default;
}

.send-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.send-btn .stop-icon {
  display: none;
}

.send-btn.is-stop {
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: none;
  color: var(--text);
}

.send-btn.is-stop .send-icon {
  display: none;
}

.send-btn.is-stop .stop-icon {
  display: block;
}

.composer-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 840px;
  margin: 8px auto 0;
  padding: 0 4px;
  color: var(--faint);
  font: 400 8.5px var(--font-ui);
}

.note-keys {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font: 400 8px var(--font-mono);
  white-space: nowrap;
}

.note-keys span {
  opacity: 0.5;
}

/* Chips de herramientas activas */

.tool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 4px 8px;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid rgba(var(--accent-rgb), 0.16);
  border-radius: 6px;
  background: rgba(var(--accent-rgb), 0.07);
  color: var(--accent);
  font: 400 8.5px var(--font-ui);
}

.tool-chip > svg {
  width: 10px;
  height: 10px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-chip button {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.65;
}

.tool-chip button:hover {
  opacity: 1;
}

.tool-chip button svg {
  width: 9px;
  height: 9px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Adjuntos */

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 2px 4px 8px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  height: 27px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-soft);
  font: 400 9px var(--font-ui);
}

.attach-chip > svg {
  width: 11px;
  height: 11px;
  flex: none;
  color: var(--accent);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attach-chip .attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-chip small {
  color: var(--faint);
  font: 400 7.5px var(--font-mono);
}

.attach-chip button {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
}

.attach-chip button:hover {
  color: #ff9a9a;
}

.attach-chip button svg {
  width: 9px;
  height: 9px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
