/* ═══════════════════════════════════════════════════════════════
   KAI — Chat Widget Styles
   Floating chat assistant for MEIKAI.
   Uses brand tokens from style.css (:root).
═══════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────
   TRIGGER BUTTON
───────────────────────────────────────────── */
.kai-trigger {
  position: fixed;
  bottom: calc(24px + var(--kai-b, 0px));
  right: 24px;
  z-index: 1000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 1px rgba(45,95,138,.15);
  transition: background .18s, transform .15s, box-shadow .18s;
}
.kai-trigger:hover {
  background: var(--blue-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.15), 0 0 0 1px rgba(30,68,104,.2);
}
.kai-trigger:active { transform: translateY(0); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.kai-trigger:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

.kai-trigger svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Unread dot */
.kai-trigger-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--warm-white);
  transition: opacity .2s;
}
.kai-trigger-dot--hidden { opacity: 0; pointer-events: none; }

/* Pulse on first visit — single cycle */
@keyframes kaiPulse {
  0%   { box-shadow: 0 0 0 0 rgba(45,95,138,.35); }
  70%  { box-shadow: 0 0 0 14px rgba(45,95,138,0); }
  100% { box-shadow: 0 0 0 0 rgba(45,95,138,0); }
}
.kai-trigger--pulse { animation: kaiPulse .9s ease-out 1; }

/* Close icon state */
.kai-trigger .kai-icon-close { display: none; }
.kai-trigger--open .kai-icon-chat { display: none; }
.kai-trigger--open .kai-icon-close { display: block; }

/* Labeled pill trigger (A4) — desktop only */
.kai-trigger-label {
  display: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  order: -1;
  line-height: 1;
}
@media (min-width: 661px) {
  .kai-trigger--labeled {
    width: auto;
    border-radius: 28px;
    padding: 0 18px 0 14px;
    gap: 7px;
    transition: background .18s, transform .15s, box-shadow .18s, width .2s, border-radius .2s, padding .2s;
  }
  .kai-trigger--labeled .kai-trigger-label { display: block; }
  .kai-trigger--labeled.kai-trigger--open {
    width: 56px;
    border-radius: 50%;
    padding: 0;
    gap: 0;
  }
  .kai-trigger--labeled.kai-trigger--open .kai-trigger-label { display: none; }
  .kai-trigger--labeled .kai-trigger-dot { right: -2px; top: -2px; }
}

/* ─────────────────────────────────────────────
   CHAT PANEL
───────────────────────────────────────────── */
.kai-panel {
  position: fixed;
  bottom: calc(92px + var(--kai-b, 0px));
  right: 24px;
  z-index: 999;
  width: 380px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  background: var(--warm-white);
  border: 1.5px solid var(--gold);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 40px rgba(0,0,0,.18), 0 4px 12px rgba(0,0,0,.08);
  opacity: 0;
  transform: translateY(12px) scale(.98);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.kai-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ─── Header ─── */
.kai-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--blue);
  color: #fff;
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid var(--gold);
  flex-shrink: 0;
}
.kai-header-info { flex: 1; min-width: 0; }
.kai-header-name {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}
.kai-header-sub {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .04em;
  opacity: .65;
  line-height: 1.3;
}
.kai-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .7;
  transition: opacity .15s;
}
.kai-close:hover { opacity: 1; }
.kai-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.kai-close svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }

/* ─── Messages Area ─── */
.kai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  min-height: 0;
  overscroll-behavior: contain;
}

/* Scrollbar styling */
.kai-messages::-webkit-scrollbar { width: 5px; }
.kai-messages::-webkit-scrollbar-track { background: transparent; }
.kai-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Message Bubbles ─── */
.kai-msg {
  max-width: 80%;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.kai-msg--ai {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border-radius: 10px 10px 10px 2px;
}

.kai-msg--user {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border-radius: 10px 10px 2px 10px;
}

.kai-msg--error {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 10px 10px 10px 2px;
  font-size: 13px;
  font-style: italic;
}
@keyframes kaiBubbleFlash {
  0%   { background: rgba(45,95,138,.12); }
  60%  { background: rgba(45,95,138,.06); }
  100% { background: var(--surface); }
}
.kai-msg--flash { animation: kaiBubbleFlash 1.2s ease-out forwards; }

.kai-msg--ai a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }
.kai-msg--ai a:hover { color: var(--blue-dark); }
.kai-msg--error a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }

/* ─── Micro-Feedback Buttons ─── */
.kai-feedback {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  justify-content: flex-end;
}
.kai-fb-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  cursor: pointer;
  color: var(--text-muted);
  opacity: .5;
  transition: opacity .15s, color .15s, border-color .15s;
  display: flex;
  align-items: center;
}
.kai-fb-btn:hover { opacity: 1; border-color: var(--border-lt); }
.kai-fb--active { opacity: 1; color: var(--blue); border-color: var(--blue); }
.kai-fb--active:hover { color: var(--blue); }

/* ─── Typing Indicator ─── */
.kai-typing {
  align-self: flex-start;
  background: var(--surface);
  border-radius: 10px 10px 10px 2px;
  padding: 10px 14px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.kai-typing-text {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.kai-typing-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}
.kai-typing-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: kaiDotPulse 1.2s ease-in-out infinite;
}
.kai-typing-dot:nth-child(2) { animation-delay: .15s; }
.kai-typing-dot:nth-child(3) { animation-delay: .3s; }

@keyframes kaiDotPulse {
  0%, 60%, 100% { opacity: .3; transform: scale(.85); }
  30%           { opacity: 1;  transform: scale(1); }
}

/* ─── Suggestion Chips ─── */
.kai-chips {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 16px 10px;
  pointer-events: none; /* pass-through when empty */
}
.kai-chip {
  background: var(--blue-tint);
  color: var(--blue);
  border: 1px solid rgba(45,95,138,.15);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  line-height: 1.3;
  pointer-events: auto;
}
.kai-chip:hover {
  background: rgba(45,95,138,.12);
  border-color: rgba(45,95,138,.25);
}
.kai-chip:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.kai-chip { animation: kaiFadeIn .25s ease-out; }
.kai-chip--idle { opacity: .75; }
.kai-chip--ask {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-lt);
  font-style: italic;
}
.kai-chip--ask:hover { background: var(--surface); color: var(--text-mid); border-color: var(--border); }
.kai-chip--assessment {
  background: var(--warm-white);
  border-color: rgba(45,95,138,.25);
  color: var(--text-2);
  font-size: 12.5px;
}
.kai-chip--assessment:hover {
  background: var(--blue-tint);
  border-color: var(--blue);
  color: var(--blue);
}

/* ─── Input Bar ─── */
.kai-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-lt);
  background: #fff;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  flex-shrink: 0;
}
.kai-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: transparent;
  padding: 6px 4px;
  line-height: 1.4;
  min-width: 0;
}
.kai-input::placeholder { color: var(--text-muted); }
.kai-input:focus-visible { outline: none; }

.kai-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .18s, opacity .18s, transform .12s, box-shadow .18s;
  box-shadow: 0 1px 3px rgba(45,95,138,.25);
}
.kai-send:hover { background: var(--blue-dark); transform: scale(1.06); box-shadow: 0 2px 8px rgba(45,95,138,.3); }
.kai-send:active { transform: scale(.96); }
.kai-send:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.kai-send:disabled { opacity: .3; cursor: default; background: var(--border); box-shadow: none; transform: none; }
.kai-send svg { width: 20px; height: 20px; fill: none; }

/* Close label: hidden on desktop, shown on mobile via media query below */
.kai-close-text { display: none; }

/* ─────────────────────────────────────────────
   RESPONSIVE — MOBILE (≤660px)
   Bottom-sheet approach: panel slides up from bottom,
   leaving 60px of the page visible above (well below
   the iOS status bar — avoids native-UI overlay issues).
   The visible strip above is covered by the backdrop,
   which also acts as a tap-to-close affordance.
───────────────────────────────────────────── */

/* Backdrop: hidden on desktop */
.kai-backdrop { display: none; }

@media (max-width: 660px) {

  /* ─── Trigger ─── */
  .kai-trigger {
    width: 52px;
    height: 52px;
    bottom: calc(20px + var(--kai-b, 0px));
    right: 20px;
  }
  .kai-trigger svg { width: 24px; height: 24px; }

  /* ─── Backdrop: dims the 60px strip + entire page behind the panel ─── */
  .kai-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0,0,0,.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  .kai-backdrop--visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* ─── Panel: bottom-sheet, starts at y=60px (never behind status bar) ─── */
  .kai-panel {
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: none;
    overflow: hidden; /* prevent panel itself from scrolling */
    border-radius: 16px 16px 0 0;
    border: none;
    border-top: 3px solid var(--gold);
    box-shadow: 0 -6px 30px rgba(0,0,0,.18);
    /* Slide animation — display toggled by JS, no display:none fight */
    opacity: 1;
    transform: translateY(calc(100% + 60px));
    transition: transform .28s cubic-bezier(.32,.72,0,1);
    z-index: 9999; /* above cookie banner (9999) + backdrop (9998) */
  }
  .kai-panel--open {
    transform: translateY(0);
    opacity: 1;
  }

  /* ─── Header ─── */
  .kai-header {
    border-radius: 0;
    padding: 14px 10px 14px 18px;
    flex-shrink: 0;
  }

  /* ─── Close button: solid white pill with blue text + icon ─── */
  .kai-close {
    height: 38px;
    width: auto;
    min-width: 38px;
    border-radius: 19px;
    background: #fff;
    border: none;
    color: var(--blue);
    opacity: 1;
    padding: 0 14px 0 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
  }
  .kai-close:hover { background: #f0f4f8; opacity: 1; }
  .kai-close svg { width: 16px; height: 16px; stroke-width: 2.5; flex-shrink: 0; }

  /* Close label: injected as <span class="kai-close-text"> via JS */
  .kai-close-text { display: inline; }

  /* ─── Messages: top-to-bottom (standard chat layout) ─── */
  .kai-messages {
    justify-content: flex-start;
    padding-top: 16px;
  }

  /* ─── Input bar: home-indicator safe area ─── */
  .kai-input-bar {
    border-radius: 0;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  }
}

/* ─────────────────────────────────────────────
   PROACTIVE NUDGE BUBBLE
───────────────────────────────────────────── */
.kai-nudge {
  position: fixed;
  bottom: calc(88px + var(--kai-b, 0px));
  right: 24px;
  z-index: 1000;
  background: #fff;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--gold);
  box-shadow: 0 4px 16px rgba(0,0,0,.12), 0 1px 4px rgba(0,0,0,.06);
  max-width: 240px;
  cursor: pointer;
  animation: kaiNudgeIn .3s ease-out;
  transition: opacity .2s, transform .15s;
}
.kai-nudge:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0,0,0,.15), 0 2px 6px rgba(0,0,0,.08);
}
.kai-nudge::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 22px;
  width: 10px;
  height: 10px;
  background: #fff;
  border-right: 1.5px solid var(--gold);
  border-bottom: 1.5px solid var(--gold);
  transform: rotate(45deg);
}
@keyframes kaiNudgeIn {
  from { opacity: 0; transform: translateY(8px) scale(.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 660px) {
  .kai-nudge {
    bottom: calc(72px + var(--kai-b, 0px));
    right: 16px;
    max-width: 200px;
    font-size: 12px;
  }
  .kai-nudge::after { right: 14px; }
}

/* ─────────────────────────────────────────────
   LEAD CAPTURE CARD
───────────────────────────────────────────── */
.kai-lead-card {
  align-self: flex-start;
  background: var(--surface);
  border: 1.5px solid var(--gold);
  border-radius: 10px;
  padding: 14px 16px;
  max-width: 90%;
  animation: kaiFadeIn .25s ease-out;
}
@keyframes kaiFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kai-lead-text {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  margin: 0 0 10px;
}
.kai-lead-form {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.kai-lead-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
  min-width: 0;
  transition: border-color .15s;
}
.kai-lead-input:focus { border-color: var(--blue); }
.kai-lead-input::placeholder { color: var(--text-muted); }
.kai-lead-btn {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 7px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.kai-lead-btn:hover { background: var(--blue-dark); }
.kai-lead-skip {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  transition: color .15s;
}
.kai-lead-skip:hover { color: var(--text); }
.kai-lead-thanks {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--blue);
  margin: 0;
  font-weight: 500;
}
.kai-lead-guide-link {
  display: inline-block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid rgba(45,95,138,.3);
  transition: border-color .15s, color .15s;
}
.kai-lead-guide-link:hover { color: var(--blue-dark); border-color: var(--blue-dark); }
/* Tier-2 lead card */
.kai-lead-card--t2 { max-width: 96%; }
.kai-lead-fields { display: flex; flex-direction: column; gap: 8px; }
.kai-lead-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-mid);
  font-weight: 500;
}
.kai-lead-select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
.kai-lead-select:focus { border-color: var(--blue); }
.kai-lead-textarea {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
  resize: none;
  line-height: 1.5;
  transition: border-color .15s;
}
.kai-lead-textarea:focus { border-color: var(--blue); }
.kai-lead-textarea::placeholder { color: var(--text-muted); }

/* ─────────────────────────────────────────────
   MICRO-CALCULATOR RESULT CARD
───────────────────────────────────────────── */
.kai-calc-card {
  background: var(--warm-white, #FAFAF8);
  border: 1px solid var(--border-lt, #E4E4E0);
  border-left: 3px solid var(--blue, #2D5F8A);
  border-radius: 0 6px 6px 0;
  padding: 14px 16px;
}
.kai-calc-label {
  font-family: var(--mono, 'IBM Plex Mono', monospace);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--blue, #2D5F8A);
  margin-bottom: 10px;
}
.kai-calc-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.kai-calc-number {
  font-family: var(--mono, 'IBM Plex Mono', monospace);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-2, #2A2A2A);
  letter-spacing: -.02em;
}
.kai-calc-unit {
  font-size: 12px;
  color: var(--text-muted, #888);
}
.kai-calc-disclaimer {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-lt, #E4E4E0);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted, #888);
  font-style: italic;
}

/* ─────────────────────────────────────────────
   HIDDEN STATE (panel closed)
───────────────────────────────────────────── */
.kai-panel:not(.kai-panel--open) { display: none; }

