/* ── AI GUL Chat Widget ──────────────────────────────────────────────────── */

#aigul-chat-wrapper {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Toggle button (mobile: round icon) ──────────────────────────────────── */
#aigul-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.5);
  transition: transform 0.2s, box-shadow 0.2s;
  outline-offset: 3px;
}
#aigul-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(2, 132, 199, 0.55);
}
#aigul-toggle-btn.aigul-btn--open {
  background: linear-gradient(135deg, #64748b, #334155);
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
#aigul-btn-label { display: none; }

/* ── Chat window (mobile: bottom sheet) ──────────────────────────────────── */
#aigul-chat-window {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 65vh;
  max-height: 65vh;
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: aigulSlideUp 0.25s ease;
}

@keyframes aigulSlideUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#aigul-chat-header {
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  color: #fff;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.aigul-header-info {
  display: flex;
  align-items: center;
  gap: 9px;
}
.aigul-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.aigul-header-name {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
}
.aigul-header-sub {
  font-size: 10px;
  opacity: 0.8;
  margin-top: 1px;
}
#aigul-close-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  padding: 5px;
  display: flex;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#aigul-close-btn:hover { background: rgba(255,255,255,0.3); }

/* ── Messages area ───────────────────────────────────────────────────────── */
#aigul-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
#aigul-messages::-webkit-scrollbar { width: 3px; }
#aigul-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.aigul-msg {
  display: flex;
  max-width: 88%;
}
.aigul-msg--user      { align-self: flex-end;  flex-direction: row-reverse; }
.aigul-msg--assistant { align-self: flex-start; }

.aigul-bubble {
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-line;
}
.aigul-msg--user .aigul-bubble {
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.aigul-msg--assistant .aigul-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
#aigul-typing {
  padding: 4px 14px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}
#aigul-typing span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: aigulDot 1.2s infinite;
}
#aigul-typing span:nth-child(2) { animation-delay: 0.2s; }
#aigul-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aigulDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ── Input form ──────────────────────────────────────────────────────────── */
#aigul-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
  background: #fff;
}
#aigul-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 9px 13px;
  font-size: 16px;
  outline: none;
  background: #f8fafc;
  color: #1e293b;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
#aigul-input:focus  { border-color: #0284c7; background: #fff; }
#aigul-input:disabled { opacity: 0.5; }

#aigul-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#aigul-send-btn:active   { transform: scale(0.93); }
#aigul-send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* ── Desktop (≥ 600px): floating popup ───────────────────────────────────── */
@media (min-width: 600px) {
  #aigul-chat-wrapper { bottom: 24px; right: 24px; }

  #aigul-toggle-btn {
    width: auto;
    height: auto;
    border-radius: 50px;
    padding: 12px 20px 12px 16px;
    gap: 8px;
    justify-content: flex-start;
  }
  #aigul-btn-label {
    display: inline;
    letter-spacing: 0.03em;
    font-size: 14px;
    font-weight: 600;
  }

  #aigul-chat-window {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    left: auto;
    width: 360px;
    height: auto;
    max-height: 520px;
    border-radius: 20px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.08);
  }

  #aigul-chat-header { padding: 14px 16px; }
  .aigul-avatar      { width: 38px; height: 38px; font-size: 18px; }
  .aigul-header-name { font-size: 15px; }
  .aigul-header-sub  { font-size: 11px; }

  #aigul-messages { padding: 16px 14px 8px; gap: 10px; }
  .aigul-bubble   { font-size: 13.5px; padding: 10px 14px; }

  #aigul-form  { padding: 10px 12px; }
  #aigul-input { font-size: 13.5px; }
}
