/* ResvBAR Ai — ويدجت مساعدة عائم */

.rv-ai {
  --rv-ai-brand: #01305f;
  --rv-ai-accent: #0089bf;
  --rv-ai-bg: #ffffff;
  --rv-ai-muted: #64748b;
  --rv-ai-line: #e2e8f0;
  --rv-ai-soft: #f1f5f9;
  --rv-ai-ink: #0f172a;
  position: fixed;
  inset-inline-start: 1.1rem;
  inset-block-end: 1.1rem;
  z-index: 1045;
  font-family: inherit;
  direction: rtl;
}

.rv-ai[hidden] {
  display: none !important;
}

@property --rv-ai-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

.rv-ai__fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  min-height: 56px;
  padding: 0;
  border: none;
  border-radius: 16px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  z-index: 1;
  overflow: visible;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), filter 0.28s ease;
}

/* صفحة إنشاء الطلب فقط: زاوية نصف دائرية على الجهة الداخلية */
.rv-ai--coach .rv-ai__fab {
  border-radius: 16px 0px 0px 16px;
}

/* هالة لونية دوّارة خلف الزر */
.rv-ai__fab-aura {
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  background: conic-gradient(
    from var(--rv-ai-angle),
    #01305f 0%,
    #0089bf 18%,
    #5ee7ff 34%,
    #38bdf8 48%,
    #0ea5e9 62%,
    #0369a1 78%,
    #01305f 100%
  );
  filter: blur(10px);
  opacity: 0.72;
  z-index: 0;
  animation: rv-ai-fab-spin-angle 5s linear infinite, rv-ai-fab-aura-breathe 3.6s ease-in-out infinite;
  pointer-events: none;
}

/* سطح الزر: بحر متحرك */
.rv-ai__fab::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(120% 140% at 12% 20%, rgba(94, 231, 255, 0.55) 0%, transparent 42%),
    radial-gradient(110% 120% at 88% 78%, rgba(14, 165, 233, 0.5) 0%, transparent 46%),
    radial-gradient(90% 100% at 55% 0%, rgba(56, 189, 248, 0.35) 0%, transparent 50%),
    linear-gradient(125deg, #012a52 0%, #014f8a 28%, #0089bf 52%, #22d3ee 72%, #0369a1 100%);
  background-size: 140% 140%, 160% 160%, 120% 120%, 220% 220%;
  box-shadow:
    0 12px 30px rgba(1, 48, 95, 0.38),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 1px 0 rgba(255, 255, 255, 0.28) inset;
  animation: rv-ai-fab-sea 7s ease-in-out infinite;
  z-index: 1;
  pointer-events: none;
}

/* لمعان زجاجي يمرّ على السطح */
.rv-ai__fab-shine {
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  background: linear-gradient(
    105deg,
    transparent 0%,
    transparent 38%,
    rgba(255, 255, 255, 0.22) 48%,
    rgba(255, 255, 255, 0.55) 50%,
    rgba(255, 255, 255, 0.18) 52%,
    transparent 62%,
    transparent 100%
  );
  background-size: 220% 100%;
  animation: rv-ai-fab-shine 4.8s ease-in-out infinite;
  z-index: 2;
  pointer-events: none;
  mix-blend-mode: soft-light;
}

.rv-ai__fab::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18) 0%, transparent 42%, rgba(1, 48, 95, 0.12) 100%);
  z-index: 2;
  pointer-events: none;
}

.rv-ai__fab:hover {
  transform: translateY(-3px) scale(1.02);
  filter: saturate(1.12) brightness(1.05);
}

.rv-ai__fab:hover .rv-ai__fab-aura {
  opacity: 0.92;
  filter: blur(12px);
  animation-duration: 3.2s, 2.2s;
}

.rv-ai__fab:hover::before {
  animation-duration: 3.5s;
  box-shadow:
    0 16px 40px rgba(1, 48, 95, 0.45),
    0 0 28px rgba(34, 211, 238, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.18) inset,
    0 1px 0 rgba(255, 255, 255, 0.35) inset;
}

.rv-ai__fab:focus-visible {
  outline: 2px solid #5ee7ff;
  outline-offset: 4px;
}

.rv-ai__fab.is-open,
.rv-ai.is-open .rv-ai__fab {
  display: none !important;
}

.rv-ai__fab-mark {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 8px rgba(1, 48, 95, 0.35);
  background: transparent;
  border: none;
  box-shadow: none;
  flex-shrink: 0;
}

.rv-ai__fab-mark::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  border-top-color: rgba(255, 255, 255, 0.85);
  border-inline-end-color: rgba(94, 231, 255, 0.55);
  animation: rv-ai-fab-spin 2.8s linear infinite;
  pointer-events: none;
}

.rv-ai__nudge {
  position: absolute;
  inset-inline-start: 0;
  inset-block-end: calc(56px + 0.55rem);
  width: max-content;
  max-width: min(260px, calc(100vw - 2.2rem));
  padding: 0.7rem 0.95rem;
  background: #fff;
  border: 1px solid rgba(1, 48, 95, 0.08);
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(1, 48, 95, 0.12);
  animation: rv-ai-nudge-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  cursor: pointer;
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.rv-ai__nudge:hover {
  border-color: rgba(0, 137, 191, 0.22);
  box-shadow: 0 14px 32px rgba(1, 48, 95, 0.16);
}

.rv-ai__nudge[hidden] {
  display: none !important;
}

.rv-ai__nudge::after {
  content: '';
  position: absolute;
  inset-inline-start: 1.35rem;
  inset-block-end: -5px;
  width: 10px;
  height: 10px;
  background: #fff;
  border-inline-end: 1px solid rgba(1, 48, 95, 0.08);
  border-block-end: 1px solid rgba(1, 48, 95, 0.08);
  transform: rotate(45deg);
}

.rv-ai__nudge-text {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.55;
  color: var(--rv-ai-brand);
  text-align: start;
  white-space: normal;
}

@keyframes rv-ai-fab-flow {
  0%,
  100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

@keyframes rv-ai-fab-spin-angle {
  to {
    --rv-ai-angle: 360deg;
  }
}

@keyframes rv-ai-fab-aura-breathe {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.62;
  }
  50% {
    transform: scale(1.06);
    opacity: 0.88;
  }
}

@keyframes rv-ai-fab-sea {
  0%,
  100% {
    background-position: 0% 40%, 100% 60%, 50% 0%, 0% 50%;
  }
  33% {
    background-position: 40% 20%, 60% 80%, 30% 40%, 50% 40%;
  }
  66% {
    background-position: 80% 70%, 20% 30%, 70% 20%, 100% 60%;
  }
}

@keyframes rv-ai-fab-shine {
  0%,
  100% {
    background-position: 140% 0;
  }
  45%,
  55% {
    background-position: -40% 0;
  }
}

@keyframes rv-ai-fab-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes rv-ai-nudge-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rv-ai__fab::before,
  .rv-ai__fab-aura,
  .rv-ai__fab-shine,
  .rv-ai__fab-mark::after {
    animation: none !important;
  }

  .rv-ai__fab:hover {
    transform: none;
    filter: none;
  }
}

.rv-ai__panel {
  position: absolute;
  inset-inline-start: 0;
  inset-block-end: calc(56px + 0.65rem);
  width: min(400px, calc(100vw - 1.5rem));
  height: min(580px, calc(100vh - 6.5rem));
  display: flex;
  flex-direction: column;
  background: var(--rv-ai-bg);
  border: 1px solid var(--rv-ai-line);
  border-radius: 20px;
  box-shadow: 0 22px 56px rgba(15, 23, 42, 0.2);
  overflow: hidden;
  transform-origin: bottom right;
  animation: rv-ai-panel-in 0.22s ease-out;
}

.rv-ai.is-open .rv-ai__panel {
  inset-block-end: 0;
  height: min(620px, calc(100vh - 1.5rem));
}

/* صفحة إنشاء الطلب فقط: كارد الشات أطول قليلاً */
.rv-ai--coach .rv-ai__panel {
  height: min(680px, calc(100vh - 5rem));
}

.rv-ai--coach.is-open .rv-ai__panel {
  height: min(720px, calc(100vh - 1.5rem));
}

.rv-ai__panel[hidden] {
  display: none !important;
  animation: none;
}

@keyframes rv-ai-panel-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.rv-ai__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1rem;
  background: linear-gradient(135deg, #01305f 0%, #024a8a 58%, #0089bf 140%);
  color: #fff;
}

.rv-ai__brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.rv-ai__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  color: #fff;
  background:
    radial-gradient(circle at 30% 25%, rgba(94, 231, 255, 0.45) 0%, transparent 48%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.22) 0%, rgba(1, 48, 95, 0.35) 100%);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    0 4px 12px rgba(1, 48, 95, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  text-shadow: 0 1px 6px rgba(1, 48, 95, 0.35);
}

.rv-ai__title {
  display: block;
  font-size: 0.98rem;
  font-weight: 800;
}

.rv-ai__status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  opacity: 0.92;
  margin-top: 0.2rem;
}

.rv-ai__status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6ee7b7;
  box-shadow: 0 0 0 3px rgba(110, 231, 183, 0.25);
}

.rv-ai__icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.rv-ai__icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.rv-ai__body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(0, 137, 191, 0.06), transparent 55%),
    #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rv-ai__welcome {
  background: #fff;
  border: 1px solid var(--rv-ai-line);
  border-radius: 16px;
  padding: 1rem 1rem 0.95rem;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
  animation: rv-ai-fade-up 0.28s ease-out;
}

@keyframes rv-ai-fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.rv-ai__welcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 137, 191, 0.1);
  color: var(--rv-ai-accent);
  font-size: 0.7rem;
  font-weight: 700;
  margin-bottom: 0.65rem;
}

.rv-ai__welcome-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--rv-ai-brand);
  line-height: 1.35;
}

.rv-ai__welcome-body {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.6;
  color: #475569;
}

.rv-ai__bubble {
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.rv-ai__bubble--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--rv-ai-line);
  color: var(--rv-ai-ink);
  border-start-start-radius: 4px;
}

.rv-ai__bubble--user {
  align-self: flex-end;
  background: var(--rv-ai-brand);
  color: #fff;
  border-start-end-radius: 4px;
}

.rv-ai__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.rv-ai__action {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: var(--rv-ai-brand);
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.rv-ai__action:hover {
  border-color: var(--rv-ai-accent);
  color: var(--rv-ai-accent);
}

.rv-ai__foot {
  border-block-start: 1px solid var(--rv-ai-line);
  background: #fff;
  padding: 0.7rem 0.75rem 0.85rem;
}

.rv-ai__form {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.rv-ai__input {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--rv-ai-line);
  border-radius: 14px;
  padding: 0.55rem 0.85rem;
  font-size: 0.9rem;
  background: #fff;
  color: var(--rv-ai-ink);
}

.rv-ai__input:focus {
  outline: none;
  border-color: var(--rv-ai-accent);
  box-shadow: 0 0 0 3px rgba(0, 137, 191, 0.15);
}

.rv-ai__send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  background: var(--rv-ai-brand);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 1.05rem;
}

.rv-ai__send:hover {
  background: var(--rv-ai-accent);
}

.rv-ai__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.rv-ai__typing {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: auto;
}

.rv-ai__typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.rv-ai__typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rv-ai-brand);
  opacity: 0.35;
  animation: rv-ai-typing-bounce 1.2s infinite ease-in-out;
}

.rv-ai__typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.rv-ai__typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.rv-ai__typing-label {
  font-size: 0.8rem;
  color: var(--rv-ai-muted);
}

@keyframes rv-ai-typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .rv-ai__typing-dots span {
    animation: none;
    opacity: 0.6;
  }
}

@media (max-width: 575.98px) {
  .rv-ai {
    inset-inline-start: 0.75rem;
    inset-block-end: 0.85rem;
  }

  .rv-ai__panel {
    width: calc(100vw - 1.5rem);
    height: min(72vh, 540px);
  }

  .rv-ai__fab {
    width: 52px;
    height: 52px;
    min-height: 52px;
  }

  .rv-ai__fab-mark {
    font-size: 0.88rem;
  }
}
