.afra-ai {
  --afra-ai-bg: #06101c;
  --afra-ai-line: rgba(173, 216, 255, 0.22);
  bottom: max(20px, env(safe-area-inset-bottom));
  font-family: "Manrope", ui-sans-serif, system-ui, sans-serif;
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  z-index: 500;
}

[dir="rtl"] .afra-ai {
  font-family: "Yekan Bakh", "YekanBakh", Tahoma, sans-serif;
  left: max(20px, env(safe-area-inset-left));
  right: auto;
}

.afra-ai__launcher {
  align-items: center;
  background: linear-gradient(135deg, rgba(9, 29, 51, 0.98), rgba(4, 12, 23, 0.98));
  border: 1px solid rgba(34, 211, 238, 0.52);
  border-radius: 999px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42), 0 0 24px rgba(34, 211, 238, 0.13);
  color: #f8fbff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 760;
  gap: 0.6rem;
  min-height: 58px;
  padding: 0.55rem 1rem 0.55rem 0.6rem;
  transition: border-color 600ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 600ms cubic-bezier(0.16, 1, 0.3, 1), transform 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

[dir="rtl"] .afra-ai__launcher { padding: 0.55rem 0.6rem 0.55rem 1rem; }
.afra-ai__launcher:hover { border-color: #22d3ee; box-shadow: 0 20px 70px rgba(0, 0, 0, 0.46), 0 0 34px rgba(34, 211, 238, 0.24); transform: translateY(-3px); }
.afra-ai__launcher img { height: 38px; object-fit: contain; width: 38px; }
.afra-ai.is-open .afra-ai__launcher { opacity: 0; pointer-events: none; transform: scale(.84); }

.afra-ai__panel {
  background: color-mix(in srgb, var(--afra-ai-bg) 96%, transparent);
  border: 1px solid var(--afra-ai-line);
  border-radius: 8px;
  bottom: 0;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.58);
  color: #f5f8fc;
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto auto auto auto;
  height: min(720px, calc(100svh - 40px));
  overflow: hidden;
  position: absolute;
  right: 0;
  width: min(430px, calc(100vw - 32px));
}

[dir="rtl"] .afra-ai__panel { left: 0; right: auto; }
.afra-ai__panel[hidden] { display: none; }
.afra-ai__panel > header { align-items: center; border-bottom: 1px solid var(--afra-ai-line); display: flex; justify-content: space-between; padding: 0.85rem 1rem; }
.afra-ai__identity { align-items: center; display: flex; gap: 0.7rem; }
.afra-ai__identity img { height: 42px; object-fit: contain; width: 42px; }
.afra-ai__identity > span { display: grid; }
.afra-ai__identity small { color: #93a9bf; }
.afra-ai__close { background: transparent; border: 1px solid var(--afra-ai-line); border-radius: 50%; color: #f5f8fc; cursor: pointer; font: 400 1.6rem/1 inherit; height: 42px; width: 42px; }
.afra-ai__close:hover { background: #22d3ee; color: #03101b; }

.afra-ai__messages { display: flex; flex-direction: column; gap: 0.8rem; overflow-y: auto; padding: 1rem; scroll-behavior: smooth; }
.afra-ai__message { align-items: end; display: flex; gap: 0.45rem; max-width: 88%; }
.afra-ai__message img { height: 26px; object-fit: contain; width: 26px; }
.afra-ai__message p { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--afra-ai-line); border-radius: 8px 8px 8px 2px; color: #edf5fc; line-height: 1.5; margin: 0; padding: 0.75rem 0.85rem; white-space: pre-wrap; }
.afra-ai__message--visitor { align-self: end; }
.afra-ai__message--visitor p { background: #0d69c7; border-color: #2682de; border-radius: 8px 8px 2px 8px; }
.afra-ai__message.is-typing p { animation: afra-ai-pulse 1s ease-in-out infinite; letter-spacing: .22em; }
.afra-ai__message.is-error p, .afra-ai__message.is-offline p { border-color: rgba(250, 170, 70, .62); }
.afra-ai__notice { background: rgba(34, 211, 238, 0.07); border: 1px solid rgba(34, 211, 238, 0.28); border-radius: 8px; padding: 0.85rem; }
.afra-ai__notice p { color: #a8bdd1; margin: 0.35rem 0 0; }

.afra-ai__quick-actions { border-top: 1px solid var(--afra-ai-line); display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.75rem 1rem; }
.afra-ai__quick-actions a, .afra-ai__quick-actions button { background: transparent; border: 1px solid var(--afra-ai-line); border-radius: 999px; color: #cae5f5; cursor: pointer; font: 700 .75rem inherit; min-height: 38px; padding: .45rem .7rem; text-decoration: none; }
.afra-ai__quick-actions a:hover, .afra-ai__quick-actions button:hover { border-color: #22d3ee; color: #fff; }

.afra-ai__handoff { border-top: 1px solid var(--afra-ai-line); display: grid; gap: .65rem; max-height: 310px; overflow-y: auto; padding: .8rem 1rem; }
.afra-ai__handoff[hidden] { display: none; }
.afra-ai__handoff label { display: grid; gap: .3rem; }
.afra-ai__handoff label > span { color: #bfd0de; font-size: .76rem; }
.afra-ai__handoff input, .afra-ai__handoff textarea { background: #020812; border: 1px solid var(--afra-ai-line); border-radius: 6px; color: #fff; font: inherit; padding: .6rem; resize: vertical; }
.afra-ai__handoff .afra-ai__consent { align-items: start; display: grid; grid-template-columns: auto 1fr; }
.afra-ai__handoff button { background: #22d3ee; border: 0; border-radius: 999px; color: #03101b; cursor: pointer; font-weight: 800; min-height: 42px; }
.afra-ai__handoff p { color: #9fbbce; margin: 0; }

.afra-ai__composer { align-items: end; border-top: 1px solid var(--afra-ai-line); display: grid; gap: 0.5rem; grid-template-columns: 1fr auto; padding: 0.8rem 1rem; }
.afra-ai__composer textarea { background: #020812; border: 1px solid var(--afra-ai-line); border-radius: 8px; color: #fff; font: inherit; max-height: 110px; min-height: 46px; padding: 0.7rem; resize: none; }
.afra-ai__composer textarea:disabled { cursor: not-allowed; opacity: .55; }
.afra-ai__composer button { background: linear-gradient(135deg, #22d3ee, #1684ef); border: 0; border-radius: 50%; color: #03101b; cursor: pointer; font: 800 1.2rem inherit; height: 46px; width: 46px; }
.afra-ai__composer button:disabled { cursor: not-allowed; filter: grayscale(1); opacity: .5; }
.afra-ai__panel > footer { border-top: 1px solid var(--afra-ai-line); color: #89a1b7; font-size: .68rem; padding: .65rem 1rem; }
.afra-ai__panel > footer label { align-items: center; display: flex; gap: .4rem; }
.afra-ai__panel > footer p { color: inherit; font-size: inherit; margin: .4rem 0 0; }
.afra-ai :focus-visible { outline: 2px solid #9af4ff; outline-offset: 3px; }

@keyframes afra-ai-pulse { 50% { opacity: .45; } }

@media (max-width: 620px) {
  .afra-ai { bottom: max(12px, env(safe-area-inset-bottom)); right: max(12px, env(safe-area-inset-right)); }
  [dir="rtl"] .afra-ai { left: max(12px, env(safe-area-inset-left)); right: auto; }
  .afra-ai__panel { border-radius: 0; bottom: calc(-1 * max(12px, env(safe-area-inset-bottom))); height: 100svh; position: fixed; right: 0; width: 100vw; }
  [dir="rtl"] .afra-ai__panel { left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .afra-ai *, .afra-ai *::before, .afra-ai *::after { animation: none !important; scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

/* V4 discreet luxury concierge */
.afra-ai__launcher {
  background: rgba(1, 6, 13, 0.94);
  border: 1px solid rgba(188, 220, 255, 0.24);
  border-radius: 2px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.42);
  font-size: 0.76rem;
  font-weight: 560;
  min-height: 48px;
  padding: 0.4rem 0.85rem 0.4rem 0.45rem;
}

[dir="rtl"] .afra-ai__launcher { padding: 0.4rem 0.45rem 0.4rem 0.85rem; }
.afra-ai__launcher:hover { border-color: rgba(34, 211, 238, 0.72); box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48); transform: translateY(-2px); }
.afra-ai__launcher img { height: 31px; width: 31px; }

.afra-ai__panel {
  background: #030914;
  border-color: rgba(188, 220, 255, 0.18);
  border-radius: 2px;
  box-shadow: 0 36px 120px rgba(0, 0, 0, 0.7);
}

.afra-ai__panel > header { min-height: 68px; padding-inline: 1.15rem; }
.afra-ai__identity img { height: 36px; width: 36px; }
.afra-ai__identity strong { font-weight: 560; }
.afra-ai__close { border-color: rgba(188, 220, 255, 0.18); height: 38px; width: 38px; }
.afra-ai__message p,
.afra-ai__notice,
.afra-ai__handoff input,
.afra-ai__handoff textarea,
.afra-ai__composer textarea { border-radius: 2px; }
.afra-ai__notice { background: transparent; border-inline: 0; }
.afra-ai__quick-actions { gap: 0; padding: 0; }
.afra-ai__quick-actions a,
.afra-ai__quick-actions button {
  border: 0;
  border-inline-end: 1px solid var(--afra-ai-line);
  border-radius: 0;
  flex: 1;
  font-weight: 520;
  min-height: 46px;
}
.afra-ai__quick-actions a:last-child,
.afra-ai__quick-actions button:last-child { border-inline-end: 0; }
.afra-ai__handoff button { border-radius: 2px; font-weight: 600; }
.afra-ai__composer button { background: #22d3ee; border-radius: 2px; }

/* V4.9 — conversational Afra AI surface; existing data and handoff flows stay intact. */
.afra-ai {
  --afra-ai-line: rgba(141, 174, 204, 0.2);
}

.afra-ai__launcher {
  backdrop-filter: blur(18px) saturate(120%);
  background: linear-gradient(145deg, rgba(7, 23, 42, 0.92), rgba(3, 11, 22, 0.94));
  border: 1px solid rgba(139, 178, 211, 0.32);
  border-radius: 999px;
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.34), 0 0 0 1px rgba(114, 154, 190, 0.05) inset;
  font-size: 0.74rem;
  min-height: 50px;
  padding: 0.45rem 0.9rem 0.45rem 0.5rem;
}

[dir="rtl"] .afra-ai__launcher { padding: 0.45rem 0.5rem 0.45rem 0.9rem; }
.afra-ai__launcher img { height: 32px; width: 32px; }

.afra-ai__panel {
  background:
    radial-gradient(circle at 88% 4%, rgba(42, 88, 130, 0.24), transparent 16rem),
    linear-gradient(180deg, rgba(7, 17, 31, 0.99), rgba(2, 8, 17, 0.995));
  border: 1px solid rgba(139, 178, 211, 0.24);
  border-radius: 26px;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.64), 0 0 0 1px rgba(154, 187, 216, 0.04) inset;
  height: min(650px, calc(100svh - 42px));
  isolation: isolate;
  width: min(400px, calc(100vw - 28px));
}

.afra-ai__panel > header {
  backdrop-filter: blur(16px);
  background: rgba(6, 17, 31, 0.68);
  border-bottom-color: rgba(139, 178, 211, 0.16);
  min-height: 70px;
  padding: 0.8rem 0.9rem 0.8rem 1rem;
}

.afra-ai__identity { gap: 0.65rem; }
.afra-ai__identity img { height: 34px; width: 34px; }
.afra-ai__identity strong { color: #edf4fa; font-size: 0.88rem; font-weight: 620; letter-spacing: -0.01em; }
.afra-ai__identity small { color: #7f95aa; font-size: 0.67rem; margin-block-start: 0.08rem; }
.afra-ai__close {
  background: rgba(255, 255, 255, 0.025);
  border-color: rgba(139, 178, 211, 0.2);
  border-radius: 50%;
  font-size: 1.25rem;
  height: 40px;
  transition: background 220ms ease, border-color 220ms ease, transform 220ms ease;
  width: 40px;
}
.afra-ai__close:hover { background: rgba(35, 70, 103, 0.72); border-color: rgba(160, 196, 226, 0.48); color: #f5f9fc; transform: rotate(4deg); }

.afra-ai__messages {
  gap: 0.9rem;
  padding: 1.15rem 1rem;
  scrollbar-color: rgba(105, 139, 170, 0.35) transparent;
  scrollbar-width: thin;
}

.afra-ai__message { align-items: end; gap: 0.55rem; max-width: 92%; }
.afra-ai__message img { height: 25px; width: 25px; }
.afra-ai__message p {
  background: linear-gradient(145deg, rgba(23, 35, 49, 0.94), rgba(12, 24, 38, 0.96));
  border: 1px solid rgba(139, 178, 211, 0.18);
  border-radius: 18px 18px 18px 5px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
  color: #dfe8f0;
  font-size: 0.8rem;
  line-height: 1.58;
  padding: 0.75rem 0.9rem;
}

.afra-ai__message--visitor p {
  background: linear-gradient(135deg, #214f7d, #173b61);
  border-color: rgba(142, 184, 222, 0.34);
  border-radius: 18px 18px 5px 18px;
  color: #f0f5f9;
}

.afra-ai__notice {
  background: rgba(10, 27, 45, 0.62);
  border: 1px solid rgba(128, 165, 198, 0.18);
  border-radius: 18px;
  color: #d5e0e9;
  padding: 0.9rem;
}
.afra-ai__notice strong { font-size: 0.76rem; font-weight: 620; }
.afra-ai__notice p { color: #869bae; font-size: 0.72rem; line-height: 1.5; }

.afra-ai__quick-actions {
  background: rgba(3, 11, 22, 0.7);
  border-top-color: rgba(139, 178, 211, 0.15);
  gap: 0.45rem;
  padding: 0.75rem 1rem;
}

.afra-ai__quick-actions a,
.afra-ai__quick-actions button {
  background: rgba(12, 31, 50, 0.68);
  border: 1px solid rgba(139, 178, 211, 0.18);
  border-radius: 999px;
  color: #b9c9d7;
  flex: 1 1 auto;
  font-size: 0.68rem;
  font-weight: 560;
  min-height: 38px;
  padding-inline: 0.85rem;
  transition: background 220ms ease, border-color 220ms ease, color 220ms ease;
}

.afra-ai__quick-actions a:last-child,
.afra-ai__quick-actions button:last-child { border-inline-end: 1px solid rgba(139, 178, 211, 0.18); }
.afra-ai__quick-actions a:hover,
.afra-ai__quick-actions button:hover { background: rgba(28, 62, 94, 0.78); border-color: rgba(159, 195, 226, 0.45); color: #f1f6fa; }

.afra-ai__handoff {
  background: rgba(3, 11, 22, 0.82);
  border-top-color: rgba(139, 178, 211, 0.15);
  gap: 0.7rem;
  padding: 0.9rem 1rem;
}
.afra-ai__handoff label > span { color: #aabaca; font-size: 0.7rem; }
.afra-ai__handoff input,
.afra-ai__handoff textarea {
  background: rgba(9, 22, 37, 0.92);
  border-color: rgba(139, 178, 211, 0.2);
  border-radius: 14px;
  min-height: 44px;
  padding: 0.7rem 0.8rem;
}
.afra-ai__handoff button {
  background: #234f79;
  border: 1px solid rgba(143, 181, 214, 0.34);
  border-radius: 999px;
  color: #f2f7fa;
  font-weight: 620;
}

.afra-ai__composer {
  background: rgba(3, 10, 20, 0.92);
  border-top-color: rgba(139, 178, 211, 0.15);
  gap: 0.55rem;
  padding: 0.8rem 0.9rem;
}
.afra-ai__composer textarea {
  background: rgba(9, 22, 37, 0.92);
  border-color: rgba(139, 178, 211, 0.2);
  border-radius: 16px;
  font-size: 0.78rem;
  min-height: 48px;
  padding: 0.78rem 0.85rem;
}
.afra-ai__composer button {
  background: #285982;
  border: 1px solid rgba(149, 187, 219, 0.3);
  border-radius: 50%;
  color: #f3f7fa;
  height: 48px;
  width: 48px;
}
.afra-ai__composer button:disabled { background: #182635; border-color: rgba(139, 178, 211, 0.12); filter: none; }

.afra-ai__panel > footer {
  background: rgba(2, 8, 17, 0.96);
  border-top-color: rgba(139, 178, 211, 0.13);
  color: #71869a;
  font-size: 0.58rem;
  line-height: 1.45;
  padding: 0.65rem 1rem 0.75rem;
}

@media (max-width: 620px) {
  .afra-ai__panel {
    border-radius: 24px 24px 0 0;
    bottom: calc(-1 * max(12px, env(safe-area-inset-bottom)));
    height: min(760px, calc(100svh - 24px));
    top: auto;
  }
}
