/* Amdel AI chat assistant widget
   Uses design tokens from styles.css (:root). Self-contained, scoped to .amdel-chat*. */

.amdel-chat-toggle {
  position: fixed;
  z-index: 90;
  right: clamp(16px, 4vw, 28px);
  bottom: clamp(16px, 4vw, 28px);
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-soft) 100%);
  box-shadow: 0 14px 34px rgba(4, 4, 20, 0.48), 0 0 0 1px rgba(4, 4, 20, 0.16);
  color: var(--navy);
  cursor: pointer;
  transition: transform 200ms ease, box-shadow 200ms ease, border-color 200ms ease;
}
.amdel-chat-toggle:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.7);
  box-shadow: 0 18px 40px rgba(4, 4, 20, 0.62);
}
.amdel-chat-toggle .amdel-chat-toggle__close { display: none; }
.amdel-chat-toggle svg { width: 27px; height: 27px; }
.amdel-chat-root.is-open .amdel-chat-toggle__open { display: none; }
.amdel-chat-root.is-open .amdel-chat-toggle__close { display: block; }

/* Unread count */
.amdel-chat-toggle__badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 50%;
  background: #d93a52;
  border: 2px solid var(--paper);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 200ms ease, transform 200ms ease;
}

/* Proactive greeting preview. It appears once per browser tab session. */
.amdel-chat-greeting {
  position: fixed;
  z-index: 89;
  right: clamp(16px, 4vw, 28px);
  bottom: calc(clamp(16px, 4vw, 28px) + 76px);
  width: min(340px, calc(100vw - 32px));
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 15px 16px;
  border: 1px solid rgba(247, 245, 242, 0.2);
  border-radius: 16px;
  background: #f7f5f2;
  box-shadow: 0 18px 42px rgba(2, 2, 12, 0.42);
  color: var(--navy);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease, box-shadow 200ms ease;
}
.amdel-chat-root.has-greeting:not(.is-open) .amdel-chat-greeting {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.amdel-chat-greeting:hover {
  box-shadow: 0 22px 48px rgba(2, 2, 12, 0.5);
}
.amdel-chat-greeting:focus-visible,
.amdel-chat-toggle:focus-visible {
  outline: 3px solid var(--paper);
  outline-offset: 3px;
}
.amdel-chat-greeting__avatar {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--navy);
}
.amdel-chat-greeting__avatar img {
  width: 23px;
  height: 23px;
  object-fit: contain;
}
.amdel-chat-greeting__content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.amdel-chat-greeting__text {
  font-size: 14px;
  font-weight: 650;
  line-height: 1.4;
}
.amdel-chat-greeting__meta {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #626171;
  font-size: 11px;
  line-height: 1.2;
}
.amdel-chat-greeting__meta strong {
  color: var(--navy);
  font-weight: 750;
}
.amdel-chat-root.has-unread:not(.is-open) .amdel-chat-toggle__badge {
  opacity: 1;
  transform: scale(1);
}

.amdel-chat-panel {
  position: fixed;
  z-index: 91;
  right: clamp(16px, 4vw, 28px);
  bottom: calc(clamp(16px, 4vw, 28px) + 72px);
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 130px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #0a0a26 0%, #07071e 60%, #050518 100%);
  box-shadow: 0 26px 60px rgba(2, 2, 12, 0.7);
  color: var(--paper);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
.amdel-chat-root.is-open .amdel-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.amdel-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 30, 66, 0.35);
}
.amdel-chat-header__avatar {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(246, 174, 53, 0.4);
  background: rgba(4, 4, 20, 0.6);
}
.amdel-chat-header__avatar img { width: 24px; height: 24px; object-fit: contain; }
.amdel-chat-header__meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.amdel-chat-header__title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.amdel-chat-header__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.amdel-chat-header__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #37d69b;
  box-shadow: 0 0 0 3px rgba(55, 214, 155, 0.18);
}
.amdel-chat-header__close {
  margin-left: auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}
.amdel-chat-header__close:hover { color: var(--gold); border-color: rgba(246, 174, 53, 0.5); }
.amdel-chat-header__close svg { width: 16px; height: 16px; }

.amdel-chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(247, 245, 242, 0.2) transparent;
}
.amdel-chat-log::-webkit-scrollbar { width: 8px; }
.amdel-chat-log::-webkit-scrollbar-thumb {
  background: rgba(247, 245, 242, 0.18);
  border-radius: 8px;
}

.amdel-chat-msg {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.amdel-chat-msg--bot {
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  background: rgba(20, 26, 54, 0.9);
  border: 1px solid var(--line);
  color: var(--paper);
}
.amdel-chat-msg--user {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-soft) 100%);
  color: var(--navy);
  font-weight: 500;
}
.amdel-chat-msg a { color: var(--gold); text-decoration: underline; }
.amdel-chat-msg--user a { color: var(--navy); }

/* typing indicator */
.amdel-chat-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 13px 15px;
  border-radius: 14px;
  border-bottom-left-radius: 5px;
  background: rgba(20, 26, 54, 0.9);
  border: 1px solid var(--line);
}
.amdel-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: amdel-chat-bounce 1.2s infinite ease-in-out;
}
.amdel-chat-typing span:nth-child(2) { animation-delay: 0.16s; }
.amdel-chat-typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes amdel-chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.amdel-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: rgba(4, 4, 20, 0.5);
}
.amdel-chat-input {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 11px 13px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6, 6, 25, 0.8);
  color: var(--paper);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  outline: none;
  transition: border-color 160ms ease;
}
.amdel-chat-input::placeholder { color: var(--muted); }
.amdel-chat-input:focus { border-color: rgba(246, 174, 53, 0.6); }
.amdel-chat-send {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-soft) 100%);
  color: var(--navy);
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease;
}
.amdel-chat-send:hover { transform: translateY(-1px); }
.amdel-chat-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.amdel-chat-send svg { width: 18px; height: 18px; }

@media (max-width: 480px) {
  .amdel-chat-greeting {
    left: 16px;
    right: 16px;
    width: auto;
  }
  .amdel-chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 82vh;
    height: 82dvh;
    border-radius: 16px 16px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .amdel-chat-toggle,
  .amdel-chat-greeting,
  .amdel-chat-panel,
  .amdel-chat-send { transition: none; }
  .amdel-chat-typing span { animation: none; }
}
