/* ==========================================================================
   Asseco AI Chat Widget — Light Theme
   Design tokens:
   - Background:    #FFFFFF
   - Surface:       #F4F5F7
   - Panel-bg:      #FAFBFC
   - Text:          #1A1D23
   - Text-muted:    #6B7280
   - Accent:        #232323  (matching theme CTA)
   - Gradient:      90deg, #F16B5E → #D529E0 → #3F5BEB → #3FA2EB
   - Border:        #E5E7EB
   - Font:          "PP Mori", arial, sans-serif
   ========================================================================== */

/* ---------- Reset & Container ---------- */

#asseco-ai-chat *,
#asseco-ai-chat *::before,
#asseco-ai-chat *::after {
  box-sizing: border-box;
}

#asseco-ai-chat {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  max-width: 50%;
  z-index: 99999;
  font-family: "PP Mori", arial, sans-serif;
  font-size: 0.75rem;
  line-height: 1.5;
  color: #1A1D23;
  border: none;
}

/* Bar entrance — slide up from below (only after bubble) */
#asseco-ai-chat.asseco-ai-chat--animate-in[data-state="collapsed"],
#asseco-ai-chat.asseco-ai-chat--animate-in[data-state="expanded"] {
  animation: asseco-bar-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Bar exit — slide down + fade out */
#asseco-ai-chat[data-state="hiding"] {
  animation: asseco-bar-out 0.35s cubic-bezier(0.4, 0, 1, 1) both;
  pointer-events: none;
}

/* ---------- Bar (always visible) ---------- */

.asseco-ai-chat__bar {
  background: #FFFFFF;
  padding: 1rem 1.5rem 1.25rem;
  position: relative;
  border-radius: 1.5rem;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.1),
    0 2px 8px rgba(0, 0, 0, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.04);
}

/* Single row: label + input + toggle */
.asseco-ai-chat__bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.asseco-ai-chat__bar-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9CA3AF;
  white-space: nowrap;
  flex-shrink: 0;
}

.asseco-ai-chat__icon {
  flex-shrink: 0;
}

/* ---------- Toggle / Minimize ---------- */

.asseco-ai-chat__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  background: #F4F5F7;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
}

.asseco-ai-chat__toggle:hover {
  background: #E5E7EB;
}

.asseco-ai-chat__toggle:active {
  transform: scale(0.92);
}

.asseco-ai-chat__chevron {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#asseco-ai-chat[data-state="collapsed"] .asseco-ai-chat__chevron,
#asseco-ai-chat[data-state="expanded"] .asseco-ai-chat__chevron {
  transform: rotate(0deg);
}

/* ---------- Form / Input ---------- */

.asseco-ai-chat__form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 0;
}

.asseco-ai-chat__input {
  flex: 1;
  border: 2px solid transparent;
  border-radius: 1.5rem;
  color: #1A1D23;
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.5rem 2.5rem 0.5rem 1rem;
  margin: 0;
  outline: none;
  width: 100%;
  min-width: 0;
  background:
    linear-gradient(#F4F5F7, #F4F5F7) padding-box,
    linear-gradient(90deg, #F16B5E, #D529E0 33%, #3F5BEB 67%, #3FA2EB) border-box;
  background-size: 100% 100%, 200% 100%;
  background-position: 0 0, 0% 0;
  transition: background-position 0.6s ease, background-size 0.3s ease, box-shadow 0.3s ease;
}

.asseco-ai-chat__input::placeholder {
  color: #9CA3AF;
  font-size: 0.75rem;
}

.asseco-ai-chat__input:focus {
  background:
    linear-gradient(#FFFFFF, #FFFFFF) padding-box,
    linear-gradient(90deg, #F16B5E, #D529E0 33%, #3F5BEB 67%, #3FA2EB) border-box;
  background-size: 100% 100%, 200% 100%;
  background-position: 0 0, 100% 0;
  box-shadow: 0 0 12px rgba(213, 41, 224, 0.1), 0 0 4px rgba(63, 91, 235, 0.08);
  animation: asseco-gradient-flow 3s linear infinite;
}

@keyframes asseco-gradient-flow {
  0% {
    background-position: 0 0, 0% 0;
  }
  100% {
    background-position: 0 0, 200% 0;
  }
}

.asseco-ai-chat__submit {
  position: absolute;
  right: 4px;
  top: 4px;
  bottom: 4px;
  margin: auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  aspect-ratio: 1;
  height: calc(100% - 8px);
  padding: 0;
  background: #232323;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.asseco-ai-chat__submit:hover {
  background: #3A3A3A;
  box-shadow: 0 2px 8px rgba(35, 35, 35, 0.25);
}

.asseco-ai-chat__submit:active {
  transform: scale(0.92);
}

.asseco-ai-chat__submit:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---------- Prompt Chips ---------- */

.asseco-ai-chat__prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0.75rem 0 0 0;
  padding: 0;
  overflow: visible;
  list-style: none;
}

.asseco-ai-chat__prompt-chip {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid #E5E7EB;
  border-radius: 1.5rem;
  color: #6B7280;
  font-family: inherit;
  font-size: 0.6875rem;
  padding: 0.375rem 0.875rem;
  margin: 0;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.asseco-ai-chat__prompt-chip:hover {
  border-color: #232323;
  color: #232323;
  background: rgba(35, 35, 35, 0.04);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* ---------- Expanded Panel (Messages) ---------- */

.asseco-ai-chat__panel {
  background: #FAFBFC;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  margin: 0 0 -1px 0;
  padding: 0;
  border-radius: 1.5rem 1.5rem 0 0;
}

#asseco-ai-chat[data-state="expanded"] .asseco-ai-chat__panel {
  max-height: 60vh;
  overflow-y: auto;
  box-shadow:
    0 -8px 32px rgba(0, 0, 0, 0.08),
    0 -2px 8px rgba(0, 0, 0, 0.04);
}

#asseco-ai-chat[data-state="expanded"] .asseco-ai-chat__bar {
  border-radius: 0 0 1.5rem 1.5rem;
}

.asseco-ai-chat__messages {
  padding: 1.5rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

/* ---------- Message Bubbles ---------- */

.asseco-ai-chat__message {
  max-width: 82%;
  padding: 0.75rem 1rem;
  margin: 0;
  border-radius: 1rem;
  font-size: 0.75rem;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: asseco-ai-chat-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.asseco-ai-chat__message--user {
  align-self: flex-end;
  background: #232323;
  color: #FFFFFF;
  border-bottom-right-radius: 0.25rem;
  box-shadow: 0 1px 4px rgba(35, 35, 35, 0.15);
}

.asseco-ai-chat__message--assistant {
  align-self: flex-start;
  background: #FFFFFF;
  color: #1A1D23;
  border: 1px solid #E5E7EB;
  border-bottom-left-radius: 0.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.asseco-ai-chat__message--assistant a {
  color: #232323;
  text-decoration: underline;
  text-decoration-color: #D1D5DB;
  text-underline-offset: 2px;
  font-weight: 500;
  transition: text-decoration-color 0.15s ease;
}

.asseco-ai-chat__message--assistant a:hover {
  text-decoration-color: #232323;
}

.asseco-ai-chat__message--assistant p {
  margin: 0 0 0.5rem;
  padding: 0;
}

.asseco-ai-chat__message--assistant p:last-child {
  margin-bottom: 0;
}

.asseco-ai-chat__message--assistant strong {
  font-weight: 600;
  color: #1A1D23;
}

.asseco-ai-chat__message--assistant ul,
.asseco-ai-chat__message--assistant ol {
  margin: 0.25rem 0 0.5rem 1.25rem;
  padding: 0;
}

.asseco-ai-chat__message--assistant li {
  margin: 0 0 0.25rem;
}

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

/* ---------- Sources ---------- */

.asseco-ai-chat__sources {
  margin: 0.625rem 0 0 0;
  padding: 0.5rem 0 0 0;
  border-top: 1px solid #E5E7EB;
  font-size: 0.625rem;
  color: #6B7280;
}

.asseco-ai-chat__sources-label {
  font-weight: 600;
  font-size: 0.5625rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #9CA3AF;
  margin: 0 0 0.25rem 0;
  padding: 0;
}

.asseco-ai-chat__sources a {
  color: #6B7280;
  text-decoration: underline;
  text-decoration-color: #D1D5DB;
  text-underline-offset: 2px;
  display: inline;
  margin: 0 0.25rem 0 0;
  padding: 0;
  line-height: 1.5;
  font-size: 0.625rem;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.asseco-ai-chat__sources a::after {
  content: ',';
  color: #9CA3AF;
  text-decoration: none;
}

.asseco-ai-chat__sources a:last-child::after {
  content: '';
}

.asseco-ai-chat__sources a:hover {
  color: #232323;
  text-decoration-color: #232323;
}

/* ---------- Typing Indicator ---------- */

.asseco-ai-chat__typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.625rem 1rem;
  margin: 0;
  background: #FFFFFF;
  border: 1px solid #E5E7EB;
  border-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  animation: asseco-ai-chat-msg-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.asseco-ai-chat__typing-dot {
  width: 0.3rem;
  height: 0.3rem;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  background: #232323;
  animation: asseco-ai-chat-bounce 1.4s ease-in-out infinite;
}

.asseco-ai-chat__typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.asseco-ai-chat__typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes asseco-ai-chat-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  30% {
    transform: translateY(-0.2rem);
    opacity: 1;
  }
}

/* ---------- Bubble State ---------- */

#asseco-ai-chat[data-state="bubble"] {
  bottom: 1.5rem;
  left: auto;
  right: 1.5rem;
  transform: none;
  width: 3.25rem;
  max-width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  overflow: hidden;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.15),
    0 2px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  animation: asseco-bubble-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

#asseco-ai-chat[data-state="bubble-exit"] {
  bottom: 1.5rem;
  left: auto;
  right: 1.5rem;
  transform: none;
  width: 3.25rem;
  max-width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
  animation: asseco-bubble-out 0.25s cubic-bezier(0.4, 0, 1, 1) both;
}

#asseco-ai-chat[data-state="bubble"] .asseco-ai-chat__bar,
#asseco-ai-chat[data-state="bubble"] .asseco-ai-chat__panel,
#asseco-ai-chat[data-state="bubble-exit"] .asseco-ai-chat__bar,
#asseco-ai-chat[data-state="bubble-exit"] .asseco-ai-chat__panel {
  display: none;
}

.asseco-ai-chat__bubble {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #F16B5E, #D529E0 40%, #3F5BEB 70%, #3FA2EB);
  cursor: pointer;
  border: none;
  padding: 0;
  margin: 0;
}

#asseco-ai-chat[data-state="bubble"] .asseco-ai-chat__bubble,
#asseco-ai-chat[data-state="bubble-exit"] .asseco-ai-chat__bubble {
  display: flex;
}

/* ---------- Animations ---------- */

@keyframes asseco-bar-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes asseco-bar-out {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(100%);
  }
}

@keyframes asseco-bubble-in {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  60% {
    transform: scale(1.2);
    opacity: 1;
  }
  80% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes asseco-bubble-out {
  from {
    transform: scale(1);
    opacity: 1;
  }
  to {
    transform: scale(0);
    opacity: 0;
  }
}

/* ---------- Error Message ---------- */

.asseco-ai-chat__message--error {
  align-self: flex-start;
  background: #FEF2F2;
  color: #DC2626;
  border: 1px solid #FECACA;
  border-bottom-left-radius: 0.25rem;
}

/* ---------- Body offset ---------- */

body.asseco-ai-chat-open {
  padding-bottom: var(--asseco-ai-chat-height, 6rem);
  transition: padding-bottom 0.3s ease;
}

body:has(#asseco-ai-chat[data-state="bubble"]),
body:has(#asseco-ai-chat[data-state="bubble-exit"]),
body:has(#asseco-ai-chat[data-state="hiding"]) {
  padding-bottom: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 64rem) {
  #asseco-ai-chat:not([data-state="bubble"]) {
    width: 60%;
    max-width: 60%;
  }
}

@media (max-width: 48.875rem) {
  #asseco-ai-chat:not([data-state="bubble"]) {
    width: calc(100% - 2rem);
    max-width: calc(100% - 2rem);
  }

  .asseco-ai-chat__bar {
    padding: 0.75rem 1rem 1rem;
  }

  #asseco-ai-chat[data-state="expanded"] .asseco-ai-chat__panel {
    max-height: 70vh;
  }

  .asseco-ai-chat__messages {
    padding: 0.75rem;
    gap: 0.5rem;
  }

  .asseco-ai-chat__message {
    max-width: 90%;
    padding: 0.5rem 0.75rem;
  }

  .asseco-ai-chat__prompts {
    flex-wrap: nowrap;
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.5rem;
    margin-bottom: -0.5rem;
  }
}

@media (max-width: 22.5rem) {
  .asseco-ai-chat__input {
    font-size: 0.6875rem;
    padding: 0.5rem 2.25rem 0.5rem 1rem;
  }

  .asseco-ai-chat__prompt-chip {
    font-size: 0.625rem;
    padding: 0.25rem 0.625rem;
  }
}

/* ---------- Scrollbar in messages ---------- */

.asseco-ai-chat__panel::-webkit-scrollbar {
  width: 0.25rem;
}

.asseco-ai-chat__panel::-webkit-scrollbar-track {
  background: transparent;
}

.asseco-ai-chat__panel::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 0.125rem;
}

.asseco-ai-chat__panel::-webkit-scrollbar-thumb:hover {
  background: #9CA3AF;
}

/* Firefox scrollbar */
.asseco-ai-chat__panel {
  scrollbar-width: thin;
  scrollbar-color: #D1D5DB transparent;
}

/* ---------- Focus ring for accessibility ---------- */

#asseco-ai-chat *:focus-visible {
  outline: 2px solid #232323;
  outline-offset: 2px;
}

#asseco-ai-chat .asseco-ai-chat__input:focus-visible {
  outline: none;
}
