/* ============================================================
   EVA X — COMPONENTS
   Reusable UI building blocks
   ============================================================ */

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-5);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: var(--ease-out);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: var(--shadow-accent);
}
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 6px 28px rgba(139,92,246,0.35); }

.btn-secondary {
  background: var(--bg-3);
  color: var(--tx);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-4); border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--tx-2);
  padding: 0 var(--sp-3);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--tx); }

.btn-danger { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { height: 32px; padding: 0 var(--sp-3); font-size: 0.8125rem; border-radius: var(--r-sm); }
.btn-lg { height: 48px; padding: 0 var(--sp-6); font-size: 0.9375rem; border-radius: var(--r-lg); }
.btn-full { width: 100%; }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--r-md);
  flex-shrink: 0;
}
.btn-icon.btn-sm { width: 32px; height: 32px; border-radius: var(--r-sm); }
.btn-icon.btn-lg { width: 48px; height: 48px; border-radius: var(--r-lg); }

/* Profile chat CTA */
.profile-actions {
  padding: var(--sp-4) var(--sp-4) 0;
}
.btn-chat {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #7c3aed, #c026d3);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: var(--ease-out);
  box-shadow: var(--shadow-accent);
}
.btn-chat:active { transform: scale(0.98); }

/* ── CARDS ───────────────────────────────────────────────── */
.card {
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  transition: var(--ease-out);
}

.card-hover:hover {
  border-color: var(--border);
  background: var(--bg-4);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-accent {
  background: var(--accent-grad-soft);
  border-color: rgba(139,92,246,0.2);
}

/* ── CHARACTER CARDS ─────────────────────────────────────── */
.char-card {
  position: relative;
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-xl);
  overflow: hidden;
  cursor: pointer;
  transition: var(--ease-out);
}

.char-card:hover {
  border-color: rgba(139,92,246,0.3);
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}

.char-card:active { transform: translateY(-2px) scale(0.99); }

.char-card-img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
  background: var(--bg-4);
}

.char-card-img-placeholder {
  width: 100%;
  aspect-ratio: 3/4;
  background: linear-gradient(135deg, var(--bg-4), var(--bg-3));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tx-4);
  font-size: 2.5rem;
  font-weight: 300;
}

.char-card-body {
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
}

.char-card-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--tx);
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
}

.char-card-age {
  font-size: 0.75rem;
  color: var(--tx-3);
  font-weight: 400;
}

.char-card-desc {
  font-size: 0.8125rem;
  color: var(--tx-3);
  margin-top: var(--sp-1);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.char-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: var(--sp-2);
}

.char-card-footer {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.char-card-footer .btn {
  flex: 1;
  height: 34px;
  font-size: 0.8125rem;
}

/* ── BADGES & TAGS ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--sp-2);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: var(--r-full);
  white-space: nowrap;
}

.badge-default { background: var(--bg-4); color: var(--tx-3); border: 1px solid var(--border); }
.badge-accent  { background: var(--accent-dim); color: var(--accent-2); }
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-warn    { background: var(--warn-dim); color: var(--warn); }
.badge-danger  { background: var(--danger-dim); color: var(--danger); }
.badge-pro     { background: var(--accent-grad); color: #fff; }

.tag {
  display: inline-block;
  padding: 3px var(--sp-2);
  background: var(--bg-4);
  color: var(--tx-3);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--r-full);
  border: 1px solid var(--border-soft);
  white-space: nowrap;
  transition: var(--ease);
}

.tag:hover { border-color: var(--accent); color: var(--accent-2); }
.tag.on { background: var(--accent-dim); color: var(--accent-2); border-color: rgba(139,92,246,0.3); }

/* ── AVATAR ──────────────────────────────────────────────── */
.ava {
  border-radius: var(--r-full);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--tx-3);
  overflow: hidden;
}

.ava-xs { width: 28px; height: 28px; font-size: 0.6875rem; }
.ava-sm { width: 36px; height: 36px; font-size: 0.8125rem; }
.ava-md { width: 44px; height: 44px; font-size: 1rem; }
.ava-lg { width: 56px; height: 56px; font-size: 1.25rem; }
.ava-xl { width: 72px; height: 72px; font-size: 1.5rem; }
.ava-2xl { width: 96px; height: 96px; font-size: 2rem; }

/* ── CHAT BUBBLES ────────────────────────────────────────── */
.msg-row {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-end;
  max-width: 85%;
  animation: msg-in 0.22s cubic-bezier(0.16,1,0.3,1) both;
}

.msg-row.user {
  flex-direction: row-reverse;
  align-self: flex-end;
  margin-left: auto;
}

.bubble {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-xl);
  font-size: 0.9375rem;
  line-height: 1.6;
  max-width: 100%;
  /* 🔥 FIX: evita texto vertical y saltos raros */
  word-break: normal;
  overflow-wrap: break-word;
  white-space: normal;
  writing-mode: horizontal-tb;
}

.bubble-ai {
  background: var(--bg-3);
  color: var(--tx);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
}

.bubble-user {
  background: var(--accent-grad);
  color: #fff;
  border-bottom-right-radius: var(--r-sm);
}

/* ── TYPING INDICATOR ────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-xl);
  border-bottom-left-radius: var(--r-sm);
  width: fit-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--tx-3);
  border-radius: var(--r-full);
  animation: typing-bounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ── STAT CARDS (dashboard) ──────────────────────────────── */
.stat-card {
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  transition: var(--ease-out);
}

.stat-card:hover { border-color: var(--border); transform: translateY(-2px); }

.stat-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-2);
}

.stat-card-value {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--tx);
  letter-spacing: -0.04em;
  line-height: 1;
}

.stat-card-label {
  font-size: 0.75rem;
  color: var(--tx-3);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── SKELETON LOADER ─────────────────────────────────────── */
.skel {
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-4) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: var(--r-md);
}

.skel-text { height: 14px; width: 100%; margin: 4px 0; }
.skel-text.w-60 { width: 60%; }
.skel-text.w-40 { width: 40%; }
.skel-card { aspect-ratio: 3/4; border-radius: var(--r-xl); }

/* ── TOGGLE ──────────────────────────────────────────────── */
.toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-4);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: var(--ease);
}

.toggle input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: var(--r-full);
  transition: var(--ease-out);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.toggle input:checked + .toggle-track::after { transform: translateX(20px); }

/* ── CONVERSATION LIST ───────────────────────────────────── */
.conv-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: var(--ease);
  position: relative;
  border-bottom: 1px solid var(--border-separator);
}

.conv-item:hover { background: var(--bg-3); }
.conv-item:active { background: var(--bg-4); }

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 0.9375rem; font-weight: 500; color: var(--tx); }
.conv-preview {
  font-size: 0.8125rem;
  color: var(--tx-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.conv-time { font-size: 0.6875rem; color: var(--tx-4); }
.conv-unread {
  min-width: 18px; height: 18px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── BOTTOM SHEET / PANEL ────────────────────────────────── */
.panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-3);
  border-top: 1px solid var(--border);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  padding: var(--sp-5) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
  z-index: 200;
  animation: panel-in 0.3s cubic-bezier(0.16,1,0.3,1) both;
}

.panel-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: var(--r-full);
  margin: 0 auto var(--sp-4);
}

/* ============================================================
   💬 CHAT FIX PRO — layout, burbujas, imágenes, input
   ============================================================ */

/* Contenedor general del chat */
.chat {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

/* Lista de mensajes */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Burbuja genérica .chat-message */
.chat-message {
  max-width: 80%;
  min-width: 60px;
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  display: inline-block;
  word-break: normal;
  overflow-wrap: break-word;
  white-space: normal;
  writing-mode: horizontal-tb;
}

.chat-message.me {
  align-self: flex-end;
  background: var(--accent-grad);
  color: #fff;
}

.chat-message.other {
  align-self: flex-start;
}

.chat-message p,
.chat-message span {
  margin: 0;
  line-height: 1.4;
}

/* Fuerza texto horizontal en cualquier hijo */
.chat-message * {
  word-break: normal !important;
  writing-mode: horizontal-tb !important;
}

/* Imágenes en el chat */
.chat-image-wrapper {
  width: 100%;
  max-height: 280px;
  overflow: hidden;
  border-radius: 12px;
  margin-top: 6px;
}

.chat-message img,
.chat-image {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
  cursor: pointer;
  transition: transform var(--t) var(--ease);
}

.chat-message img:hover {
  transform: scale(1.02);
}

/* Input área del chat */
.chat-input {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.chat-input input {
  flex: 1;
  padding: 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  outline: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color var(--t);
}

.chat-input input:focus {
  border-color: var(--accent);
}

.chat-input button {
  background: var(--accent-grad);
  border: none;
  border-radius: var(--r-md);
  padding: 0 16px;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  transition: opacity var(--t);
}

.chat-input button:active {
  opacity: 0.85;
}

/* Responsive */
@media (max-width: 768px) {
  .chat-message { max-width: 90%; }
  .chat-message img { max-height: 220px; }
}

/* ── THEME COLOR PICKER ── */
.color-picker-bar {
  display: flex; align-items: center; gap: 8px;
  background: rgba(10, 10, 12, 0.65);
  backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 5px;
  margin-left: auto; margin-right: 8px;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  width: 34px; height: 34px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.color-picker-bar.expanded {
  width: auto; padding: 5px 10px;
}
.color-dot {
  width: 22px; height: 22px;
  border-radius: 50%; flex-shrink: 0;
  border: 2px solid transparent; cursor: pointer;
  transition: transform 0.2s var(--ease), border-color 0.2s;
  display: none;
}
.color-picker-bar.expanded .color-dot {
  display: block;
}
.color-picker-bar .color-dot.active {
  display: block;
  border-color: #ffffff;
  box-shadow: 0 0 12px var(--theme-glow);
}
.color-picker-bar.expanded .color-dot.active {
  transform: scale(1.15);
}
