/* ── ELE WIDGET — PIA Chat ─────────────────────────────────────── */

:root {
  --ele-purple: #691CFF;
  --ele-teal:   #00D6C5;
  --ele-ink:    #1A1A2E;
  --ele-body:   #4D4D4D;
  --ele-muted:  #7A7D8A;
  --ele-bg:     #F0F2F6;
  --ele-white:  #FFFFFF;
  --ele-border: #E3E5EC;
}

/* ── BUBBLE ─────────────────────────────────────────────────────── */
.ele-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ele-purple);
  box-shadow: 0 4px 16px rgba(105, 28, 255, 0.25);
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  padding: 0;
  transition: transform 200ms ease, box-shadow 200ms ease;
  outline: none;
}
.ele-bubble:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(105, 28, 255, 0.35);
}
.ele-bubble:active {
  transform: scale(0.97);
}
.ele-bubble svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

/* Badge */
.ele-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ele-teal);
  color: var(--ele-white);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ele-white);
  opacity: 0;
  transform: scale(0);
  transition: opacity 200ms ease, transform 200ms ease;
}
.ele-badge.is-visible {
  opacity: 1;
  transform: scale(1);
}

/* ── PROACTIVE GREETING ─────────────────────────────────────────── */
.ele-greeting {
  position: fixed;
  bottom: 88px;
  right: 20px;
  width: 280px;
  background: var(--ele-white);
  border: 1px solid var(--ele-border);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  padding: 14px 16px;
  z-index: 9998;
  font-family: 'Inter', sans-serif;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 280ms ease, transform 280ms ease;
  pointer-events: none;
}
.ele-greeting.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}
.ele-greeting-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.ele-greeting-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ele-purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 600;
  color: var(--ele-white);
  flex-shrink: 0;
}
.ele-greeting-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--ele-ink);
  line-height: 1;
}
.ele-greeting-role {
  font-size: 10px;
  color: var(--ele-muted);
  line-height: 1;
  margin-top: 2px;
}
.ele-greeting-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  color: var(--ele-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 150ms ease;
  outline: none;
}
.ele-greeting-close:hover { color: var(--ele-ink); }
.ele-greeting-text {
  font-size: 13px;
  color: var(--ele-body);
  line-height: 1.5;
  cursor: pointer;
}

/* ── PANEL ──────────────────────────────────────────────────────── */
.ele-panel {
  position: fixed;
  bottom: 88px;
  right: 20px;
  width: 380px;
  height: 520px;
  min-width: 320px;
  min-height: 400px;
  max-width: 520px;
  max-height: 720px;
  resize: none;
  background: var(--ele-white);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: auto;
  font-family: 'Inter', sans-serif;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 300ms ease, transform 300ms ease;
  pointer-events: none;
}
.ele-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Header */
.ele-header {
  background: var(--ele-purple);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 16px 16px 0 0;
  flex-shrink: 0;
}
.ele-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--ele-white);
  flex-shrink: 0;
}
.ele-header-info {
  flex: 1;
  min-width: 0;
}
.ele-header-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--ele-white);
  line-height: 1.2;
}
.ele-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.ele-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ele-teal);
  flex-shrink: 0;
}
.ele-header-online {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}
.ele-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ele-header-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: rgba(255, 255, 255, 0.7);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms ease, background 150ms ease;
  outline: none;
}
.ele-header-btn:hover {
  color: var(--ele-white);
  background: rgba(255, 255, 255, 0.1);
}

/* Messages area */
.ele-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.ele-messages::-webkit-scrollbar {
  width: 4px;
}
.ele-messages::-webkit-scrollbar-track {
  background: transparent;
}
.ele-messages::-webkit-scrollbar-thumb {
  background: var(--ele-border);
  border-radius: 2px;
}

/* Message rows */
.ele-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}
.ele-msg-row--ele { align-self: flex-start; }
.ele-msg-row--user { align-self: flex-end; flex-direction: row-reverse; }

/* Ele avatar in messages */
.ele-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ele-purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  color: var(--ele-white);
  flex-shrink: 0;
  align-self: flex-end;
  overflow: hidden;
}

.ele-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* Bubbles */
.ele-bubble-msg {
  max-width: 85%;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  border-radius: 2px 12px 12px 12px;
  background: var(--ele-bg);
  color: var(--ele-ink);
  animation: eleFadeIn 250ms ease;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
}
.ele-msg-row--user .ele-bubble-msg {
  background: var(--ele-purple);
  color: var(--ele-white);
  border-radius: 12px 2px 12px 12px;
}

/* Links inside Ele messages */
.ele-bubble-msg a {
  color: var(--ele-purple);
  font-weight: 500;
  text-decoration: none;
}
.ele-bubble-msg a:hover { text-decoration: underline; }

/* Booking button */
.ele-booking-btn {
  display: inline-block;
  border: 1px solid var(--ele-purple);
  border-radius: 8px;
  padding: 6px 14px;
  color: var(--ele-purple) !important;
  font-weight: 500;
  text-decoration: none !important;
  margin-top: 8px;
  font-size: 13px;
  transition: background 150ms ease, color 150ms ease;
}
.ele-booking-btn:hover {
  background: var(--ele-purple);
  color: var(--ele-white) !important;
  text-decoration: none !important;
}

/* Typing indicator */
.ele-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 14px;
}
.ele-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ele-muted);
  animation: eleTypingBounce 1.2s ease-in-out infinite;
}
.ele-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ele-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Input area */
.ele-input-area {
  border-top: 0.5px solid var(--ele-border);
  padding: 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.ele-input {
  flex: 1;
  border-radius: 20px;
  background: var(--ele-bg);
  border: none;
  outline: none;
  padding: 8px 16px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  color: var(--ele-ink);
  resize: none;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
}
.ele-input::placeholder { color: var(--ele-muted); }

.ele-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ele-purple);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms ease, transform 150ms ease;
  outline: none;
}
.ele-send-btn:hover { background: #5a15e0; }
.ele-send-btn:active { transform: scale(0.93); }
.ele-send-btn:disabled { background: var(--ele-border); cursor: not-allowed; }
.ele-send-btn svg {
  width: 16px;
  height: 16px;
}

/* Footer */
.ele-footer {
  text-align: center;
  padding: 4px 0 8px;
  font-size: 10px;
  color: var(--ele-muted);
  flex-shrink: 0;
}

/* ── ANIMATIONS ─────────────────────────────────────────────────── */
@keyframes eleFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes eleTypingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

/* ── FILE UPLOAD ────────────────────────────────────────────────── */
.ele-file-hidden {
  display: none;
}
.ele-attach-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--ele-muted);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms ease;
  outline: none;
  flex-shrink: 0;
}
.ele-attach-btn:hover {
  color: var(--ele-purple);
}
.ele-bubble-file {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ele-file-preview {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  object-fit: contain;
}
.ele-file-name {
  font-size: 11px;
  opacity: 0.7;
}
.ele-file-icon {
  font-size: 20px;
}

/* ── PANEL SIZES ────────────────────────────────────────────────── */
.ele-panel--md { width: 380px; height: 520px; }
.ele-panel--lg { width: 440px; height: 620px; }
.ele-panel--xl { width: 500px; height: 700px; }

/* ── MOBILE (< 640px) ───────────────────────────────────────────── */
@media (max-width: 639px) {
  /* Remove tap highlight flash on iOS/Android */
  .ele-bubble,
  .ele-header-btn,
  .ele-send-btn,
  .ele-greeting-close,
  .ele-greeting-text {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .ele-bubble {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }
  .ele-bubble svg {
    width: 23px;
    height: 23px;
  }
  .ele-greeting {
    bottom: 80px;
    right: 16px;
    width: calc(100vw - 32px);
    max-width: 320px;
  }
  .ele-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: none;
    max-height: none;
    min-width: unset;
    min-height: unset;
    resize: none;
    border-radius: 0;
    transform: translateY(100%);
    transition: transform 350ms ease, opacity 200ms ease;
    opacity: 1;
  }
  .ele-panel.is-open {
    transform: translateY(0);
    opacity: 1;
  }
  .ele-header {
    border-radius: 0;
    padding-top: max(14px, env(safe-area-inset-top));
  }
  .ele-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  /* Prevent iOS zoom on input focus (font-size must be >= 16px) */
  .ele-input {
    font-size: 16px;
  }
}

/* ── MOBILE KEYBOARD FIX (≤ 768px) ─────────────────────────────── */
@media (max-width: 768px) {
  .ele-panel.is-open {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .ele-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }
  .ele-input-area {
    flex-shrink: 0;
    padding: 12px 16px;
    padding-bottom: env(safe-area-inset-bottom, 12px);
    background: var(--ele-white);
    border-top: 1px solid var(--ele-border);
  }
}

/* ── REDUCED MOTION ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ele-bubble,
  .ele-panel,
  .ele-greeting,
  .ele-bubble-msg,
  .ele-badge {
    transition: none;
    animation: none;
  }
  .ele-panel { transform: none; opacity: 0; }
  .ele-panel.is-open { opacity: 1; }
  .ele-typing-dot { animation: none; }
}

/* ── DARK MODE ──────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  .ele-panel         { background: #12121C; }
  .ele-header        { background: #691CFF; }
  .ele-bubble-msg    { background: #1E1E2E; color: #E0E0EC; border: 1px solid #2A2A3C; }
  .ele-msg-row--user .ele-bubble-msg { background: #691CFF; color: white; border: none; }
  .ele-input         { background: #1A1A28; color: #E0E0EC; border: 1px solid #2A2A3C; }
  .ele-input::placeholder { color: #666680; }
  .ele-input-area    { border-top-color: #2A2A3C; }
  .ele-send-btn      { background: #691CFF; }
  .ele-send-btn:disabled { background: #2A2A3C; }
  .ele-footer        { color: #555568; }
  .ele-greeting      { background: #1E1E2E; color: #E0E0EC; border: 1px solid #2A2A3C; box-shadow: 0 4px 20px rgba(0,0,0,0.4); }
  .ele-greeting-name { color: #E0E0EC; }
  .ele-greeting-text { color: #C0C0CC; }
  .ele-messages::-webkit-scrollbar-thumb { background: #2A2A3C; }
}
