/* KreweCatch Widget — companion stylesheet
 * Can be loaded via <link> or injected by widget.js.
 * Scoped under .kc-* and #kc-* to avoid collisions.
 */

/* ── Floating trigger button ──────────────────────────────────────────────── */

#kc-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  user-select: none;
}

#kc-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

#kc-trigger:active {
  transform: translateY(0);
}

/* Dark theme trigger */
#kc-trigger.kc-dark {
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid #334155;
}

/* Light theme trigger */
#kc-trigger.kc-light {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #cbd5e1;
}

/* ── Chat panel ───────────────────────────────────────────────────────────── */

#kc-panel {
  position: fixed;
  bottom: 80px;
  right: 24px;
  z-index: 9998;
  width: 400px;
  height: 520px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;

  /* Slide-up animation */
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.18s ease;
}

#kc-panel.kc-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Dark theme panel */
#kc-panel.kc-dark {
  background: #0f172a;
  border: 1px solid #1e293b;
  color: #e2e8f0;
}

/* Light theme panel */
#kc-panel.kc-light {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #0f172a;
}

/* ── Panel header ─────────────────────────────────────────────────────────── */

.kc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  flex-shrink: 0;
}

.kc-dark .kc-header {
  background: #1e293b;
  border-bottom: 1px solid #334155;
}

.kc-light .kc-header {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.kc-header-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.kc-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.kc-close-btn:hover {
  opacity: 1;
}

.kc-dark .kc-close-btn {
  color: #94a3b8;
}

.kc-light .kc-close-btn {
  color: #475569;
}

/* ── Mode tabs (Analyze / Chat) ───────────────────────────────────────────── */

.kc-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  flex-shrink: 0;
}

.kc-dark .kc-tabs {
  background: #1e293b;
  border-bottom: 1px solid #334155;
}

.kc-light .kc-tabs {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.kc-tab {
  flex: 1;
  padding: 8px 10px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s, background 0.15s;
  border-bottom: 2px solid transparent;
}

.kc-tab:hover {
  opacity: 0.9;
}

.kc-dark .kc-tab {
  color: #e2e8f0;
}

.kc-light .kc-tab {
  color: #0f172a;
}

.kc-tab.kc-tab-active {
  opacity: 1;
  border-bottom-color: #8b5cf6;
}

.kc-dark .kc-tab.kc-tab-active {
  background: #0f172a;
}

.kc-light .kc-tab.kc-tab-active {
  background: #fff;
}

/* ── Message history ─────────────────────────────────────────────────────── */

.kc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.kc-messages::-webkit-scrollbar {
  width: 4px;
}

.kc-dark .kc-messages::-webkit-scrollbar-track {
  background: #0f172a;
}
.kc-dark .kc-messages::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}
.kc-light .kc-messages::-webkit-scrollbar-track {
  background: #f8fafc;
}
.kc-light .kc-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* ── Individual message bubbles ──────────────────────────────────────────── */

.kc-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kc-msg-user {
  align-items: flex-end;
}

.kc-msg-char {
  align-items: flex-start;
}

.kc-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  word-break: break-word;
}

/* User bubble */
.kc-dark .kc-msg-user .kc-bubble {
  background: #1e3a5f;
  color: #bfdbfe;
  border-bottom-right-radius: 3px;
}
.kc-light .kc-msg-user .kc-bubble {
  background: #dbeafe;
  color: #1e3a5f;
  border-bottom-right-radius: 3px;
}

/* Character bubble */
.kc-dark .kc-msg-char .kc-bubble {
  background: #1e293b;
  border-bottom-left-radius: 3px;
}
.kc-light .kc-msg-char .kc-bubble {
  background: #f1f5f9;
  border-bottom-left-radius: 3px;
}

.kc-char-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0 2px;
}

.kc-char-text {
  white-space: pre-wrap;
}

/* ── Loading state ───────────────────────────────────────────────────────── */

.kc-msg-loading .kc-bubble {
  display: flex;
  align-items: center;
  gap: 6px;
}

.kc-dots {
  display: flex;
  gap: 4px;
}

.kc-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #64748b;
  animation: kc-bounce 1.1s infinite ease-in-out;
}

.kc-dots span:nth-child(1) { animation-delay: 0s; }
.kc-dots span:nth-child(2) { animation-delay: 0.18s; }
.kc-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes kc-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Input area ──────────────────────────────────────────────────────────── */

.kc-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  flex-shrink: 0;
}

.kc-dark .kc-input-area {
  background: #0f172a;
  border-top: 1px solid #1e293b;
}

.kc-light .kc-input-area {
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

.kc-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}

.kc-dark .kc-input {
  background: #1e293b;
  color: #e2e8f0;
}
.kc-dark .kc-input::placeholder { color: #64748b; }
.kc-dark .kc-input:focus { box-shadow: 0 0 0 2px #3b82f6; }

.kc-light .kc-input {
  background: #f1f5f9;
  color: #0f172a;
}
.kc-light .kc-input::placeholder { color: #94a3b8; }
.kc-light .kc-input:focus { box-shadow: 0 0 0 2px #3b82f6; }

.kc-submit {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
  flex-shrink: 0;
}

.kc-submit:hover:not(:disabled) {
  background: #1d4ed8;
}

.kc-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.kc-footer {
  font-size: 11px;
  text-align: center;
  padding: 8px 14px 10px;
  flex-shrink: 0;
  opacity: 0.55;
  line-height: 1.4;
}

.kc-dark .kc-footer {
  color: #94a3b8;
  border-top: 1px solid #1e293b;
}

.kc-light .kc-footer {
  color: #64748b;
  border-top: 1px solid #e2e8f0;
}

/* ── Welcome message ─────────────────────────────────────────────────────── */

.kc-welcome {
  font-size: 13px;
  line-height: 1.6;
  opacity: 0.75;
  text-align: center;
  padding: 8px;
}

/* ── Mobile responsive ───────────────────────────────────────────────────── */

@media (max-width: 479px) {
  #kc-panel {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100dvh;
    border-radius: 0;
  }

  #kc-trigger {
    right: 16px;
    bottom: 16px;
  }
}
