/* ============================================================
   AI ASSISTANT WIDGET — АР Подшипник
   ============================================================ */

#ai-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Trigger button ── */
#ai-trigger {
  position: relative;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: linear-gradient(140deg, #EC1E21 0%, #7B0000 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(236,30,33,0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: white;
  gap: 1px;
}
#ai-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 7px 32px rgba(236,30,33,0.62);
}
/* Spinning dashed gear ring */
#ai-trigger::before {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2.5px dashed rgba(236,30,33,0.5);
  animation: aiGearSpin 10s linear infinite;
  pointer-events: none;
}
@keyframes aiGearSpin { to { transform: rotate(360deg); } }
/* Pulse glow */
#ai-trigger::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  animation: aiPulse 2.8s ease-out infinite;
  pointer-events: none;
}
@keyframes aiPulse {
  0%   { box-shadow: 0 0 0 0 rgba(236,30,33,0.5); }
  70%  { box-shadow: 0 0 0 18px rgba(236,30,33,0); }
  100% { box-shadow: 0 0 0 0 rgba(236,30,33,0); }
}
.ai-trigger-title { font-size: 0.82rem; font-weight: 800; line-height: 1; }
.ai-trigger-label { font-size: 0.58rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.85; line-height: 1; }
.ai-online {
  position: absolute;
  top: 4px; right: 4px;
  width: 13px; height: 13px;
  background: #22C55E;
  border-radius: 50%;
  border: 2.5px solid white;
  animation: aiDotBlink 2s ease-in-out infinite;
}
@keyframes aiDotBlink { 0%,100%{transform:scale(1)} 50%{transform:scale(1.18)} }

/* ── Tooltip bubble ── */
#ai-bubble {
  position: absolute;
  bottom: 76px; right: 0;
  width: 238px;
  background: white;
  border-radius: 14px 14px 2px 14px;
  padding: 13px 32px 13px 13px;
  box-shadow: 0 4px 28px rgba(0,0,0,0.16);
  border: 1px solid #EDE0E0;
  cursor: pointer;
  opacity: 0;
  transform: translateY(14px) scale(0.88);
  transform-origin: bottom right;
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
#ai-bubble.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
#ai-bubble-tag { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: #EC1E21; margin-bottom: 4px; }
#ai-bubble-msg { font-size: 0.8rem; line-height: 1.44; color: #1A1A1A; }
#ai-bubble-dismiss {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; cursor: pointer;
  color: #9CA3AF; font-size: 16px; line-height: 1;
  padding: 0; width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
}
#ai-bubble-dismiss:hover { color: #EC1E21; }

/* ── Chat window ── */
#ai-chat {
  position: absolute;
  bottom: 76px; right: 0;
  width: 374px; height: 542px;
  background: white;
  border-radius: 18px;
  box-shadow: 0 10px 52px rgba(0,0,0,0.18);
  border: 1px solid rgba(0,0,0,0.07);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.9) translateY(18px);
  transform-origin: bottom right;
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}
#ai-chat.open { opacity: 1; transform: scale(1) translateY(0); pointer-events: auto; }

/* Header */
.aic-header {
  background: linear-gradient(135deg, #EC1E21 0%, #860000 100%);
  color: white;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
}
.aic-avatar {
  width: 40px; height: 40px;
  background: rgba(255,255,255,0.18);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.aic-hinfo { flex: 1; min-width: 0; }
.aic-hname { font-weight: 700; font-size: 0.9rem; line-height: 1.2; }
.aic-hsub { font-size: 0.71rem; opacity: 0.82; display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.aic-hsub::before { content:''; width:6px; height:6px; background:#4ADE80; border-radius:50%; flex-shrink:0; }
.aic-close {
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.15);
  border: none; border-radius: 50%; color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.2s;
  font-size: 18px; line-height: 1; padding: 0;
}
.aic-close:hover { background: rgba(255,255,255,0.3); }

/* Messages */
.aic-msgs {
  flex: 1; overflow-y: auto;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 10px;
  background: #FAF5F5;
  scroll-behavior: smooth;
}
.aic-msgs::-webkit-scrollbar { width: 3px; }
.aic-msgs::-webkit-scrollbar-thumb { background: #ddd0d0; border-radius: 3px; }

.aic-row { display: flex; gap: 7px; max-width: 96%; }
.aic-row.bot { align-self: flex-start; }
.aic-row.usr { align-self: flex-end; flex-direction: row-reverse; }
.aic-row-ico {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #EC1E21, #860000);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: flex-end;
}
.aic-row-body { display: flex; flex-direction: column; gap: 5px; }
.aic-bbl { padding: 9px 13px; border-radius: 14px; font-size: 0.845rem; line-height: 1.52; }
.aic-row.bot .aic-bbl {
  background: white; border: 1px solid #EDE0E0;
  border-radius: 3px 14px 14px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); color: #1A1A1A;
}
.aic-row.usr .aic-bbl { background: #EC1E21; color: white; border-radius: 14px 3px 14px 14px; }

/* Bearing card */
.ai-card {
  background: #FFF8F8; border: 1.5px solid #F2CBCB;
  border-radius: 10px; padding: 11px 13px; font-size: 0.8rem; margin-top: 2px;
}
.ai-card-code { font-weight: 800; font-size: 0.98rem; color: #EC1E21; margin-bottom: 2px; }
.ai-card-type { font-size: 0.72rem; color: #6B7280; margin-bottom: 7px; }
.ai-card table { width: 100%; border-collapse: collapse; font-size: 0.79rem; }
.ai-card table td { padding: 3px 0; }
.ai-card table td:first-child { color: #6B7280; }
.ai-card table td:last-child { font-weight: 600; text-align: right; }
.ai-card table tr { border-bottom: 1px solid #EDE0E0; }
.ai-card table tr:last-child { border-bottom: none; }
.ai-card-avail {
  margin-top: 8px; display: inline-flex; align-items: center; gap: 5px;
  background: #F0FDF4; color: #166534; border-radius: 20px;
  padding: 3px 9px; font-size: 0.72rem; font-weight: 600;
}
.ai-card-avail::before { content:'●'; font-size:0.55rem; color:#22C55E; }

/* Quick replies */
.aic-quick { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.aic-qbtn {
  background: white; border: 1.5px solid #EC1E21; color: #EC1E21;
  padding: 4px 11px; border-radius: 18px; font-size: 0.79rem;
  font-weight: 600; cursor: pointer; font-family: inherit;
  transition: all 0.18s; white-space: nowrap;
}
.aic-qbtn:hover { background: #EC1E21; color: white; }
.aic-qbtn:disabled { opacity: 0.45; pointer-events: none; }

/* Typing dots */
.aic-typing-row { display: flex; gap: 7px; align-self: flex-start; }
.aic-typing-ico {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #EC1E21, #860000);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: flex-end;
}
.aic-typing-dots {
  padding: 10px 13px; background: white; border: 1px solid #EDE0E0;
  border-radius: 3px 14px 14px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex; align-items: center; gap: 5px;
}
.aic-typing-dots span {
  width: 7px; height: 7px; background: #9CA3AF; border-radius: 50%;
  animation: aiDotBounce 1.2s ease-in-out infinite;
}
.aic-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.aic-typing-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes aiDotBounce {
  0%,80%,100% { transform: translateY(0); opacity: 0.4; }
  40%          { transform: translateY(-7px); opacity: 1; }
}

/* Input row */
.aic-input-row {
  display: flex; gap: 7px; align-items: center;
  padding: 10px 12px; border-top: 1px solid #EDE0E0;
  background: white; flex-shrink: 0;
}
.aic-input {
  flex: 1; border: 1.5px solid #EDE0E0; border-radius: 22px;
  padding: 8px 14px; font-size: 0.84rem; font-family: inherit;
  outline: none; transition: border-color 0.2s; line-height: 1.4;
  background: #FAF5F5;
}
.aic-input:focus { border-color: #EC1E21; background: white; }
.aic-input::placeholder { color: #9CA3AF; }
.aic-send {
  width: 36px; height: 36px; background: #EC1E21;
  border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; color: white;
  transition: background 0.2s, transform 0.15s;
}
.aic-send:hover { background: #8B0000; transform: scale(1.07); }
.aic-send svg { margin-left: 2px; }

/* Success card */
.ai-success {
  background: #F0FDF4; border: 1.5px solid #22C55E;
  border-radius: 10px; padding: 15px; text-align: center; margin-top: 3px;
}
.ai-success-ico {
  width: 44px; height: 44px; background: #22C55E; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 9px; color: white; font-size: 22px;
}
.ai-success p { font-size: 0.835rem; color: #166534; line-height: 1.48; }
.ai-success a { color: #EC1E21; font-weight: 600; }

/* Mobile */
@media (max-width: 479px) {
  #ai-chat {
    position: fixed; bottom: 0; right: 0; left: 0;
    width: 100%; height: 90vh;
    border-radius: 18px 18px 0 0;
  }
  #ai-widget { bottom: 16px; right: 16px; }
}
@media print { #ai-widget { display: none !important; } }
