/* ══ AI CHAT ══ */

/* FAB */
#ai-fab {
  position: fixed;
  bottom: 100px;
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--blue-main);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,80,160,0.35);
  z-index: 1000;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}
#ai-fab:active { transform: scale(0.93); box-shadow: 0 2px 8px rgba(0,80,160,0.25); }
#ai-fab .ai-fab-icon { width: 28px; height: 28px; object-fit: contain; filter: brightness(0) invert(1); position: relative; z-index: 1; }
#ai-fab .ai-fab-pulse {
  position: absolute;
  top: -3px; right: -3px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #CF142B;
  border: 2px solid #fff;
  display: none;
  z-index: 2;
}
#ai-fab.has-new .ai-fab-pulse { display: block; }

/* Sonar attention rings */
#ai-fab.fab-attention::before,
#ai-fab.fab-attention::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--blue-main);
  animation: fab-sonar 2.4s ease-out infinite;
  z-index: 0;
}
#ai-fab.fab-attention::after { animation-delay: 1.0s; }

@keyframes fab-sonar {
  0%   { transform: scale(1);   opacity: 0.55; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* Hide FAB when any overlay is open */
body.ma-overlay-open #ai-fab { opacity: 0; pointer-events: none; transition: opacity 0.2s; }

/* Backdrop */
#ai-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1050;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#ai-backdrop.open { opacity: 1; pointer-events: all; }

/* Panel */
#ai-panel {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: 72dvh;
  background: #fff;
  border-radius: 20px 20px 0 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32,0.72,0,1);
  box-shadow: 0 -6px 32px rgba(0,50,120,0.18);
  overflow: hidden;
}
#ai-panel.open { transform: translateY(0); }

/* Handle */
#ai-handle {
  width: 36px; height: 4px;
  background: rgba(0,0,0,0.14);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

/* Header */
#ai-header {
  display: flex;
  align-items: center;
  padding: 10px 14px 12px;
  border-bottom: 1px solid rgba(0,60,120,0.08);
  flex-shrink: 0;
  gap: 10px;
}
#ai-header-avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--blue-main);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
#ai-header-avatar img { width: 22px; height: 22px; filter: brightness(0) invert(1); object-fit: contain; }
#ai-header-name { font-size: 14px; font-weight: 700; color: var(--text); }
#ai-header-sub { font-size: 10px; color: var(--text-light); font-weight: 600; }
#ai-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-light);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}

/* Messages */
#ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.ai-msg-wrap { display: flex; flex-direction: column; max-width: 85%; }
.ai-msg-wrap.user { align-self: flex-end; align-items: flex-end; }
.ai-msg-wrap.assistant { align-self: flex-start; align-items: flex-start; }

.ai-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.55;
  font-weight: 500;
  word-break: break-word;
}
.ai-bubble p { margin: 0 0 4px; }
.ai-bubble p:last-child { margin: 0; }
.ai-msg-wrap.user .ai-bubble {
  background: var(--blue-main);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}
.ai-msg-wrap.assistant .ai-bubble {
  background: #f0f4f8;
  color: var(--text);
  border-radius: 16px 16px 16px 4px;
}

/* Action chips */
.ai-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ai-action-chip {
  padding: 6px 12px;
  border: 1.5px solid var(--blue-main);
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--blue-main);
  cursor: pointer;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.ai-action-chip:active { background: var(--blue-main); color: #fff; }

/* Icon suggestions grid (5 icons, 5-column) */
.ai-icon-suggestions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-top: 14px;
}
.ai-icon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: var(--blue-ice);
  border: 1.5px solid var(--blue-wash);
  border-radius: 12px;
  padding: 10px 4px 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.14s, border-color 0.14s;
}
.ai-icon-btn:active { background: var(--blue-wash); border-color: var(--blue-main); }
.ai-icon-btn-img { width: 26px; height: 26px; object-fit: contain; }
.ai-icon-btn-label { font-size: 9.5px; font-weight: 700; color: var(--text); text-align: center; line-height: 1.2; }

/* New Chat button */
#ai-new-chat {
  margin-left: auto;
  background: none;
  border: 1.5px solid rgba(0,60,120,0.14);
  border-radius: 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 10px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s;
}
#ai-new-chat:active { border-color: var(--blue-main); color: var(--blue-main); }

/* Quick suggestions (initial state) */
.ai-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ai-suggestion {
  padding: 7px 13px;
  background: var(--blue-ice);
  border: 1.5px solid var(--blue-wash);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue-main);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Typing indicator */
#ai-typing { display: none; align-self: flex-start; padding: 10px 14px; }
#ai-typing.show { display: flex; gap: 5px; align-items: center; }
.ai-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-light);
  animation: ai-bounce 1.2s infinite ease-in-out;
}
.ai-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Flowing paragraph animation */
@keyframes ara-flow {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ara-chunk {
  opacity: 0;
  animation: ara-flow 0.38s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  margin: 0 0 4px;
}
.ara-chunk:last-child { margin-bottom: 0; }

/* Formatting colors */
.ara-red  { color: #CF142B; font-weight: 600; }
.ara-blue { color: #0077B6; font-weight: 600; }

/* Input bar */
#ai-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(0,60,120,0.08);
  flex-shrink: 0;
  background: #fff;
}
#ai-input {
  flex: 1;
  border: 1.5px solid rgba(0,60,120,0.14);
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text);
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s;
}
#ai-input:focus { border-color: var(--blue-main); background: #fff; }
#ai-input::placeholder { color: var(--text-light); }
#ai-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--blue-main);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
}
#ai-send:active { transform: scale(0.9); }
#ai-send svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
#ai-send:disabled { background: #ccc; cursor: default; }
