/* Al Majd chat — uses site :root tokens (styles.css) for light/dark */

.am-chat {
  /* Fallbacks if loaded without main stylesheet */
  --am-primary: var(--primary, #c41e3a);
  --am-primary-mid: var(--primary-mid, #d32f2f);
  --am-primary-dark: var(--primary-dark, #a01830);
  --am-primary-deep: var(--primary-deep, #8b1538);
  --am-surface: var(--cream, #ffffff);
  --am-surface-2: var(--cream-warm, #fafafa);
  --am-muted: var(--gray-100, #f5f5f4);
  --am-border: var(--gray-200, #e7e5e4);
  --am-text: var(--gray-800, #292524);
  --am-text-soft: var(--gray-600, #57534e);
  --am-font: var(--font-sans, 'DM Sans', system-ui, sans-serif);
  --am-display: var(--font-display, 'Plus Jakarta Sans', system-ui, sans-serif);
  --am-radius: var(--radius-xl, 20px);
  --am-radius-sm: var(--radius, 12px);
  --am-shadow: var(--shadow-lg, 0 12px 32px rgba(0, 0, 0, 0.12));
  --am-shadow-fab: var(--shadow-md, 0 4px 16px rgba(0, 0, 0, 0.1));
  --am-transition: var(--transition, 0.25s ease-out);

  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 99990;
  font-family: var(--am-font);
  color: var(--am-text);
  -webkit-font-smoothing: antialiased;
}

.am-chat__backdrop {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: rgba(28, 25, 23, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.am-chat[data-open='true'] .am-chat__backdrop {
  opacity: 1;
  pointer-events: auto;
}

[data-theme='dark'] .am-chat__backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.am-chat__fab {
  position: relative;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-full, 9999px);
  border: none;
  cursor: pointer;
  color: var(--white, #fff);
  font-family: var(--am-display);
  background: linear-gradient(
    135deg,
    var(--am-primary-deep) 0%,
    var(--am-primary) 45%,
    var(--am-primary-mid) 100%
  );
  box-shadow: var(--am-shadow-fab), 0 0 0 0 rgba(196, 30, 58, 0.35);
  transition:
    transform var(--am-transition),
    box-shadow var(--am-transition),
    filter var(--am-transition);
}

.am-chat__fab:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(0, 0, 0, 0.12)), 0 0 0 4px rgba(196, 30, 58, 0.18);
}

.am-chat__fab:active {
  transform: translateY(0);
}

.am-chat__fab:focus-visible {
  outline: 2px solid var(--am-primary);
  outline-offset: 3px;
}

.am-chat__fab--pulse {
  animation: am-chat-fab-pulse 2.4s ease-in-out infinite;
}

@keyframes am-chat-fab-pulse {
  0%,
  100% {
    box-shadow: var(--am-shadow-fab), 0 0 0 0 rgba(196, 30, 58, 0.35);
  }
  50% {
    box-shadow: var(--am-shadow-fab), 0 0 0 10px rgba(196, 30, 58, 0);
  }
}

.am-chat__fab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
}

.am-chat__fab-icon svg {
  width: 100%;
  height: 100%;
}

.am-chat__fab-label {
  font-weight: 700;
  letter-spacing: var(--letter-spacing-wide, 0.02em);
  font-size: 0.95rem;
}

.am-chat__panel {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: calc(100% + 12px);
  width: min(400px, calc(100vw - 32px));
  max-height: min(640px, 72vh);
  display: flex;
  flex-direction: column;
  background: var(--am-surface);
  border-radius: var(--am-radius);
  box-shadow: var(--am-shadow);
  border: 1px solid var(--am-border);
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  transition:
    opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

.am-chat[data-open='true'] .am-chat__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.am-chat__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem 0.85rem;
  background: var(--am-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--am-border);
}

.am-chat__brand {
  display: flex;
  gap: 0.65rem;
  align-items: stretch;
  min-width: 0;
}

.am-chat__accent-bar {
  width: 4px;
  border-radius: var(--radius-full, 9999px);
  background: linear-gradient(180deg, var(--am-primary-mid), var(--am-primary-dark));
  flex-shrink: 0;
}

.am-chat__head-text {
  min-width: 0;
}

.am-chat__title {
  margin: 0;
  font-family: var(--am-display);
  font-weight: 800;
  font-size: 1.02rem;
  color: var(--gray-900, #1c1917);
  letter-spacing: var(--letter-spacing-tight, -0.03em);
  line-height: var(--line-height-tight, 1.2);
}

.am-chat__subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--am-text-soft);
  font-weight: 500;
  line-height: var(--line-height-snug, 1.35);
}

.am-chat__status {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full, 9999px);
  flex: 0 0 auto;
  margin-top: 0.35rem;
  background: #10b981;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.am-chat__browse {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem 0.65rem;
  background: var(--am-surface-2);
  border-bottom: 1px solid var(--am-border);
}

.am-chat__browse-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--am-primary);
  text-decoration: none;
  padding: 0.35rem 0.5rem;
  border-radius: var(--am-radius-sm);
  transition:
    color var(--am-transition),
    background var(--am-transition),
    transform var(--am-transition);
}

.am-chat__browse-link:hover {
  color: var(--am-primary-dark);
  background: rgba(196, 30, 58, 0.08);
  transform: translateX(2px);
}

.am-chat__browse-link:focus-visible {
  outline: 2px solid var(--am-primary);
  outline-offset: 2px;
}

.am-chat__browse-link svg {
  width: 0.85rem;
  height: 0.85rem;
  flex-shrink: 0;
  opacity: 0.85;
}

.am-chat__body {
  flex: 1;
  min-height: 200px;
  max-height: 38vh;
  padding: 0.85rem 0.9rem;
  overflow-y: auto;
  background: var(--am-muted);
  scroll-behavior: smooth;
}

.am-chat__row {
  display: flex;
  margin-bottom: 0.65rem;
}

.am-chat__row--bot {
  justify-content: flex-start;
}

.am-chat__row--user {
  justify-content: flex-end;
}

.am-chat__bubble {
  max-width: 88%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--am-radius-sm);
  font-size: 0.9rem;
  line-height: var(--line-height-body, 1.65);
  box-shadow: var(--shadow, 0 2px 8px rgba(0, 0, 0, 0.06));
}

.am-chat__bubble--bot {
  background: var(--am-surface);
  color: var(--am-text);
  border: 1px solid var(--am-border);
  border-bottom-left-radius: 6px;
}

.am-chat__bubble--user {
  background: linear-gradient(135deg, var(--am-primary) 0%, var(--am-primary-dark) 100%);
  color: var(--white, #fff);
  border: none;
  border-bottom-right-radius: 6px;
  box-shadow: 0 8px 22px rgba(196, 30, 58, 0.2);
}

.am-chat__welcome {
  opacity: 0;
  transform: translateY(8px);
}

.am-chat__welcome--in {
  animation: am-chat-welcome-in 0.55s ease forwards;
}

@keyframes am-chat-welcome-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.am-chat__typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-width: 64px;
}

.am-chat__dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--gray-400, #a8a29e);
  animation: am-chat-bounce 1.1s infinite ease-in-out;
}

.am-chat__dot:nth-child(2) {
  animation-delay: 0.12s;
}

.am-chat__dot:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes am-chat-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.am-chat__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem 0.35rem;
  background: var(--am-muted);
  border-top: 1px solid var(--am-border);
}

.am-chat__chip {
  border: 1px solid var(--am-border);
  background: var(--am-surface);
  color: var(--am-text);
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.38rem 0.65rem;
  border-radius: var(--radius-full, 9999px);
  cursor: pointer;
  font-family: inherit;
  transition:
    transform var(--am-transition),
    border-color var(--am-transition),
    box-shadow var(--am-transition),
    background var(--am-transition);
}

.am-chat__chip:hover {
  transform: translateY(-1px);
  border-color: rgba(196, 30, 58, 0.35);
  box-shadow: 0 8px 20px rgba(196, 30, 58, 0.1);
}

.am-chat__chip:focus-visible {
  outline: 2px solid var(--am-primary);
  outline-offset: 2px;
}

.am-chat__chip:active {
  transform: translateY(0);
}

.am-chat__foot {
  padding: 0.65rem 0.85rem 0.85rem;
  background: var(--am-surface);
  border-top: 1px solid var(--am-border);
}

.am-chat__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.am-chat__btn {
  border-radius: var(--am-radius-sm);
  padding: 0.45rem 0.75rem;
  font-weight: 700;
  font-size: 0.78rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition:
    transform var(--am-transition),
    box-shadow var(--am-transition),
    background var(--am-transition),
    border-color var(--am-transition);
}

.am-chat__btn--ghost {
  background: var(--am-surface);
  border-color: var(--am-border);
  color: var(--am-text);
}

.am-chat__btn--ghost:hover {
  transform: translateY(-1px);
  border-color: rgba(196, 30, 58, 0.25);
  box-shadow: var(--shadow, 0 2px 8px rgba(0, 0, 0, 0.06));
}

.am-chat__btn--primary {
  background: linear-gradient(135deg, var(--am-primary) 0%, var(--am-primary-dark) 100%);
  color: var(--white, #fff);
  border: none;
}

.am-chat__btn--primary:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(196, 30, 58, 0.28);
}

.am-chat__btn--wa {
  background: #22c55e;
  color: #fff;
  border: none;
}

.am-chat__btn--wa:hover {
  background: #16a34a;
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(34, 197, 94, 0.28);
}

.am-chat__btn:focus-visible {
  outline: 2px solid var(--am-primary);
  outline-offset: 2px;
}

.am-chat__composer {
  display: flex;
  gap: 0.45rem;
  align-items: stretch;
}

.am-chat__composer-input {
  flex: 1;
  border-radius: var(--am-radius-sm);
  border: 1px solid var(--am-border);
  padding: 0.6rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  background: var(--am-surface);
  color: var(--am-text);
  transition:
    border-color var(--am-transition),
    box-shadow var(--am-transition);
}

.am-chat__composer-input::placeholder {
  color: var(--gray-400, #a8a29e);
}

.am-chat__composer-input:focus {
  border-color: rgba(196, 30, 58, 0.45);
  box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.12);
}

.am-chat__send {
  border: none;
  border-radius: var(--am-radius-sm);
  padding: 0 1rem;
  cursor: pointer;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--white, #fff);
  font-family: inherit;
  background: linear-gradient(135deg, var(--am-primary) 0%, var(--am-primary-dark) 100%);
  transition:
    transform var(--am-transition),
    filter var(--am-transition),
    box-shadow var(--am-transition);
}

.am-chat__send:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  box-shadow: 0 10px 24px rgba(196, 30, 58, 0.25);
}

.am-chat__send:focus-visible {
  outline: 2px solid var(--am-primary);
  outline-offset: 2px;
}

.am-chat__form {
  padding: 0.65rem 0.85rem 0.85rem;
  border-top: 1px solid var(--am-border);
  background: var(--am-surface);
}

.am-chat__form-title {
  margin: 0 0 0.55rem;
  font-family: var(--am-display);
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--gray-900, #1c1917);
}

.am-chat__label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--am-text-soft);
  margin-bottom: 0.45rem;
}

.am-chat__input,
.am-chat__textarea {
  border-radius: var(--am-radius-sm);
  border: 1px solid var(--am-border);
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.85rem;
  outline: none;
  resize: vertical;
  min-height: 0;
  background: var(--am-surface);
  color: var(--am-text);
  transition:
    border-color var(--am-transition),
    box-shadow var(--am-transition);
}

.am-chat__input:focus,
.am-chat__textarea:focus {
  border-color: rgba(196, 30, 58, 0.45);
  box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.12);
}

.am-chat__form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.am-chat__form-note {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--am-text-soft);
}

@media (max-width: 480px) {
  .am-chat__panel {
    width: calc(100vw - 24px);
    max-height: min(82vh, 640px);
  }

  .am-chat__body {
    max-height: min(36vh, 280px);
  }

  .am-chat__fab-label {
    display: none;
  }

  .am-chat__fab {
    padding: 0.95rem;
    border-radius: var(--radius-full, 9999px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .am-chat__fab--pulse {
    animation: none;
  }

  .am-chat__panel,
  .am-chat__backdrop,
  .am-chat__fab,
  .am-chat__chip,
  .am-chat__send,
  .am-chat__btn {
    transition: none;
  }

  .am-chat__dot {
    animation: none;
  }

  .am-chat__welcome--in {
    animation: none;
    opacity: 1;
    transform: none;
  }
}
