/* ────────────────────────────────────────────────────────────────
   KA chat shell — KueSync (Slate) themed copy for kuesync.com.
   Diverged from the shared krometis.com palette on purpose: colors match index.html :root.
   ──────────────────────────────────────────────────────────────── */

/* ── Floating action button ──────────────────────────────────────── */
#ka-chat-fab {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #151D23;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
#ka-chat-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
}
#ka-chat-fab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
#ka-chat-fab[aria-expanded="true"] {
  opacity: 0;
  pointer-events: none;
}

/* ── Modal overlay + panel ──────────────────────────────────────── */
#ka-chat-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  color: #f0f0f0;
}
#ka-chat-modal[hidden] { display: none; }

#ka-chat-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: ka-chat-fade-in 0.18s ease;
}

#ka-chat-panel {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  width: min(420px, calc(100vw - 3rem));
  max-height: min(720px, calc(100vh - 3rem));
  background: #0E1419;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* Strong drop-shadow + thin inner light ring give the panel real
     elevation against the pure-black page background. */
  box-shadow:
    0 18px 56px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(255, 255, 255, 0.03);
  animation: ka-chat-slide-up 0.22s ease;
}

@keyframes ka-chat-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ka-chat-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ─────────────────────────────────────────────────────── */
#ka-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.125rem;
  background: #151D23;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
#ka-chat-identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
#ka-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #1C2731;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ka-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}
#ka-chat-titles { min-width: 0; }
#ka-chat-title {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#ka-chat-subtitle {
  font-size: 12.5px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.65);
  line-height: 1.25;
  margin-top: 3px;
  letter-spacing: 0.02em;
}
#ka-chat-close {
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  padding: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-shrink: 0;
}
#ka-chat-close:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
#ka-chat-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ── Body ───────────────────────────────────────────────────────── */
#ka-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.125rem;
  background: #0E1419;
  color: #f0f0f0;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
}

#ka-chat-intro {
  color: #f0f0f0;
  background: #1C2731;
  padding: 1rem 1.125rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 0.75rem;
  font-size: 14.5px;
  line-height: 1.5;
}
#ka-chat-intro p { margin: 0 0 0.6em 0; }
#ka-chat-intro p:last-child { margin-bottom: 0; }

#ka-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.ka-chat-msg { display: flex; max-width: 100%; }
.ka-chat-msg-user { justify-content: flex-end; }
.ka-chat-msg-assistant { justify-content: flex-start; }
.ka-chat-msg-content {
  padding: 0.7rem 0.95rem;
  border-radius: 12px;
  max-width: 92%;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 14.5px;
  line-height: 1.5;
}
.ka-chat-msg-user .ka-chat-msg-content {
  background: #3D8BFF;
  color: #ECF1F4;
}
.ka-chat-msg-assistant .ka-chat-msg-content {
  background: #1C2731;
  color: #f0f0f0;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.ka-chat-typing { color: #6e6e6e; }
.ka-chat-typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  animation: ka-chat-blink 1s steps(1) infinite;
  color: #555;
}
@keyframes ka-chat-blink { 50% { opacity: 0; } }

#ka-chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.875rem;
}
.ka-chat-suggestion {
  text-align: left;
  background: #1C2731;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font-size: 13.5px;
  color: #e8e8e8;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.ka-chat-suggestion:hover {
  background: #2E4053;
  border-color: rgba(120, 170, 255, 0.4);
  color: #fff;
}
.ka-chat-suggestion:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ── Input row ──────────────────────────────────────────────────── */
#ka-chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 0.875rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: #0E1419;
  flex-shrink: 0;
  align-items: center;
}
#ka-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  /* 16px minimum prevents iOS Safari from auto-zooming on focus.
     Don't lower this without testing on iPhone — anything < 16px will zoom. */
  font-size: 16px;
  font-family: inherit;
  background: #1C2731;
  color: #f0f0f0;
  line-height: 1.3;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#ka-chat-input::placeholder { color: rgba(255, 255, 255, 0.4); }
#ka-chat-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}
/* Send button — inverted to white so the primary action reads cleanly
   against the dark panel. */
#ka-chat-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #3D8BFF;
  color: #fff;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#ka-chat-send:hover { background: #3D8BFF; }
#ka-chat-send:disabled { background: #2A3640; color: #8B98A1; cursor: not-allowed; }
#ka-chat-send:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ── Footer ─────────────────────────────────────────────────────── */
#ka-chat-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem 0.7rem;
  background: #0E1419;
  font-size: 10.5px;
  color: #6e6e6e;
  flex-shrink: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  letter-spacing: 0.02em;
}
#ka-chat-reset {
  background: transparent;
  border: 0;
  color: #6e6e6e;
  font-size: 10.5px;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  font-family: inherit;
  letter-spacing: 0.02em;
  transition: color 0.15s ease;
}
#ka-chat-reset:hover { color: #f0f0f0; text-decoration: underline; }
#ka-chat-reset:focus-visible { outline: 2px solid #fff; outline-offset: 2px; border-radius: 4px; }
#ka-chat-built-by {
  user-select: none;
  color: #6e6e6e;
  text-decoration: none;
}
a#ka-chat-built-by {
  cursor: pointer;
  transition: color 0.15s ease;
}
a#ka-chat-built-by:hover {
  color: #f0f0f0;
  text-decoration: underline;
}
a#ka-chat-built-by:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #ka-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 14px 14px 0 0;
  }
  /* Lifted enough to clear a two-line footer on the Analytics page
     without floating awkwardly on the K&A page. */
  #ka-chat-fab {
    bottom: 4rem;
    right: 1.25rem;
  }
}

/* Short viewports (landscape phones / shallow windows) — lift the bubble
   so it never crowds a footer or content edge. */
@media (max-height: 600px) {
  #ka-chat-fab {
    bottom: 3rem;
  }
}

/* ── Reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #ka-chat-fab,
  #ka-chat-backdrop,
  #ka-chat-panel,
  .ka-chat-typing::after { animation: none; transition: none; }
}
