/* ============================================================
   MARIAR — AI Robot Assistant Character & Chat
   ============================================================ */

.ai-assistant-widget {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 1000;
  font-family: 'Cairo', sans-serif;
  direction: rtl;
}

/* Hint bubble */
.ai-robot-hint {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: white;
  color: var(--primary-800, #1a3a6b);
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.2);
  border: 1px solid rgba(37, 99, 235, 0.12);
  opacity: 0;
  pointer-events: none;
  animation: aiHintPop 6s ease-in-out 2s infinite;
}

.ai-hint-tail {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: white;
  border-right: 1px solid rgba(37, 99, 235, 0.12);
  border-bottom: 1px solid rgba(37, 99, 235, 0.12);
}

.ai-assistant-widget.open .ai-robot-hint,
.ai-assistant-widget.hint-dismissed .ai-robot-hint {
  animation: none;
  opacity: 0;
}

@keyframes aiHintPop {
  0%, 70%, 100% { opacity: 0; transform: translateX(-50%) scale(0.85) translateY(6px); }
  10%, 55% { opacity: 1; transform: translateX(-50%) scale(1) translateY(0); }
}

/* Robot trigger button */
.ai-robot-trigger {
  position: relative;
  width: 96px;
  height: 110px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
  pointer-events: auto;
}

.ai-robot-trigger:hover {
  transform: scale(1.06);
}

.ai-robot-trigger:active {
  transform: scale(0.96);
}

.ai-robot-character {
  width: 96px;
  height: 104px;
  display: block;
  filter: drop-shadow(0 10px 24px rgba(37, 99, 235, 0.35));
  animation: robotFloat 3.5s ease-in-out infinite;
}

@keyframes robotFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.robot-shadow {
  animation: robotShadow 3.5s ease-in-out infinite;
  transform-origin: center;
}

@keyframes robotShadow {
  0%, 100% { transform: scaleX(1); opacity: 0.25; }
  50% { transform: scaleX(0.85); opacity: 0.15; }
}

.robot-antenna-bulb {
  animation: robotAntennaPulse 2s ease-in-out infinite;
}

@keyframes robotAntennaPulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.robot-blink {
  animation: robotBlink 4s ease-in-out infinite;
}

.robot-blink-right { animation-delay: 0.1s; }

@keyframes robotBlink {
  0%, 92%, 100% { transform: scaleY(0); transform-origin: center; }
  95% { transform: scaleY(1); }
}

.robot-core-inner {
  animation: robotCorePulse 2.5s ease-in-out infinite;
}

@keyframes robotCorePulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.3); }
  transform-box: fill-box;
  transform-origin: center;
}

.robot-arm-left {
  transform-origin: 25px 76px;
  animation: robotArmIdleLeft 3s ease-in-out infinite;
}

.robot-arm-right {
  transform-origin: 95px 76px;
}

@keyframes robotArmIdleLeft {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-6deg); }
}

/* Pulse ring around robot */
.ai-robot-pulse-ring {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 2px solid rgba(37, 99, 235, 0.35);
  animation: aiPulseRing 2.5s ease-out infinite;
  pointer-events: none;
}

@keyframes aiPulseRing {
  0% { transform: scale(0.85); opacity: 0.6; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* Open state — wave animation */
.ai-assistant-widget.open .ai-robot-character {
  animation: robotGreet 0.8s ease forwards;
}

.ai-assistant-widget.open .robot-arm-right {
  animation: robotWave 0.8s ease-in-out 0.1s;
}

.ai-assistant-widget.open .robot-arm-left {
  animation: robotWaveLeft 0.8s ease-in-out 0.2s;
}

.ai-assistant-widget.open .ai-robot-pulse-ring {
  animation: none;
  opacity: 0;
}

@keyframes robotGreet {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-12px) scale(1.05); }
  60% { transform: translateY(-4px) scale(1.02) rotate(-3deg); }
  100% { transform: translateY(-6px) scale(1); }
}

@keyframes robotWave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-28deg); }
  50% { transform: rotate(-12deg); }
  75% { transform: rotate(-24deg); }
}

@keyframes robotWaveLeft {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(18deg); }
  50% { transform: rotate(8deg); }
  75% { transform: rotate(16deg); }
}

.ai-assistant-widget.open .ai-robot-trigger {
  transform: scale(0.92) translateY(-4px);
}

/* Chat panel */
.ai-chat-panel {
  position: absolute;
  bottom: 118px;
  left: 0;
  width: 380px;
  max-height: min(520px, calc(100vh - 160px));
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(37, 99, 235, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(0.92);
  transform-origin: bottom left;
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1), visibility 0.35s;
  pointer-events: none;
}

.ai-assistant-widget.open .ai-chat-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ai-assistant-widget.open .ai-chat-panel {
  animation: aiPanelBounce 0.5s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes aiPanelBounce {
  0% { transform: translateY(24px) scale(0.92); }
  60% { transform: translateY(-4px) scale(1.01); }
  100% { transform: translateY(0) scale(1); }
}

/* Connector line robot → panel */
.ai-assistant-widget.open::before {
  content: '';
  position: absolute;
  bottom: 108px;
  left: 48px;
  width: 2px;
  height: 14px;
  background: linear-gradient(to top, rgba(37, 99, 235, 0.4), transparent);
  animation: aiConnectorGrow 0.4s ease forwards;
}

@keyframes aiConnectorGrow {
  from { height: 0; opacity: 0; }
  to { height: 14px; opacity: 1; }
}

/* Header */
.ai-chat-header {
  background: linear-gradient(135deg, #1a3a6b 0%, #2563eb 100%);
  color: white;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.ai-chat-header-robot {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: aiHeaderRobotBob 3s ease-in-out infinite;
}

@keyframes aiHeaderRobotBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.ai-header-robot-mini {
  width: 36px;
  height: 36px;
}

.ai-chat-title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: right;
}

.ai-chat-title {
  font-size: 15px;
  font-weight: 800;
}

.ai-chat-subtitle {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.65);
  font-weight: 500;
}

.ai-chat-status {
  font-size: 10px;
  color: #a5f3fc;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.ai-status-dot {
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  animation: aiStatusPulse 1.5s ease-in-out infinite;
}

@keyframes aiStatusPulse {
  0%, 100% { opacity: 0.5; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

.ai-chat-close {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

/* Messages */
.ai-chat-messages {
  flex: 1;
  min-height: 200px;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}

.ai-msg {
  display: flex;
  gap: 8px;
  max-width: 92%;
  animation: aiMsgIn 0.35s ease forwards;
}

@keyframes aiMsgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-msg.bot {
  align-self: flex-start;
}

.ai-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #1a3a6b);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.ai-msg.user .ai-msg-avatar {
  background: var(--primary-500, #2563eb);
}

.ai-msg-bubble {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.65;
  text-align: right;
}

.ai-msg.bot .ai-msg-bubble {
  background: white;
  color: #1e293b;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  border: 1px solid #e2e8f0;
}

.ai-msg.user .ai-msg-bubble {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.25);
}

.ai-msg-text a {
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
}

.ai-msg.bot .ai-msg-text a {
  color: #2563eb;
}

.ai-msg-time {
  font-size: 9px;
  opacity: 0.55;
  margin-top: 4px;
  align-self: flex-end;
}

/* Quick choices */
.ai-chat-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  background: rgba(248, 250, 252, 0.9);
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.ai-choice-btn {
  background: white;
  border: 1px solid #dbeafe;
  color: #1d4ed8;
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Cairo', sans-serif;
}

.ai-choice-btn:hover {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

/* Input area */
.ai-chat-input-area {
  padding: 12px 14px;
  background: white;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  outline: none;
  font-size: 13px;
  font-family: 'Cairo', sans-serif;
  text-align: right;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-chat-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.ai-chat-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #1a3a6b);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.ai-chat-send:hover {
  transform: scale(1.06);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}

.ai-chat-send:active {
  transform: scale(0.95);
}

/* Typing indicator */
.ai-msg.bot .typing-indicator {
  display: flex;
  gap: 5px;
  padding: 4px 0;
}

.ai-msg.bot .typing-indicator span {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: aiTypingBounce 1s infinite alternate;
}

.ai-msg.bot .typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.ai-msg.bot .typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aiTypingBounce {
  from { transform: translateY(0); opacity: 0.4; }
  to { transform: translateY(-6px); opacity: 1; }
}

.ai-assistant-widget.thinking .robot-core-inner {
  animation: robotThinking 0.6s ease-in-out infinite;
}

@keyframes robotThinking {
  0%, 100% { fill: #fbbf24; }
  50% { fill: #60a5fa; }
}

/* Mobile */
@media (max-width: 480px) {
  .ai-assistant-widget {
    bottom: 80px;
    left: 16px;
    z-index: 999;
  }

  .ai-chat-panel {
    width: calc(100vw - 32px);
    left: 0;
    bottom: 112px;
    max-height: calc(100vh - 200px);
  }

  .ai-robot-trigger {
    width: 80px;
    height: 92px;
  }

  .ai-robot-character {
    width: 80px;
    height: 88px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-robot-character,
  .robot-shadow,
  .robot-antenna-bulb,
  .robot-blink,
  .robot-core-inner,
  .robot-arm-left,
  .ai-robot-pulse-ring,
  .ai-robot-hint,
  .ai-chat-header-robot,
  .ai-status-dot {
    animation: none !important;
  }

  .ai-chat-panel {
    transition: opacity 0.2s ease, visibility 0.2s;
    transform: none !important;
  }

  .ai-assistant-widget.open .ai-chat-panel {
    animation: none;
  }
}
