/* =======================================================================
   Ehitale AI Widget — FINAL v6
   Pixel-accurate BotPenguin replication (Images 3 & 4 reference)
   
   KEY CORRECTIONS vs previous versions:
   ✓ Flat vivid blue header (no gradient) with proper rounded corners
   ✓ Chip items CENTERED (emoji + text, centered alignment)
   ✓ Sentence Case chip text (JS handles conversion)
   ✓ Grey filled-circle send button (not transparent paper plane)
   ✓ 8px spacing system throughout
   ✓ Generous bubble padding (16px 20px)
   ✓ Large border-radius on all bubbles
   ✓ Pure white chat background
   ✓ App-like feel, not web-like
   ======================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,500;0,600;0,700&display=swap');

/* ── CSS Variables ─────────────────────────────────────────────────────── */
#ehitale-widget-root {
  --blue:    #2563EB;          /* BotPenguin vivid blue — PHP overrides this */
  --blue-dk: #1D4ED8;
  --ink:     #1C1C1E;
  --sub:     #6B7280;
  --bdr:     #E5E7EB;
  --bg-msg:  #EEEFF1;          /* bot bubble background — light grey */
  --bg-page: #FFFFFF;          /* chat area background — pure white */
  --white:   #FFFFFF;
  --send-bg: #9CA3AF;          /* send button grey */
  --r-bubble:18px;             /* bubble corner radius */
  --shadow:  0 8px 40px rgba(0,0,0,.15), 0 2px 8px rgba(0,0,0,.08);
  --ff:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing scale */
  --sp-1: 4px;   --sp-2: 8px;   --sp-3: 12px;
  --sp-4: 16px;  --sp-5: 20px;  --sp-6: 24px;
}

/* ── Base reset ──────────────────────────────────────────────────────────*/
#ehitale-widget-root,
#ehitale-widget-root * {
  box-sizing: border-box; margin: 0; padding: 0;
  font-family: var(--ff);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Root positioning ────────────────────────────────────────────────── */
#ehitale-widget-root   { position: fixed; z-index: 2147483647; }
.ehi-pos-bottom-right  { bottom: 24px; right: 24px; }
.ehi-pos-bottom-left   { bottom: 24px; left:  24px; }

/* ═══════════════════════════════════════════════════════════════════════
   LAUNCHER  —  white ring + solid fill circle
   ══════════════════════════════════════════════════════════════════════ */
.ehi-launcher {
  position: relative; display: block;
  width: 56px; height: 56px; border-radius: 50%;
  border: none; padding: 0; background: transparent;
  cursor: pointer; outline: none;
  transition: transform .22s ease;
}
.ehi-launcher:hover  { transform: scale(1.07); }
.ehi-launcher:active { transform: scale(.94);  }

.ehi-launcher::before {
  content: ''; position: absolute; inset: -4px; border-radius: 50%;
  border: 3px solid var(--white);
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  pointer-events: none;
}
.ehi-launcher-circle {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--blue); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.ehi-launcher-circle img,
.ehi-launcher-circle svg { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }

.ehi-badge {
  position: absolute; top: 0; right: 0;
  min-width: 18px; height: 18px; border-radius: 9px;
  background: #EF4444; border: 2px solid var(--white);
  font-size: 10px; font-weight: 700; color: var(--white);
  display: flex; align-items: center; justify-content: center; padding: 0 3px; z-index: 1;
}
.ehi-badge.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════════════════
   PANEL CONTAINER
   ══════════════════════════════════════════════════════════════════════ */
.ehi-panel {
  position: absolute;
  width: 380px; max-height: 600px;
  background: var(--bg-page);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  bottom: 72px;
  transition: opacity .2s ease, transform .28s cubic-bezier(.34,1.2,.64,1);
}
.ehi-pos-bottom-right .ehi-panel { right: 0; transform-origin: bottom right; }
.ehi-pos-bottom-left  .ehi-panel { left:  0; transform-origin: bottom left;  }
.ehi-panel.hidden { opacity: 0; transform: scale(.88) translateY(14px); pointer-events: none; }

/* ═══════════════════════════════════════════════════════════════════════
   HEADER  — flat vivid blue, generously padded, all elements centered
   Reference: BotPenguin Image 3/4 — flat blue card, 76px tall
   ══════════════════════════════════════════════════════════════════════ */
.ehi-header {
  flex-shrink: 0;
  background: var(--blue);
  padding: 14px 20px 14px 16px;
  display: flex; align-items: center; gap: 14px;
  min-height: 76px;
  border-radius: 16px 16px 0 0;
}

/* Avatar: white circle, border, icon/image inside */
.ehi-h-av {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--white);
  border: 3px solid rgba(255,255,255,.75);
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.ehi-h-av img, .ehi-h-av svg {
  width: 100%; height: 100%; object-fit: cover; display: block;
}

/* Name + subtitle */
.ehi-h-info { flex: 1; min-width: 0; }
.ehi-h-name {
  font-size: 18px; font-weight: 700; line-height: 1.2;
  color: var(--white);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ehi-h-sub {
  display: flex; align-items: center; gap: 5px;
  margin-top: 3px;
  font-size: 12.5px; font-weight: 400;
  color: rgba(255,255,255,.82); line-height: 1.3;
}
.ehi-h-sub svg { flex-shrink: 0; }

/* Action buttons: dots + close */
.ehi-h-btns { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ehi-h-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.22);
  border: none; cursor: pointer; color: var(--white);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.ehi-h-btn:hover { background: rgba(255,255,255,.38); }
.ehi-h-btn svg   { display: block; }

/* ═══════════════════════════════════════════════════════════════════════
   MESSAGES AREA  — pure white, scrollable
   ══════════════════════════════════════════════════════════════════════ */
.ehi-messages {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 20px 16px 8px;
  background: var(--bg-page);
  display: flex; flex-direction: column;
  gap: 0;
}
.ehi-messages::-webkit-scrollbar { width: 3px; }
.ehi-messages::-webkit-scrollbar-thumb { background: var(--bdr); border-radius: 3px; }

/* Spacer between message groups */
.ehi-gap { height: 16px; flex-shrink: 0; }

/* Message row */
.ehi-msg { display: flex; align-items: flex-end; gap: 10px; }
.ehi-msg + .ehi-msg { margin-top: 8px; }
.ehi-msg.user { flex-direction: row-reverse; }

/* Bot avatar circle — sits to the LEFT */
.ehi-av {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--white); border: 1.5px solid var(--bdr);
  overflow: hidden; flex-shrink: 0; align-self: flex-end;
  display: flex; align-items: center; justify-content: center;
}
.ehi-av img, .ehi-av svg { width: 100%; height: 100%; object-fit: cover; display: block; }
.ehi-av.ghost  { visibility: hidden; }    /* preserve column width, hide avatar */
.ehi-av.hidden { display: none; }         /* collapse completely (e.g. user messages) */

/* ── BUBBLES ─────────────────────────────────────────────────────────── */
.ehi-bubble {
  max-width: 82%;
  padding: 16px 20px;
  font-size: 15.5px; font-weight: 400; line-height: 1.6;
  word-break: break-word;
  letter-spacing: -.01em;
}

/* Bot bubble — light grey, flat top-left */
.ehi-msg.ai .ehi-bubble {
  background: var(--bg-msg);
  color: var(--ink);
  border-radius: 4px var(--r-bubble) var(--r-bubble) var(--r-bubble);
}

/* User bubble — vivid blue, flat bottom-right */
.ehi-msg.user .ehi-bubble {
  background: var(--blue);
  color: var(--white);
  border-radius: var(--r-bubble) var(--r-bubble) 4px var(--r-bubble);
}

/* Timestamp row: "Bot · 12:35 PM" */
.ehi-ts {
  font-size: 11.5px; color: var(--sub); font-weight: 400;
  padding: 5px 0 14px 48px;    /* indent to align under bubble (past avatar) */
  line-height: 1;
}
.ehi-ts.user-ts { text-align: right; padding-right: 2px; padding-left: 0; }

/* Typing indicator */
.ehi-typing .ehi-bubble {
  display: flex; align-items: center; gap: 5px;
  padding: 18px 20px;
  background: var(--bg-msg);
  border-radius: 4px var(--r-bubble) var(--r-bubble) var(--r-bubble);
}
.ehi-td {
  width: 7px; height: 7px; border-radius: 50%;
  background: #9CA3AF; opacity: .6;
  animation: ehiType .9s ease-in-out infinite;
}
.ehi-td:nth-child(2) { animation-delay: .18s; }
.ehi-td:nth-child(3) { animation-delay: .36s; }

/* ═══════════════════════════════════════════════════════════════════════
   CHIP CARD  — BotPenguin-accurate
   
   Layout:
     [avatar 38px] [chip-card — fills remaining width]
                       [icon  text]    ← CENTERED in each row
                       ──────────────
                       [icon  text]    ← CENTERED
   
   The card aligns with bot bubbles (avatar on left).
   Items are CENTERED (not left-aligned).
   ══════════════════════════════════════════════════════════════════════ */
.ehi-chip-row {
  display: flex; align-items: flex-start;
  gap: 10px;
  margin-top: 8px;
}

.ehi-chip-card {
  flex: 1;
  background: var(--white);
  border: 1px solid var(--bdr);
  border-radius: 4px 14px 14px 14px;  /* matches bot bubble shape */
  overflow: hidden;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}

/* Individual chip button — CENTERED content */
.ehi-chip {
  display: flex;
  align-items: center;
  justify-content: center;            /* CENTER all chip content */
  gap: 10px;
  width: 100%;
  min-height: 52px;                   /* comfortable touch target */
  padding: 12px 20px;
  border: none;
  border-bottom: 1px solid var(--bdr);
  background: var(--white);
  cursor: pointer;
  font-size: 15px; font-weight: 600;  /* bolder than messages */
  color: var(--blue);
  text-align: center;
  line-height: 1.3;
  transition: background .12s ease;
  -webkit-tap-highlight-color: rgba(37,99,235,.1);
}
.ehi-chip:last-child  { border-bottom: none; }
.ehi-chip:hover       { background: #EFF6FF; }
.ehi-chip:active      { background: #DBEAFE; }
.ehi-chip-ico         { font-size: 20px; flex-shrink: 0; line-height: 1; }

/* ── Product cards ───────────────────────────────────────────────────── */
.ehi-products { display: flex; gap: 10px; overflow-x: auto; padding: 8px 0 4px 48px; scrollbar-width: none; }
.ehi-products::-webkit-scrollbar { display: none; }
.ehi-prod {
  min-width: 114px; max-width: 114px;
  background: var(--white); border: 1px solid var(--bdr);
  border-radius: 12px; overflow: hidden; cursor: pointer; flex-shrink: 0;
  transition: box-shadow .18s;
}
.ehi-prod:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.ehi-prod img   { width: 100%; height: 82px; object-fit: cover; display: block; background: var(--bg-msg); }
.ehi-prod-inf   { padding: 8px 10px 10px; }
.ehi-prod-name  { font-size: 12px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ehi-prod-price { font-size: 12px; font-weight: 700; color: var(--blue); margin-top: 3px; }

/* ═══════════════════════════════════════════════════════════════════════
   INPUT AREA
   Reference: large pill, grey border, smiley + grey-circle send
   ══════════════════════════════════════════════════════════════════════ */
.ehi-input-area {
  flex-shrink: 0;
  padding: 12px 16px 16px;
  background: var(--bg-page);
  border-top: 1px solid var(--bdr);
}

.ehi-input-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--white);
  border: 1.5px solid var(--bdr);
  border-radius: 32px;
  padding: 10px 10px 10px 18px;
  min-height: 52px;
  transition: border-color .18s;
}
.ehi-input-pill:focus-within { border-color: var(--blue); }

.ehi-ta {
  flex: 1; border: none; outline: none; background: transparent;
  resize: none; min-height: 22px; max-height: 84px;
  font-size: 15px; font-weight: 400; line-height: 1.4;
  color: var(--ink);
}
.ehi-ta::placeholder { color: #B0B7C3; font-weight: 400; }

/* Smiley button — just emoji, no border */
.ehi-smiley {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; display: flex; align-items: center; justify-content: center;
  opacity: .65; transition: opacity .14s, transform .14s;
  line-height: 1;
}
.ehi-smiley:hover { opacity: 1; transform: scale(1.1); }

/* Send — grey FILLED circle with white arrow (BotPenguin style) */
.ehi-send {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--send-bg);           /* grey filled circle */
  border: none; cursor: pointer;
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .15s;
}
.ehi-send:hover    { background: var(--blue); transform: scale(1.06); }
.ehi-send:disabled { background: var(--bdr); cursor: default; transform: none; }
.ehi-send svg      { display: block; }

/* Mic button — SVG icon, shown only when voice enabled */
.ehi-mic {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: transparent; border: none; cursor: pointer;
  color: var(--sub); opacity: .7;
  display: flex; align-items: center; justify-content: center;
  transition: all .14s;
}
.ehi-mic:hover  { opacity: 1; color: var(--blue); }
.ehi-mic.active { background: #EF4444; color: var(--white); opacity: 1; animation: ehiPulse 1.2s ease infinite; }

/* Footer line */
.ehi-footer {
  text-align: center; margin-top: 8px;
  font-size: 11.5px; font-weight: 400; color: var(--sub); line-height: 1;
}
.ehi-footer b { color: var(--blue); font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════════════
   MINIMISED PILL
   ══════════════════════════════════════════════════════════════════════ */
.ehi-mini {
  display: flex; align-items: center; gap: 10px;
  background: var(--blue); color: var(--white);
  padding: 10px 16px 10px 12px; border-radius: 32px;
  cursor: pointer; box-shadow: 0 4px 18px rgba(37,99,235,.35);
  user-select: none; white-space: nowrap;
}
.ehi-mini.hidden { display: none; }
.ehi-mini-av {
  width: 28px; height: 28px; border-radius: 50%;
  overflow: hidden; border: 2px solid rgba(255,255,255,.5); flex-shrink: 0;
  background: var(--white); display: flex; align-items: center; justify-content: center;
}
.ehi-mini-av img { width: 100%; height: 100%; object-fit: cover; }
.ehi-mini-lbl { font-size: 13px; font-weight: 600; }
.ehi-mini-x {
  margin-left: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(255,255,255,.22); border: none; cursor: pointer;
  color: var(--white); font-size: 11px;
  display: flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0;
}
.ehi-mini-x:hover { background: rgba(255,255,255,.4); }

/* Escalation banner */
.ehi-esc {
  flex-shrink: 0; background: #FFFBEB;
  border-top: 1px solid #FDE68A; padding: 10px 16px;
  font-size: 13px; color: #78350F;
  display: flex; align-items: center; gap: 8px;
}
.ehi-esc button {
  margin-left: auto; background: #F59E0B; color: var(--white);
  border: none; border-radius: 10px; padding: 6px 14px;
  font-size: 12px; font-weight: 700; cursor: pointer; flex-shrink: 0;
  font-family: var(--ff);
}

/* ── Animations ──────────────────────────────────────────────────────── */
@keyframes ehiIn    { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)} }
@keyframes ehiType  { 0%,60%,100%{transform:translateY(0);opacity:.6}30%{transform:translateY(-5px);opacity:1} }
@keyframes ehiPulse { 0%,100%{box-shadow:0 0 0 0 rgba(239,68,68,.4)}60%{box-shadow:0 0 0 8px rgba(239,68,68,0)} }

/* ═══════════════════════════════════════════════════════════════════════
   MOBILE ≤ 600px  —  full viewport overlay, launcher above nav
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {

  .ehi-pos-bottom-right,
  .ehi-pos-bottom-left {
    bottom: 80px !important; right: 16px !important; left: auto !important;
  }
  .ehi-pos-bottom-left { left: 16px !important; right: auto !important; }

  /* Launcher slightly smaller */
  .ehi-launcher, .ehi-launcher-circle { width: 52px; height: 52px; }

  /* Panel: genuine full-screen, slide-up */
  .ehi-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important; max-width: 100vw !important;
    height: 100dvh !important; max-height: 100dvh !important;
    border-radius: 0 !important; box-shadow: none !important;
    transition: transform .32s cubic-bezier(.32,1.2,.64,1) !important;
    transform-origin: bottom center !important;
  }
  .ehi-panel.hidden { transform: translateY(100%) !important; opacity: 1 !important; }

  /* Header: flat on mobile */
  .ehi-header { border-radius: 0 !important; min-height: 72px !important; }

  /* Chips: no extra left margin on mobile */
  .ehi-chip { min-height: 56px; font-size: 16px; }

  /* Input safe-area (iOS notch) */
  .ehi-input-area {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  }

  /* Timestamp indent less on mobile */
  .ehi-ts { padding-left: 0; }

  /* Mini pill fixed */
  .ehi-mini { position: fixed; bottom: 80px; right: 16px; }
  .ehi-pos-bottom-left .ehi-mini { right: auto; left: 16px; }
}
