/* ═══════════════════════════════════════════════════════════════════════════
 * thoria-apple.css — Rediseño Apple/iMessage del chat ThorIA
 *
 * Se carga DESPUÉS de thoria.css → sus reglas tienen prioridad. No toca la
 * lógica JS (clases .message.user/.bot, .timestamp, .thoria-input, etc.).
 * Solo cambia el look & feel.
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Drawer principal — Glass morphism estilo macOS Big Sur ──────────── */
#thoriaGlobal .thoria-drawer,
.thoria-drawer {
  background: rgba(255, 255, 255, 0.92) !important;
  backdrop-filter: blur(40px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(40px) saturate(180%) !important;
  border-radius: 18px !important;
  border: 1px solid rgba(255, 255, 255, 0.5) !important;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.04),
    0 24px 70px -12px rgba(15, 23, 42, 0.28),
    0 8px 24px -8px rgba(15, 23, 42, 0.14) !important;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
    'Inter', 'Segoe UI', Roboto, sans-serif !important;
  letter-spacing: -0.005em;
  overflow: hidden;
}

[data-theme="dark"] #thoriaGlobal .thoria-drawer,
[data-theme="dark"] .thoria-drawer {
  background: rgba(28, 28, 30, 0.92) !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
  color: #f1f5f9 !important;
}

/* Animación de apertura suave */
@keyframes thoriaSlideIn {
  from { transform: translateX(16px) scale(0.985); opacity: 0; }
  to   { transform: translateX(0)     scale(1);     opacity: 1; }
}
#thoriaGlobal .thoria-drawer.open,
.thoria-drawer.open {
  animation: thoriaSlideIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Header del drawer (más limpio, sin gradiente naranja agresivo) ──── */
#thoriaGlobal .thoria-drawer-header,
.thoria-drawer-header {
  background: linear-gradient(135deg,
    rgba(255, 248, 240, 0.85) 0%,
    rgba(255, 237, 213, 0.65) 100%) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
  color: #0f172a !important;
  padding: 14px 16px !important;
  backdrop-filter: blur(20px);
}

[data-theme="dark"] #thoriaGlobal .thoria-drawer-header,
[data-theme="dark"] .thoria-drawer-header {
  background: linear-gradient(135deg,
    rgba(124, 45, 18, 0.35) 0%,
    rgba(154, 52, 18, 0.22) 100%) !important;
  border-bottom-color: rgba(255, 255, 255, 0.08) !important;
  color: #fef3c7 !important;
}

.thoria-drawer-header .font-semibold {
  font-weight: 600 !important;
  font-size: 15px !important;
  letter-spacing: -0.01em;
  color: inherit;
}

/* Botón cerrar más sutil */
.thoria-drawer-close {
  background: rgba(0, 0, 0, 0.04) !important;
  border: 0 !important;
  color: #64748b !important;
  width: 28px !important;
  height: 28px !important;
  border-radius: 50% !important;
  padding: 0 !important;
  font-size: 13px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease !important;
}
.thoria-drawer-close:hover {
  background: rgba(0, 0, 0, 0.08) !important;
  color: #0f172a !important;
  transform: scale(1.08);
}
[data-theme="dark"] .thoria-drawer-close {
  background: rgba(255, 255, 255, 0.08) !important;
  color: #cbd5e1 !important;
}
[data-theme="dark"] .thoria-drawer-close:hover {
  background: rgba(255, 255, 255, 0.16) !important;
}

/* Botón exportar y otros del header */
.thoria-export {
  background: rgba(255, 255, 255, 0.7) !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  color: #475569 !important;
  padding: 4px 10px !important;
  border-radius: 999px !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
}
.thoria-export:hover {
  background: #fff !important;
  border-color: rgba(249, 115, 22, 0.4) !important;
  color: #c2410c !important;
}

/* ─── Área de mensajes — Espaciado y scroll suaves ────────────────────── */
.thoria-messages {
  background: transparent !important;
  padding: 20px 18px !important;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.thoria-messages::-webkit-scrollbar {
  width: 6px;
}
.thoria-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}
[data-theme="dark"] .thoria-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
}

/* Welcome message — más sobrio */
.thoria-messages .welcome-message {
  text-align: center;
  padding: 24px 16px 12px;
  color: #64748b !important;
  font-size: 14px !important;
  background: transparent !important;
  border: 0 !important;
}
.thoria-messages .welcome-message strong {
  color: #c2410c;
  font-weight: 600;
}

/* ─── Burbujas de mensaje — Estilo iMessage ──────────────────────────── */
.thoria-messages .message {
  display: inline-block !important;
  max-width: 78% !important;
  padding: 10px 14px !important;
  border-radius: 18px !important;
  margin: 6px 0 !important;
  font-size: 14px !important;
  line-height: 1.45 !important;
  word-wrap: break-word;
  position: relative;
  animation: thoriaMsgPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  letter-spacing: -0.005em;
  clear: both;
  float: left;
}

@keyframes thoriaMsgPop {
  from { transform: scale(0.94) translateY(4px); opacity: 0; }
  to   { transform: scale(1)     translateY(0);  opacity: 1; }
}

/* Burbuja del USUARIO (derecha, azul iMessage) */
.thoria-messages .message.user {
  background: linear-gradient(135deg, #007AFF 0%, #0066D6 100%) !important;
  color: #fff !important;
  float: right !important;
  margin-left: 22% !important;
  border-bottom-right-radius: 5px !important;
  text-align: left;
}
[data-theme="dark"] .thoria-messages .message.user {
  background: linear-gradient(135deg, #0A84FF 0%, #006EE6 100%) !important;
}

/* Burbuja de THORIA (izquierda, blanca con sombra suave) */
.thoria-messages .message.bot {
  background: #fff !important;
  color: #0f172a !important;
  float: left !important;
  margin-right: 22% !important;
  border-bottom-left-radius: 5px !important;
  border: 1px solid rgba(0, 0, 0, 0.04);
}
[data-theme="dark"] .thoria-messages .message.bot {
  background: #2a2a2c !important;
  color: #f1f5f9 !important;
  border-color: rgba(255, 255, 255, 0.06);
}

/* Limpiar floats entre mensajes */
.thoria-messages::after {
  content: "";
  display: table;
  clear: both;
}

/* Timestamp más sutil */
.thoria-messages .message .timestamp {
  display: block !important;
  font-size: 10px !important;
  opacity: 0.55 !important;
  margin-top: 4px !important;
  text-align: right;
  letter-spacing: 0.02em;
}
.thoria-messages .message.user .timestamp {
  color: rgba(255, 255, 255, 0.85) !important;
}

/* ─── Markdown rendering dentro de las burbujas ───────────────────────── */
.thoria-messages .message strong,
.thoria-messages .message b {
  font-weight: 600;
}
.thoria-messages .message ul,
.thoria-messages .message ol {
  margin: 6px 0 6px 18px;
  padding-left: 4px;
}
.thoria-messages .message ul li,
.thoria-messages .message ol li {
  margin: 2px 0;
}
.thoria-messages .message code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Menlo, Monaco, 'Courier New', monospace;
  font-size: 12.5px;
}
.thoria-messages .message.user code {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}
.thoria-messages .message pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 10px 12px;
  border-radius: 8px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: 'SF Mono', Menlo, Monaco, 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 1.5;
}
.thoria-messages .message.user pre {
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
}
.thoria-messages .message pre code {
  background: transparent;
  padding: 0;
}
.thoria-messages .message a {
  color: #007AFF;
  text-decoration: none;
  border-bottom: 1px solid rgba(0, 122, 255, 0.3);
}
.thoria-messages .message a:hover {
  border-bottom-color: #007AFF;
}
.thoria-messages .message.user a {
  color: #fff;
  border-bottom-color: rgba(255, 255, 255, 0.5);
}
.thoria-messages .message blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid rgba(0, 0, 0, 0.15);
  font-style: italic;
  opacity: 0.85;
}

/* ─── Typing indicator (3 puntos saltando estilo iMessage) ────────────── */
.thoria-typing {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  padding: 14px 18px !important;
  background: #fff !important;
  border-radius: 18px !important;
  border-bottom-left-radius: 5px !important;
  margin: 6px 0 !important;
  float: left !important;
  border: 1px solid rgba(0, 0, 0, 0.04);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  animation: thoriaMsgPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  clear: both;
}
[data-theme="dark"] .thoria-typing {
  background: #2a2a2c !important;
  border-color: rgba(255, 255, 255, 0.06);
}
.thoria-typing .dot {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  display: inline-block;
  animation: thoriaTypingDot 1.3s infinite ease-in-out;
}
.thoria-typing .dot:nth-child(1) { animation-delay: 0s; }
.thoria-typing .dot:nth-child(2) { animation-delay: 0.18s; }
.thoria-typing .dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes thoriaTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ─── Chips de sugerencias rápidas ────────────────────────────────────── */
.thoria-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 8px;
  margin-top: 4px;
}
.thoria-suggestion-chip {
  background: rgba(0, 122, 255, 0.08);
  border: 1px solid rgba(0, 122, 255, 0.18);
  color: #0066D6;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  letter-spacing: -0.005em;
}
.thoria-suggestion-chip:hover {
  background: rgba(0, 122, 255, 0.15);
  border-color: rgba(0, 122, 255, 0.35);
  transform: translateY(-1px);
}
[data-theme="dark"] .thoria-suggestion-chip {
  background: rgba(10, 132, 255, 0.15);
  border-color: rgba(10, 132, 255, 0.3);
  color: #60a5fa;
}

/* ─── Input area — Estilo iMessage ────────────────────────────────────── */
.thoria-input-row,
.thoria-input-area {
  padding: 12px 14px !important;
  background: rgba(248, 250, 252, 0.7) !important;
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .thoria-input-row,
[data-theme="dark"] .thoria-input-area {
  background: rgba(20, 20, 22, 0.7) !important;
  border-top-color: rgba(255, 255, 255, 0.08);
}

.thoria-input {
  background: #fff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  border-radius: 22px !important;
  padding: 10px 18px !important;
  font-size: 14px !important;
  color: #0f172a !important;
  transition: all 0.18s ease !important;
  font-family: inherit !important;
  letter-spacing: -0.005em;
}
.thoria-input:focus {
  outline: 0 !important;
  border-color: rgba(0, 122, 255, 0.5) !important;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12) !important;
}
.thoria-input::placeholder {
  color: #94a3b8 !important;
}
[data-theme="dark"] .thoria-input {
  background: rgba(58, 58, 60, 0.9) !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
  color: #f1f5f9 !important;
}
[data-theme="dark"] .thoria-input::placeholder {
  color: #64748b !important;
}

/* Botón enviar — Estilo Apple "send" */
.thoria-send {
  background: linear-gradient(135deg, #007AFF 0%, #0066D6 100%) !important;
  border: 0 !important;
  border-radius: 22px !important;
  padding: 10px 18px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  color: #fff !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
  letter-spacing: -0.005em;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}
.thoria-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.4);
}
.thoria-send:active {
  transform: translateY(0) scale(0.97);
  transition-duration: 0.06s;
}
.thoria-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ─── Estado LLM en header — más minimalista ──────────────────────────── */
.thoria-llm-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.6);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}
.llm-indicators {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
}
.llm-indicator {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: #475569;
  font-weight: 500;
}
.llm-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cbd5e1;
}
.llm-indicator[data-active] .llm-dot {
  background: #16a34a;
  box-shadow: 0 0 6px rgba(22, 163, 74, 0.5);
}
.llm-settings-btn {
  background: transparent;
  border: 0;
  padding: 2px 4px;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.llm-settings-btn:hover { opacity: 1; }

/* ─── Responsive — Móvil ──────────────────────────────────────────────── */
@media (max-width: 720px) {
  #thoriaGlobal .thoria-drawer,
  .thoria-drawer {
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    top: 56px !important;
    bottom: 8px !important;
    border-radius: 16px !important;
  }
  .thoria-messages .message {
    max-width: 88% !important;
    font-size: 14px !important;
  }
  .thoria-suggestion-chip {
    font-size: 12px;
    padding: 6px 12px;
  }
}

/* ─── Reduced motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .thoria-messages .message,
  .thoria-drawer.open,
  .thoria-typing .dot {
    animation: none !important;
  }
}
