/* =====================================================================
   Goya 1.1 — UI/UX enhancements (loaded after frontend.min.css)
   ===================================================================== */

/* ---------- Window: softer shape, entrance animation ---------- */
#gy-chatbot-container {
  border-radius: 1.25rem;
  box-shadow: 0 18px 50px -12px rgba(15, 23, 42, .35), 0 2px 8px rgba(15, 23, 42, .08);
  border: 1px solid rgba(15, 23, 42, .06);
  transform-origin: bottom right;
  animation: gy-window-in .28s cubic-bezier(.2, .8, .2, 1);
  transition: max-width .25s ease, height .25s ease;
}

#gy-chatbot-container[data-position="bottom-left"] {
  transform-origin: bottom left;
}

@keyframes gy-window-in {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Expanded (desktop only) */
@media (min-width: 601px) {
  #gy-chatbot-container.gy-expanded {
    max-width: min(560px, calc(100vw - 3rem));
    height: min(760px, calc(100vh - 9rem));
  }
}

/* ---------- Header ---------- */
#gy-chatbot-header {
  position: relative;
  gap: .6em;
  padding: .9em 1.1em .9em .8em;
  background-image: linear-gradient(135deg,
    rgba(255, 255, 255, .14), rgba(255, 255, 255, 0) 60%);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .06);
}

#gy-chatbot-header .gy-header-avatar {
  border: 2px solid rgba(255, 255, 255, .55);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.gy-header-actions {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: .15em;
}

#gy-chatbot-container .gy-header-actions button,
#gy-chatbot-container #gy-chatbot-close-btn {
  margin: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--gy-header-text);
  cursor: pointer;
  opacity: .85;
  transition: background .15s, opacity .15s, transform .15s;
}

#gy-chatbot-container .gy-header-actions button:hover,
#gy-chatbot-container #gy-chatbot-close-btn:hover {
  background: rgba(255, 255, 255, .18);
  opacity: 1;
}

#gy-chatbot-container .gy-header-actions button svg,
#gy-chatbot-container #gy-chatbot-close-btn svg {
  width: 18px;
  height: 18px;
}

/* Icon swaps for toggle buttons (ID-scoped to beat the base "button svg" rule) */
#gy-chatbot-container .gy-theme-toggle .gy-icon-sun,
#gy-chatbot-container .gy-expand-toggle .gy-icon-collapse { display: none; }
#gy-chatbot-container.gy-theme-dark .gy-theme-toggle .gy-icon-sun { display: block; }
#gy-chatbot-container.gy-theme-dark .gy-theme-toggle .gy-icon-moon { display: none; }
#gy-chatbot-container.gy-expanded .gy-expand-toggle .gy-icon-collapse { display: block; }
#gy-chatbot-container.gy-expanded .gy-expand-toggle .gy-icon-expand { display: none; }

@media (max-width: 600px) {
  #gy-chatbot-container .gy-expand-toggle { display: none !important; }
}

/* ---------- Messages ---------- */
#gy-chat-messages {
  padding: 1.1em 1.1em .5em;
  overscroll-behavior: contain;
  position: relative;
}

.gy-user-message,
.gy-bot-message {
  position: relative;
  max-width: 88%;
  padding: .75em .95em;
  border-radius: 1.1em;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
  animation: gy-msg-in .22s ease-out;
}

.gy-user-message { border-bottom-left-radius: .3em; }
.gy-bot-message  { border-bottom-right-radius: .3em; }

@keyframes gy-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.gy-message-time { opacity: .55; font-size: .68em; }

/* ---------- Copy button on bot messages ---------- */
.gy-copy-btn {
  position: absolute;
  top: .35em;
  inset-inline-start: .35em;
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: .6em;
  background: color-mix(in srgb, var(--gy-container-bg) 85%, transparent);
  color: var(--gy-bot-msg-text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
  cursor: pointer;
  opacity: 0;
  transform: scale(.9);
  transition: opacity .15s, transform .15s;
}

.gy-bot-message:hover .gy-copy-btn,
.gy-copy-btn:focus-visible { opacity: 1; transform: scale(1); }

@media (hover: none) {
  .gy-copy-btn { opacity: .7; transform: none; }
}

.gy-copy-btn svg { width: 15px; height: 15px; }
.gy-copy-btn.gy-copied { color: #16a34a; opacity: 1; }

/* ---------- Scroll-to-bottom ---------- */
.gy-scroll-bottom {
  position: absolute;
  inset-inline-end: 1.1em;
  bottom: 5.2em;
  z-index: 3;
  width: 36px;
  height: 36px;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--gy-container-bg);
  color: var(--gy-primary-color);
  box-shadow: 0 4px 14px rgba(15, 23, 42, .25);
  cursor: pointer;
  animation: gy-msg-in .2s ease-out;
}

.gy-scroll-bottom.gy-visible { display: inline-flex; }
.gy-scroll-bottom svg { width: 18px; height: 18px; }

/* ---------- Input area ---------- */
#gy-chat-form {
  gap: .4em;
  padding: .75em 1em;
  border-top: 1px solid rgba(15, 23, 42, .08);
}

#gy-chatbot-container #gy-chat-input {
  border-radius: 1.4em;
  transition: border-color .15s, box-shadow .15s;
}

#gy-chatbot-container #gy-send-btn:active,
#gy-chatbot-container #gy-voice-btn:active,
#gy-chatbot-container #gy-file-btn:active { transform: scale(.94); }

#gy-chatbot-container #gy-send-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Toast ---------- */
.gy-toast {
  position: absolute;
  inset-inline: 0;
  bottom: 5.4em;
  margin-inline: auto;
  width: fit-content;
  max-width: 80%;
  padding: .45em .9em;
  border-radius: 999px;
  background: rgba(17, 24, 39, .92);
  color: #fff;
  font-size: 12px;
  z-index: 5;
  pointer-events: none;
  animation: gy-msg-in .2s ease-out;
}

/* ---------- Accessibility ---------- */
#gy-chatbot-container button:focus-visible,
#gy-chatbot-open-btn:focus-visible,
#gy-chatbot-container a:focus-visible {
  outline: 2px solid var(--gy-accent-color);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  #gy-chatbot-container,
  .gy-user-message,
  .gy-bot-message,
  .gy-scroll-bottom,
  .gy-toast {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Mobile: bottom sheet feel + safe areas ---------- */
@media (max-width: 600px) {
  #gy-chatbot-container {
    border-radius: 1.1rem 1.1rem 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .gy-user-message,
  .gy-bot-message { max-width: 92%; }

  #gy-chat-form { padding-bottom: calc(.75em + env(safe-area-inset-bottom, 0)); }
}

/* ---------- Dark theme (overrides CSS variables on the container) ---------- */
#gy-chatbot-container.gy-theme-dark {
  --gy-container-bg: #111827;
  --gy-bot-msg-bg: #1f2937;
  --gy-bot-msg-text: #f3f4f6;
  --gy-input-bg: #1f2937;
  --gy-input-text: #f9fafb;
  --gy-icon-btn-icon: #93c5fd;
  --gy-quick-replies-bg: #0f172a;
  --gy-quick-item-bg: #1f2937;
  --gy-quick-item-text: #f3f4f6;
  --gy-quick-item-border: #374151;
  --gy-quick-item-hover-bg: #273449;
  --gy-quick-item-hover-text: #fff;
  --gy-card-bg: #1f2937;
  --gy-card-border: #374151;
  --gy-card-title: #f3f4f6;
  --gy-card-hover-bg: #273449;
  --gy-card-old-price: #9ca3af;
  --gy-scrollbar-track: #1f2937;
  --gy-scrollbar-thumb: #4b5563;
  --gy-scrollbar-thumb-hover: #6b7280;
  color-scheme: dark;
  border-color: rgba(255, 255, 255, .08);
}

#gy-chatbot-container.gy-theme-dark #gy-chat-form {
  border-top-color: rgba(255, 255, 255, .08);
}

#gy-chatbot-container.gy-theme-dark .gy-copy-btn {
  background: rgba(31, 41, 55, .9);
  color: #f3f4f6;
}

/* ---------- Keep the window clear of the launcher button (popup mode) ---------- */
body:not(.gy-chatbot-sidebar-mode) #gy-chatbot-container {
  --gy-win-bottom: calc(var(--gy-btn-bottom-desktop, 2.5rem) + 64px + 14px);
  bottom: var(--gy-win-bottom) !important;
  top: auto !important;
  height: min(555px, calc(100vh - var(--gy-win-bottom) - 16px)) !important;
}

body:not(.gy-chatbot-sidebar-mode) #gy-chatbot-container.gy-expanded {
  height: min(760px, calc(100vh - var(--gy-win-bottom) - 16px)) !important;
}

@supports (height: 100dvh) {
  body:not(.gy-chatbot-sidebar-mode) #gy-chatbot-container {
    height: min(555px, calc(100dvh - var(--gy-win-bottom) - 16px)) !important;
  }
  body:not(.gy-chatbot-sidebar-mode) #gy-chatbot-container.gy-expanded {
    height: min(760px, calc(100dvh - var(--gy-win-bottom) - 16px)) !important;
  }
}

@media (max-width: 600px) {
  body:not(.gy-chatbot-sidebar-mode) #gy-chatbot-container {
    --gy-win-bottom: calc(var(--gy-btn-bottom-mobile, 1.5rem) + 56px + 14px);
    left: 8px !important;
    right: 8px !important;
    width: auto;
    max-width: none;
    border-radius: 1.1rem;
    padding-bottom: 0;
  }
}

/* ---------- Human chat (live operator) ---------- */
#gy-chatbot-container .gy-header-actions .gy-human-btn {
  width: auto;
  min-width: 0;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: .35em;
  height: 30px;
  margin: 0 .3em 0 0;
  padding: 0 .75em;
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  color: var(--gy-header-text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
}
#gy-chatbot-container .gy-header-actions .gy-human-btn[hidden] { display: none !important; }
#gy-chatbot-container .gy-header-actions .gy-human-btn:hover { background: rgba(255, 255, 255, .28); opacity: 1; }
#gy-chatbot-container .gy-header-actions .gy-human-btn.is-active { background: #16a34a; border-color: #16a34a; color: #fff; opacity: 1; }
#gy-chatbot-container .gy-header-actions .gy-human-btn svg { width: 15px; height: 15px; }

.gy-human-banner {
  display: flex;
  align-items: center;
  gap: .6em;
  padding: .5em 1em;
  background: #ecfdf5;
  color: #065f46;
  border-bottom: 1px solid #a7f3d0;
  font-size: 12.5px;
}
.gy-human-banner[hidden] { display: none !important; }
.gy-human-banner[data-state="waiting"] { background: #fffbeb; color: #92400e; border-bottom-color: #fde68a; }
.gy-human-banner-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: gy-dirty-blink 1.4s infinite;
}
@keyframes gy-dirty-blink { 50% { opacity: .3; } }
.gy-human-banner-text { flex: 1; }
.gy-human-banner .gy-human-end {
  border: 0;
  border-radius: 999px;
  padding: .25em .8em;
  background: rgba(0, 0, 0, .08);
  color: inherit;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.gy-human-banner .gy-human-end:hover { background: rgba(0, 0, 0, .16); }

.gy-agent-message { border-inline-start: 3px solid #16a34a; }
.gy-agent-label {
  margin-bottom: .25em;
  color: #15803d;
  font-size: 11.5px;
  font-weight: 700;
}

.gy-system-message,
.gy-system-inline {
  display: block;
  align-self: center;
  margin: .4em auto;
  max-width: 90%;
  padding: .3em .8em;
  border-radius: 999px;
  background: rgba(100, 116, 139, .12);
  color: #475569;
  font-size: 11.5px;
  font-style: normal;
  text-align: center;
}

#gy-chatbot-container.gy-theme-dark .gy-human-banner { background: #052e22; color: #6ee7b7; border-bottom-color: #065f46; }
#gy-chatbot-container.gy-theme-dark .gy-human-banner[data-state="waiting"] { background: #3b2a0b; color: #fcd34d; border-bottom-color: #7a5a14; }
#gy-chatbot-container.gy-theme-dark .gy-agent-label { color: #4ade80; }
#gy-chatbot-container.gy-theme-dark .gy-system-message,
#gy-chatbot-container.gy-theme-dark .gy-system-inline { background: rgba(148, 163, 184, .16); color: #cbd5e1; }

/* Human-chat button stays visible but dimmed while no operator is online */
#gy-chatbot-container .gy-header-actions .gy-human-btn.is-offline { opacity: .55; }

/* ---------- Default launcher icon: white chat bubble + sparkle ---------- */
#gy-chatbot-open-btn.circle-style svg.gy-bot-avatar .gy-chat-glyph { fill: #fff; }
#gy-chatbot-open-btn.circle-style svg.gy-bot-avatar .gy-chat-dot { fill: var(--gy-primary-color); }
#gy-chatbot-open-btn.circle-style svg.gy-bot-avatar .gy-chat-spark { fill: #fff; opacity: .92; transform-box: fill-box; transform-origin: center; }
#gy-chatbot-open-btn.circle-style svg.gy-bot-avatar .gy-chat-glyph { transform-box: fill-box; transform-origin: center; transition: transform .25s ease; }
#gy-chatbot-open-btn.circle-style:hover svg.gy-bot-avatar .gy-chat-glyph { transform: scale(1.06); }

@media (prefers-reduced-motion: no-preference) {
  #gy-chatbot-open-btn.circle-style svg.gy-bot-avatar .gy-chat-spark { animation: gy-spark 3.2s ease-in-out infinite; }
  @keyframes gy-spark {
    0%, 70%, 100% { transform: scale(1) rotate(0); opacity: .92; }
    85% { transform: scale(1.25) rotate(20deg); opacity: 1; }
  }
}
