/* =========================================================
   FreelancerNK AI Sales Consultant v1.1 — "Golden Hour"
   Premium light theme (Intercom/Tidio class)
   Palette:
     --fnk-gold    #F4A300  primary brand (launcher, user bubbles, CTAs)
     --fnk-navy    #10263A  secondary (header, headings)
     --fnk-bg      #FFFFFF  surfaces
     --fnk-accent  #EAF4FF  AI bubbles / soft accents
   No external font or asset requests (GDPR-safe, cache-safe).
   ========================================================= */

#fnk-ai-root {
  --fnk-gold: #F4A300;
  --fnk-gold-deep: #DE8F00;
  --fnk-navy: #10263A;
  --fnk-navy-2: #1A3550;
  --fnk-bg: #FFFFFF;
  --fnk-accent: #EAF4FF;
  --fnk-text: #1C2B3A;
  --fnk-muted: #64748B;
  --fnk-line: rgba(16, 38, 58, .10);
  position: fixed;
  z-index: 999999;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--fnk-text);
  -webkit-font-smoothing: antialiased;
}
#fnk-ai-root *, #fnk-ai-root *::before, #fnk-ai-root *::after { box-sizing: border-box; }

/* ---------------- Launcher: golden orb ---------------- */
.fnk-launcher {
  position: relative;
  width: 64px; height: 64px;
  border: 0; padding: 0; cursor: pointer;
  border-radius: 50%;
  background: linear-gradient(140deg, #FFB627 0%, var(--fnk-gold) 45%, var(--fnk-gold-deep) 100%);
  box-shadow: 0 8px 26px rgba(244, 163, 0, .45), 0 3px 8px rgba(16, 38, 58, .18);
  display: grid; place-items: center;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s,
              opacity .2s ease, visibility .2s;
}
.fnk-launcher:active { transform: scale(.95); }
.fnk-launcher:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 12px 32px rgba(244,163,0,.55), 0 4px 10px rgba(16,38,58,.2); }
.fnk-launcher:focus-visible { outline: 3px solid var(--fnk-navy); outline-offset: 3px; }
.fnk-launcher svg { width: 30px; height: 30px; fill: #FFFFFF; }

/* gentle recurring pulse */
.fnk-launcher::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(244, 163, 0, .55);
  animation: fnk-pulse 4.5s ease-out infinite;
  pointer-events: none;
}
@keyframes fnk-pulse {
  0%, 78% { box-shadow: 0 0 0 0 rgba(244,163,0,.5); }
  90%     { box-shadow: 0 0 0 16px rgba(244,163,0,0); }
  100%    { box-shadow: 0 0 0 0 rgba(244,163,0,0); }
}

/* notification badge */
.fnk-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 21px; height: 21px; padding: 0 5px;
  border-radius: 999px;
  background: #E23D3D; color: #fff;
  font-size: 12px; font-weight: 700; line-height: 21px; text-align: center;
  border: 2.5px solid #fff;
  animation: fnk-pop .35s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes fnk-pop { from { transform: scale(0); } }
.fnk-badge[hidden] { display: none; }

/* tooltip */
.fnk-tip {
  position: absolute; right: 76px; top: 50%; transform: translateY(-50%) translateX(6px);
  background: var(--fnk-navy); color: #fff;
  font-size: 13px; font-weight: 500; white-space: nowrap;
  padding: 9px 14px; border-radius: 12px;
  box-shadow: 0 6px 18px rgba(16,38,58,.28);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .25s cubic-bezier(.22,1.2,.36,1);
}
.fnk-tip::after {
  content: ""; position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
  border: 6px solid transparent; border-left-color: var(--fnk-navy);
}
.fnk-launcher:hover .fnk-tip,
.fnk-launcher:focus-visible .fnk-tip { opacity: 1; transform: translateY(-50%) translateX(0); }
#fnk-ai-root.fnk-is-open .fnk-tip { opacity: 0 !important; }

/* ---------------- Panel: white glass ---------------- */
.fnk-panel {
  position: absolute; right: 0; bottom: 82px;
  width: 396px; max-width: calc(100vw - 32px);
  height: 620px; max-height: calc(100vh - 130px);
  display: flex; flex-direction: column;
  border-radius: 20px;
  background: rgba(255, 255, 255, .86);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
          backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid rgba(16, 38, 58, .09);
  box-shadow: 0 24px 64px rgba(16, 38, 58, .22), 0 4px 14px rgba(16, 38, 58, .10);
  overflow: hidden;
  opacity: 0; transform: translateY(14px) scale(.96); transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .24s ease, transform .28s cubic-bezier(.22,1.2,.36,1);
}
.fnk-panel.fnk-open { opacity: 1; transform: none; pointer-events: auto; }
@supports not (backdrop-filter: blur(1px)) {
  .fnk-panel { background: #FFFFFF; } /* solid fallback for older browsers */
}

/* ---------------- Header: operator profile ---------------- */
.fnk-header {
  flex-shrink: 0; position: relative;
  padding: 14px 18px 13px;
  background: linear-gradient(140deg, #16324A 0%, var(--fnk-navy) 70%);
  color: #fff;
}
.fnk-header::after {          /* subtle gold hairline */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--fnk-gold), transparent);
  opacity: .8;
}
.fnk-header-row { display: flex; align-items: center; gap: 13px; }
.fnk-avatar-wrap { position: relative; flex-shrink: 0; }
.fnk-avatar {
  width: 54px; height: 54px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.85);
  box-shadow: 0 3px 10px rgba(0,0,0,.25);
  display: block; object-fit: cover; background: var(--fnk-accent);
}
.fnk-status-dot {
  position: absolute; right: 1px; bottom: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: #2ECC71; border: 2.5px solid var(--fnk-navy);
  animation: fnk-breathe 2.6s ease-in-out infinite;
}
@keyframes fnk-breathe { 0%,100% { box-shadow: 0 0 0 0 rgba(46,204,113,.5);} 55% { box-shadow: 0 0 0 5px rgba(46,204,113,0);} }
.fnk-name { font-weight: 700; font-size: 16.5px; letter-spacing: .2px; }
.fnk-role { font-size: 12.5px; color: #BBD2E6; margin-top: 1px; }
.fnk-status-line { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #9FC3DF; margin-top: 3px; }
.fnk-online { color: #7BE3A8; font-weight: 600; }
.fnk-min {
  margin-left: auto; align-self: flex-start;
  width: 32px; height: 32px; border: 0; border-radius: 9px; cursor: pointer;
  background: rgba(255,255,255,.12); color: #DDEAF5;
  font-size: 18px; line-height: 1;
  transition: background .2s;
}
.fnk-min:hover { background: rgba(255,255,255,.22); color: #fff; }
.fnk-min:active { transform: scale(.93); }
.fnk-min:focus-visible { outline: 2px solid var(--fnk-gold); }

/* ---------------- Messages ---------------- */
.fnk-messages {
  flex: 1; overflow-y: auto;
  padding: 18px 16px 6px;
  background:
    radial-gradient(60% 40% at 100% 0%, rgba(234,244,255,.7), transparent 70%),
    linear-gradient(#FDFEFF, #F7FAFD);
  scrollbar-width: thin; scrollbar-color: rgba(16,38,58,.22) transparent;
  overscroll-behavior: contain;
}
.fnk-messages::-webkit-scrollbar { width: 5px; }
.fnk-messages::-webkit-scrollbar-track { background: transparent; }
.fnk-messages::-webkit-scrollbar-thumb {
  background: rgba(16,38,58,.18); border-radius: 999px;
}
.fnk-messages::-webkit-scrollbar-thumb:hover { background: rgba(244,163,0,.55); }
.fnk-row { display: flex; gap: 9px; margin-bottom: 5px; align-items: flex-end; animation: fnk-rise .3s ease both; }
.fnk-row.fnk-from-user { justify-content: flex-end; }
@keyframes fnk-rise { from { opacity: 0; transform: translateY(8px); } }
.fnk-mini-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  object-fit: cover; border: 1.5px solid #fff;
  box-shadow: 0 1px 4px rgba(16,38,58,.18);
  background: var(--fnk-accent);
}
.fnk-msg {
  max-width: 78%; padding: 11px 15px;
  white-space: pre-wrap; word-wrap: break-word;
  font-size: 14.5px;
}
.fnk-msg.fnk-bot {
  background: var(--fnk-accent);
  color: var(--fnk-navy);
  border: 1px solid rgba(16,38,58,.07);
  border-radius: 16px 16px 16px 5px;
}
.fnk-msg.fnk-user {
  background: linear-gradient(135deg, #FFB627, var(--fnk-gold) 60%, var(--fnk-gold-deep));
  color: #FFFFFF; font-weight: 600;
  border-radius: 16px 16px 5px 16px;
  box-shadow: 0 3px 10px rgba(244,163,0,.30);
  text-shadow: 0 1px 1px rgba(122,74,0,.25); /* readability on gold */
}
.fnk-msg.fnk-error { background: #FDF0F0; border-color: rgba(214,69,69,.35); color: #A33A3A; }
.fnk-time {
  font-size: 10.5px; color: var(--fnk-muted);
  margin: 2px 40px 9px; opacity: .75;
}
.fnk-time.fnk-t-user { text-align: right; margin: 2px 4px 9px; }
.fnk-time.fnk-hidden { display: none; }   /* only the latest timestamp shows */

/* conversation divider */
.fnk-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 2px 4px 14px; color: var(--fnk-muted); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .6px;
}
.fnk-divider::before, .fnk-divider::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(16,38,58,.14), transparent);
}

/* delivery receipts */
.fnk-receipt {
  text-align: right; font-size: 10.5px; color: var(--fnk-muted);
  margin: -6px 4px 9px; opacity: .8;
  animation: fnk-fadein .3s ease both;
}
.fnk-receipt.fnk-seen { color: var(--fnk-gold-deep); font-weight: 600; }

/* lead confirmation card */
.fnk-lead-card {
  background: linear-gradient(150deg, #FFF7E6, #FFFDF7);
  border: 1px solid rgba(244,163,0,.45);
  border-radius: 16px; padding: 14px 16px; margin: 2px 0 12px 37px;
  font-size: 14px; animation: fnk-rise .35s ease both;
}
.fnk-lead-card b { color: var(--fnk-gold-deep); }

/* typing indicator */
.fnk-typing-wrap { animation: fnk-rise .25s ease both; }
.fnk-typing-label {
  font-size: 11px; color: var(--fnk-muted);
  margin: 2px 0 10px 40px; opacity: .85;
  animation: fnk-fadein .4s ease both;
}
@keyframes fnk-fadein { from { opacity: 0; } to { opacity: .85; } }
.fnk-typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.fnk-typing i {
  width: 7px; height: 7px; border-radius: 50%; background: #8FA8BF;
  animation: fnk-blink 1.2s ease-in-out infinite;
}
.fnk-typing i:nth-child(2) { animation-delay: .18s; }
.fnk-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes fnk-blink { 0%,80%,100% { opacity: .3; transform: translateY(0);} 40% { opacity: 1; transform: translateY(-3px);} }

/* ---------------- Quick actions ---------------- */
.fnk-chips {
  display: flex; flex-wrap: nowrap; gap: 8px;
  padding: 6px 16px 12px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;   /* momentum on iOS */
  touch-action: pan-x pan-y;           /* horizontal swipes belong to this row, not the browser */
  overscroll-behavior-x: contain;      /* never triggers page back-navigation on over-swipe */
  scrollbar-width: none;               /* one swipeable row — chat area stays large */
  cursor: grab;
}
.fnk-chips-wrap { position: relative; flex-shrink: 0; }
.fnk-chips-wrap.fnk-hiddenrow { display: none; }
.fnk-chip-nav {
  position: absolute; top: 50%; transform: translateY(-58%);
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid rgba(16,38,58,.14);
  background: rgba(255,255,255,.96); color: var(--fnk-navy);
  font-size: 17px; line-height: 1; font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 10px rgba(16,38,58,.16);
  display: none; align-items: center; justify-content: center;
  z-index: 2; transition: background .15s, transform .15s, opacity .15s;
}
.fnk-chip-nav:hover { background: #FFF4DE; }
.fnk-chip-nav:active { transform: translateY(-58%) scale(.92); }
.fnk-chip-nav:focus-visible { outline: 2px solid var(--fnk-gold-deep); }
.fnk-nav-l { left: 6px; }
.fnk-nav-r { right: 6px; }
/* Arrows only on devices with a mouse/trackpad; touch users swipe natively */
@media (hover: hover) and (pointer: fine) {
  .fnk-chips-wrap.fnk-fade-l .fnk-nav-l { display: flex; }
  .fnk-chips-wrap.fnk-fade-r .fnk-nav-r { display: flex; }
}

/* Edge fades appear only on the side(s) with more content (classes set by JS) */
.fnk-chips-wrap.fnk-fade-r .fnk-chips {
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 92%, transparent 100%);
          mask-image: linear-gradient(90deg, #000 0, #000 92%, transparent 100%);
}
.fnk-chips-wrap.fnk-fade-l .fnk-chips {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 8%, #000 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 8%, #000 100%);
}
.fnk-chips-wrap.fnk-fade-l.fnk-fade-r .fnk-chips {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 8%, #000 92%, transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 8%, #000 92%, transparent 100%);
}
.fnk-chips::-webkit-scrollbar { display: none; }
.fnk-chips.fnk-dragging { cursor: grabbing; }
.fnk-chips.fnk-dragging .fnk-chip { pointer-events: none; }  /* no accidental clicks mid-drag */
.fnk-chip {
  flex-shrink: 0; min-height: 40px;
  border: 1.5px solid rgba(244,163,0,.65);
  background: #FFFFFF; color: var(--fnk-navy);
  font-size: 13px; font-weight: 600; font-family: inherit;
  padding: 9px 15px; border-radius: 999px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(16,38,58,.06);
  transition: background .18s, transform .15s, box-shadow .18s;
}
.fnk-chip:active { transform: scale(.97); }
.fnk-chip:hover { background: #FFF4DE; transform: translateY(-1px); box-shadow: 0 3px 9px rgba(244,163,0,.25); }
.fnk-chip:focus-visible { outline: 2px solid var(--fnk-navy); }

/* ---------------- Consent ---------------- */
.fnk-consent {
  display: none; align-items: flex-start; gap: 9px;
  margin: 0 16px 10px; padding: 11px 13px; border-radius: 13px;
  background: #FFF9EE; border: 1px solid rgba(244,163,0,.4);
  font-size: 12px; color: #5B6B7B;
}
.fnk-consent.fnk-show { display: flex; }
.fnk-consent input { margin-top: 2px; accent-color: var(--fnk-gold-deep); }
.fnk-consent a { color: var(--fnk-gold-deep); font-weight: 600; }

/* ---------------- Composer ---------------- */
/* =====================================================================
   COMPOSER — hardened against theme/page-builder CSS interference.
   Every selector is anchored to #fnk-ai-root and layout-critical
   properties carry !important, so global rules from Astra, Elementor,
   or form plugins (e.g. `textarea { width:100% !important }`) can
   never break this row. Pure flexbox, no absolute positioning.
   ===================================================================== */
#fnk-ai-root .fnk-composer {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  gap: 10px;
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box !important;
  padding: 12px 14px 13px;
  background: rgba(255,255,255,.92);
  border-top: 1px solid var(--fnk-line);
}
#fnk-ai-root .fnk-composer .fnk-input {
  /* flex:1 + min-width:0 = input takes exactly the remaining width and can
     always shrink; its intrinsic textarea width can never overflow the row */
  flex: 1 1 0% !important;
  min-width: 0 !important;
  width: auto !important;
  max-width: 100% !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  float: none !important;
  resize: none; max-height: 110px;
  background: #F4F7FA; color: var(--fnk-text);
  border: 1.5px solid rgba(16,38,58,.12);
  border-radius: 999px;
  padding: 12px 18px; min-height: 48px;
  font: inherit; font-size: 14.5px; line-height: 1.4;
  -webkit-appearance: none; appearance: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
#fnk-ai-root .fnk-composer .fnk-input::placeholder { color: #90A0B0; }
#fnk-ai-root .fnk-composer .fnk-input:focus {
  outline: none; background: #fff;
  border-color: var(--fnk-gold);
  box-shadow: 0 0 0 3.5px rgba(244,163,0,.22);
}
#fnk-ai-root .fnk-composer .fnk-send {
  /* Fixed-size, non-shrinking, always ≥44px touch target, always clickable */
  flex: 0 0 48px !important;
  width: 48px !important;
  height: 48px !important;
  min-width: 48px !important;
  min-height: 48px !important;
  margin: 0 !important;
  padding: 0 !important;
  position: static !important;
  box-sizing: border-box !important;
  border: 0; border-radius: 50%; cursor: pointer;
  background: linear-gradient(135deg, #FFB627, var(--fnk-gold) 60%, var(--fnk-gold-deep));
  box-shadow: 0 4px 12px rgba(244,163,0,.4);
  display: grid !important; place-items: center;
  transition: transform .15s, filter .2s, box-shadow .2s;
}
#fnk-ai-root .fnk-composer .fnk-send svg { width: 19px; height: 19px; fill: #FFFFFF; pointer-events: none; }
.fnk-send:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: 0 6px 16px rgba(244,163,0,.5); }
.fnk-send:active { transform: scale(.94); }
.fnk-send:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }
.fnk-send:focus-visible { outline: 2.5px solid var(--fnk-navy); outline-offset: 2px; }

.fnk-footnote {
  flex-shrink: 0; text-align: center; font-size: 10.5px; color: var(--fnk-muted);
  padding: 0 12px 9px; background: rgba(255,255,255,.92);
}

/* honeypot */
#fnk-ai-root .fnk-hp {
  display: none !important;
  position: absolute !important; left: -9999px;
  opacity: 0; height: 0; width: 0; pointer-events: none;
}

/* ---------------- Mobile ---------------- */
@media (max-width: 560px) {
  #fnk-ai-root { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .fnk-panel {
    position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%;
    border-radius: 18px 18px 0 0;
    /* Fallback chain: vh -> dvh -> live visualViewport height (set by JS).
       The panel resizes WITH the on-screen keyboard, so the composer and
       newest messages always stay visible and nothing is covered. */
    height: 100vh;  max-height: 100vh;
    height: 100dvh; max-height: 100dvh;
    height: var(--fnk-vvh, 100dvh); max-height: var(--fnk-vvh, 100dvh);
  }
  /* While the full-screen chat sheet is open, the floating launcher is
     hidden entirely — it can never cover the Send button, composer, quick
     actions, or any interactive UI. It scale-fades back when minimised.
     (Closing remains available via the header minimise button and Esc.) */
  #fnk-ai-root.fnk-is-open .fnk-launcher {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(.6);
  }
  #fnk-ai-root .fnk-composer { padding-bottom: calc(13px + env(safe-area-inset-bottom, 0px)); }
  #fnk-ai-root .fnk-composer .fnk-input { font-size: 16px; }
  .fnk-footnote { padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px)); }
  .fnk-tip { display: none; }
}

/* Tablets / iPad: comfortable floating panel, larger than phone sheet */
@media (min-width: 561px) and (max-width: 1024px) {
  .fnk-panel { width: 420px; height: 640px; }
}

/* ---------------- Reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  #fnk-ai-root *, #fnk-ai-root *::before, #fnk-ai-root *::after {
    animation: none !important; transition: none !important;
  }
}
