/* ========================================================================
   Ask Kaf layout, typography and tap target fixes
   Append this file AFTER the existing ask-kaf.css on the private sandbox.
   Do not add this to the live site. Nothing here is a deploy step.

   Assumes the markup created by ask-kaf.js:
     .ask-kaf
       .ask-kaf-dock?                (present in the Nov 17+ sandbox JS)
         button#ask-kaf-launcher.ask-kaf-launcher
           img.ask-kaf-head
           span
         button.ask-kaf-dismiss?     (optional hide control)
       button.ask-kaf-restore?       (optional, shown after dismiss)
       #ask-kaf-panel.ask-kaf-panel
         img.ask-kaf-mascot? / img.ask-kaf-avatar?   (kept hidden)
         .ask-kaf-card
           .ask-kaf-header
             .ask-kaf-heading h2#ask-kaf-title + p.ask-kaf-sub
             button.ask-kaf-close
           .ask-kaf-transcript
             .ask-kaf-row .ask-kaf-head.ask-kaf-msg-avatar
           .ask-kaf-suggest .ask-kaf-chips .ask-kaf-chip
                          .ask-kaf-questions .ask-kaf-qbtn
                          .ask-kaf-link
           form.ask-kaf-composer
             textarea#ask-kaf-input.ask-kaf-input
             button.ask-kaf-send
   Also works when the dock wrapper is missing and the launcher is a
   direct child of .ask-kaf (older bubble JS).
   ======================================================================== */

.ask-kaf {
  --ak-bg: #040B04;
  --ak-elev: #0A1D0B;
  --ak-panel: #0E2A0E;
  --ak-ink: #F2FFF1;
  --ak-muted: rgba(200, 222, 199, 0.72);
  --ak-accent: #B1FC03;
  --ak-cyan: #00E1FF;
  --ak-rule: rgba(200, 222, 199, 0.12);
  --ak-font: "DM Sans", system-ui, sans-serif;
  --ak-display: "Montserrat", "DM Sans", system-ui, sans-serif;
  --ak-edge: 16px;
  --ak-gap: 12px;
  --ak-launcher-h: 60px;
  --ak-z-launcher: 240;
  --ak-z-panel: 241;
  --ak-safe-right: max(var(--ak-edge), env(safe-area-inset-right, 0px));
  --ak-safe-left: max(var(--ak-edge), env(safe-area-inset-left, 0px));
  --ak-safe-bottom: max(var(--ak-edge), env(safe-area-inset-bottom, 0px));
  --ak-safe-top: max(var(--ak-edge), env(safe-area-inset-top, 0px));
  --ak-max-h: calc(100dvh - var(--ak-launcher-h) - var(--ak-gap) - var(--ak-safe-top) - var(--ak-safe-bottom));
}

/* ----- Launcher / dock: stay visible, never sit under the panel ----- */

.ask-kaf-dock {
  position: fixed !important;
  right: var(--ak-safe-right) !important;
  bottom: var(--ak-safe-bottom) !important;
  left: auto !important;
  top: auto !important;
  z-index: var(--ak-z-launcher) !important;
  display: inline-flex !important;
  align-items: flex-end;
  transform: none !important;
}

body.ask-kaf-open .ask-kaf-dock,
.ask-kaf-dock.is-tucked {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  transform: none !important;
}

.ask-kaf-launcher {
  position: fixed;
  right: var(--ak-safe-right);
  bottom: var(--ak-safe-bottom);
  left: auto;
  top: auto;
  z-index: var(--ak-z-launcher);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 44px;
  min-height: 44px;
  height: var(--ak-launcher-h);
  padding: 6px 18px 6px 6px;
  overflow: hidden;
  border: 1px solid rgba(177, 252, 3, 0.35);
  border-radius: 999px;
  background: rgba(10, 29, 11, 0.92);
  color: #E6F0E5;
  font-family: var(--ak-display);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  transform: none !important;
}

.ask-kaf-dock .ask-kaf-launcher {
  position: relative !important;
  right: auto !important;
  bottom: auto !important;
  z-index: auto;
}

.ask-kaf-launcher:hover {
  background: rgba(14, 42, 14, 0.96);
  border-color: rgba(177, 252, 3, 0.55);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.ask-kaf-launcher:focus-visible {
  outline: 3px solid var(--ak-accent);
  outline-offset: 3px;
}

.ask-kaf-launcher[aria-expanded="true"] {
  opacity: 1 !important;
  pointer-events: auto !important;
  transform: none !important;
}

/* Head sits fully inside a circle. No peeking past the pill. */
.ask-kaf-launcher img,
.ask-kaf-launcher .ask-kaf-head,
.ask-kaf-dock .ask-kaf-launcher img,
.ask-kaf-dock .ask-kaf-launcher .ask-kaf-head {
  width: 48px !important;
  height: 48px !important;
  margin: 0 !important;
  border-radius: 50% !important;
  object-fit: cover !important;
  object-position: center !important;
  background: #040B04;
  flex: none;
  filter: none;
  overflow: hidden;
}

/* Optional hide control: keep a small visual, but a 44px hit area */
.ask-kaf-dismiss {
  appearance: none;
  position: absolute;
  top: -8px;
  right: -6px;
  z-index: 2;
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(177, 252, 3, 0.45);
  background: #0A1D0B;
  color: #E6F0E5;
  font: 600 15px/1 var(--ak-display);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.ask-kaf-dismiss::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
}

.ask-kaf-dismiss:focus-visible {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

.ask-kaf-restore {
  appearance: none;
  position: fixed;
  right: var(--ak-safe-right);
  bottom: var(--ak-safe-bottom);
  z-index: var(--ak-z-launcher);
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(177, 252, 3, 0.45);
  background: #0A1D0B;
  color: #E6F0E5;
  font-family: var(--ak-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.ask-kaf-restore:focus-visible {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

/* ----- Panel: opens above the launcher, with a gap, never full bleed ----- */

.ask-kaf-panel {
  position: fixed !important;
  right: var(--ak-safe-right) !important;
  bottom: calc(var(--ak-safe-bottom) + var(--ak-launcher-h) + var(--ak-gap)) !important;
  left: auto !important;
  top: auto !important;
  z-index: var(--ak-z-panel) !important;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - var(--ak-safe-left) - var(--ak-safe-right))) !important;
  height: min(640px, var(--ak-max-h)) !important;
  max-height: var(--ak-max-h) !important;
  background: transparent !important;
  color: var(--ak-ink);
  border: 0;
  box-shadow: none;
  overflow: hidden !important;
  font-family: var(--ak-font);
  pointer-events: auto;
}

.ask-kaf-panel[hidden] {
  display: none !important;
}

.ask-kaf-mascot,
.ask-kaf-avatar {
  display: none !important;
}

.ask-kaf-card {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  color: var(--ak-ink);
  background:
    radial-gradient(420px 180px at 100% 0%, rgba(177, 252, 3, 0.06), transparent 55%),
    radial-gradient(380px 160px at 0% 0%, rgba(0, 225, 255, 0.07), transparent 50%),
    rgba(10, 29, 11, 0.88);
  border: 1px solid rgba(177, 252, 3, 0.14);
  border-radius: 22px;
  box-shadow:
    0 28px 70px rgba(0, 0, 0, 0.58),
    0 0 40px rgba(14, 42, 14, 0.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.12);
  backdrop-filter: blur(18px) saturate(1.12);
}

.ask-kaf-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 14px 18px;
  border-bottom: 1px solid var(--ak-rule);
  background: rgba(4, 11, 4, 0.55);
  border-radius: 22px 22px 0 0;
}

.ask-kaf-heading {
  flex: 1;
  min-width: 0;
}

.ask-kaf-heading h2,
#ask-kaf-title {
  margin: 0;
  font-family: var(--ak-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ak-ink);
}

.ask-kaf-sub {
  margin: 4px 0 0;
  color: var(--ak-muted);
  font-family: var(--ak-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.ask-kaf-close {
  appearance: none;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--ak-rule);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ak-ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ask-kaf-close:hover {
  border-color: var(--ak-accent);
  color: var(--ak-accent);
}

.ask-kaf-close:focus-visible {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

.ask-kaf-transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.ask-kaf-msg-avatar,
.ask-kaf-transcript .ask-kaf-head {
  width: 40px !important;
  height: 40px !important;
  border-radius: 50% !important;
  object-fit: cover !important;
  object-position: center !important;
  flex: none;
  background: #040B04;
  filter: none;
}

/* ----- Chips, links, composer: 44px tap targets ----- */

.ask-kaf-link,
.ask-kaf-chip,
.ask-kaf-qbtn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  font-family: var(--ak-font);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-align: left;
}

.ask-kaf-chip,
.ask-kaf-qbtn {
  border: 1px solid var(--ak-rule);
  background: rgba(14, 42, 14, 0.7);
  color: var(--ak-ink);
}

.ask-kaf-link {
  border: 1px solid rgba(177, 252, 3, 0.35);
  background: rgba(177, 252, 3, 0.08);
  color: var(--ak-accent);
  font-family: var(--ak-display);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.ask-kaf-chip:hover,
.ask-kaf-qbtn:hover,
.ask-kaf-chip[aria-pressed="true"] {
  border-color: var(--ak-accent);
  color: var(--ak-accent);
  background: rgba(177, 252, 3, 0.08);
}

.ask-kaf-chip:focus-visible,
.ask-kaf-qbtn:focus-visible,
.ask-kaf-link:focus-visible {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

.ask-kaf-suggest-label,
.ask-kaf-msg-name {
  font-family: var(--ak-display);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.ask-kaf-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--ak-rule);
  background: rgba(4, 11, 4, 0.65);
}

.ask-kaf-input {
  width: 100%;
  resize: none;
  box-sizing: border-box;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--ak-rule);
  background: rgba(4, 11, 4, 0.7);
  color: var(--ak-ink);
  font: 15px/1.4 var(--ak-font);
}

.ask-kaf-input:focus {
  outline: none;
  border-color: rgba(177, 252, 3, 0.55);
  box-shadow: 0 0 0 2px rgba(177, 252, 3, 0.2);
}

.ask-kaf-send {
  appearance: none;
  min-width: 72px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--ak-accent);
  color: #041004;
  font-family: var(--ak-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.ask-kaf-send:hover {
  background: #C8FF3A;
}

.ask-kaf-send:focus-visible {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

.ask-kaf-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Do not lock the whole page unless the sheet is open on a small screen. */
body.ask-kaf-open {
  overflow: auto;
}

/* Beat the older max-width 600px full viewport rules so the panel
   still clears the launcher on large phones and in landscape. */
@media (max-width: 600px) {
  .ask-kaf-panel {
    top: auto !important;
    left: auto !important;
    right: var(--ak-safe-right) !important;
    bottom: calc(var(--ak-safe-bottom) + var(--ak-launcher-h) + var(--ak-gap)) !important;
    width: min(400px, calc(100vw - var(--ak-safe-left) - var(--ak-safe-right))) !important;
    height: min(640px, var(--ak-max-h)) !important;
    max-height: var(--ak-max-h) !important;
    background: transparent !important;
  }

  .ask-kaf-card {
    border-radius: 22px !important;
    border-top: 1px solid rgba(177, 252, 3, 0.14);
  }

  .ask-kaf-header {
    border-radius: 22px 22px 0 0;
    padding-top: 16px;
  }

  .ask-kaf-dock {
    right: var(--ak-safe-right) !important;
    bottom: var(--ak-safe-bottom) !important;
  }

  .ask-kaf-dock .ask-kaf-launcher,
  .ask-kaf-launcher {
    min-height: 44px;
    height: var(--ak-launcher-h);
    padding: 4px 16px 4px 4px;
  }

  .ask-kaf-dock .ask-kaf-launcher img,
  .ask-kaf-dock .ask-kaf-launcher .ask-kaf-head,
  .ask-kaf-launcher img,
  .ask-kaf-launcher .ask-kaf-head {
    width: 44px !important;
    height: 44px !important;
    margin: 0 !important;
  }
}

/* Near full width bottom sheet under 480px, still above the launcher. */
@media (max-width: 479.98px) {
  .ask-kaf {
    --ak-edge: 10px;
    --ak-launcher-h: 56px;
  }

  .ask-kaf-panel {
    left: var(--ak-safe-left) !important;
    right: var(--ak-safe-right) !important;
    width: auto !important;
    height: min(80dvh, var(--ak-max-h)) !important;
    max-height: var(--ak-max-h) !important;
    bottom: calc(var(--ak-safe-bottom) + var(--ak-launcher-h) + var(--ak-gap)) !important;
    top: auto !important;
  }

  .ask-kaf-card {
    border-radius: 18px 18px 14px 14px;
  }

  .ask-kaf-header {
    border-radius: 18px 18px 0 0;
  }

  body.ask-kaf-open {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ask-kaf-dock,
  .ask-kaf-launcher,
  .ask-kaf-panel,
  .ask-kaf-row,
  body {
    transition: none !important;
    animation: none !important;
  }
}

/* Rows must not stretch to fill the transcript. */
.ask-kaf-row,
.ask-kaf-row-kaf,
.ask-kaf-row-user {
  flex: 0 0 auto;
  height: auto;
}

/* ========================================================================
   Sandbox adaptation (Nov 20 2026)
   The live sandbox CSS is the Nov 17 widget plus a Nov 19 "go live" block.
   Selectors already match (.ask-kaf-dock is present). These rules cancel
   two Nov 19 behaviors that would fight this file: a 432px page push on
   wide screens when the panel is open, and a 52px icon-only circular
   launcher under 600px (with a non-square head). The panel stays above
   the visible pill launcher with a gap.
   ======================================================================== */

@media (min-width: 1200px) {
  body.ask-kaf-open {
    padding-right: 0 !important;
  }
}

@media (max-width: 600px) {
  .ask-kaf-dock .ask-kaf-launcher,
  .ask-kaf-launcher {
    width: auto !important;
    height: var(--ak-launcher-h) !important;
    min-height: 44px !important;
    padding: 4px 16px 4px 4px !important;
    gap: 10px !important;
    justify-content: flex-start !important;
    border-radius: 999px !important;
  }

  .ask-kaf-dock .ask-kaf-launcher > span {
    position: static !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    clip-path: none !important;
    white-space: nowrap !important;
    border: 0 !important;
    padding: 0 !important;
  }

  .ask-kaf-dock .ask-kaf-dismiss {
    display: grid !important;
  }
}

/* 2026-11-20: Marco asked for the old Kaf head back. Popup and tap target fixes stay. */
.ask-kaf .ask-kaf-launcher img,
.ask-kaf .ask-kaf-launcher .ask-kaf-head,
.ask-kaf-dock .ask-kaf-launcher img,
.ask-kaf-dock .ask-kaf-launcher .ask-kaf-head {
  width: 46px !important;
  height: 50px !important;
  margin: 0 !important;
  border-radius: 0 !important;
  object-fit: contain !important;
  object-position: center 30% !important;
  background: transparent !important;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.28)) !important;
}
.ask-kaf .ask-kaf-msg-avatar,
.ask-kaf .ask-kaf-transcript .ask-kaf-head {
  width: 40px !important;
  height: 46px !important;
  border-radius: 0 !important;
  object-fit: contain !important;
  object-position: center 30% !important;
  background: transparent !important;
}
@media (max-width: 599.98px) {
  .ask-kaf .ask-kaf-launcher img,
  .ask-kaf .ask-kaf-launcher .ask-kaf-head,
  .ask-kaf-dock .ask-kaf-launcher img,
  .ask-kaf-dock .ask-kaf-launcher .ask-kaf-head {
    width: 42px !important;
    height: 46px !important;
  }
}
