/* ===========================
   Al-Asmaa — Live Chat (universal)
   Mobile : bottom-sheet | Desktop : side-panel
   =========================== */

.asmaa-chat,
.asmaa-chat * {
  box-sizing: border-box;
}

.asmaa-chat {
  --chat-w: 380px;
  --chat-bg: rgba(10, 14, 26, 0.92);
  --chat-bg-soft: rgba(15, 19, 36, 0.82);
  --chat-border: rgba(212, 162, 76, 0.22);
  --chat-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 4px 14px rgba(0, 0, 0, 0.4);
  font-family: var(--font-body, 'Outfit', sans-serif);
  color: var(--text-primary, #eae6df);
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 950;
}

/* ----- FAB (Floating Action Button) ----- */
.asmaa-chat-fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(255, 230, 160, 0.45);
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 235, 180, 0.55), transparent 60%),
    linear-gradient(140deg, var(--gold-deep, #a67c2e) 0%, var(--gold, #d4a24c) 50%, var(--gold-bright, #ffd866) 100%);
  color: #1a1208;
  cursor: pointer;
  pointer-events: auto;
  display: grid;
  place-items: center;
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.45),
    0 4px 12px rgba(212, 162, 76, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s, opacity 0.3s;
  z-index: 951;
}
.asmaa-chat-fab:hover { transform: translateY(-2px) scale(1.04); }
.asmaa-chat-fab:active { transform: translateY(0) scale(0.96); }
.asmaa-chat-fab:focus-visible {
  outline: 2px solid var(--gold-bright, #ffd866);
  outline-offset: 3px;
}
.asmaa-chat-fab-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 2;
}
.asmaa-chat-fab-icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 2.2;
}
.asmaa-chat-fab-pulse {
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  border: 2px solid rgba(255, 216, 102, 0.6);
  opacity: 0;
  animation: asmaaChatPulse 2.6s ease-out infinite;
  pointer-events: none;
}
@keyframes asmaaChatPulse {
  0%   { transform: scale(0.95); opacity: 0.55; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}
.asmaa-chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ruby, #ef4444);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid var(--bg-deep, #050811);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.55);
  animation: asmaaChatBadgePop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 3;
}
@keyframes asmaaChatBadgePop {
  0%   { transform: scale(0); }
  100% { transform: scale(1); }
}
.asmaa-chat.has-new .asmaa-chat-fab {
  animation: asmaaChatJiggle 1.2s ease-in-out;
}
@keyframes asmaaChatJiggle {
  0%, 100% { transform: rotate(0); }
  20%, 60% { transform: rotate(-7deg); }
  40%, 80% { transform: rotate(7deg); }
}

/* ----- Backdrop (mobile only) ----- */
.asmaa-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 17, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s;
  pointer-events: none;
  z-index: 952;
}
.asmaa-chat.is-open .asmaa-chat-backdrop {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ----- Panel ----- */
.asmaa-chat-panel {
  position: fixed;
  background: var(--chat-bg);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--chat-border);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  z-index: 953;

  /* MOBILE default — bottom sheet */
  left: 0;
  right: 0;
  bottom: 0;
  height: min(82vh, 720px);
  max-height: 100dvh;
  border-radius: 24px 24px 0 0;
  border-bottom: none;
  transform: translateY(100%);
  transition: transform 0.42s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s;
  opacity: 0;
}
.asmaa-chat.is-open .asmaa-chat-panel {
  transform: translateY(0);
  opacity: 1;
}

/* ----- Header ----- */
.asmaa-chat-header {
  position: relative;
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(212, 162, 76, 0.1);
  background: linear-gradient(180deg, rgba(212, 162, 76, 0.07), transparent);
  cursor: grab;
  touch-action: pan-y;
}
.asmaa-chat-header:active { cursor: grabbing; }
.asmaa-chat-grip {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(212, 162, 76, 0.35);
}
.asmaa-chat-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.asmaa-chat-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(212, 162, 76, 0.22), rgba(212, 162, 76, 0.08));
  border: 1px solid rgba(212, 162, 76, 0.28);
  display: grid;
  place-items: center;
  color: var(--gold-bright, #ffd866);
  flex-shrink: 0;
}
.asmaa-chat-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}
.asmaa-chat-title-stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.asmaa-chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text-primary, #eae6df);
  font-family: var(--font-display, 'Syne'), 'Outfit', sans-serif;
}
.asmaa-chat-subtitle {
  font-size: 11.5px;
  color: var(--text-secondary, #9a978f);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.1px;
}
.asmaa-chat-subtitle::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald, #2dd4a0);
  box-shadow: 0 0 8px var(--emerald, #2dd4a0);
  animation: asmaaChatLiveDot 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes asmaaChatLiveDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.85); }
}
.asmaa-chat-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary, #9a978f);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.asmaa-chat-close svg { width: 16px; height: 16px; }
.asmaa-chat-close:hover {
  color: var(--text-primary, #eae6df);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(212, 162, 76, 0.25);
}
.asmaa-chat-close:focus-visible {
  outline: 2px solid var(--gold-bright, #ffd866);
  outline-offset: 2px;
}

/* ----- Body ----- */
.asmaa-chat-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 14px 4px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.asmaa-chat-body::-webkit-scrollbar { width: 6px; }
.asmaa-chat-body::-webkit-scrollbar-track { background: transparent; }
.asmaa-chat-body::-webkit-scrollbar-thumb {
  background: rgba(212, 162, 76, 0.25);
  border-radius: 4px;
}
.asmaa-chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(212, 162, 76, 0.45);
}

/* ----- Empty state ----- */
.asmaa-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 14px;
  color: var(--text-secondary, #9a978f);
}
.asmaa-chat-empty-glyph {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(212, 162, 76, 0.2), rgba(212, 162, 76, 0.04));
  border: 1px solid rgba(212, 162, 76, 0.2);
  display: grid;
  place-items: center;
  color: var(--gold, #d4a24c);
}
.asmaa-chat-empty-glyph svg { width: 26px; height: 26px; stroke-width: 1.8; }
.asmaa-chat-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #eae6df);
  font-family: var(--font-display, 'Syne'), 'Outfit', sans-serif;
}
.asmaa-chat-empty-text {
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 240px;
}

/* ----- Messages list ----- */
.asmaa-chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.asmaa-chat-msg {
  --msg-color: var(--gold, #d4a24c);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: asmaaChatMsgIn 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes asmaaChatMsgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.asmaa-chat-msg.is-mine {
  flex-direction: row-reverse;
}

.asmaa-chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--msg-color);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.asmaa-chat-bubble {
  max-width: calc(100% - 44px);
  padding: 7px 12px 8px;
  border-radius: 14px;
  background: var(--bg-card, rgba(15, 19, 36, 0.85));
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  position: relative;
}
.asmaa-chat-msg.is-mine .asmaa-chat-bubble {
  background: linear-gradient(135deg, rgba(212, 162, 76, 0.18), rgba(212, 162, 76, 0.08));
  border-color: rgba(212, 162, 76, 0.28);
}
.asmaa-chat-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 1px;
}
.asmaa-chat-from {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--msg-color);
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.asmaa-chat-msg.is-mine .asmaa-chat-from {
  color: var(--gold-bright, #ffd866);
}
.asmaa-chat-time {
  font-size: 10px;
  color: var(--text-muted, #5c5952);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.asmaa-chat-text {
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-primary, #eae6df);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.asmaa-chat-msg.is-system {
  justify-content: center;
}
.asmaa-chat-msg-system {
  font-size: 11.5px;
  color: var(--text-muted, #5c5952);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 999px;
  font-style: italic;
}

/* ----- Typing indicator ----- */
.asmaa-chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 4px;
  font-size: 11.5px;
  color: var(--text-secondary, #9a978f);
  font-style: italic;
}
.asmaa-chat-typing-dots {
  display: inline-flex;
  gap: 3px;
}
.asmaa-chat-typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold, #d4a24c);
  animation: asmaaChatTypingDot 1.2s ease-in-out infinite;
}
.asmaa-chat-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.asmaa-chat-typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes asmaaChatTypingDot {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-3px); }
}

/* ----- Footer / Form ----- */
.asmaa-chat-footer {
  flex-shrink: 0;
  padding: 8px 12px max(10px, env(safe-area-inset-bottom)) 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background: linear-gradient(180deg, transparent, rgba(212, 162, 76, 0.03));
}
.asmaa-chat-rules {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  color: var(--text-muted, #5c5952);
  margin-bottom: 8px;
  padding: 0 4px;
}
.asmaa-chat-rules svg {
  width: 11px;
  height: 11px;
  stroke-width: 2.2;
  color: var(--gold, #d4a24c);
  flex-shrink: 0;
}
.asmaa-chat-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.asmaa-chat-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(5, 8, 17, 0.6);
  border: 1px solid rgba(212, 162, 76, 0.15);
  border-radius: 14px;
  padding: 0 12px;
  transition: border-color 0.2s, background 0.2s;
}
.asmaa-chat-input-wrap:focus-within {
  border-color: rgba(212, 162, 76, 0.5);
  background: rgba(5, 8, 17, 0.75);
}
.asmaa-chat-input-glow {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: linear-gradient(120deg, transparent, rgba(212, 162, 76, 0.18), transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.asmaa-chat-input-wrap:focus-within .asmaa-chat-input-glow { opacity: 1; }
.asmaa-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary, #eae6df);
  font-family: inherit;
  font-size: 14px;
  padding: 11px 0;
  outline: none;
  min-width: 0;
}
.asmaa-chat-input::placeholder { color: var(--text-muted, #5c5952); }
.asmaa-chat-counter {
  font-size: 10.5px;
  color: var(--text-muted, #5c5952);
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
.asmaa-chat-counter.is-warn { color: var(--ruby, #ef4444); }

.asmaa-chat-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 230, 160, 0.45);
  background: linear-gradient(140deg, var(--gold-deep, #a67c2e), var(--gold, #d4a24c) 55%, var(--gold-bright, #ffd866));
  color: #1a1208;
  cursor: pointer;
  display: grid;
  place-items: center;
  align-self: center;
  box-shadow:
    0 4px 14px rgba(212, 162, 76, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: transform 0.18s, box-shadow 0.25s, opacity 0.2s;
}
.asmaa-chat-send svg { width: 18px; height: 18px; }
.asmaa-chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow:
    0 6px 18px rgba(212, 162, 76, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.asmaa-chat-send:active:not(:disabled) { transform: translateY(0) scale(0.96); }
.asmaa-chat-send:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: saturate(0.6);
}
.asmaa-chat-send:focus-visible {
  outline: 2px solid var(--gold-bright, #ffd866);
  outline-offset: 2px;
}

/* ----- Desktop : side panel (≥720px) ----- */
@media (min-width: 720px) {
  .asmaa-chat-fab {
    width: 60px;
    height: 60px;
    bottom: 24px;
    right: 24px;
  }
  .asmaa-chat-fab-icon { width: 28px; height: 28px; }

  .asmaa-chat-backdrop { display: none; }

  .asmaa-chat-panel {
    left: auto;
    right: 22px;
    bottom: 100px;
    top: auto;
    width: var(--chat-w);
    height: min(640px, calc(100vh - 140px));
    max-height: calc(100vh - 140px);
    border-radius: 22px;
    border: 1px solid var(--chat-border);
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s;
  }
  .asmaa-chat.is-open .asmaa-chat-panel {
    transform: translateY(0) scale(1);
  }
  .asmaa-chat-grip { display: none; }
  .asmaa-chat-header { cursor: default; padding-top: 14px; }
}

/* ----- Reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
  .asmaa-chat-fab-pulse,
  .asmaa-chat-msg,
  .asmaa-chat-typing-dots i,
  .asmaa-chat.has-new .asmaa-chat-fab,
  .asmaa-chat-fab-badge,
  .asmaa-chat-subtitle::before {
    animation: none !important;
  }
  .asmaa-chat-panel {
    transition: opacity 0.2s !important;
  }
}

/* ----- Reposition FAB to avoid overlap with mobile bottom controls ----- */
/* During Classic game (player input is fixed at bottom) */
body.has-game-input .asmaa-chat-fab {
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + 88px);
}

@media (min-width: 720px) {
  body.has-game-input .asmaa-chat-fab {
    bottom: 24px;
  }
}
