/* ============================================================
   Ask Leo — Charleston Locksmith Pro chat assistant
   Brand-native: charcoal #1d1c27 + coral #ff5d4e, with Leo's
   gold mane as the signature accent. Montserrat / Poppins.
   ============================================================ */
#ask-leo {
  --leo-ink: #1d1c27;
  --leo-ink-2: #2a2933;
  --leo-coral: #ff5d4e;
  --leo-coral-2: #e04a3d;
  --leo-gold: #e1913c;
  --leo-gold-2: #f4b45a;
  --leo-cream: #faf7f2;
  --leo-line: #e9e5dd;
  --leo-muted: #6b6a73;
  --leo-white: #fff;
  --leo-shadow: 0 18px 50px -12px rgba(20, 18, 30, .45);
  --leo-radius: 20px;

  position: fixed;
  left: clamp(14px, 3vw, 26px);
  bottom: clamp(14px, 3vw, 26px);
  z-index: 99990;
  font-family: "Poppins", system-ui, sans-serif;
  color: var(--leo-ink);
}
#ask-leo *, #ask-leo *::before, #ask-leo *::after { box-sizing: border-box; }
#ask-leo button { font-family: inherit; cursor: pointer; border: 0; background: none; }

/* ---------- Launcher ---------- */
.leo-launcher {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 20px 8px 8px;
  background: var(--leo-ink);
  color: var(--leo-white);
  border-radius: 999px;
  box-shadow: var(--leo-shadow);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s;
}
.leo-launcher:hover { transform: translateY(-3px) scale(1.02); }
.leo-launcher:active { transform: translateY(-1px) scale(.99); }
.leo-launcher__ring {
  position: relative;
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 50%;
  padding: 3px;
  background: conic-gradient(from 210deg, var(--leo-gold), var(--leo-gold-2), var(--leo-gold));
  display: grid; place-items: center;
}
.leo-launcher__face {
  width: 100%; height: 100%; border-radius: 50%;
  object-fit: cover; object-position: 50% 22%;
  background: var(--leo-cream);
  display: block;
}
.leo-launcher__label { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.leo-launcher__name {
  font-family: "Montserrat", sans-serif;
  font-weight: 800; font-size: 1.05rem; letter-spacing: .3px;
}
.leo-launcher__sub { font-size: .72rem; color: #c9c6d1; font-weight: 500; }
.leo-launcher__pulse {
  position: absolute; top: 6px; right: 6px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #2ece6a; border: 2px solid var(--leo-ink);
}
.leo-launcher__pulse::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid #2ece6a; opacity: .7;
  animation: leo-ping 2.2s ease-out infinite;
}
@keyframes leo-ping { 0% { transform: scale(.6); opacity: .7; } 70%,100% { transform: scale(1.7); opacity: 0; } }

/* idle attention nudge on the launcher */
.leo[data-open="false"] .leo-launcher { animation: leo-bob 5.5s ease-in-out 2s infinite; }
@keyframes leo-bob { 0%,92%,100% { transform: translateY(0); } 95% { transform: translateY(-4px); } 97% { transform: translateY(-2px); } }

/* ---------- Nudge bubble ---------- */
.leo-nudge {
  position: absolute; bottom: calc(100% + 14px); left: 4px;
  max-width: 240px;
  background: var(--leo-white); color: var(--leo-ink);
  padding: 12px 30px 12px 14px;
  border-radius: 16px 16px 16px 4px;
  box-shadow: var(--leo-shadow);
  font-size: .86rem; font-weight: 500; line-height: 1.35;
  transform-origin: bottom left;
  animation: leo-pop .4s cubic-bezier(.2,1.2,.3,1) both;
}
.leo-nudge p { margin: 0; }
.leo-nudge::after {
  content: ""; position: absolute; top: 100%; left: 16px;
  border: 8px solid transparent; border-top-color: var(--leo-white); border-bottom: 0;
}
.leo-nudge__x {
  position: absolute; top: 6px; right: 8px;
  font-size: 1.1rem; line-height: 1; color: var(--leo-muted);
}
@keyframes leo-pop { from { opacity: 0; transform: scale(.7) translateY(8px); } to { opacity: 1; transform: none; } }
.leo[data-open="true"] .leo-nudge,
.leo-nudge[hidden] { display: none; }

/* ---------- Panel ---------- */
.leo-panel {
  position: absolute; left: 0; bottom: 0;
  width: min(384px, calc(100vw - 28px));
  height: min(600px, calc(100vh - 40px));
  display: none;               /* visibility is driven by [data-open], not the hidden attr */
  flex-direction: column;
  background: var(--leo-white);
  border-radius: var(--leo-radius);
  box-shadow: var(--leo-shadow);
  overflow: hidden;
  transform-origin: bottom left;
}
.leo[data-open="true"] .leo-panel {
  display: flex;
  animation: leo-panel-in .34s cubic-bezier(.2,.9,.25,1) both;
}
@keyframes leo-panel-in { from { opacity: 0; transform: translateY(18px) scale(.96); } to { opacity: 1; transform: none; } }
.leo[data-open="true"] .leo-launcher { display: none; }

/* Header */
.leo-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 14px 16px;
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(255,93,78,.28), transparent 55%),
    var(--leo-ink);
  color: var(--leo-white);
  border-bottom: 3px solid var(--leo-gold);
}
.leo-head__avatar { position: relative; width: 46px; height: 46px; flex: 0 0 46px; }
.leo-head__avatar img {
  width: 100%; height: 100%; border-radius: 50%;
  object-fit: cover; object-position: 50% 22%;
  background: var(--leo-cream);
  border: 2px solid var(--leo-gold-2);
}
.leo-head__status {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #2ece6a; border: 2px solid var(--leo-ink);
}
.leo-head__id { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.leo-head__name { font-family: "Montserrat", sans-serif; font-weight: 800; font-size: 1.15rem; letter-spacing: .3px; }
.leo-head__tag { font-size: .72rem; color: #d7d4e0; font-weight: 500; }
.leo-head__min { color: #d7d4e0; padding: 6px; border-radius: 8px; transition: background .2s, color .2s; }
.leo-head__min:hover { background: rgba(255,255,255,.12); color: #fff; }

/* Log */
.leo-log {
  flex: 1 1 auto; overflow-y: auto;
  padding: 18px 16px 8px;
  background:
    linear-gradient(var(--leo-cream), var(--leo-cream));
  scroll-behavior: smooth;
}
.leo-log:focus-visible { outline: 2px solid var(--leo-coral); outline-offset: -2px; }

.leo-msg { display: flex; gap: 8px; margin-bottom: 14px; max-width: 100%; align-items: flex-end; }
.leo-msg__av {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
  object-fit: cover; object-position: 50% 22%;
  background: var(--leo-white); border: 1.5px solid var(--leo-gold-2);
}
.leo-msg__bubble {
  padding: 11px 14px; border-radius: 16px;
  font-size: .9rem; line-height: 1.5;
  box-shadow: 0 2px 8px rgba(20,18,30,.06);
  overflow-wrap: anywhere;
}
.leo-msg--leo .leo-msg__bubble { background: var(--leo-white); border: 1px solid var(--leo-line); border-bottom-left-radius: 5px; }
.leo-msg--user { flex-direction: row-reverse; }
.leo-msg--user .leo-msg__bubble {
  background: var(--leo-coral); color: #fff;
  border-bottom-right-radius: 5px;
}
.leo-msg--user .leo-msg__av { display: none; }

.leo-cta {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 9px; padding: 9px 15px;
  background: var(--leo-ink); color: #fff !important;
  font-family: "Montserrat", sans-serif; font-weight: 700; font-size: .82rem;
  border-radius: 999px; text-decoration: none;
  transition: background .2s, transform .2s;
}
.leo-cta:hover { background: var(--leo-coral); transform: translateY(-1px); }
.leo-cta svg { width: 15px; height: 15px; }

/* typing indicator */
.leo-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.leo-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--leo-gold); opacity: .5; animation: leo-dot 1.2s infinite; }
.leo-typing span:nth-child(2) { animation-delay: .18s; }
.leo-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes leo-dot { 0%,60%,100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Chips */
.leo-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 6px 14px 12px; background: var(--leo-cream); }
.leo-chip {
  padding: 7px 13px; font-size: .78rem; font-weight: 500;
  background: var(--leo-white); color: var(--leo-ink);
  border: 1px solid var(--leo-line); border-radius: 999px;
  transition: border-color .2s, color .2s, transform .15s;
}
.leo-chip:hover { border-color: var(--leo-coral); color: var(--leo-coral-2); transform: translateY(-1px); }
.leo-chips[hidden] { display: none; }

/* Form */
.leo-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 12px 6px; background: var(--leo-white);
  border-top: 1px solid var(--leo-line);
}
.leo-input {
  flex: 1 1 auto; resize: none; max-height: 120px;
  padding: 11px 14px; border: 1px solid var(--leo-line);
  border-radius: 14px; font-size: .9rem; line-height: 1.4;
  background: var(--leo-cream); color: var(--leo-ink);
  transition: border-color .2s, box-shadow .2s;
}
.leo-input:focus { outline: 0; border-color: var(--leo-coral); box-shadow: 0 0 0 3px rgba(255,93,78,.15); }
.leo-input::placeholder { color: #9d9ba6; }
.leo-send {
  flex: 0 0 44px; width: 44px; height: 44px; border-radius: 12px;
  background: var(--leo-coral); color: #fff;
  display: grid; place-items: center;
  transition: background .2s, transform .15s;
}
.leo-send:hover { background: var(--leo-coral-2); }
.leo-send:active { transform: scale(.94); }
.leo-send:disabled { opacity: .5; cursor: default; }

.leo-fineprint { margin: 0; padding: 0 14px 12px; font-size: .68rem; color: var(--leo-muted); text-align: center; }
.leo-fineprint a { color: var(--leo-coral-2); font-weight: 600; text-decoration: none; }

.screen-reader-text {
  position: absolute !important; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Focus visibility */
#ask-leo button:focus-visible,
#ask-leo a:focus-visible,
#ask-leo textarea:focus-visible { outline: 2px solid var(--leo-coral); outline-offset: 2px; }

/* Mobile: dock as a bottom sheet */
@media (max-width: 480px) {
  #ask-leo { left: 10px; right: 10px; bottom: 10px; }
  .leo-launcher__sub { display: none; }
  .leo-panel {
    width: 100%;
    height: min(78vh, 600px);
    left: 0; right: 0;
  }
  .leo-nudge { max-width: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  #ask-leo *, #ask-leo *::before, #ask-leo *::after { animation: none !important; transition: none !important; }
}
