/* =========================================================
   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: 24px;
  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;
}
.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: 16px 18px 15px;
  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: 58px; height: 58px; 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: .1px; }
.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); }
.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-row { display: flex; gap: 9px; margin-bottom: 4px; 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: 3px 40px 10px; opacity: .8;
}
.fnk-time.fnk-t-user { text-align: right; margin: 3px 4px 10px; }

/* 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 { 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: wrap; gap: 8px; padding: 6px 16px 10px; background: transparent; }
.fnk-chip {
  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: 8px 14px; 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: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 ---------------- */
.fnk-composer {
  flex-shrink: 0; display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 14px 13px;
  background: rgba(255,255,255,.92);
  border-top: 1px solid var(--fnk-line);
}
.fnk-input {
  flex: 1; resize: none; max-height: 110px;
  background: #F4F7FA; color: var(--fnk-text);
  border: 1.5px solid rgba(16,38,58,.12);
  border-radius: 999px;
  padding: 11px 18px; font: inherit; font-size: 14.5px; line-height: 1.4;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.fnk-input::placeholder { color: #90A0B0; }
.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-send {
  width: 46px; height: 46px; flex-shrink: 0; 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; place-items: center;
  transition: transform .15s, filter .2s, box-shadow .2s;
}
.fnk-send svg { width: 19px; height: 19px; fill: #FFFFFF; }
.fnk-send:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: 0 6px 16px rgba(244,163,0,.5); }
.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-hp { position: absolute; left: -9999px; opacity: 0; height: 0; width: 0; }

/* ---------------- Mobile ---------------- */
@media (max-width: 560px) {
  #fnk-ai-root { right: 14px; bottom: 14px; }
  .fnk-panel {
    position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%;
    height: 90vh;  max-height: 90vh;
    height: 90dvh; max-height: 90dvh;
    border-radius: 20px 20px 0 0;
  }
  .fnk-tip { display: none; }
}

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