/* ─── Widget container ───────────────────────────────────────────── */
#ks-chat-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  font-family: var(--font-body, 'Plus Jakarta Sans', sans-serif);
}

/* ─── Toggle button ──────────────────────────────────────────────── */
#ks-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0EA5E9, #22D3EE);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(14, 165, 233, 0.45), 0 0 0 0 rgba(14,165,233,0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#ks-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(14, 165, 233, 0.6);
}
#ks-chat-toggle:focus-visible {
  outline: 2px solid #0EA5E9;
  outline-offset: 3px;
}
#ks-chat-toggle:active { transform: scale(0.95); }
.ks-chat-icon { font-size: 1.4rem; line-height: 1; }

/* ─── Panel ──────────────────────────────────────────────────────── */
#ks-chat-panel {
  position: absolute;
  bottom: calc(100% + 0.75rem);
  right: 0;
  width: 360px;
  max-height: 540px;
  display: flex;
  flex-direction: column;
  border-radius: 1rem;
  overflow: hidden;
  background: #0D1526;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5), 0 0 0 1px rgba(14,165,233,0.12);
  border: 1px solid rgba(14,165,233,0.15);
}
#ks-chat-panel[hidden] { display: none; }

/* ─── Header ─────────────────────────────────────────────────────── */
#ks-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  background: #0EA5E9;
  flex-shrink: 0;
}
#ks-chat-title-wrap { display: flex; align-items: center; gap: 0.625rem; }
#ks-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}
#ks-chat-title    { font-weight: 600; font-size: 0.95rem; color: #fff; line-height: 1.2; }
#ks-chat-subtitle {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.85);
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
/* Green online dot */
#ks-chat-subtitle::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22C55E;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(34,197,94,0.6);
}
#ks-chat-close {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#ks-chat-close:hover { background: rgba(255,255,255,0.28); border-color: rgba(255,255,255,0.4); }
#ks-chat-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ─── Messages ───────────────────────────────────────────────────── */
#ks-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}
#ks-chat-messages::-webkit-scrollbar { width: 4px; }
#ks-chat-messages::-webkit-scrollbar-track { background: transparent; }
#ks-chat-messages::-webkit-scrollbar-thumb { background: rgba(14,165,233,0.25); border-radius: 4px; }

.ks-msg {
  max-width: 85%;
  padding: 0.55rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 300;
  line-height: 1.55;
  word-break: break-word;
}
.ks-msg--assistant {
  align-self: flex-start;
  background: rgba(14,165,233,0.10);
  border: 1px solid rgba(14,165,233,0.2);
  color: #e2e8f0;
  border-radius: 4px 14px 14px 14px;
}
.ks-msg--emphasis {
  background: rgba(14,165,233,0.16);
  border-color: rgba(14,165,233,0.32);
  color: #e2e8f0;
}
.ks-msg--user {
  align-self: flex-end;
  background: rgba(14,165,233,0.22);
  border: 1px solid rgba(14,165,233,0.35);
  color: #fff;
  border-radius: 14px 4px 14px 14px;
}
.ks-msg--summary {
  align-self: flex-start;
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.25);
  color: #e2e8f0;
  border-radius: 4px 14px 14px 14px;
  max-width: 92%;
}
.ks-msg--summary::before {
  content: '\2713  SUMMARY GENERATED';
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #4ade80;
  margin-bottom: 0.45rem;
}

/* Typing indicator */
.ks-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.75rem 0.9rem;
}
.ks-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #0EA5E9;
  animation: ks-bounce 1.2s infinite ease-in-out;
}
.ks-typing span:nth-child(2) { animation-delay: 0.2s; }
.ks-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ks-bounce {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.4; }
  40%            { transform: scale(1);   opacity: 1; }
}

/* ─── CTA buttons ────────────────────────────────────────────────── */
.ks-cta-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-self: flex-start;
  width: 100%;
  max-width: 85%;
}
.ks-cta-btn {
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  text-align: left;
  min-height: 44px;
  transition: filter 0.15s, transform 0.1s;
}
.ks-cta-btn:hover         { filter: brightness(1.12); transform: translateY(-1px); }
.ks-cta-btn:active        { transform: translateY(0); }
.ks-cta-btn:focus-visible { outline: 2px solid #0EA5E9; outline-offset: 2px; }
.ks-cta-btn--primary {
  background: linear-gradient(135deg, #0EA5E9, #22D3EE);
  color: #fff;
  box-shadow: 0 2px 10px rgba(14,165,233,0.3);
}
.ks-cta-btn--secondary {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  color: #cbd5e1;
}
.ks-cta-btn--secondary:hover { background: rgba(255,255,255,0.12); }

/* ─── Input row ──────────────────────────────────────────────────── */
#ks-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(14,165,233,0.12);
  background: rgba(14,165,233,0.03);
  flex-shrink: 0;
}
#ks-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid rgba(14,165,233,0.2);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.05);
  color: #e2e8f0;
  font-size: 0.8rem;
  font-family: inherit;
  line-height: 1.5;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
#ks-chat-input:focus        { outline: none; border-color: #0EA5E9; background: rgba(14,165,233,0.07); }
#ks-chat-input:disabled     { opacity: 0.45; }
#ks-chat-input::placeholder { color: rgba(255,255,255,0.3); }
#ks-chat-send {
  height: 44px;
  padding: 0 1rem;
  border-radius: 0.5rem;
  background: linear-gradient(135deg, #0EA5E9, #22D3EE);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  transition: filter 0.15s, transform 0.1s;
  min-width: 60px;
  box-shadow: 0 2px 10px rgba(14,165,233,0.3);
}
#ks-chat-send:hover         { filter: brightness(1.1); transform: translateY(-1px); }
#ks-chat-send:active        { transform: translateY(0); }
#ks-chat-send:focus-visible { outline: 2px solid #0EA5E9; outline-offset: 2px; }
#ks-chat-send:disabled      { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ─── Mobile — full bottom sheet ─────────────────────────────────── */
@media (max-width: 400px) {
  #ks-chat-panel {
    position: fixed;
    bottom: 0; right: 0; left: 0;
    width: 100%;
    max-height: 80dvh;
    border-radius: 1rem 1rem 0 0;
  }
  #ks-chat-widget { bottom: 1rem; right: 1rem; }
}

/* ─── Light theme overrides ──────────────────────────────────────── */
[data-theme="light"] #ks-chat-panel {
  background: #f8fafc;
  border: 1px solid rgba(14,165,233,0.18);
  box-shadow: 0 12px 48px rgba(0,0,0,0.12);
}
[data-theme="light"] .ks-msg--emphasis     { background: rgba(14,165,233,0.12); border-color: rgba(14,165,233,0.28); color: #0f172a; }
[data-theme="light"] .ks-msg--summary      { background: rgba(34,197,94,0.08); border-color: rgba(34,197,94,0.3); color: #0f172a; }
[data-theme="light"] .ks-msg--summary::before { color: #16a34a; }
[data-theme="light"] .ks-msg--assistant  {
  background: rgba(14,165,233,0.08);
  border-color: rgba(14,165,233,0.18);
  color: #0f172a;
}
[data-theme="light"] .ks-msg--user       {
  background: rgba(14,165,233,0.18);
  border-color: rgba(14,165,233,0.3);
  color: #0f172a;
}
[data-theme="light"] #ks-chat-input      { background: #fff; border-color: #cbd5e1; color: #0f172a; }
[data-theme="light"] #ks-chat-input::placeholder { color: #94a3b8; }
[data-theme="light"] #ks-chat-input-row  { border-top-color: rgba(14,165,233,0.12); background: rgba(14,165,233,0.02); }
[data-theme="light"] .ks-cta-btn--secondary { background: #e2e8f0; border-color: #cbd5e1; color: #334155; }
[data-theme="light"] .ks-cta-btn--secondary:hover { background: #cbd5e1; }
