/* Azarakhsh Support Chat — isolated widget styles (Shadow DOM) */
:host, .azs-shell {
  --azs-primary: #4f46e5;
  --azs-accent: #0ea5e9;
  --azs-on-primary: #ffffff;
  --azs-radius: 22px;
  --azs-shadow: 0 22px 60px -28px rgba(15, 23, 42, 0.55);
  --azs-gap: 12px;
  --azs-edge: 16px;
  --azs-mobile-nav: 0px;
  --azs-launcher-size: 64px;
  --azs-safe-bottom: env(safe-area-inset-bottom, 0px);
  all: initial;
  font-family: Vazir, Tahoma, sans-serif;
  direction: rtl;
  color: #0f172a;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.azs-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.azs-shell *,
.azs-shell *::before,
.azs-shell *::after {
  box-sizing: border-box;
  font-family: Vazir, Tahoma, sans-serif;
}

.azs-shell button,
.azs-shell textarea,
.azs-shell input {
  font: inherit;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
}

/* Floating anchor — position set by JS (left/top = top-left of launcher cluster) */
.azs-anchor {
  position: fixed;
  z-index: 2;
  width: auto;
  height: auto;
  pointer-events: none;
  touch-action: none;
}

.azs-anchor.is-dragging {
  cursor: grabbing;
}

.azs-launcher-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  transform-origin: bottom left;
}

.azs-launcher {
  position: relative;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  cursor: grab;
  border-radius: 999px;
  padding: 12px 22px 12px 12px;
  min-height: var(--azs-launcher-size);
  color: var(--azs-on-primary);
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--azs-accent) 42%, var(--azs-primary)),
    var(--azs-primary) 58%
  );
  box-shadow:
    0 18px 40px -18px color-mix(in srgb, var(--azs-primary) 75%, #0f172a),
    0 10px 24px -16px rgba(15, 23, 42, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease, opacity 0.2s ease;
  white-space: nowrap;
  overflow: visible;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  animation: azs-launcher-enter 0.7s cubic-bezier(0.22, 1, 0.36, 1) both,
    azs-launcher-float 3.6s ease-in-out 0.9s infinite;
}

.azs-anchor.is-dragging .azs-launcher {
  cursor: grabbing;
  animation: none;
  transform: scale(1.04);
}

.azs-launcher:hover {
  transform: translateY(-4px) scale(1.03);
  animation-play-state: paused;
}

.azs-hide {
  pointer-events: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(255, 255, 255, 0.95);
  color: #64748b;
  box-shadow: 0 8px 20px -12px rgba(15, 23, 42, 0.45);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0.72;
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.azs-hide:hover {
  opacity: 1;
  color: #0f172a;
  transform: scale(1.06);
}

.azs-launcher-glow {
  position: absolute;
  inset: -10px;
  border-radius: inherit;
  background: radial-gradient(
    circle at 30% 30%,
    color-mix(in srgb, var(--azs-accent) 55%, transparent),
    transparent 62%
  );
  opacity: 0.55;
  z-index: -1;
  pointer-events: none;
  filter: blur(8px);
}

.azs-launcher-ring {
  position: absolute;
  inset: -14px;
  border-radius: inherit;
  pointer-events: none;
  z-index: -1;
  opacity: 0;
  background: conic-gradient(
    from 210deg,
    transparent 0deg,
    color-mix(in srgb, #fff 90%, var(--azs-accent)) 38deg,
    transparent 78deg,
    color-mix(in srgb, var(--azs-accent) 85%, #fff) 140deg,
    transparent 185deg,
    #fff 250deg,
    transparent 300deg,
    color-mix(in srgb, var(--azs-primary) 70%, #fff) 330deg,
    transparent 360deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 2px;
}

.azs-launcher.is-sparkling .azs-launcher-ring {
  animation: azs-diamond-ring 1.85s ease-out 0.15s 1 both;
}

.azs-launcher-shine {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.azs-launcher-shine::before {
  content: '';
  position: absolute;
  top: -40%;
  left: -60%;
  width: 42%;
  height: 180%;
  background: linear-gradient(
    105deg,
    transparent 0%,
    rgba(255, 255, 255, 0.08) 35%,
    rgba(255, 255, 255, 0.55) 50%,
    rgba(255, 255, 255, 0.08) 65%,
    transparent 100%
  );
  transform: translateX(-120%) rotate(18deg);
  opacity: 0;
}

.azs-launcher.is-sparkling .azs-launcher-shine::before {
  animation: azs-shine-sweep 1.35s ease-out 0.35s 1 both;
}

.azs-spark {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #fff;
  transform: rotate(45deg) scale(0);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  box-shadow:
    0 0 10px rgba(255, 255, 255, 0.95),
    0 0 18px color-mix(in srgb, var(--azs-accent) 70%, transparent);
  border-radius: 1.5px;
}

.azs-spark::after {
  content: '';
  position: absolute;
  inset: -3px;
  background: inherit;
  border-radius: inherit;
  opacity: 0.35;
  filter: blur(2px);
}

.azs-launcher.is-sparkling .azs-spark-1 { top: -6px; right: 18%; animation: azs-diamond-pop 1.2s cubic-bezier(0.22, 1, 0.36, 1) 0.2s 1 both; }
.azs-launcher.is-sparkling .azs-spark-2 { top: 12%; left: -8px; animation: azs-diamond-pop 1.25s cubic-bezier(0.22, 1, 0.36, 1) 0.35s 1 both; }
.azs-launcher.is-sparkling .azs-spark-3 { bottom: -4px; left: 28%; animation: azs-diamond-pop 1.2s cubic-bezier(0.22, 1, 0.36, 1) 0.48s 1 both; }
.azs-launcher.is-sparkling .azs-spark-4 { top: 42%; right: -7px; width: 7px; height: 7px; animation: azs-diamond-pop 1.15s cubic-bezier(0.22, 1, 0.36, 1) 0.55s 1 both; }
.azs-launcher.is-sparkling .azs-spark-5 { top: -10px; left: 42%; width: 6px; height: 6px; animation: azs-diamond-pop 1.1s cubic-bezier(0.22, 1, 0.36, 1) 0.62s 1 both; }

.azs-launcher-icon {
  position: relative;
  z-index: 2;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.38), transparent 55%),
    rgba(255, 255, 255, 0.14);
  overflow: hidden;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.azs-launcher-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border: 0;
}

.azs-launcher-label {
  position: relative;
  z-index: 2;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.015em;
  text-shadow: 0 1px 0 rgba(15, 23, 42, 0.12);
  padding-inline-end: 2px;
}

.azs-panel {
  pointer-events: none;
  position: absolute;
  bottom: calc(var(--azs-launcher-size) + var(--azs-gap));
  left: 0;
  right: auto;
  width: min(392px, calc(100vw - 24px));
  height: min(620px, calc(100vh - var(--azs-launcher-size) - 100px - var(--azs-mobile-nav) - var(--azs-safe-bottom)));
  max-height: calc(100vh - var(--azs-launcher-size) - 88px - var(--azs-mobile-nav) - var(--azs-safe-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--azs-radius);
  background: #fff;
  box-shadow: var(--azs-shadow);
  border: 1px solid rgba(148, 163, 184, 0.25);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom left;
  transition: opacity 0.22s ease, transform 0.22s ease;
  visibility: hidden;
  z-index: 2;
}

.azs-anchor.is-open .azs-panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  visibility: visible;
  top: 0;
  bottom: auto;
  width: min(392px, calc(100vw - 24px));
  height: min(620px, calc(100vh - 24px - var(--azs-mobile-nav) - var(--azs-safe-bottom)));
  max-height: calc(100vh - 24px - var(--azs-mobile-nav) - var(--azs-safe-bottom));
}

.azs-anchor.is-open .azs-launcher-wrap {
  display: none !important;
}

.azs-anchor.is-dragging .azs-panel {
  transition: none;
}

.azs-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--azs-on-primary);
  background: var(--azs-primary);
  flex: 0 0 auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.azs-anchor.is-dragging .azs-header {
  cursor: grabbing;
}

.azs-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
}

.azs-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border: 0;
}

.azs-head-text {
  min-width: 0;
  flex: 1;
}

.azs-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: inherit;
}

.azs-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.88;
  color: inherit;
}

.azs-close {
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}

.azs-body {
  flex: 1;
  overflow: auto;
  padding: 14px;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 40%);
  min-height: 0;
}

.azs-msg {
  max-width: 88%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.azs-msg-bot {
  margin-left: 0;
  margin-right: auto;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 6px;
  color: #0f172a;
}

.azs-msg-user {
  margin-right: 0;
  margin-left: auto;
  background: var(--azs-primary);
  color: var(--azs-on-primary);
  border-bottom-right-radius: 6px;
}

.azs-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}

.azs-chip {
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #334155;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.azs-chip:hover {
  border-color: var(--azs-accent);
  color: var(--azs-primary);
}

/* Composer */
.azs-footer {
  border-top: 1px solid rgba(226, 232, 240, 0.9);
  padding: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  flex: 0 0 auto;
}

.azs-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  border-radius: 22px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow:
    0 10px 28px -22px rgba(15, 23, 42, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.azs-composer:focus-within {
  border-color: color-mix(in srgb, var(--azs-accent) 55%, #cbd5e1);
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--azs-accent) 18%, transparent),
    0 12px 30px -20px rgba(15, 23, 42, 0.4);
}

.azs-input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  border: 0;
  border-radius: 0;
  padding: 10px 4px;
  font-size: 14px;
  line-height: 1.55;
  outline: none;
  background: transparent;
  color: #0f172a;
  box-shadow: none;
}

.azs-input::placeholder {
  color: #94a3b8;
}

.azs-send {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--azs-accent) 35%, var(--azs-primary)),
    var(--azs-primary)
  );
  color: var(--azs-on-primary);
  cursor: pointer;
  box-shadow:
    0 10px 22px -12px color-mix(in srgb, var(--azs-primary) 80%, #0f172a),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transition: transform 0.18s ease, opacity 0.18s ease, filter 0.18s ease;
}

.azs-send:hover:not(:disabled) {
  transform: scale(1.06);
  filter: brightness(1.05);
}

.azs-send:active:not(:disabled) {
  transform: scale(0.96);
}

.azs-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.azs-send svg {
  width: 20px;
  height: 20px;
  display: block;
  fill: currentColor;
  transform: scaleX(-1);
}

.azs-typing {
  font-size: 12px;
  color: #64748b;
  margin: 4px 2px 8px;
}

.azs-error {
  color: #b91c1c;
  font-size: 12px;
  margin: 0 2px 8px;
}

.azs-card {
  margin: 0 0 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  background: #fff;
  font-size: 13px;
  line-height: 1.6;
}

.azs-card-confirm { border-color: #fcd34d; background: #fffbeb; }
.azs-card-draft { border-color: #c7d2fe; background: #eef2ff; }
.azs-card-done { border-color: #86efac; background: #ecfdf5; }
.azs-card-title { margin: 0 0 6px; font-weight: 800; font-size: 13px; }
.azs-card-text { margin: 0 0 8px; color: #334155; white-space: pre-wrap; word-break: break-word; }
.azs-card-btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--azs-primary);
  color: var(--azs-on-primary);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.azs-card-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Tiny edge tab when dismissed — not a wide mid-screen chip */
.azs-recover {
  position: fixed;
  z-index: 3;
  pointer-events: auto;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--azs-accent) 35%, var(--azs-primary)),
    var(--azs-primary)
  );
  color: var(--azs-on-primary);
  box-shadow: 0 10px 24px -14px rgba(15, 23, 42, 0.55);
  opacity: 0.72;
  bottom: calc(12px + var(--azs-mobile-nav) + var(--azs-safe-bottom));
  right: 10px;
  left: auto;
  top: auto;
  transform: none;
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.azs-recover:hover,
.azs-recover:focus-visible {
  opacity: 1;
  transform: scale(1.06);
  outline: none;
}

.azs-recover[data-edge='left'] {
  right: auto;
  left: 10px;
}

.azs-shell.is-dismissed .azs-recover {
  display: inline-flex;
  animation: azs-recover-in 0.35s ease both;
}

.azs-shell.is-dismissed .azs-anchor {
  display: none;
}

.azs-recover-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.azs-recover-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border: 0;
}

.azs-recover-label {
  display: none;
}

.azs-shell[data-template='brand'] .azs-header {
  background: linear-gradient(135deg, var(--azs-primary), var(--azs-accent));
}

.azs-shell[data-template='brand'] .azs-body {
  background:
    radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--azs-accent) 16%, transparent), transparent 42%),
    linear-gradient(180deg, #f8fafc, #fff 50%);
}

.azs-shell[data-template='soft'] .azs-panel { border-radius: 28px; }
.azs-shell[data-template='soft'] .azs-header { background: #0f172a; }
.azs-shell[data-template='soft'] .azs-msg-bot { background: #f1f5f9; border-color: transparent; }
.azs-shell[data-template='soft'] .azs-msg { border-radius: 22px; }

.azs-shell.is-embedded {
  position: absolute;
  inset: 0;
}

.azs-shell.is-embedded .azs-anchor {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
}

.azs-shell.is-embedded .azs-launcher-wrap,
.azs-shell.is-embedded .azs-hide,
.azs-shell.is-embedded .azs-recover {
  display: none !important;
}

.azs-shell.is-embedded .azs-panel {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  max-height: none;
  bottom: auto;
  right: auto;
  left: auto;
  opacity: 1;
  transform: none;
  pointer-events: auto;
  visibility: visible;
  box-shadow: none;
  border-radius: 16px;
}

@keyframes azs-launcher-enter {
  from { opacity: 0; transform: translateY(18px) scale(0.86); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes azs-launcher-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes azs-diamond-ring {
  0% { opacity: 0; transform: scale(0.72) rotate(0deg); filter: blur(1px) brightness(1.2); }
  18% { opacity: 1; }
  55% { opacity: 0.95; transform: scale(1.08) rotate(140deg); filter: blur(0.2px) brightness(1.35); }
  100% { opacity: 0; transform: scale(1.28) rotate(260deg); filter: blur(1.5px) brightness(1); }
}

@keyframes azs-shine-sweep {
  0% { opacity: 0; transform: translateX(-130%) rotate(18deg); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateX(320%) rotate(18deg); }
}

@keyframes azs-diamond-pop {
  0% { opacity: 0; transform: rotate(45deg) scale(0); }
  28% { opacity: 1; transform: rotate(45deg) scale(1.15); }
  70% { opacity: 0.85; transform: rotate(45deg) scale(0.92); }
  100% { opacity: 0; transform: rotate(45deg) scale(0.35) translateY(-6px); }
}

@keyframes azs-recover-in {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 0.72; transform: scale(1); }
}

@media (max-width: 768px) {
  .azs-shell {
    --azs-mobile-nav: 72px;
    --azs-edge: 12px;
  }

  .azs-recover {
    width: 38px;
    height: 38px;
    opacity: 0.55;
    bottom: calc(10px + var(--azs-mobile-nav) + var(--azs-safe-bottom));
    right: 8px;
  }

  .azs-recover[data-edge='left'] {
    left: 8px;
    right: auto;
  }

  .azs-recover:hover,
  .azs-recover:focus-visible {
    opacity: 0.95;
  }

  .azs-launcher-label {
    font-size: 13px;
  }

  .azs-launcher {
    padding: 10px 16px 10px 10px;
    gap: 10px;
    min-height: 56px;
  }

  .azs-launcher-icon {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 420px) {
  .azs-launcher-label {
    display: none;
  }

  .azs-launcher {
    padding: 10px;
    border-radius: 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .azs-launcher,
  .azs-launcher.is-sparkling .azs-launcher-ring,
  .azs-launcher.is-sparkling .azs-launcher-shine::before,
  .azs-launcher.is-sparkling .azs-spark-1,
  .azs-launcher.is-sparkling .azs-spark-2,
  .azs-launcher.is-sparkling .azs-spark-3,
  .azs-launcher.is-sparkling .azs-spark-4,
  .azs-launcher.is-sparkling .azs-spark-5,
  .azs-shell.is-dismissed .azs-recover {
    animation: none !important;
  }
}
