/* Kharis chat. Uses the FCG brand: navy, cobalt, cyan, Inter, Cormorant Garamond. */
.kh-root {
  --kh-navy: #0d1b2e;
  --kh-navy-2: #16304f;
  --kh-cobalt: #1a56db;
  --kh-cyan: #38bdf8;
  --kh-ice: #eef4fb;
  --kh-line: #dbe5f0;
  --kh-ink: #101d31;
  --kh-muted: #52627a;
  --kh-online: #22c55e;
  --kh-ease: cubic-bezier(.23, 1, .32, 1);
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: calc(var(--kh-keyboard-offset, 0px) + max(20px, env(safe-area-inset-bottom)));
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: "Inter", Arial, sans-serif;
  color: var(--kh-ink);
  pointer-events: none;
}
.kh-root > * { pointer-events: auto; }
.kh-root *, .kh-root *::before, .kh-root *::after { box-sizing: border-box; }
.kh-root [hidden] { display: none !important; }
.kh-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Avatar with online dot */
.kh-avatar { position: relative; flex: 0 0 auto; width: 44px; height: 44px; }
.kh-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: contain; display: block; border: 2px solid #fff; background: var(--kh-navy); }
.kh-avatar-lg { width: 48px; height: 48px; }
.kh-dot { position: absolute; right: 0; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; background: var(--kh-cyan); border: 2px solid #fff; }
.kh-root[data-connection="connected"] .kh-dot { background: var(--kh-online); }
.kh-root[data-connection="connected"] .kh-dot::after { content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--kh-online); opacity: 0; animation: kh-pulse 2.6s ease-out infinite; }
@keyframes kh-pulse { 0% { transform: scale(.8); opacity: .7; } 70%, 100% { transform: scale(2); opacity: 0; } }

/* Launcher */
.kh-launcher {
  display: inline-flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 8px 22px 8px 8px;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--kh-navy); color: #fff;
  box-shadow: 0 12px 30px rgba(13, 27, 46, .28), 0 2px 6px rgba(13, 27, 46, .12);
  font: inherit; text-align: left;
  transition: transform .25s var(--kh-ease), box-shadow .25s var(--kh-ease), background .2s;
}
.kh-launcher-text { display: grid; line-height: 1.2; }
.kh-launcher-text strong { font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.kh-launcher-text small { font-size: 12px; color: #a9d8f5; }
.kh-launcher:focus-visible, .kh-close:focus-visible, .kh-chip:focus-visible, .kh-send:focus-visible,
.kh-nudge-open:focus-visible, .kh-nudge-close:focus-visible { outline: 3px solid var(--kh-cyan); outline-offset: 3px; }
.kh-open .kh-launcher { background: var(--kh-navy-2); }

/* Nudge bubble */
.kh-nudge {
  position: relative; display: flex; align-items: flex-start;
  max-width: 300px; border-radius: 18px 18px 6px 18px;
  background: #fff; border: 1px solid var(--kh-line);
  box-shadow: 0 16px 36px rgba(13, 27, 46, .16);
  opacity: 0; transform: translateY(8px) scale(.98);
  transition: opacity .35s var(--kh-ease), transform .35s var(--kh-ease);
}
.kh-nudge.kh-in { opacity: 1; transform: none; }
.kh-nudge-open {
  display: grid; gap: 4px; padding: 14px 8px 14px 16px;
  border: 0; background: none; cursor: pointer; text-align: left; font: inherit; color: var(--kh-ink);
}
.kh-nudge-name { font-size: 12px; font-weight: 700; color: var(--kh-cobalt); letter-spacing: .02em; }
.kh-nudge-text { font-size: 14px; line-height: 1.45; }
.kh-nudge-close {
  flex: 0 0 auto; width: 44px; height: 44px; margin: 4px 4px 0 0;
  border: 0; border-radius: 50%; background: none; color: var(--kh-muted);
  font-size: 20px; line-height: 1; cursor: pointer;
}

/* Panel */
.kh-panel {
  display: flex; flex-direction: column;
  width: min(400px, 100%);
  height: min(640px, calc(var(--kh-viewport-height, 100dvh) - 120px));
  min-height: 0;
  border-radius: 22px; overflow: hidden;
  background: #fff; border: 1px solid var(--kh-line);
  box-shadow: 0 30px 70px rgba(13, 27, 46, .24), 0 4px 12px rgba(13, 27, 46, .08);
  animation: kh-rise .32s var(--kh-ease);
}
@keyframes kh-rise { from { opacity: 0; transform: translateY(12px) scale(.985); } to { opacity: 1; transform: none; } }

.kh-header {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 12px 16px 18px;
  background: linear-gradient(135deg, var(--kh-navy) 0%, var(--kh-navy-2) 100%);
  color: #fff;
}
.kh-header .kh-dot { border-color: var(--kh-navy); }
.kh-who { flex: 1 1 auto; min-width: 0; }
.kh-title { margin: 0; font-family: "Cormorant Garamond", Georgia, serif; font-size: 24px; font-weight: 700; line-height: 1.05; color: #fff; }
.kh-status { display: flex; align-items: center; gap: 6px; margin: 4px 0 0; font-size: 12.5px; color: #c7e6fb; }
.kh-status-dot { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--kh-cyan); }
.kh-root[data-connection="connected"] .kh-status-dot { background: var(--kh-online); }
.kh-close {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .08); color: #fff; font-size: 24px; line-height: 1; cursor: pointer;
  transition: background .2s;
}

.kh-log {
  flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px 8px; background: var(--kh-ice);
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.kh-row { display: flex; flex: 0 0 auto; }
.kh-user { justify-content: flex-end; }
.kh-bubble {
  max-width: 86%; padding: 11px 14px; border-radius: 18px;
  font-size: 14.5px; line-height: 1.5; overflow-wrap: anywhere;
  animation: kh-fade .25s var(--kh-ease);
}
@keyframes kh-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.kh-agent .kh-bubble { background: #fff; color: var(--kh-ink); border: 1px solid var(--kh-line); border-bottom-left-radius: 6px; }
.kh-user .kh-bubble { background: var(--kh-cobalt); color: #fff; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.kh-bubble p { margin: 0; }
.kh-bubble p + p, .kh-bubble p + ul, .kh-bubble ul + p { margin-top: 8px; }
.kh-bubble ul { margin: 6px 0 0; padding-left: 18px; }
.kh-bubble li + li { margin-top: 3px; }
.kh-bubble a { color: var(--kh-cobalt); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.kh-bubble strong { font-weight: 700; }

.kh-typing { display: inline-flex; gap: 5px; align-items: center; padding: 14px 16px; }
.kh-typing span { width: 7px; height: 7px; border-radius: 50%; background: #93a3b8; animation: kh-bounce 1.2s infinite ease-in-out; }
.kh-typing span:nth-child(2) { animation-delay: .15s; }
.kh-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes kh-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.kh-chips { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 16px 12px; background: var(--kh-ice); }
.kh-chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid #bcd3ee; background: #fff; color: var(--kh-cobalt);
  font: 600 13px/1.25 "Inter", Arial, sans-serif; cursor: pointer; text-align: left;
  transition: background .2s, border-color .2s;
}

.kh-form {
  flex: 0 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  margin: 0; padding: 12px 12px 10px 16px;
  border-top: 1px solid var(--kh-line); background: #fff;
}
.kh-input {
  flex: 1 1 auto; min-width: 0; min-height: 44px; max-height: 120px; resize: none;
  padding: 11px 14px; border: 1px solid #c8d6e6; border-radius: 14px;
  font: 16px/1.4 "Inter", Arial, sans-serif; color: var(--kh-ink); background: #fff;
}
.kh-input:focus { outline: none; border-color: var(--kh-cobalt); box-shadow: 0 0 0 3px rgba(26, 86, 219, .15); }
.kh-send {
  flex: 0 0 auto; display: grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--kh-cobalt); color: #fff; cursor: pointer;
  transition: background .2s, transform .2s var(--kh-ease);
}
.kh-send:disabled { background: #9db5d8; cursor: default; }
.kh-foot { flex: 0 0 auto; margin: 0; padding: 0 16px 12px; background: #fff; font-size: 12px; line-height: 1.45; color: var(--kh-muted); }
.kh-foot a { color: var(--kh-cobalt); font-weight: 600; }

@media (hover: hover) and (pointer: fine) {
  .kh-launcher:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(13, 27, 46, .32); }
  .kh-close:hover { background: rgba(255, 255, 255, .18); }
  .kh-chip:hover { background: #f1f6fd; border-color: var(--kh-cobalt); }
  .kh-send:not(:disabled):hover { background: #1747b8; transform: scale(1.05); }
  .kh-nudge-close:hover { background: var(--kh-ice); }
}

/* Phones: compact launcher and a near full-height sheet */
@media (max-width: 640px) {
  .kh-root { left: 12px; right: 12px; bottom: calc(var(--kh-keyboard-offset, 0px) + max(12px, env(safe-area-inset-bottom))); gap: 10px; }
  .kh-launcher { min-height: 56px; padding: 6px; border-radius: 50%; }
  .kh-launcher .kh-avatar { width: 44px; height: 44px; }
  .kh-launcher-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .kh-panel { width: 100%; height: calc(var(--kh-viewport-height, 100dvh) - 92px); border-radius: 18px; }
  .kh-nudge { max-width: min(300px, 100%); }
  body:has(.request-form :is(input, select, textarea):focus) .kh-root:not(.kh-open) { visibility: hidden; }
}

/* Short windows and an open software keyboard keep the composer in view. */
.kh-compact.kh-open .kh-launcher, .kh-compact .kh-chips { display: none; }
.kh-compact .kh-panel { height: calc(var(--kh-viewport-height, 100dvh) - 40px); }
.kh-compact .kh-header { padding: 8px 12px; }
.kh-compact .kh-avatar-lg { width: 40px; height: 40px; }
.kh-compact .kh-log { padding: 10px 12px; }
.kh-compact .kh-input { max-height: 64px; }
.kh-compact .kh-form { padding: 8px 12px; }
.kh-compact .kh-foot { padding: 0 12px 8px; }

@media (prefers-reduced-motion: reduce) {
  .kh-root *, .kh-root *::before, .kh-root *::after { animation: none !important; transition: none !important; }
  .kh-log { scroll-behavior: auto; }
}
