/* Màgic chat widget. Same visual language as the previous WPBot skin, scoped to #magic-chat.
   Hex (exact sRGB of the former oklch tokens) and vh fallbacks keep iOS < 15.4 readable. */
#magic-chat {
  --mc-brand: #d5583c;
  --mc-action: #a1331a;
  --mc-ink: #2a2220;
  --mc-muted: #625551;
  --mc-surface: #fefbfa;
  --mc-soft: #f8f0ee;
  --mc-line: #e3d4d0;
  position: fixed; right: 24px; bottom: 24px; z-index: 99990;
  font: 400 16px/1.5 'Titillium Web', sans-serif; color: var(--mc-ink);
}
#magic-chat *, #magic-chat *::before, #magic-chat *::after { box-sizing: border-box; }
#magic-chat [hidden] { display: none !important; }
#magic-chat .magic-chat-sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
#magic-chat button { font: inherit; cursor: pointer; }
#magic-chat :is(button, a, input):focus-visible { outline: 2px solid var(--mc-action); outline-offset: 3px; }

/* Launcher */
#magic-chat .magic-chat-launcher {
  position: relative; isolation: isolate;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-width: 144px; height: 54px; padding: 0 20px; margin: 0;
  border: 1px solid #85311e; border-radius: 28px;
  background: var(--mc-action); color: var(--mc-surface);
  font: 600 17px/1 'Titillium Web', sans-serif;
  box-shadow: 0 4px 16px rgba(42, 34, 32, .16);
  animation: magic-launch-float 5s cubic-bezier(.45,0,.55,1) infinite;
  transition: background-color 180ms cubic-bezier(.2,.7,.3,1);
}
#magic-chat .magic-chat-launcher::after {
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  box-shadow: 0 6px 20px rgba(161, 51, 26, .18);
  animation: magic-launch-shadow 5s cubic-bezier(.45,0,.55,1) infinite;
}
#magic-chat .magic-chat-launcher:hover { background: #982f17; }
#magic-chat .magic-chat-launcher:is(:hover,:focus-visible),
#magic-chat .magic-chat-launcher:is(:hover,:focus-visible)::after { animation-play-state: paused; }
#magic-chat .magic-chat-launcher-icon { width: 24px; height: 24px; flex: none; }
#magic-chat.is-open .magic-chat-launcher { display: none; }
@keyframes magic-launch-float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -2px; } }
@keyframes magic-launch-shadow { 0%, 100% { opacity: .3; } 50% { opacity: .75; } }

/* Panel */
#magic-chat .magic-chat-panel {
  position: fixed; right: 24px; bottom: 24px;
  display: flex; flex-direction: column;
  width: 390px; height: min(610px, calc(100vh - 48px)); max-height: calc(100vh - 48px);
  height: min(610px, calc(100dvh - 48px)); max-height: calc(100dvh - 48px);
  border: 1px solid var(--mc-line); border-radius: 20px; overflow: hidden;
  background: var(--mc-surface); color: var(--mc-ink);
  box-shadow: 0 16px 48px rgba(42, 34, 32, .18);
}
#magic-chat .magic-chat-header {
  flex: 0 0 88px; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 16px 22px; border-bottom: 1px solid var(--mc-line);
}
#magic-chat .magic-chat-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
#magic-chat .magic-chat-brand img { display: block; height: 28px; width: 112px; object-fit: contain; object-position: left; }
#magic-chat .magic-chat-brand span { color: var(--mc-muted); font-size: 14px; line-height: 1.2; }
#magic-chat .magic-chat-close {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0; margin: 0;
  border: 1px solid var(--mc-line); border-radius: 50%; background: var(--mc-soft); color: var(--mc-ink);
}
#magic-chat .magic-chat-close svg { width: 20px; height: 20px; }
#magic-chat .magic-chat-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 20px; -webkit-overflow-scrolling: touch; scroll-behavior: auto;
}

/* Messages */
#magic-chat .magic-chat-log { margin: 0; padding: 0; list-style: none; }
#magic-chat .magic-msg { margin: 0 0 16px; padding: 0; list-style: none; }
#magic-chat .magic-bubble {
  padding: 12px 16px; border-radius: 12px; background: var(--mc-soft);
  overflow-wrap: anywhere; text-align: left;
}
#magic-chat .magic-msg-user .magic-bubble { margin-left: 36px; background: #ffe3dc; white-space: pre-line; }
#magic-chat .magic-msg-error .magic-bubble { border: 1px solid var(--mc-line); }
#magic-chat .magic-bubble p { margin: 0 0 .75em; }
#magic-chat .magic-bubble p:last-child { margin-bottom: 0; }
#magic-chat .magic-bubble a { color: var(--mc-action); text-decoration: underline; text-underline-offset: 3px; }

/* Static greeting, not part of the stored conversation. */
#magic-chat .magic-chat-welcome {
  display: inline-block; max-width: 100%; margin: 0 0 16px; padding: 12px 16px;
  border-radius: 12px; background: var(--mc-soft); color: var(--mc-ink); overflow-wrap: anywhere;
}

/* Prompts */
#magic-chat .magic-chat-prompt {
  display: flex; align-items: center; width: 100%; min-height: 46px;
  padding: 11px 14px; margin: 8px 0; border: 1px solid var(--mc-line); border-radius: 10px;
  background: var(--mc-surface); color: var(--mc-action);
  font: 600 16px/1.4 'Titillium Web', sans-serif; text-align: left;
}
#magic-chat .magic-chat-prompt:hover { background: var(--mc-soft); }

/* Footer */
#magic-chat .magic-chat-footer { flex: none; padding: 14px 16px 16px; border-top: 1px solid var(--mc-line); }
#magic-chat .magic-chat-form { display: flex; align-items: center; gap: 8px; margin: 0; }
#magic-chat .magic-chat-form input {
  flex: 1 1 0; width: 0; min-width: 0; height: 48px; margin: 0; padding: 10px 12px;
  border: 1px solid var(--mc-line); border-radius: 10px; background: var(--mc-soft); color: var(--mc-ink);
  font: 400 16px/1.5 'Titillium Web', sans-serif; box-shadow: none;
}
#magic-chat .magic-chat-form input::placeholder { color: var(--mc-muted); opacity: 1; }
#magic-chat .magic-chat-send {
  flex: 0 0 48px; display: grid; place-items: center; width: 48px; height: 48px; padding: 0; margin: 0;
  border: 0; border-radius: 10px; background: var(--mc-action); color: var(--mc-surface);
}
#magic-chat .magic-chat-send svg { width: 22px; height: 22px; }
#magic-chat button:disabled { opacity: .55; cursor: wait; }
#magic-chat .magic-chat-footnote { margin: 10px 0 0; font-size: 13px; line-height: 1.3; color: var(--mc-muted); text-align: center; }
#magic-chat .magic-chat-footnote a { display: inline-block; padding: 6px 0; color: var(--mc-action); text-decoration: underline; text-underline-offset: 3px; }
#magic-chat .magic-chat-whatsapp { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-left: 5px; }

/* Rich replies: readable text, then real source previews outside the bubble. */
#magic-chat .magic-bubble:has(.magic-rich-answer) { background: transparent; padding: 0; border-radius: 0; }
#magic-chat .magic-answer-body { background: var(--mc-soft); padding: 14px 16px; border-radius: 12px; line-height: 1.6; }
#magic-chat .magic-answer-body p { margin: 0 0 .75em; white-space: pre-line; }
#magic-chat .magic-answer-body p:last-child { margin-bottom: 0; }
#magic-chat .magic-answer-body strong { font-weight: 700; }
#magic-chat .magic-answer-body :is(ul, ol) { margin: .65em 0; padding: 0 0 0 1.2em; list-style-position: outside; }
#magic-chat .magic-answer-body ul { list-style-type: disc; }
#magic-chat .magic-answer-body ol { list-style-type: decimal; }
#magic-chat .magic-answer-body li { display: list-item; margin: .4em 0; padding: 0; }
#magic-chat .magic-answer-body li::marker { color: var(--mc-muted); }
#magic-chat .magic-sources { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 10px; }
#magic-chat a.magic-source-card {
  display: grid; grid-template-columns: 58px minmax(0, 1fr) 16px; align-items: center; gap: 10px;
  min-height: 86px; padding: 10px; margin: 0; border: 1px solid var(--mc-line); border-radius: 12px;
  background: var(--mc-surface); color: var(--mc-ink); text-decoration: none; text-align: left;
  transition: border-color 160ms cubic-bezier(.2,.7,.3,1), background-color 160ms cubic-bezier(.2,.7,.3,1);
}
#magic-chat a.magic-source-card:hover { border-color: var(--mc-action); background: var(--mc-soft); }
#magic-chat .magic-source-thumb {
  display: grid; place-items: center; position: relative; width: 58px; height: 64px;
  overflow: hidden; border-radius: 7px; background: var(--mc-soft); color: var(--mc-muted);
}
#magic-chat .magic-source-thumb > svg { width: 24px; height: 24px; }
#magic-chat .magic-source-thumb > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; margin: 0; padding: 0; border-radius: 0; }
#magic-chat .magic-source-logo > img { object-fit: contain; background: var(--mc-surface); }
#magic-chat .magic-source-copy { display: grid; gap: 3px; min-width: 0; }
#magic-chat .magic-source-meta { font-size: .75rem; line-height: 1.3; color: var(--mc-muted); }
#magic-chat .magic-source-title { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
#magic-chat .magic-source-excerpt {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  font-size: .8125rem; line-height: 1.4; color: var(--mc-muted);
}
#magic-chat .magic-source-arrow { width: 16px; height: 16px; color: var(--mc-action); }

/* Typing status */
#magic-chat .magic-msg-typing .magic-bubble { display: inline-block; padding: 10px 14px; }
#magic-chat .magic-typing { display: inline-flex; align-items: center; gap: 10px; font-size: .875rem; color: var(--mc-muted); }
#magic-chat .magic-typing-dots { display: inline-flex; gap: 4px; align-items: center; }
#magic-chat .magic-typing-dots i {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .3;
  animation: magic-typing-dot 1.4s cubic-bezier(.45,0,.55,1) infinite;
}
#magic-chat .magic-typing-dots i:nth-child(2) { animation-delay: 160ms; }
#magic-chat .magic-typing-dots i:nth-child(3) { animation-delay: 320ms; }
@keyframes magic-typing-dot { 0%, 60%, 100% { opacity: .3; } 30% { opacity: .85; } }

@media (prefers-reduced-motion: reduce) {
  #magic-chat .magic-chat-launcher, #magic-chat .magic-chat-launcher::after { animation: none; translate: none; }
  #magic-chat .magic-chat-launcher, #magic-chat a.magic-source-card { transition: none; }
  #magic-chat .magic-typing-dots i { animation: none; opacity: .6; }
}
@media (max-width: 600px) {
  #magic-chat { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  #magic-chat .magic-chat-panel {
    right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    width: calc(100vw - 24px);
    height: min(600px, calc(100vh - 24px)); max-height: calc(100vh - 24px);
    height: min(600px, calc(100dvh - 24px - env(safe-area-inset-bottom)));
    max-height: calc(100dvh - 24px - env(safe-area-inset-bottom));
  }
  #magic-chat .magic-chat-scroll { padding: 20px 16px; }
}
