/* ============================================================
   ARIA Chatbot — aria.css  (PATCHED)
   Fixes:
     1. Mobile close button covered by chat window (z-index)
     2. iOS momentum scrolling for messages
     3. Mobile scroll/touch improvements
   
   HOW TO APPLY: Replace your current aria.css with this file,
   OR just apply the MOBILE PATCH section at the bottom of your
   existing aria.css.
   ============================================================ */

/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables ── */
:root {
  --aria-navy:        #0a1f44;
  --aria-navy-mid:    #12305f;
  --aria-navy-light:  #1a3a6b;
  --aria-accent:      #e8622c;
  --aria-accent-soft: #fdf0ea;
  --aria-white:       #ffffff;
  --aria-surface:     #f5f7fa;
  --aria-border:      #e4e8ef;
  --aria-text:        #1a2332;
  --aria-muted:       #6b7a92;
  --aria-bubble-user: #0a1f44;
  --aria-bubble-aria: #f0f2f5;
  --aria-shadow:      0 8px 40px rgba(10,31,68,.18), 0 2px 12px rgba(10,31,68,.10);
  --aria-radius:      18px;
  --aria-font:        'DM Sans', system-ui, sans-serif;
  --aria-font-mono:   'DM Mono', monospace;
  --aria-transition:  all .22s cubic-bezier(.4,0,.2,1);
}

/* ============================================================
   LAUNCHER BUTTON
   ============================================================ */
#aria-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 10000; /* ✅ FIX: must be ABOVE #aria-window (9999) */
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--aria-navy);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(10,31,68,.35);
  transition: var(--aria-transition);
  outline: none;
}

#aria-launcher:hover {
  transform: scale(1.08);
  background: var(--aria-navy-mid);
  box-shadow: 0 6px 28px rgba(10,31,68,.45);
}

#aria-launcher:active { transform: scale(.96); }

#aria-launcher .aria-icon-chat,
#aria-launcher .aria-icon-close {
  transition: var(--aria-transition);
  position: absolute;
}

#aria-launcher .aria-icon-close { opacity: 0; transform: rotate(-90deg) scale(.7); }

#aria-launcher.open .aria-icon-chat  { opacity: 0; transform: rotate(90deg) scale(.7); }
#aria-launcher.open .aria-icon-close { opacity: 1; transform: rotate(0deg) scale(1); }

/* Notification badge */
#aria-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: var(--aria-accent);
  border: 2px solid #fff;
  border-radius: 50%;
  font-family: var(--aria-font);
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--aria-transition);
  animation: aria-pulse-badge 2s ease infinite;
}

#aria-badge.hidden { opacity: 0; transform: scale(0); pointer-events: none; }

@keyframes aria-pulse-badge {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,98,44,.5); }
  50%       { box-shadow: 0 0 0 5px rgba(232,98,44,0); }
}

/* ============================================================
   CHAT WINDOW
   ============================================================ */
#aria-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 9999;
  width: 390px;
  height: 580px;
  display: flex;
  flex-direction: column;
  background: var(--aria-white);
  border-radius: var(--aria-radius);
  box-shadow: var(--aria-shadow);
  font-family: var(--aria-font);
  overflow: hidden;

  /* Closed state */
  opacity: 0;
  transform: translateY(20px) scale(.96);
  pointer-events: none;
  transition: opacity .25s cubic-bezier(.4,0,.2,1),
              transform .25s cubic-bezier(.4,0,.2,1);
}

#aria-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
#aria-header {
  background: linear-gradient(135deg, var(--aria-navy) 0%, var(--aria-navy-light) 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

#aria-header::before {
  content: '';
  position: absolute;
  top: -30px;
  right: -30px;
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,.04);
  border-radius: 50%;
}

#aria-header::after {
  content: '';
  position: absolute;
  bottom: -40px;
  left: 40px;
  width: 100px;
  height: 100px;
  background: rgba(255,255,255,.03);
  border-radius: 50%;
}

.aria-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  border: 2px solid rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.aria-avatar img,
.aria-msg-avatar img {
  filter: brightness(0) invert(1);
}

.aria-header-info { flex: 1; min-width: 0; }

.aria-header-name {
  color: var(--aria-white);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2px;
  margin: 0 0 2px;
}

.aria-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  color: rgba(255,255,255,.7);
  font-size: 12px;
}

.aria-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  animation: aria-breathe 2.5s ease infinite;
}

@keyframes aria-breathe {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}

.aria-header-actions { display: flex; gap: 4px; }

.aria-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.8);
  transition: var(--aria-transition);
  /* ✅ FIX: Ensure touch events work on mobile */
  -webkit-tap-highlight-color: rgba(255,255,255,.2);
  touch-action: manipulation;
}

.aria-header-btn:hover {
  background: rgba(255,255,255,.18);
  color: #fff;
}

/* ── Messages area ── */
#aria-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* ✅ FIX: iOS momentum scrolling */
  overscroll-behavior: contain;       /* ✅ FIX: Prevent page scroll bleed-through */
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

#aria-messages::-webkit-scrollbar { width: 4px; }
#aria-messages::-webkit-scrollbar-track { background: transparent; }
#aria-messages::-webkit-scrollbar-thumb { background: var(--aria-border); border-radius: 4px; }

/* ── Message bubbles ── */
.aria-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 86%;
  animation: aria-msg-in .2s ease;
}

@keyframes aria-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.aria-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.aria-msg.aria { align-self: flex-start; }

.aria-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--aria-navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.aria-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.aria-msg.user .aria-bubble {
  background: var(--aria-bubble-user);
  color: var(--aria-white);
  border-bottom-right-radius: 4px;
}

.aria-msg.aria .aria-bubble {
  background: var(--aria-bubble-aria);
  color: var(--aria-text);
  border-bottom-left-radius: 4px;
}

.aria-bubble ul {
  margin: 6px 0 0 0;
  padding-left: 18px;
}
.aria-bubble ul li { margin-bottom: 3px; }
.aria-bubble strong { font-weight: 600; }

/* Timestamp */
.aria-msg-time {
  font-size: 10px;
  color: var(--aria-muted);
  margin-top: 3px;
  padding: 0 4px;
  align-self: flex-end;
}

.aria-msg.user .aria-msg-time { text-align: right; }

/* ── Typing indicator ── */
#aria-typing {
  display: none;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  animation: aria-msg-in .2s ease;
}

#aria-typing.visible { display: flex; }

.aria-typing-bubble {
  background: var(--aria-bubble-aria);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.aria-dot {
  width: 7px;
  height: 7px;
  background: var(--aria-muted);
  border-radius: 50%;
  animation: aria-bounce 1.2s ease infinite;
}
.aria-dot:nth-child(2) { animation-delay: .18s; }
.aria-dot:nth-child(3) { animation-delay: .36s; }

@keyframes aria-bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: .5; }
  40%            { transform: translateY(-5px); opacity: 1;  }
}

/* ── Action cards (summary, confirm, etc.) ── */
.aria-card {
  background: var(--aria-white);
  border: 1px solid var(--aria-border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 8px;
  font-size: 13px;
}

.aria-card-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--aria-navy);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.aria-card-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--aria-surface);
  color: var(--aria-text);
  font-size: 12.5px;
}

.aria-card-row:last-child { border-bottom: none; }
.aria-card-row-label { color: var(--aria-muted); font-weight: 500; }

.aria-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.aria-btn {
  flex: 1;
  padding: 9px 12px;
  border-radius: 10px;
  border: none;
  font-family: var(--aria-font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--aria-transition);
  touch-action: manipulation; /* ✅ FIX: Faster tap on mobile */
}

.aria-btn-primary {
  background: var(--aria-navy);
  color: var(--aria-white);
}
.aria-btn-primary:hover { background: var(--aria-navy-mid); }

.aria-btn-secondary {
  background: var(--aria-surface);
  color: var(--aria-text);
  border: 1px solid var(--aria-border);
}
.aria-btn-secondary:hover { background: var(--aria-border); }

/* Quick reply chips */
.aria-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.aria-chip {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--aria-border);
  background: var(--aria-white);
  color: var(--aria-navy);
  font-family: var(--aria-font);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--aria-transition);
  white-space: nowrap;
  touch-action: manipulation; /* ✅ FIX: Faster tap on mobile */
}

.aria-chip:hover {
  border-color: var(--aria-navy);
  background: var(--aria-surface);
}

/* Success / error banners */
.aria-toast {
  margin: 0 4px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  animation: aria-msg-in .2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.aria-toast.success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.aria-toast.error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ── Divider (date / label) ── */
.aria-divider {
  text-align: center;
  font-size: 11px;
  color: var(--aria-muted);
  position: relative;
  margin: 4px 0;
}

.aria-divider::before,
.aria-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--aria-border);
}
.aria-divider::before { left: 0; }
.aria-divider::after  { right: 0; }

/* ── Input area ── */
#aria-input-area {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--aria-border);
  background: var(--aria-white);
  flex-shrink: 0;
}

.aria-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--aria-surface);
  border: 1.5px solid var(--aria-border);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color .18s;
}

.aria-input-row:focus-within {
  border-color: var(--aria-navy);
}

#aria-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--aria-font);
  font-size: 14px;
  color: var(--aria-text);
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 22px;
  line-height: 1.5;
  padding: 0;
}

#aria-input::placeholder { color: var(--aria-muted); }

#aria-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--aria-navy);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--aria-transition);
  touch-action: manipulation;
}

#aria-send:hover { background: var(--aria-navy-mid); transform: scale(1.05); }
#aria-send:disabled { background: var(--aria-border); cursor: not-allowed; transform: none; }

/* ── Footer ── */
#aria-footer {
  text-align: center;
  padding: 6px 16px 10px;
  font-size: 11px;
  color: var(--aria-muted);
  background: var(--aria-white);
  flex-shrink: 0;
}

#aria-footer a {
  color: var(--aria-navy);
  font-weight: 600;
  text-decoration: none;
  transition: color .18s;
}
#aria-footer a:hover { color: var(--aria-accent); }

/* ── Close Button ── */
.aria-close-btn {
  display: none; /* Hidden on desktop — launcher button closes it */
}

@media (max-width: 480px) {
  .aria-close-btn {
    display: flex !important; /* Always visible on mobile */
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.15) !important;
    border-radius: 8px !important;
    width: 34px !important;
    height: 34px !important;
  }
  .aria-close-btn:hover {
    background: rgba(255,255,255,0.25) !important;
  }
}

/* ============================================================
   MOBILE — PATCHED
   ============================================================ */
@media (max-width: 480px) {
  #aria-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;     /* ✅ FIX: Prevent overflow on small phones */
    border-radius: 0;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    /* ✅ FIX: Prevent window from blocking the launcher close button */
    /* The launcher z-index (10000) is now above window (9999) */
  }

  #aria-window.open {
    transform: translateY(0) scale(1);
  }

  #aria-window:not(.open) {
    transform: translateY(100%);
  }

  #aria-launcher {
    bottom: 20px;
    right: 20px;
    z-index: 10000; /* ✅ Must stay above window on mobile */
  }

  /* ✅ FIX: Make chat window leave space for the launcher button at bottom */
  #aria-messages {
    padding-bottom: 0;
    /* iOS safe area support */
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  #aria-input-area {
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  }

  /* ✅ FIX: Larger touch targets on mobile */
  .aria-chip {
    padding: 8px 14px;
    font-size: 13px;
  }

  .aria-btn {
    padding: 12px 16px;
    font-size: 14px;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  #aria-window, #aria-launcher, .aria-msg,
  .aria-dot, .aria-status-dot { animation: none !important; transition: none !important; }
}

/* ── Inline Confirm Card ── */
.aria-confirm-card {
  background: var(--aria-white);
  border: 1.5px solid #fecaca;
  border-radius: 12px;
  padding: 14px 16px;
  margin: 4px 0;
  animation: aria-msg-in .2s ease;
}

.aria-confirm-text {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--aria-text);
  margin: 0 0 12px;
  line-height: 1.5;
}

.aria-confirm-text small {
  display: block;
  font-weight: 400;
  color: var(--aria-muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ── Danger Button ── */
.aria-btn-danger {
  background: #dc2626;
  color: #ffffff;
}
.aria-btn-danger:hover { background: #b91c1c; }

/* ── Restored messages — slightly faded ── */
.aria-msg.aria-restored .aria-bubble {
  opacity: 0.72;
}

/* ── Rate limit bubble ── */
.aria-rl-bubble {
  background: #fef9c3 !important;
  color: #713f12 !important;
  border: 1px solid #fde68a;
  font-size: 13px;
}

.aria-rl-bubble a { color: var(--aria-accent) !important; }

/* ── Status text in header ── */
#aria-status-text {
  transition: color .2s;
}

/* ── Toast links ── */
.aria-toast a {
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
}