@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Brand tokens ── */
:root {
  --red:          #e8192c;
  --red-dark:     #c0121f;
  --red-soft:     rgba(232, 25, 44, 0.08);
  --navy:         #0d1128;
  --navy-light:   #1a2040;
  --white:        #ffffff;
  --bg:           #f3f4f6;
  --bubble-bot:   #f3f4f6;
  --bubble-user:  #e8192c;
  --text:         #111827;
  --muted:        #6b7280;
  --border:       #e5e7eb;
  --shadow:       0 8px 40px rgba(13, 17, 40, 0.18);
  --radius:       16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f2f5;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Page shell — simulates widget floating on a page ── */
.page-shell {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 24px 16px 35px 16px;
}

/* ── Chat panel ── */
.chat-panel {
  width: min(1000px, 100%);
  background: var(--white);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 92vh;
  min-height: 0;
}

/* ── Header ── */
.chat-header {
  background: var(--navy);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.k-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -0.5px;
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-name {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.2px;
}

.header-status {
  color: #9ca3af;
  font-size: 12px;
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 5px;
}

.header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.product-badge {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  color: #e5e7eb;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Nav links & ghost buttons ── */
.ghost-button,
.nav-link {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: #e5e7eb;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s;
  white-space: nowrap;
}

.ghost-button:hover,
.nav-link:hover {
  background: rgba(255,255,255,0.18);
}

.ghost-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Messages area ── */
.messages {
  flex: 1 1 0%;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--white);
  min-height: 0;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.empty-state p {
  font-size: 13px;
  color: var(--muted);
}

/* ── Message bubbles ── */
.message {
  max-width: 82%;
  min-width: 0;
  padding: 8px 12px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 16px;
  animation: rise 160ms ease-out;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
  font-weight: 450;
  /* white-space: pre-wrap; */
}

.message.assistant {
  align-self: flex-start;
  background: var(--bubble-bot);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.message.assistant::before {
  content: 'KSOLVES';
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--red);
  margin-bottom: 5px;
}

.message.system {
  align-self: center;
  background: var(--red-soft);
  color: var(--red-dark);
  border: 1px solid rgba(232,25,44,0.15);
  border-radius: 10px;
  font-size: 13px;
  max-width: 90%;
  text-align: center;
}

/* ── Typing indicator ── */
.loader-message {
  display: flex;
  align-items: center;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  height: 22px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
  opacity: 0.7;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40%           { transform: scale(1); }
}

/* ── Composer ── */
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
}

.grow { flex: 1; display: flex; align-items: center; }

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  resize: none;
}

.field textarea {
  max-height: 120px;
  resize: none;
  line-height: 1.5;
  display: block;
  padding: 10px 14px;
  overflow-y: auto;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--red);
  background: #fff;
}

/* Send button — red circle */
.send-button {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--red);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.12s;
  flex-shrink: 0;
}

.send-button:hover  { background: var(--red-dark); transform: scale(1.06); }
.send-button:active { transform: scale(0.96); }
.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Powered by footer ── */
.powered-by {
  text-align: center;
  padding: 8px;
  font-size: 11px;
  color: var(--muted);
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.powered-by strong {
  color: var(--red);
  font-weight: 700;
}

/* ── Inline contact form card ── */
.inline-form-card {
  align-self: flex-start;
  width: 100%;
  max-width: 480px;
  padding: 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  animation: rise 160ms ease-out;
  overflow: hidden;

  flex-shrink: 0;
  min-height: fit-content;
}

.inline-form { display: grid; gap: 10px; }

.inline-form-actions {
  display: flex;
  justify-content: flex-end;
}

.inline-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inline-form .field span {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}

.inline-form .field input,
.inline-form .field select {
  padding: 9px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.inline-form .send-button {
  width: auto;
  height: auto;
  border-radius: 10px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  min-width: 130px;
}

/* ── OTP card ── */
#otp-card {
  width: 100%;
  max-width: 420px;
}

.otp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.otp-subtext {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 12px;
  line-height: 1.5;
}

.otp-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#otp-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-size: 1.4rem;
  letter-spacing: 8px;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: monospace;
  outline: none;
  transition: border-color 0.15s;
}

#otp-input:focus { border-color: var(--red); background: #fff; }

.otp-error {
  font-size: 12px;
  color: var(--red);
  margin-top: 4px;
}

.otp-resend {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
}

.otp-resend a {
  color: var(--red);
  text-decoration: none;
  font-weight: 500;
}

.otp-resend a:hover { text-decoration: underline; }

#otp-card .send-button {
  width: auto;
  height: auto;
  min-width: 80px;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  flex-shrink: 0;
}

/* ── Hidden UI kept for JS ── */
.hidden-ui { display: none; }

/* ── Markdown message content ── */
.message { line-height: 1.55; }
.message * { margin-top: 0; margin-bottom: 0; }
.message ul, .message ol { padding-left: 18px; }
.message li { margin: 3px 0; }
.message h1,.message h2,.message h3,.message h4,.message h5,.message h6 {
  font-size: inherit;
  font-weight: 600;
}
.message p + p,
.message p + ul, .message p + ol,
.message ul + p, .message ol + p { margin-top: 6px; }
.message code {
  background: rgba(0,0,0,0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}
.message.user code { background: rgba(255,255,255,0.2); }


/* ── Responsive ── */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Misc legacy ── */
.product-selector-strip { display: none; }
.eyebrow, .meta-label, .stats-grid, .stat-card { display: none; }

@media (max-width: 500px) {
  .chat-panel { 
    border-radius: 0; 
    height: 100dvh;       /* 🚀 Forces it to fill the exact height of the mobile screen perfectly */
    max-height: 100dvh; 
    box-shadow: none;     /* 🚀 Removes the floating shadow so it feels like a native app */
  }
  
  .page-shell { 
    padding: 0; 
    align-items: flex-start; /* 🚀 Anchors the chat right to the top edge of the screen */
  }
  
  .inline-form-row { grid-template-columns: 1fr; }
  .message { max-width: 92%; }
  
  /* 🚀 Hide the product badge on mobile */
  .product-badge { display: none !important; }
}

/* --- OTP Card --- */
#otp-card.inline-form-card {
  overflow: hidden;
}

#otp-card #otp-form {
  width: 100%;
  box-sizing: border-box;
}

/* Default: side by side */
.otp-input-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

.otp-input-row input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;              /* ← guarantees full width in both layouts */
  box-sizing: border-box;
}

.otp-verify-btn {
  flex: 0 0 72px;           /* ← fixed width button, never shrinks */
  white-space: nowrap;
}

/* Stack vertically on anything under 480px */
@media (max-width: 480px) {
  #otp-card.inline-form-card {
    padding: 12px;
  }

  .otp-input-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .otp-input-row input {
    width: 100%;
    min-width: 0;
  }

  .otp-verify-btn {
    width: 100%;
    flex: unset;            /* ← release the 72px fixed width when stacked */
  }

  .otp-subtext {
    font-size: 13px;
    word-break: break-word;
  }

  .otp-resend {
    font-size: 12px;
    word-break: break-word;
  }
}



/* ─── Product Version Picker Responsive Fixes ─── */

/* 1. Stop the card from clipping the dropdown menu */
#version-picker-card.inline-form-card {
  overflow: visible !important;
}

#version-picker-select {
  min-width: 0 !important; /* Forces the select box to shrink safely instead of overflowing */
  text-overflow: ellipsis; 
}

/* 2. Stack the dropdown and button vertically on mobile screens */
@media (max-width: 480px) {
  #version-picker-form > div {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  
  #version-picker-select {
    width: 100% !important;
  }
  
  #version-picker-form .send-button {
    width: 100% !important;
  }
}