/* ============================================================
   Keyin Onboarding Agent — Chat Widget Styles

   Keyin College brand colors:
     Primary Red:   #C41230
     Dark Red:      #8C0D22
     Light Gray:    #F5F5F5
     Text Dark:     #1A1A1A
     Text Medium:   #555555
   ============================================================ */

/* ─── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --keyin-red:    #C41230;
  --keyin-dark:   #8C0D22;
  --keyin-accent: #E8B4BC;
  --bg-page:      #F0F2F5;
  --bg-chat:      #FFFFFF;
  --bg-msg-user:  #C41230;
  --bg-msg-norm:  #F0F2F5;
  --text-dark:    #1A1A1A;
  --text-med:     #555555;
  --text-light:   #888888;
  --border:       #E0E0E0;
  --shadow-card:  0 2px 16px rgba(0,0,0,0.10);
  --shadow-btn:   0 2px 8px rgba(196,18,48,0.25);
  --radius-lg:    16px;
  --radius-msg:   18px;
  --font-main:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-dark);
  -webkit-font-smoothing: antialiased;
}

/* ─── Page layout ──────────────────────────────────────────── */
.page-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

/* ─── Chat widget container ────────────────────────────────── */
.chat-widget {
  width: 100%;
  max-width: 640px;
  height: 92vh;
  max-height: 800px;
  background: var(--bg-chat);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
}

/* Minimized state */
.chat-widget.minimized {
  height: auto;
  max-height: none;
}

.chat-widget.minimized .chat-body,
.chat-widget.minimized .chat-input-area {
  display: none;
}

/* ─── Header ───────────────────────────────────────────────── */
.chat-header {
  background: linear-gradient(135deg, var(--keyin-red) 0%, var(--keyin-dark) 100%);
  color: white;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.chat-header:hover {
  background: linear-gradient(135deg, #D41540 0%, #9C0D22 100%);
}

.header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.3);
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.header-status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ADE80;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.15s;
}

.header-btn:hover { background: rgba(255,255,255,0.25); }
.header-btn.active { background: rgba(255,255,255,0.3); }

/* ─── Setup wizard ─────────────────────────────────────────── */
.setup-panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.setup-panel.hidden { display: none; }

.setup-welcome {
  text-align: center;
  padding: 12px 0;
}

.setup-welcome h2 {
  font-size: 22px;
  color: var(--keyin-red);
  margin-bottom: 8px;
}

.setup-welcome p {
  color: var(--text-med);
  font-size: 14px;
  line-height: 1.6;
}

.setup-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dark);
}

.form-group input,
.form-group select {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: var(--font-main);
  color: var(--text-dark);
  background: white;
  transition: border-color 0.15s;
  width: 100%;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--keyin-red);
  box-shadow: 0 0 0 3px rgba(196,18,48,0.1);
}

.btn-primary {
  background: var(--keyin-red);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 13px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: var(--shadow-btn);
  font-family: var(--font-main);
}

.btn-primary:hover {
  background: var(--keyin-dark);
  box-shadow: 0 4px 12px rgba(196,18,48,0.35);
}

.btn-primary:active { transform: scale(0.98); }

.skip-link {
  text-align: center;
  font-size: 13px;
  color: var(--text-light);
}

.skip-link a {
  color: var(--keyin-red);
  text-decoration: none;
  cursor: pointer;
}

.skip-link a:hover { text-decoration: underline; }

/* ─── Chat body (messages) ─────────────────────────────────── */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

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

/* ─── Messages ─────────────────────────────────────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgSlideIn 0.2s ease;
}

@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--keyin-red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  color: white;
}

.msg-row.user .msg-avatar {
  background: #CBD5E1;
  font-size: 14px;
}

.msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius-msg);
  font-size: 14.5px;
  line-height: 1.55;
  word-wrap: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--bg-msg-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-row.norman .msg-bubble {
  background: var(--bg-msg-norm);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

/* Inline images in chat */
.msg-images {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.msg-image-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  max-width: 320px;
}

.msg-image-card img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  transition: opacity 0.15s;
}

.msg-image-card img:hover { opacity: 0.92; }

.msg-image-caption {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-med);
  background: #FAFAFA;
  border-top: 1px solid var(--border);
  line-height: 1.4;
}

/* Timestamp */
.msg-time {
  font-size: 11px;
  color: var(--text-light);
  padding: 0 4px;
  align-self: flex-end;
  margin-bottom: 2px;
}

.msg-row.user .msg-time { text-align: right; }

/* ─── Typing indicator ─────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.typing-dots {
  background: var(--bg-msg-norm);
  border: 1px solid var(--border);
  border-radius: var(--radius-msg);
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--text-light);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* ─── Input area ───────────────────────────────────────────── */
.chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-msg-norm);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-row:focus-within {
  border-color: var(--keyin-red);
  box-shadow: 0 0 0 3px rgba(196,18,48,0.08);
}

#messageInput {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  font-family: var(--font-main);
  color: var(--text-dark);
  resize: none;
  min-height: 22px;
  max-height: 120px;
  padding: 4px 0;
  line-height: 1.4;
}

#messageInput:focus { outline: none; }
#messageInput::placeholder { color: var(--text-light); }

.input-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-light);
  transition: all 0.15s;
  flex-shrink: 0;
}

.input-btn:hover { color: var(--keyin-red); background: rgba(196,18,48,0.08); }
.input-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-btn.send-btn {
  background: var(--keyin-red);
  color: white;
}

.input-btn.send-btn:hover {
  background: var(--keyin-dark);
  color: white;
}

.input-btn.mic-btn.recording {
  background: rgba(196,18,48,0.12);
  color: var(--keyin-red);
  animation: micPulse 1s infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196,18,48,0.3); }
  50%       { box-shadow: 0 0 0 6px rgba(196,18,48,0); }
}

.input-hint {
  font-size: 11px;
  color: var(--text-light);
  text-align: center;
  margin-top: 6px;
}

/* ─── Image lightbox ───────────────────────────────────────── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: pointer;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.lightbox.open { display: flex; }

.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  color: white;
  font-size: 28px;
  cursor: pointer;
  background: rgba(0,0,0,0.4);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ─── Phase progress bar ───────────────────────────────────── */
.phase-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px 0;
  flex-shrink: 0;
}

.phase-step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.4s;
}

.phase-step.active  { background: var(--keyin-red); }
.phase-step.done    { background: var(--keyin-accent); }

.phase-label {
  font-size: 11px;
  color: var(--text-light);
  text-align: right;
  padding: 4px 16px 8px;
  flex-shrink: 0;
}

/* ─── Error/info banner ────────────────────────────────────── */
.banner {
  margin: 8px 14px 0;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  display: none;
}

.banner.error {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FECACA;
  display: block;
}

.banner.info {
  background: #EFF6FF;
  color: #1E40AF;
  border: 1px solid #BFDBFE;
  display: block;
}

/* ─── Voice status ─────────────────────────────────────────── */
.voice-status {
  font-size: 12px;
  color: var(--keyin-red);
  text-align: center;
  padding: 4px 0 0;
  min-height: 18px;
}

/* ─── Responsive (phone) ───────────────────────────────────── */
@media (max-width: 480px) {
  .page-wrapper { padding: 0; }

  .chat-widget {
    border-radius: 0;
    height: 100vh;
    max-height: none;
    max-width: none;
  }

  .msg-bubble { max-width: 88%; font-size: 14px; }
  .header-name { font-size: 15px; }
}

/* ─── Embeddable widget mode ───────────────────────────────── */
/* When loaded in an iframe on keyin.com, hide the page background */
body.embedded {
  background: transparent;
}

body.embedded .page-wrapper {
  padding: 0;
  min-height: 100vh;
}

body.embedded .chat-widget {
  border-radius: 0;
  height: 100vh;
  max-height: none;
  box-shadow: none;
}
