/* =========================================================================
   CHATKÎA — Embeddable Chat Widget Styles
   All colors/sizes are CSS custom properties on .chatkia-root, so a site
   integrating this widget can re-theme it entirely by overriding the
   variables below (either in their own stylesheet or inline).
   Every selector is prefixed "chatkia-" and scoped under .chatkia-root so
   dropping this onto any host page will not leak or collide with their CSS.
   ========================================================================= */

.chatkia-root, .chatkia-root * , .chatkia-root *::before, .chatkia-root *::after {
  box-sizing: border-box;
}

.chatkia-root {
  /* ---- Brand / theme tokens (safe to override) ---- */
  --chatkia-font:            'Source Sans 3', 'Segoe UI', -apple-system, sans-serif;

  --chatkia-primary:         #0078d4;   /* brand primary */
  --chatkia-primary-dark:    #005a9e;
  --chatkia-primary-light:   #e8f1fb;
  --chatkia-accent:          #038387;   /* secondary brand accent */

  --chatkia-surface:         #ffffff;   /* panel / card background */
  --chatkia-surface-soft:    #faf9f8;   /* muted panel background */
  --chatkia-border:          #edebe9;
  --chatkia-text:            #201f1e;
  --chatkia-text-muted:      #605e5c;
  --chatkia-text-faint:      #a19f9d;

  /* message bubble colors — independent of brand so they can be tuned alone */
  --chatkia-sender-bg:       var(--chatkia-primary);
  --chatkia-sender-text:     #ffffff;
  --chatkia-receiver-bg:     #f3f2f1;
  --chatkia-receiver-text:   var(--chatkia-text);

  --chatkia-status-online:   #107c10;
  --chatkia-status-away:     #d8a10a;
  --chatkia-status-offline:  #a19f9d;

  --chatkia-radius-lg:       16px;
  --chatkia-radius-md:       10px;
  --chatkia-radius-sm:       6px;
  --chatkia-shadow:          0 12px 40px rgba(0,0,0,.20);
  --chatkia-shadow-sm:       0 2px 8px rgba(0,0,0,.12);

  /* ---- Assets (point these at your own files) ---- */
  --chatkia-logo-mark:       url('assets/images/chatkia-logo-mark.png');  /* square mark, used on launcher */
  --chatkia-logo-full:       url('assets/images/chatkia-logo.png');       /* wordmark lockup, used in header */
  --chatkia-bg-pattern:      url('assets/images/bg-pattern.webp');
  --chatkia-accent-pattern:  url('assets/images/payment-pattern.png');

  /* ---- Layout ---- */
  --chatkia-launcher-size:   72px;
  --chatkia-panel-width:     380px;
  --chatkia-panel-height:    640px;
  --chatkia-panel-min-height: 420px;
  --chatkia-header-h:        62px;
  --chatkia-agents-h:        68px;
  --chatkia-gap-edge:        24px;
  --chatkia-z:                999999;

  font-family: var(--chatkia-font);
  position: fixed;
  z-index: var(--chatkia-z);
  bottom: 0; right: 0;
}

/* Positioning modes, set via data-position on .chatkia-root */
.chatkia-root[data-position="bottom-right"] { }
.chatkia-root[data-position="middle-right"] .chatkia-launcher-wrap { top: 50%; bottom: auto; transform: translateY(-50%); }
.chatkia-root[data-position="middle-right"] .chatkia-panel { top: 50%; bottom: auto; transform: translateY(-50%); }

.chatkia-launcher-wrap {
  position: fixed;
  right: var(--chatkia-gap-edge);
  bottom: var(--chatkia-gap-edge);
  z-index: var(--chatkia-z);
}

/* ── LAUNCHER BUTTON + PULSE ── */
.chatkia-launcher {
  position: relative;
  width: var(--chatkia-launcher-size);
  height: var(--chatkia-launcher-size);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--chatkia-surface);
  background: linear-gradient(150deg, var(--chatkia-primary-light), var(--chatkia-surface) 60%);
  box-shadow: var(--chatkia-shadow), 0 0 0 4px rgba(255,255,255,.7), 0 0 0 5px rgba(0,0,0,.06);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: transform .18s ease, box-shadow .18s ease;
}
.chatkia-launcher:hover { transform: translateY(-3px); box-shadow: 0 18px 46px rgba(0,0,0,.26), 0 0 0 4px rgba(255,255,255,.7), 0 0 0 5px rgba(0,0,0,.08); }
.chatkia-launcher:active { transform: translateY(0) scale(.97); }

.chatkia-launcher-logo {
  width: 76%; height: 76%; object-fit: contain; position: relative; z-index: 2;
  border-radius: 50%;
}

.chatkia-pulse-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--chatkia-primary);
  opacity: 0;
  animation: chatkia-pulse 2.6s cubic-bezier(.35,.0,.25,1) infinite;
  pointer-events: none;
}
.chatkia-pulse-ring.r2 { animation-delay: .7s; }
.chatkia-pulse-ring.r3 { animation-delay: 1.4s; }

@keyframes chatkia-pulse {
  0%   { transform: scale(1);    opacity: .45; }
  70%  { transform: scale(1.85); opacity: 0; }
  100% { transform: scale(1.85); opacity: 0; }
}

.chatkia-launcher-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: #d13438; color: #fff;
  border: 2px solid var(--chatkia-surface);
  border-radius: 999px; font-size: 10.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  z-index: 3;
}
.chatkia-launcher-badge[hidden] { display: none; }

.chatkia-root.chatkia-open .chatkia-launcher-wrap { display: none; }

/* ── PANEL ── */
.chatkia-panel {
  position: fixed;
  right: var(--chatkia-gap-edge);
  bottom: var(--chatkia-gap-edge);
  width: var(--chatkia-panel-width);
  height: var(--chatkia-panel-height);
  max-height: calc(100vh - (2 * var(--chatkia-gap-edge)));
  background: var(--chatkia-surface-soft);
  border-radius: var(--chatkia-radius-lg);
  box-shadow: var(--chatkia-shadow);
  border: 1px solid var(--chatkia-border);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: var(--chatkia-z);
  opacity: 0; transform: translateY(16px) scale(.98);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.chatkia-root.chatkia-open .chatkia-panel {
  opacity: 1; transform: translateY(0) scale(1); pointer-events: auto;
}

.chatkia-panel.chatkia-full {
  width: 100vw; height: 100dvh; max-height: 100dvh;
  right: 0; bottom: 0; top: 0; left: 0;
  border-radius: 0; transform: none !important; top: 0 !important;
}

/* Full-screen mode: keep content off the browser edges and centered in a
   comfortable reading column on wide viewports. */
.chatkia-panel.chatkia-full .chatkia-header,
.chatkia-panel.chatkia-full .chatkia-agents,
.chatkia-panel.chatkia-full .chatkia-messages,
.chatkia-panel.chatkia-full .chatkia-attach-preview,
.chatkia-panel.chatkia-full .chatkia-composer-outer,
.chatkia-panel.chatkia-full .chatkia-footer {
  padding-left: max(24px, calc(50% - 380px));
  padding-right: max(24px, calc(50% - 380px));
}

/* ── HEADER ── */
.chatkia-header {
  height: var(--chatkia-header-h); flex-shrink: 0;
  background: var(--chatkia-primary);
  color: #fff;
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
}
.chatkia-icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: transparent; color: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 0;
  transition: background .12s ease;
}
.chatkia-icon-btn:hover { background: rgba(255,255,255,.16); }
.chatkia-icon-btn svg { width: 19px; height: 19px; fill: currentColor; }

.chatkia-menu-wrap { position: relative; }

.chatkia-brand { display: flex; align-items: center; margin-left: 6px; }
.chatkia-brand-logo { height: 36px; width: auto; max-width: 160px; object-fit: contain; }

.chatkia-header-spacer { flex: 1; }
.chatkia-header-actions { display: flex; align-items: center; gap: 2px; }

/* menu dropdown (Chat / History / Media) */
.chatkia-menu-dropdown {
  position: absolute; top: calc(100% + 8px); left: 0;
  width: 190px;
  background: var(--chatkia-surface);
  border: 1px solid var(--chatkia-border);
  border-radius: var(--chatkia-radius-md);
  box-shadow: var(--chatkia-shadow);
  padding: 6px;
  display: none;
  z-index: 5;
}
.chatkia-menu-dropdown.chatkia-show { display: block; }
.chatkia-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: none; background: none; border-radius: var(--chatkia-radius-sm);
  color: var(--chatkia-text); font-size: 13.5px; font-weight: 600; font-family: var(--chatkia-font);
  cursor: pointer; text-align: left;
}
.chatkia-menu-item svg { width: 17px; height: 17px; fill: var(--chatkia-text-muted); flex-shrink: 0; }
.chatkia-menu-item:hover { background: var(--chatkia-surface-soft); }
.chatkia-menu-item.chatkia-active { background: var(--chatkia-primary-light); color: var(--chatkia-primary); }
.chatkia-menu-item.chatkia-active svg { fill: var(--chatkia-primary); }

/* ── AGENTS STRIP ── */
.chatkia-agents {
  height: var(--chatkia-agents-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--chatkia-surface);
  border-bottom: 1px solid var(--chatkia-border);
  overflow-x: auto;
}
.chatkia-agent { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chatkia-agent-avatar { position: relative; width: 34px; height: 34px; flex-shrink: 0; }
.chatkia-agent-avatar img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block;
  background: var(--chatkia-primary-light);
}
.chatkia-agent-avatar .chatkia-initials {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--chatkia-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.chatkia-status-dot {
  position: absolute; bottom: -1px; right: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--chatkia-surface);
}
.chatkia-status-dot.online  { background: var(--chatkia-status-online); }
.chatkia-status-dot.away    { background: var(--chatkia-status-away); }
.chatkia-status-dot.offline { background: var(--chatkia-status-offline); }

.chatkia-agent-info { line-height: 1.25; }
.chatkia-agent-name { font-size: 12.5px; font-weight: 700; color: var(--chatkia-text); white-space: nowrap; }
.chatkia-agent-status { font-size: 10.5px; color: var(--chatkia-text-muted); }
.chatkia-agent-status.online  { color: var(--chatkia-status-online); }
.chatkia-agent-status.away    { color: var(--chatkia-status-away); }
.chatkia-agent-status.offline { color: var(--chatkia-text-faint); }

/* ── BODY / VIEWS ── */
.chatkia-body { flex: 1; min-height: 0; position: relative; }
.chatkia-view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.chatkia-view[hidden] { display: none; }

/* Chat view */
.chatkia-messages {
  flex: 1; overflow-y: auto; padding: 16px 14px;
  display: flex; flex-direction: column; gap: 12px;
  background-color: var(--chatkia-surface-soft);
  background-image:
    linear-gradient(rgba(250,249,248,.93), rgba(250,249,248,.93)),
    var(--chatkia-bg-pattern);
  background-size: cover; background-position: top center; background-repeat: no-repeat;
}
.chatkia-day-divider { text-align: center; font-size: 11px; color: var(--chatkia-text-faint); margin: 4px 0; }
.chatkia-msg-row { display: flex; gap: 8px; max-width: 84%; }
.chatkia-msg-row.chatkia-sent { align-self: flex-end; flex-direction: row-reverse; }
.chatkia-msg-row.chatkia-received { align-self: flex-start; }
.chatkia-msg-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex-shrink: 0; margin-top: 2px; }
.chatkia-msg-bubble-wrap { display: flex; flex-direction: column; gap: 2px; }
.chatkia-msg-bubble {
  padding: 9px 13px; border-radius: var(--chatkia-radius-md);
  font-size: 13.5px; line-height: 1.48; word-wrap: break-word; white-space: pre-wrap;
}
.chatkia-sent .chatkia-msg-bubble {
  background: var(--chatkia-sender-bg); color: var(--chatkia-sender-text);
  border-bottom-right-radius: 3px;
}
.chatkia-received .chatkia-msg-bubble {
  background: var(--chatkia-receiver-bg); color: var(--chatkia-receiver-text);
  border-bottom-left-radius: 3px;
}
.chatkia-msg-time { font-size: 10px; color: var(--chatkia-text-faint); padding: 0 3px; }
.chatkia-sent .chatkia-msg-time { text-align: right; }
.chatkia-msg-file-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--chatkia-radius-md);
  background: rgba(255,255,255,.16);
  font-size: 12.5px; font-weight: 600;
}
.chatkia-received .chatkia-msg-file-chip { background: var(--chatkia-surface); border: 1px solid var(--chatkia-border); }
.chatkia-msg-file-chip svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }

.chatkia-typing { align-self: flex-start; display: flex; gap: 4px; padding: 10px 14px; background: var(--chatkia-receiver-bg); border-radius: var(--chatkia-radius-md); border-bottom-left-radius: 3px; }
.chatkia-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--chatkia-text-faint); animation: chatkia-typing-bounce 1.2s infinite ease-in-out; }
.chatkia-typing span:nth-child(2) { animation-delay: .15s; }
.chatkia-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatkia-typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* History view */
.chatkia-history-list { flex: 1; overflow-y: auto; padding: 6px; }
.chatkia-history-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 10px; border-radius: var(--chatkia-radius-md);
  cursor: pointer; border-bottom: 1px solid var(--chatkia-border);
}
.chatkia-history-item:hover { background: var(--chatkia-surface); }
.chatkia-history-item img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.chatkia-history-top { display: flex; justify-content: space-between; gap: 6px; }
.chatkia-history-title { font-size: 13px; font-weight: 700; color: var(--chatkia-text); }
.chatkia-history-time { font-size: 10.5px; color: var(--chatkia-text-faint); flex-shrink: 0; }
.chatkia-history-preview { font-size: 12px; color: var(--chatkia-text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Media view */
.chatkia-media-grid { flex: 1; overflow-y: auto; padding: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chatkia-media-tile {
  aspect-ratio: 1; border-radius: var(--chatkia-radius-sm); overflow: hidden;
  background: var(--chatkia-surface); border: 1px solid var(--chatkia-border);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.chatkia-media-tile img { width: 100%; height: 100%; object-fit: cover; }
.chatkia-media-tile.chatkia-media-file { flex-direction: column; gap: 6px; padding: 8px; text-align: center; }
.chatkia-media-tile.chatkia-media-file svg { width: 22px; height: 22px; fill: var(--chatkia-primary); }
.chatkia-media-tile.chatkia-media-file span { font-size: 10px; color: var(--chatkia-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.chatkia-empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 30px; text-align: center; color: var(--chatkia-text-muted); font-size: 13px; }
.chatkia-empty-state svg { width: 40px; height: 40px; fill: var(--chatkia-text-faint); }

/* ── ATTACHMENT PREVIEW ── */
.chatkia-attach-preview {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--chatkia-surface);
  font-size: 12.5px; color: var(--chatkia-text); flex-shrink: 0;
}
.chatkia-attach-preview[hidden] { display: none; }
.chatkia-attach-preview svg { width: 16px; height: 16px; fill: var(--chatkia-primary); flex-shrink: 0; }
.chatkia-attach-preview-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatkia-attach-remove { border: none; background: none; cursor: pointer; color: var(--chatkia-text-faint); font-size: 16px; line-height: 1; padding: 2px 4px; }
.chatkia-attach-remove:hover { color: #d13438; }

/* ── COMPOSER (pill-style message box) ── */
.chatkia-composer-outer {
  flex-shrink: 0;
  padding: 10px 14px 14px;
  background: var(--chatkia-surface);
  border-top: 1px solid var(--chatkia-border);
}
.chatkia-composer {
  display: flex; flex-direction: column;
  border: 1px solid var(--chatkia-border);
  border-radius: 18px;
  background: var(--chatkia-surface-soft);
  padding: 10px 12px 8px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.chatkia-composer:focus-within {
  border-color: var(--chatkia-primary);
  box-shadow: 0 0 0 3px var(--chatkia-primary-light);
  background: var(--chatkia-surface);
}
.chatkia-composer-textarea {
  width: 100%; border: none; background: transparent; outline: none; resize: none;
  font-family: var(--chatkia-font); font-size: 13.5px; color: var(--chatkia-text);
  line-height: 1.45; max-height: 90px; padding: 2px 2px 8px;
}
.chatkia-composer-textarea::placeholder { color: var(--chatkia-text-faint); }
.chatkia-composer-toolbar {
  display: flex; align-items: center; gap: 6px;
}
.chatkia-composer-spacer { flex: 1; }
.chatkia-composer .chatkia-attach-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: transparent; color: var(--chatkia-text-muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
  transition: background .12s ease, color .12s ease;
}
.chatkia-composer .chatkia-attach-btn:hover { background: var(--chatkia-border); color: var(--chatkia-primary); }
.chatkia-composer .chatkia-attach-btn svg { width: 18px; height: 18px; fill: currentColor; }
.chatkia-send-btn {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--chatkia-primary), var(--chatkia-accent));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s ease, opacity .12s ease;
}
.chatkia-send-btn svg { width: 16px; height: 16px; fill: currentColor; }
.chatkia-send-btn:hover { transform: scale(1.06); }
.chatkia-send-btn:active { transform: scale(.96); }
.chatkia-send-btn:disabled { opacity: .45; cursor: default; transform: none; }

/* ── FOOTER ── */
.chatkia-footer {
  flex-shrink: 0; text-align: center; padding: 6px 10px;
  font-size: 10.5px; color: var(--chatkia-text-faint);
  background: var(--chatkia-surface);
  border-top: 1px solid var(--chatkia-border);
}
.chatkia-footer strong { color: var(--chatkia-text-muted); font-weight: 700; }

/* ── SCROLLBAR (webkit, subtle) ── */
.chatkia-root .chatkia-messages::-webkit-scrollbar,
.chatkia-root .chatkia-history-list::-webkit-scrollbar,
.chatkia-root .chatkia-media-grid::-webkit-scrollbar,
.chatkia-root .chatkia-agents::-webkit-scrollbar { width: 6px; height: 6px; }
.chatkia-root .chatkia-messages::-webkit-scrollbar-thumb,
.chatkia-root .chatkia-history-list::-webkit-scrollbar-thumb,
.chatkia-root .chatkia-media-grid::-webkit-scrollbar-thumb { background: var(--chatkia-border); border-radius: 4px; }

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  .chatkia-launcher-wrap { right: 16px; bottom: 16px; }
  .chatkia-panel,
  .chatkia-root[data-position="middle-right"] .chatkia-panel {
    width: 100vw !important; height: 100dvh !important; max-height: 100dvh !important;
    right: 0 !important; bottom: 0 !important; top: 0 !important; left: 0 !important;
    border-radius: 0 !important; transform: none !important;
  }
  .chatkia-resize-btn { display: none; }
  .chatkia-media-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .chatkia-pulse-ring { animation: none; opacity: .25; }
  .chatkia-launcher, .chatkia-panel { transition: none; }
}