:root{
  --ai-chat-z: 2147483000;
  --ai-chat-bg: #0b1020;
  --ai-chat-panel: rgba(255,255,255,0.96);
  --ai-chat-border: rgba(15,23,42,0.12);
  --ai-chat-text: #0f172a;
  --ai-chat-muted: rgba(15,23,42,0.65);
  --ai-chat-primary: #1d4ed8;
  --ai-chat-primary2: #22c55e;
  --ai-chat-shadow: 0 18px 50px rgba(2,6,23,0.25);
  --ai-chat-radius: 18px;
  --ai-chat-radius-sm: 14px;
}

.sr-only{
  position:absolute!important;
  width:1px;height:1px;
  padding:0;margin:-1px;
  overflow:hidden;clip:rect(0,0,0,0);
  white-space:nowrap;border:0;
}

.ai-chat{ position: relative; z-index: var(--ai-chat-z); }

.ai-chat-widget{
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 440px;
  max-width: calc(100vw - 36px);
  height: 640px;
  max-height: calc(100vh - 120px);
  background: var(--ai-chat-panel);
  color: var(--ai-chat-text);
  border: 1px solid var(--ai-chat-border);
  border-radius: var(--ai-chat-radius);
  box-shadow: 0 20px 60px rgba(2,6,23,0.3), 0 0 0 1px rgba(255,255,255,0.1) inset;
  overflow: hidden;
  z-index: var(--ai-chat-z);
  backdrop-filter: blur(20px);

  /* animation */
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  pointer-events: none;
  transition: opacity 180ms ease, transform 220ms cubic-bezier(.2,.9,.2,1);
}

.ai-chat[data-ai-chat-opened="1"] .ai-chat-widget{
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce){
  .ai-chat-widget{
    transition: none;
  }
}

.ai-chat-header{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 14px;
  background: linear-gradient(180deg, rgba(29,78,216,0.08), rgba(255,255,255,0));
  border-bottom: 1px solid rgba(15,23,42,0.08);
  backdrop-filter: blur(10px);
}
.ai-chat-title{ display:flex; align-items:center; gap: 10px; }
.ai-chat-avatar{
  width: 40px; height: 40px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(29,78,216,0.95), rgba(37,99,235,0.9));
  box-shadow: 0 4px 16px rgba(29,78,216,0.3), 0 0 0 2px rgba(255,255,255,0.1) inset;
  position: relative;
}
.ai-chat-avatar:before{
  content:"";
  position:absolute;
  inset: 9px;
  background: #fff;
  mask: url("../assets/svgicons/robot.svg") center / contain no-repeat;
  -webkit-mask: url("../assets/svgicons/robot.svg") center / contain no-repeat;
  opacity: 0.92;
}
.ai-chat-title__h{ font-weight: 700; font-size: 15px; line-height: 1.3; color: var(--ai-chat-text); }
.ai-chat-title__sub{ font-size: 12px; color: var(--ai-chat-muted); margin-top: 2px; }

.ai-chat-close{
  border: 0;
  background: rgba(15,23,42,0.06);
  width: 36px; height: 36px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: rgba(15,23,42,0.7);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-chat-close:hover{ 
  background: rgba(15,23,42,0.12); 
  transform: scale(1.05);
  color: rgba(15,23,42,0.9);
}
.ai-chat-close:focus{ outline: none; box-shadow: 0 0 0 4px rgba(59,130,246,0.25); }

.ai-chat-body{
  height: calc(100% - 66px - 92px);
  overflow: hidden;
}
.ai-chat-messages{
  height: 100%;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.ai-chat-messages::-webkit-scrollbar{
  width: 6px;
}
.ai-chat-messages::-webkit-scrollbar-track{
  background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb{
  background: rgba(15,23,42,0.2);
  border-radius: 3px;
}
.ai-chat-messages::-webkit-scrollbar-thumb:hover{
  background: rgba(15,23,42,0.3);
}

.ai-chat-msg{
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 86%;
}
.ai-chat-msg--user{ 
  align-self: flex-end; 
}
.ai-chat-msg--user .ai-chat-meta{
  text-align: right;
}
.ai-chat-msg--bot{ align-self: flex-start; }

.ai-chat-bubble{
  padding: 12px 14px;
  border-radius: var(--ai-chat-radius-sm);
  border: 1px solid var(--ai-chat-border);
  background: #fff;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.ai-chat-bubble a{
  color: var(--ai-chat-primary);
  text-decoration: none;
  font-weight: 700;
}
.ai-chat-bubble a:hover{
  text-decoration: underline;
}
.ai-chat-bubble p{ margin: 0 0 8px; }
.ai-chat-bubble p:last-child{ margin-bottom: 0; }
.ai-chat-msg--bot .ai-chat-bubble{
  background: rgba(255,255,255,0.98);
  border-color: rgba(15,23,42,0.08);
}
.ai-chat-msg--user .ai-chat-bubble{
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  border-color: #1e40af;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
.ai-chat-msg--user .ai-chat-bubble a{
  color: #ffffff;
  text-decoration: underline;
  opacity: 0.95;
}
.ai-chat-msg--user .ai-chat-bubble a:hover{
  opacity: 1;
}
.ai-chat-meta{
  font-size: 11px;
  color: rgba(15,23,42,0.6);
  padding: 0 6px;
  font-weight: 500;
  margin-top: 2px;
}
.ai-chat-msg--user .ai-chat-meta{
  color: rgba(255,255,255,0.7);
}

.ai-chat-footer{
  border-top: 1px solid rgba(15,23,42,0.08);
  padding: 14px 16px 16px;
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(10px);
}
.ai-chat-form{
  display:flex;
  align-items:center;
  gap: 10px;
}
.ai-chat-inputwrap{ flex: 1; }
.ai-chat-input{
  width: 100%;
  height: 44px;
  border-radius: 16px;
  border: 1px solid var(--ai-chat-border);
  padding: 0 16px;
  font-size: 14px;
  outline: none;
  background: #fff;
  transition: all 0.2s ease;
}
.ai-chat-input:focus{
  border-color: rgba(29,78,216,0.4);
  box-shadow: 0 0 0 4px rgba(59,130,246,0.15);
  background: #fafbfc;
}
.ai-chat-send{
  width: 44px; height: 44px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}
.ai-chat-send:hover:not(:disabled){
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37,99,235,0.4);
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}
.ai-chat-send:active:not(:disabled){
  transform: translateY(0);
}
.ai-chat-send:disabled{ 
  opacity: 0.5; 
  cursor: not-allowed; 
  transform: none;
}
.ai-chat-send:focus{ outline: none; box-shadow: 0 0 0 4px rgba(59,130,246,0.3); }
.ai-chat-hint{
  margin-top: 8px;
  font-size: 11px;
  color: rgba(15,23,42,0.55);
}

/* typing indicator */
.ai-chat-typing{
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.ai-chat-typing__dot{
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(15,23,42,0.45);
  animation: aiChatDot 1.1s infinite ease-in-out;
}
.ai-chat-typing__dot:nth-child(2){ animation-delay: 0.12s; }
.ai-chat-typing__dot:nth-child(3){ animation-delay: 0.24s; }
@keyframes aiChatDot{
  0%, 100% { transform: translateY(0); opacity: 0.55; }
  50% { transform: translateY(-3px); opacity: 1; }
}

/* cards */
.ai-chat-cards{
  margin-top: 10px;
  display: grid;
  gap: 10px;
}
.ai-chat-card{
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(15,23,42,0.1);
  border-radius: 16px;
  text-decoration: none;
  background: rgba(255,255,255,0.98);
  transition: all 0.25s ease;
}
.ai-chat-card:hover{
  border-color: rgba(29,78,216,0.3);
  box-shadow: 0 8px 24px rgba(29,78,216,0.15);
  transform: translateY(-2px);
  background: #fff;
}
.ai-chat-card__img{
  width: 78px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  background: rgba(15,23,42,0.06);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.ai-chat-card__title{
  font-weight: 800;
  font-size: 13px;
  line-height: 1.25;
  color: var(--ai-chat-text);
}
.ai-chat-card__meta{
  margin-top: 4px;
  font-size: 12px;
  color: rgba(15,23,42,0.62);
}

/* offer list inside reply_html */
.ai-chat-offers{
  margin-top: 2px;
}
.ai-chat-offers__title{
  font-weight: 800;
  margin-bottom: 8px;
}
.ai-chat-offers__list{
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
}
.ai-chat-offers__item{
  margin: 0;
}
.ai-chat-offers__link{
  display: inline-block;
}
.ai-chat-offers__meta{
  margin-top: 2px;
  font-size: 12px;
  color: rgba(15,23,42,0.66);
}
.ai-chat-offers__hint{
  margin-top: 10px;
  font-size: 11px;
  color: rgba(15,23,42,0.55);
}

/* Mobile: full-screen overlay */
@media (max-width: 767px){
  .ai-chat-widget{
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    z-index: 2147483647 !important;
  }
  
  .ai-chat-header{
    padding: 14px 16px 12px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
  }
  
  .ai-chat-footer{
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* note: visibility controlled via JS (hidden attr + data-ai-chat-opened) */

/* Hide JivoChat widget when AI chat is open on mobile */
@media (max-width: 767px){
  .ai-chat[data-ai-chat-opened="1"] ~ jdiv,
  .ai-chat[data-ai-chat-opened="1"] ~ #jivo-iframe-container,
  .ai-chat[data-ai-chat-opened="1"] ~ .jivo-iframe-container,
  body:has(.ai-chat[data-ai-chat-opened="1"]) jdiv,
  body:has(.ai-chat[data-ai-chat-opened="1"]) #jivo-iframe-container,
  body:has(.ai-chat[data-ai-chat-opened="1"]) [class*="jivo"],
  body:has(.ai-chat[data-ai-chat-opened="1"]) [id*="jivo"]{
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}


