/* ===============================
   Ask Adam Lite — Premium Widget UI (Enhanced Contrast)
   =============================== */

/* ---- Scope reset & guards (resist theme overrides) ---- */
#aalite-widget, .aalite-embed {
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--aa-text, #111827) !important; /* Added !important for better override */
}
#aalite-widget *, .aalite-embed * { 
  box-sizing: border-box; 
}

/* Neutralize aggressive theme styles */
#aalite-widget button, .aalite-embed button,
#aalite-widget textarea, .aalite-embed textarea {
  appearance: none; -webkit-appearance: none;
  background: none; border: 0; font: inherit; 
  color: inherit !important; /* Stronger inheritance */
}

/* Make sure we float over sticky headers/footers */
#aalite-widget { z-index: 999999; }

/* Force our rounded corners/background in case themes inject theirs */
#aalite-widget .aalite-panel, .aalite-embed .aalite-panel {
  border-radius: 20px !important;
  background: var(--aa-panel-bg, rgba(255,255,255,0.95)) !important;
  border: 1px solid var(--aa-panel-border, rgba(0,0,0,0.12)) !important;
  color: var(--aa-text, #111827) !important;
}

/* Close button with better contrast */
.aalite-close {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--aa-close-bg, rgba(0,0,0,0.08)) !important;
  color: var(--aa-close-text, #374151) !important; 
  transition: all .2s ease;
  font-weight: 600;
}
.aalite-close:hover { 
  background: var(--aa-close-hover-bg, rgba(0,0,0,0.15)) !important; 
  color: var(--aa-close-hover-text, #111827) !important;
}

/* Ensure embed panels are visible and centered nicely */
.aalite-embed .aalite-panel { display: block; margin: 10px auto; }

/* If theme zeroes buttons, make our FAB still visible */
#aalite-widget .aalite-btn { display: block; }

/* ===============================
   Enhanced Design tokens with better fallbacks
   =============================== */
:root {
  /* Teal colors */
  --aa-teal-1: #17a2a2; 
  --aa-teal-2: #0891b2; 
  --aa-teal-3: #0e7490;
  
  /* Light theme colors with better contrast */
  --aa-bg: #ffffff; 
  --aa-bg-soft: #f8fafc; 
  --aa-panel-bg: rgba(255,255,255,0.95);
  --aa-panel-border: rgba(0,0,0,0.12);
  --aa-border: #e5e7eb;
  --aa-text: #111827; 
  --aa-text-strong: #000000;
  --aa-muted: #6b7280;
  --aa-close-bg: rgba(0,0,0,0.08);
  --aa-close-text: #374151;
  --aa-close-hover-bg: rgba(0,0,0,0.15);
  --aa-close-hover-text: #111827;
  
  /* Shadows and effects */
  --aa-shadow: 0 12px 40px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08);
  --aa-shadow-soft: 0 6px 24px rgba(0,0,0,0.12);
  --aa-radius-xl: 20px;
  --aa-grad: linear-gradient(135deg, var(--aa-teal-1), var(--aa-teal-2));
  --aa-trans: all .25s cubic-bezier(.22,.61,.36,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark theme with high contrast */
    --aa-bg: #0f172a; 
    --aa-bg-soft: #1e293b; 
    --aa-panel-bg: rgba(15,23,42,0.95);
    --aa-panel-border: rgba(255,255,255,0.15);
    --aa-border: #334155;
    --aa-text: #f8fafc; 
    --aa-text-strong: #ffffff;
    --aa-muted: #94a3b8;
    --aa-close-bg: rgba(255,255,255,0.10);
    --aa-close-text: #cbd5e1;
    --aa-close-hover-bg: rgba(255,255,255,0.20);
    --aa-close-hover-text: #f8fafc;
    
    /* Enhanced shadows for dark mode */
    --aa-shadow: 0 20px 60px rgba(0,0,0,0.55), 0 6px 20px rgba(0,0,0,0.35);
    --aa-shadow-soft: 0 10px 28px rgba(0,0,0,0.45);
  }
}

/* ===============================
   Floating positions
   =============================== */
#aalite-widget.aalite-pos-bottom-right { position: fixed; right: 20px; bottom: 20px; }
#aalite-widget.aalite-pos-bottom-left  { position: fixed; left: 20px; bottom: 20px; }

/* ===============================
   Floating action button (FAB)
   =============================== */
#aalite-widget .aalite-btn{
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--aa-grad); 
  box-shadow: var(--aa-shadow-soft);
  cursor: pointer; position: relative; transition: var(--aa-trans);
}
#aalite-widget .aalite-btn::after{
  content:'✦'; position:absolute; inset:0; display:grid; place-items:center;
  color: #ffffff !important; /* Ensure white icon on colored background */
  font-size: 22px; text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
#aalite-widget .aalite-btn:hover{ transform: translateY(-2px) scale(1.02); }
#aalite-widget .aalite-btn:active{ transform: translateY(0) scale(.98); }

/* ===============================
   Panel with improved contrast
   =============================== */
#aalite-widget .aalite-panel,
.aalite-embed .aalite-panel{
  width: 360px; max-width: 100%; max-height: 70vh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--aa-panel-bg);
  backdrop-filter: saturate(120%) blur(18px);
  -webkit-backdrop-filter: saturate(120%) blur(18px);
  border: 1px solid var(--aa-panel-border);
  border-radius: var(--aa-radius-xl);
  box-shadow: var(--aa-shadow);
  color: var(--aa-text) !important;
}

@media (prefers-color-scheme: dark){
  #aalite-widget .aalite-panel, .aalite-embed .aalite-panel{
    background: linear-gradient(180deg, rgba(15,23,42,0.95), rgba(11,15,23,0.98));
    border-color: rgba(255,255,255,0.15) !important;
  }
}

/* ===============================
   Header with better text contrast
   =============================== */
.aalite-panel .aalite-head{
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(23,162,162,0.12), rgba(8,145,178,0.08));
  border-bottom: 1px solid var(--aa-border);
  color: var(--aa-text) !important;
}
.aalite-avatar{ 
  width: 30px; height: 30px; border-radius: 50%; 
  object-fit: cover; box-shadow: 0 2px 8px rgba(0,0,0,0.15); 
}
.aalite-avatar.aa-fallback{ 
  display: grid; place-items: center; 
  background: var(--aa-teal-2); 
  color: #ffffff !important; 
  font-weight: 700; 
}
.aalite-head strong{ 
  color: var(--aa-text-strong) !important; 
  letter-spacing: 0.2px; 
  font-weight: 600;
}

/* ===============================
   Body with enhanced message contrast
   =============================== */
.aalite-body{ 
  padding: 14px; overflow: auto; flex: 1; 
  background: var(--aa-bg); 
  color: var(--aa-text) !important;
}

.aa-msg{
  position: relative; margin: 10px 0; padding: 12px 14px; max-width: 85%;
  border-radius: 14px; line-height: 1.5; font-size: 14px; 
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  animation: aaPop .18s ease-out;
}

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

/* User messages with high contrast */
.aa-msg.user{ 
  margin-left: auto; 
  background: linear-gradient(135deg, #dcfdf7, #a7f3d0); 
  border: 1px solid #6ee7b7; 
  color: #064e3b !important;
}

/* Bot messages with improved readability */
.aa-msg.bot{ 
  background: linear-gradient(180deg, var(--aa-bg-soft), #f1f5f9); 
  border: 1px solid var(--aa-border); 
  color: var(--aa-text) !important;
}

/* Dark mode message improvements */
@media (prefers-color-scheme: dark) {
  .aa-msg.user {
    background: linear-gradient(135deg, #064e3b, #065f46);
    border: 1px solid #059669;
    color: #d1fae5 !important;
  }
  
  .aa-msg.bot {
    background: linear-gradient(180deg, var(--aa-bg-soft), #334155);
    border: 1px solid var(--aa-border);
    color: var(--aa-text) !important;
  }
}

/* Error messages */
.aa-msg.err{ 
  background: #fef2f2; 
  border: 1px solid #fecaca; 
  color: #991b1b !important; 
}

@media (prefers-color-scheme: dark) {
  .aa-msg.err {
    background: #450a0a;
    border: 1px solid #7f1d1d;
    color: #fca5a5 !important;
  }
}

/* Code styling with better contrast */
.aa-msg.bot code, .aa-msg.user code{
  background: rgba(0,0,0,0.08); 
  padding: 0.2rem 0.4rem; 
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; 
  font-size: 12px;
  color: #1f2937 !important;
  border: 1px solid rgba(0,0,0,0.1);
}

@media (prefers-color-scheme: dark) {
  .aa-msg.bot code, .aa-msg.user code {
    background: rgba(255,255,255,0.1);
    color: #e5e7eb !important;
    border: 1px solid rgba(255,255,255,0.2);
  }
}

/* Sources with improved visibility */
.aa-sources{ 
  font-size: 12px; 
  color: var(--aa-muted) !important; 
  margin-top: 6px; 
}
.aa-sources a{ 
  color: var(--aa-teal-2) !important; 
  text-decoration: none; 
  font-weight: 500;
}
.aa-sources a:hover{ 
  text-decoration: underline; 
  color: var(--aa-teal-1) !important;
}

/* Typing indicator */
.aa-typing{ 
  display: inline-flex; 
  gap: 4px; 
  align-items: center; 
}
.aa-typing::after{
  content: ''; width: 32px; height: 6px; border-radius: 6px;
  background: radial-gradient(var(--aa-muted) 2px, transparent 3px) 0 50%/8px 6px repeat-x;
  animation: aaDots 1.2s infinite steps(3,start);
}
@keyframes aaDots{ to{ transform: translateX(24px); } }

/* ===============================
   Form with enhanced contrast
   =============================== */
.aalite-form{
  display: flex; gap: 10px; padding: 12px; 
  border-top: 1px solid var(--aa-border);
  background: var(--aa-bg-soft);
}

.aalite-form textarea{
  flex: 1; min-height: 42px; max-height: 160px; resize: none;
  padding: 12px 14px; border: 1px solid var(--aa-border);
  border-radius: 12px; transition: var(--aa-trans);
  background: var(--aa-bg) !important;
  color: var(--aa-text) !important;
  font-size: 14px;
  min-width: 0;
}

.aalite-form textarea::placeholder {
  color: var(--aa-muted) !important;
  opacity: 0.8;
}

.aalite-form textarea:focus{ 
  outline: none; 
  border-color: var(--aa-teal-2); 
  box-shadow: 0 0 0 3px rgba(8,145,178,0.15); 
}

.aalite-form button{
  padding: 0 16px; border-radius: 12px;
  background: linear-gradient(135deg, #17a2a2, #0891b2);
  color: #ffffff !important;
  border: 0; cursor: pointer; font-weight: 600;
  transition: var(--aa-trans); min-width: 86px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  flex-shrink: 0;
  flex-grow: 0;
}

.aalite-form button:hover{ 
  transform: translateY(-1px); 
  box-shadow: var(--aa-shadow-soft); 
  background: linear-gradient(135deg, #0891b2, #0e7490);
}

.aalite-form button:disabled{ 
  opacity: 0.6; 
  cursor: not-allowed; 
  transform: none; 
}

/* ===============================
   Small screens
   =============================== */
@media (max-width: 480px){
  #aalite-widget .aalite-panel{ width: calc(100vw - 24px); }
}

/* ===============================
   Theme compatibility overrides
   =============================== */
#aalite-widget button, .aalite-embed button {
  line-height: 1 !important;
  box-shadow: none !important;
  text-decoration: none !important;
}

#aalite-widget .aalite-btn { 
  background-clip: padding-box !important; 
}

#aalite-widget .aalite-close {
  background-clip: padding-box !important;
  font-weight: 700 !important;
}

/* Force text colors in case themes override */
#aalite-widget * {
  color: inherit !important;
}

#aalite-widget .aalite-panel * {
  color: var(--aa-text) !important;
}

#aalite-widget .aalite-btn::after,
#aalite-widget .aalite-form button {
  color: #ffffff !important;
}

/* Ensure proper inheritance for nested elements */
#aalite-widget .aa-msg,
#aalite-widget .aa-msg *,
.aalite-embed .aa-msg,
.aalite-embed .aa-msg * {
  color: inherit !important;
}

/* ===============================
   Floating widget — Pro UI layout
   =============================== */
#aalite-widget.aalite-pos-bottom-right { position: fixed; right: 20px; bottom: 20px; }
#aalite-widget.aalite-pos-bottom-left  { position: fixed; left: 20px;  bottom: 20px; }

#aalite-widget.aalite-pos-bottom-right .aalite-panel { margin-right: 76px; }
#aalite-widget.aalite-pos-bottom-left  .aalite-panel { margin-left:  76px; }

.aa-pro-ui .aalite-panel {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity .3s ease, transform .3s cubic-bezier(.34,1.56,.64,1);
}
.aa-pro-ui .aalite-panel.visible {
    opacity: 1; transform: translateY(0) scale(1); pointer-events: all;
}
.aa-pro-ui .glassy {
    background: rgba(25,25,35,.95);
    backdrop-filter: blur(16px) saturate(180%);
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,.1);
    box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.aa-pro-ui .aalite-btn {
    width: 64px; height: 64px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #00f5a0, #00d9ff);
    color: #fff; border: none; cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,255,200,.4);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1), box-shadow .3s, background .3s;
    overflow: hidden;
}
.aa-pro-ui .aalite-btn:hover { transform: scale(1.08) rotate(5deg); box-shadow: 0 6px 30px rgba(0,255,200,.6); }
.aa-pro-ui .aalite-btn:active { transform: scale(1.02); }
.aa-pro-ui .fab-icon { position: absolute; transition: opacity .3s, transform .3s; }
.aa-pro-ui .fab-icon-plus  { opacity: 1; transform: rotate(0deg) scale(1); }
.aa-pro-ui .fab-icon-close { opacity: 0; transform: rotate(90deg) scale(.8); }
.aa-pro-ui .aalite-btn.is-open .fab-icon-plus  { opacity: 0; transform: rotate(-90deg) scale(.8); }
.aa-pro-ui .aalite-btn.is-open .fab-icon-close { opacity: 1; transform: rotate(0deg) scale(1); }
.aa-pro-ui .aalite-btn.is-open { background: linear-gradient(135deg, #ff6b6b, #ff8e53); box-shadow: 0 6px 30px rgba(255,107,107,.5); }
.aa-pro-ui .aa-placeholder { text-align: center; padding: 2rem 1.5rem; color: #d0d0d0; font-style: italic; font-size: 15px; }
.aa-pro-ui .anna-textarea {
    background: #0d1117; color: #fff; border: 1px solid #2d2f35;
    border-radius: 14px; padding: 12px 16px; resize: none; font-size: 14px;
    line-height: 1.5; min-height: 44px; transition: border-color .2s, box-shadow .2s;
}
.aa-pro-ui .anna-textarea:focus { outline: none; border-color: #00d9ff; box-shadow: 0 0 0 3px rgba(0,217,255,.15); }
.aa-pro-ui .glowing {
    background: linear-gradient(90deg, #00d9ff, #00f5a0); border: none;
    border-radius: 12px; color: #fff; padding: 12px; cursor: pointer;
    transition: opacity .2s, transform .2s;
}
.aa-pro-ui .glowing:hover { opacity: .9; transform: scale(1.05); }
.aa-pro-ui .glowing:active { transform: scale(0.98); }
.aa-pro-ui .sleek {
    padding: 18px 20px;
    background: linear-gradient(135deg, rgba(0,245,160,.15), rgba(0,217,255,.15));
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.aa-pro-ui .anna-title { font-size: 16px; font-weight: 600; color: #fff; letter-spacing: .3px; }
.aa-pro-ui .anna-subtitle { font-size: 13px; color: rgba(255,255,255,.65); }
.aa-pro-ui .anna-input-wrap { display: flex; gap: 10px; align-items: flex-end; }

/* ===============================
   Image upload (vision)
   =============================== */
.aalite-image-preview {
    position: relative;
    display: inline-block;
    margin: 0 0 8px;
}
.aalite-image-preview-img {
    max-width: 120px;
    max-height: 120px;
    border-radius: 10px;
    display: block;
    border: 1px solid rgba(0,0,0,.1);
}
.aalite-image-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #ff6b6b;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.aalite-image-remove:hover { background: #ff5252; }
.aalite-attach {
    background: transparent;
    border: 1px solid rgba(0,0,0,.15);
    border-radius: 10px;
    color: inherit;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, border-color .2s, opacity .2s;
}
.aalite-attach:hover { background: rgba(0,0,0,.05); }
.aalite-attach:disabled { opacity: .5; cursor: not-allowed; }
.aa-msg-img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    display: block;
    margin-bottom: 4px;
}

/* Pro UI variants for the floating widget */
.aa-pro-ui .aalite-attach {
    border: 1px solid #2d2f35;
    color: #fff;
    background: #0d1117;
    border-radius: 12px;
    padding: 10px;
}
.aa-pro-ui .aalite-attach:hover { background: #161b22; border-color: #00d9ff; }
.aa-pro-ui .aalite-image-preview-img { border-color: rgba(255,255,255,.15); }

/* ===============================
   Embed image-upload layout fixes
   =============================== */
#aalite-widget .anna-input-wrap,
.aalite-embed .anna-input-wrap {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: flex-end;
  width: 100%;
  flex-wrap: nowrap;
}

#aalite-widget .aalite-attach,
.aalite-embed .aalite-attach {
  flex-shrink: 0;
  flex-grow: 0;
  width: 42px;
  min-width: 42px;
}

#aalite-widget .aalite-image-preview,
.aalite-embed .aalite-image-preview {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(23, 162, 162, 0.08);
  border-top: 1px solid var(--aa-border);
  border-bottom: 1px solid var(--aa-border);
  font-size: 12px;
  color: var(--aa-muted);
  width: 100%;
  box-sizing: border-box;
  order: -1;
}

#aalite-widget .aalite-form,
.aalite-embed .aalite-form {
  flex-wrap: wrap;
}
