/* ============================================================
   GapGPT Assistant — chat widget
   RTL, Persian-first. Signature element: the glowing avatar.
   ============================================================ */

#gg-root {
  position: fixed;
  z-index: 99999;
  direction: rtl;
  font-family: Vazirmatn, Tahoma, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.8;
  --gg-c: var(--gg-color, #2563eb);
  --gg-c-soft: color-mix(in srgb, var(--gg-c) 14%, transparent);
  --gg-c-deep: color-mix(in srgb, var(--gg-c) 78%, #0b1120);
  --ink: #16202e;
  --ink-soft: #5b6b80;
  --line: rgba(22, 32, 46, 0.08);
  --bg-msgs: #eef1f7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#gg-root * { box-sizing: border-box; font-family: inherit; }

/* ---------- Floating button ---------- */
#gg-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.35), transparent 42%),
    linear-gradient(135deg, var(--gg-c), var(--gg-c-deep));
  box-shadow:
    0 12px 30px color-mix(in srgb, var(--gg-c) 38%, transparent),
    0 3px 8px rgba(15, 23, 42, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: gg-pulse 2.6s ease-out infinite;
}
#gg-btn:hover { transform: translateY(-2px) scale(1.05); }
#gg-btn:focus-visible {
  outline: 3px solid var(--gg-c);
  outline-offset: 3px;
}
#gg-btn svg { width: 29px; height: 29px; fill: #fff; }

#gg-root.open #gg-btn {
  animation: none;
  transform: scale(0.88);
}

@keyframes gg-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--gg-c) 42%, transparent), 0 12px 30px color-mix(in srgb, var(--gg-c) 38%, transparent), 0 3px 8px rgba(15,23,42,.18), inset 0 1px 0 rgba(255,255,255,.28); }
  70%  { box-shadow: 0 0 0 16px transparent, 0 12px 30px color-mix(in srgb, var(--gg-c) 38%, transparent), 0 3px 8px rgba(15,23,42,.18), inset 0 1px 0 rgba(255,255,255,.28); }
  100% { box-shadow: 0 0 0 0 transparent, 0 12px 30px color-mix(in srgb, var(--gg-c) 38%, transparent), 0 3px 8px rgba(15,23,42,.18), inset 0 1px 0 rgba(255,255,255,.28); }
}

/* ---------- Chat window ---------- */
#gg-box {
  display: none;
  position: absolute;
  width: 372px;
  max-width: calc(100vw - 24px);
  height: 548px;
  max-height: calc(100vh - 120px);
  flex-direction: column;
  background: #fff;
  border-radius: 22px;
  overflow: hidden;
  box-shadow:
    0 24px 70px rgba(15, 23, 42, 0.28),
    0 6px 20px rgba(15, 23, 42, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.6);
  animation: gg-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.pos-bottom #gg-box { bottom: 76px; }
.pos-top #gg-box    { top: 76px; }
.pos-left #gg-box   { left: 0; }
.pos-right #gg-box  { right: 0; }
#gg-root.open #gg-box { display: flex; }

@keyframes gg-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Header ---------- */
#gg-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 15px 14px 15px 16px;
  color: #fff;
  background:
    radial-gradient(circle at 0% 0%, rgba(255, 255, 255, 0.18), transparent 55%),
    linear-gradient(135deg, var(--gg-c), var(--gg-c-deep));
  position: relative;
}
#gg-head::after {
  content: "";
  position: absolute;
  inset-inline-start: 0; inset-inline-end: 0; bottom: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.22);
}

#gg-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 0 0 1.5px rgba(255, 255, 255, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.15);
}
#gg-avatar svg { width: 23px; height: 23px; fill: #fff; }

#gg-titles { flex: 1; min-width: 0; }
#gg-title {
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#gg-status {
  font-size: 12px;
  opacity: 0.95;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}
#gg-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

#gg-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s, transform 0.15s;
}
#gg-close:hover { background: rgba(255, 255, 255, 0.32); }
#gg-close:active { transform: scale(0.92); }
#gg-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#gg-close svg { width: 17px; height: 17px; }

/* ---------- Messages ---------- */
#gg-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px;
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--gg-c) 7%, transparent), transparent 42%),
    radial-gradient(circle at 0% 100%, color-mix(in srgb, var(--gg-c) 5%, transparent), transparent 40%),
    var(--bg-msgs);
  scroll-behavior: smooth;
}
#gg-msgs::-webkit-scrollbar { width: 8px; }
#gg-msgs::-webkit-scrollbar-thumb { background: rgba(22, 32, 46, 0.18); border-radius: 8px; }
#gg-msgs::-webkit-scrollbar-thumb:hover { background: rgba(22, 32, 46, 0.3); }
#gg-msgs::-webkit-scrollbar-track { background: transparent; }

.gg-m {
  max-width: 84%;
  padding: 10px 15px;
  margin: 0 0 11px;
  line-height: 1.85;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: gg-msg 0.22s ease;
  backdrop-filter: blur(2px);
}
@keyframes gg-msg {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.gg-m.bot {
  background: #fff;
  color: var(--ink);
  border-radius: 6px 18px 18px 18px;
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  margin-left: auto;
}
.gg-m.usr {
  background: linear-gradient(135deg, var(--gg-c), var(--gg-c-deep));
  color: #fff;
  border-radius: 18px 6px 18px 18px;
  margin-right: auto;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--gg-c) 26%, transparent);
}

.gg-m.typing { padding: 12px 16px; }
.gg-dots { display: inline-flex; gap: 4px; align-items: center; height: 12px; }
.gg-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gg-c);
  animation: gg-dot 1.2s infinite ease-in-out;
}
.gg-dots i:nth-child(2) { animation-delay: 0.15s; }
.gg-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes gg-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Input form ---------- */
#gg-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--line);
}
#gg-in {
  flex: 1;
  min-width: 0;
  border: 1px solid #e2e6ee;
  background: #f6f8fb;
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 14px;
  color: var(--ink);
  outline: 0;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
#gg-in::placeholder { color: #9aa8b9; }
#gg-in:focus {
  border-color: var(--gg-c);
  background: #fff;
  box-shadow: 0 0 0 3px var(--gg-c-soft);
}
#gg-send {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  background: linear-gradient(135deg, var(--gg-c), var(--gg-c-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.15s, opacity 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--gg-c) 30%, transparent);
}
#gg-send:hover { transform: scale(1.07); }
#gg-send:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }
#gg-send:focus-visible { outline: 3px solid var(--gg-c-soft); outline-offset: 2px; }
#gg-send svg { width: 20px; height: 20px; fill: #fff; transform: scaleX(-1); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #gg-btn, #gg-box, .gg-m, .gg-dots i { animation: none !important; }
  #gg-msgs { scroll-behavior: auto; }
}

/* ---------- Mobile: fullscreen ---------- */
@media (max-width: 480px) {
  #gg-root.open #gg-btn { display: none; }
  #gg-box {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: 0;
  }
  #gg-head { padding-top: calc(15px + env(safe-area-inset-top, 0px)); }
  #gg-form { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
}
