/* =============================================================================
   NMS Health Coach — Widget Styles
   Fonts: Satoshi (body), system fallbacks
   ============================================================================= */

/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  --orange:       #ff4f00;
  --orange-deep:  #b53800;
  --blue:         #2458ef;
  --blue-light:   #3d72ff;
  --ink:          #222323;
  --gray:         #616263;
  --line:         #e0e1e2;
  --cream:        #fbf7ef;
  --surface:      rgba(255, 255, 255, 0.9);
  --shadow:       0 20px 60px rgba(34, 35, 35, 0.14);
  --font:         "Satoshi", "Avenir Next", "Segoe UI", Arial, sans-serif;
  --radius-pill:  999px;
  --radius-widget: 24px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
}

/* ── Page background (demo stage only) ─────────────────────────────────────── */
body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left,  rgba(255, 79,  0, 0.06), transparent 22%),
    radial-gradient(circle at top right, rgba(0,  80, 255, 0.05), transparent 18%),
    linear-gradient(180deg, #fffdf8 0%, var(--cream) 100%);
}

.watermark {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 0;
}

.watermark img {
  width: clamp(220px, 42vw, 620px);
  opacity: 0.04;
  filter: grayscale(100%);
}

.stage {
  position: relative;
  min-height: 100vh;
  padding: 24px;
  z-index: 1;
}

/* ── Chat widget ────────────────────────────────────────────────────────────── */
.chat-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(350px, calc(100vw - 24px));
  height: min(680px, calc(100vh - 32px));
  min-height: 480px;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-widget);
  border: 1px solid rgba(224, 225, 226, 0.9);
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,255,255,0.9));
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  overflow: hidden;
  z-index: 1000;
  /* Transitions used by collapse / close */
  transition:
    height  320ms cubic-bezier(0.4, 0, 0.2, 1),
    opacity 200ms ease,
    transform 200ms ease;
}

/* Collapsed state — only the topbar is visible */
.chat-widget.collapsed {
  height: 54px;
  min-height: 0;
}

/* Hidden state — chat is closed, mini bubble takes over */
.chat-widget.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.94) translateY(8px);
}

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(224, 225, 226, 0.8);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(250,247,240,0.9)),
    linear-gradient(135deg, rgba(255,79,0,0.04), transparent 45%);
  /* Prevent topbar from shrinking when widget collapses */
  flex-shrink: 0;
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-brand-mark {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  object-fit: contain;
}

.chat-brand-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--orange);
  letter-spacing: 0.01em;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chat-action {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--gray);
  font-size: 16px;
  cursor: pointer;
  transition: background 120ms ease;
}

.chat-action:hover { background: #f2f4f7; }

.chat-action.is-muted {
  color: var(--orange);
  background: rgba(255, 79, 0, 0.08);
}

/* Expand button icon swap */
#btn-expand .icon-expand   { display: none; }
#btn-expand .icon-collapse { display: block; }

#btn-expand.is-collapsed .icon-expand   { display: block; }
#btn-expand.is-collapsed .icon-collapse { display: none; }

#btn-sound .icon-sound-off { display: none; }
#btn-sound.is-muted .icon-sound-on  { display: none; }
#btn-sound.is-muted .icon-sound-off { display: block; }

/* ── Chat body ──────────────────────────────────────────────────────────────── */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 13px 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28), transparent 26%),
    rgba(255, 252, 246, 0.9);
}

/* ── Message groups ─────────────────────────────────────────────────────────── */
.message-group + .message-group { margin-top: 14px; }

.agent-label {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0 0 6px 6px;
  color: var(--orange);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  font-variant: small-caps;
}

.agent-label img {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

/* ── User bubble ────────────────────────────────────────────────────────────── */
.user-bubble-row {
  display: flex;
  justify-content: flex-end;
}

.user-bubble {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: 20px;
  background: linear-gradient(160deg, var(--blue-light) 0%, var(--blue) 100%);
  color: white;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 6px 18px rgba(36, 88, 239, 0.18);
}

/* ── Assistant bubble (animated gradient border) ────────────────────────────── */
.companion-shell {
  position: relative;
  padding: 1.5px;
  border-radius: 22px;
  overflow: hidden;
}

/* Rotating conic gradient creates the "magic" animated border */
.companion-shell::before {
  content: "";
  position: absolute;
  inset: -100%;
  background: conic-gradient(
    from 0deg,
    #ef40ff,
    #ff4f00 30%,
    #ffaa00 50%,
    #ff4f00 70%,
    #ef40ff 100%
  );
  transform-origin: center;
  animation: spin-border 5s linear infinite;
}

@keyframes spin-border {
  to { transform: rotate(360deg); }
}

.companion-bubble {
  position: relative;
  z-index: 1;
  border-radius: 20.5px;
  background: white;
  padding: 14px 15px 12px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

/* ── Markdown content inside assistant bubble ───────────────────────────────── */
.companion-bubble p               { margin: 0 0 8px; }
.companion-bubble p:last-child    { margin-bottom: 0; }
.companion-bubble > *:first-child { margin-top: 0; }

.companion-bubble strong { font-weight: 700; color: var(--ink); }
.companion-bubble em     { font-style: italic; }

.companion-bubble ul,
.companion-bubble ol {
  margin: 6px 0 8px;
  padding-left: 18px;
}
.companion-bubble ul:last-child,
.companion-bubble ol:last-child { margin-bottom: 0; }

.companion-bubble li             { margin-bottom: 4px; line-height: 1.5; }
.companion-bubble li:last-child  { margin-bottom: 0; }

.companion-bubble h1,
.companion-bubble h2,
.companion-bubble h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin: 10px 0 4px;
}

.companion-bubble code {
  background: #f2f1ef;
  padding: 1px 5px;
  border-radius: 5px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12px;
}

.companion-bubble pre {
  background: #f2f1ef;
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0;
}
.companion-bubble pre code { background: none; padding: 0; }

.companion-bubble blockquote {
  border-left: 3px solid var(--orange);
  margin: 8px 0;
  padding: 2px 10px;
  color: var(--gray);
  font-style: italic;
}

.companion-bubble hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

/* ── Lesson pill (pinned to bottom of a course card) ────────────────────────── */
.course-card-lesson {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 6px 10px 8px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(255, 79, 0, 0.06);
  border: 1px solid rgba(255, 79, 0, 0.18);
  font-size: 10px;
  color: var(--orange);
  line-height: 1.35;
}

.course-card-lesson-icon {
  flex-shrink: 0;
  font-size: 11px;
}

.course-card-lesson-text {
  font-weight: 500;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
}

/* ── Response chips (clarifying-question answer options, below AI bubble) ───── */
.response-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.response-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--orange);
  background: rgba(255, 79, 0, 0.04);
  color: var(--orange);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.response-chip:hover {
  background: rgba(255, 79, 0, 0.10);
  transform: translateY(-1px);
}

/* ── Course cards (inside the AI reply bubble) ──────────────────────────────── */
.course-cards {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.course-cards::-webkit-scrollbar { display: none; }

.course-card {
  flex-shrink: 0;
  width: 160px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(34, 35, 35, 0.07);
  transition: transform 180ms ease, box-shadow 180ms ease;
  display: flex;
  flex-direction: column;
}

.course-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(34, 35, 35, 0.13);
}

.course-card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--cream);
  overflow: hidden;
  flex-shrink: 0;
}

.course-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.course-card-body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.course-card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}

.course-card-author {
  font-size: 10px;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.course-card-rating {
  font-size: 10px;
  font-weight: 600;
  color: var(--orange);
  margin-top: auto;
  padding-top: 4px;
}

/* ── Event section (below course cards) ─────────────────────────────────────── */
.event-section {
  margin-top: 10px;
}

.event-inline-intro {
  font-size: 12px;
  line-height: 1.45;
  color: var(--gray);
  margin-bottom: 8px;
}

.event-cards {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.event-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  text-decoration: none;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(34, 35, 35, 0.05);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.event-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(34, 35, 35, 0.10);
}

.event-card-thumb {
  width: 58px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--cream);
}

.event-card-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.event-card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  display: block;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.event-card-date {
  font-size: 10px;
  font-weight: 500;
  color: var(--gray);
}

/* ── Typing indicator ───────────────────────────────────────────────────────── */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 20px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c8d8ff;
  animation: bounce 1.1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.30s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.5; }
  40%           { transform: translateY(-4px); opacity: 1;   }
}

/* ── Message timestamp ──────────────────────────────────────────────────────── */
.message-meta {
  margin-top: 6px;
  color: var(--gray);
  font-size: 11px;
  text-align: right;
}

/* ── Date separator (WhatsApp-style day divider) ────────────────────────────── */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0 10px;
}

.date-separator span {
  background: rgba(34, 35, 35, 0.07);
  color: var(--gray);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 13px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.02em;
}

/* ── Quick reply chips ──────────────────────────────────────────────────────── */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 13px;
}

/* Compact strip — moves above the input after first message */
/*
 * overflow-x:auto implicitly clips overflow-y too, so we add 3px vertical
 * padding to keep borders and shadows fully visible at all viewport widths.
 */
.quick-replies.compact {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
  gap: 5px;
  margin-top: 0;
  padding: 3px 13px 4px;
  border-top: 1px solid rgba(224, 225, 226, 0.7);
}
.quick-replies.compact::-webkit-scrollbar { display: none; }

.quick-replies.compact .quick-reply {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 11px;
  box-shadow: none;          /* shadows would be clipped anyway — remove cleanly */
}

/* Suppress the upward lift in the compact strip — it pushes chips into the clip boundary */
.quick-replies.compact .quick-reply:hover {
  transform: none;
  box-shadow: none;
}

/*
 * Each chip sizes itself to its content — no fixed widths or equal columns.
 * Rule: padding 9px 11px, centred content, single line always (white-space: nowrap).
 * If a chip's label is too long to fit one line, shorten the text — don't remove nowrap.
 */
.quick-reply {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 9px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(34, 35, 35, 0.04);
  transition: border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.quick-reply:hover       { transform: translateY(-1px); box-shadow: 0 5px 12px rgba(34,35,35,0.08); }
.quick-reply.selected    { border-color: var(--orange); border-width: 1.5px; }

/* ── Input area ─────────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 11px 12px 13px;
  border-top: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(250,247,240,0.9));
  flex-shrink: 0;
}

/* Pill container — three visual states: idle / focused / has-text */
.chat-input-row {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--radius-pill);
  background: #f1f0ef;
  border: 1.5px solid transparent;
  transition: border-color 200ms ease, box-shadow 200ms ease, background 200ms ease;
}

.chat-input-row:focus-within,
.chat-input-row.has-text {
  border-color: var(--orange);
  box-shadow: 0 0 0 1px var(--orange);
  background: #ffffff;
}

/* Idle overlay — pencil icon + label, centred, non-interactive */
.input-idle-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--gray);
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  user-select: none;
  transition: opacity 180ms ease;
}

.chat-input-row:focus-within .input-idle-label,
.chat-input-row.has-text     .input-idle-label {
  opacity: 0;
}

/* Actual text input */
.chat-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 13px 16px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  outline: none;
}

/* Send button — collapses to zero width when idle, springs open when has-text */
.send-button {
  flex-shrink: 0;
  width: 0;
  align-self: stretch;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--orange);
  color: white;
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition:
    width   240ms cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 180ms ease,
    background 140ms ease;
}

.chat-input-row.has-text .send-button {
  width: 62px;
  opacity: 1;
  pointer-events: auto;
}

.chat-input-row.has-text .send-button:hover { background: var(--orange-deep); }

/* ── Footer note ────────────────────────────────────────────────────────────── */
.footer-note {
  margin-top: 8px;
  color: var(--gray);
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Mini bubble (shown when chat is closed) ────────────────────────────────── */
/*
 * Flush to the right edge — both left corners rounded, right edge borderless.
 * Spinning gradient border via ::before / ::after pseudo-elements.
 */
.chat-bubble {
  position: fixed;
  right: 0;
  /* top is set by JS; fallback keeps it visible if JS hasn't run yet */
  top: calc(100vh - 148px);
  width: 76px;
  height: 76px;
  border-radius: 16px 0 0 16px;
  border: none;
  background: transparent;
  box-shadow: -4px 0 20px rgba(34, 35, 35, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: grab;
  padding: 0;
  overflow: hidden;
  z-index: 1001;
  /* Hidden by default; becomes .visible when chat is closed */
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
  transition: opacity 220ms ease, transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chat-bubble.dragging { cursor: grabbing; transition: none; }

/* Spinning conic gradient — same palette as companion bubble border */
.chat-bubble::before {
  content: "";
  position: absolute;
  inset: -100%;
  background: conic-gradient(
    from 0deg,
    #ef40ff,
    #ff4f00 30%,
    #ffaa00 50%,
    #ff4f00 70%,
    #ef40ff 100%
  );
  transform-origin: center;
  animation: spin-border 4s linear infinite;
  animation-play-state: paused;  /* only spin when visible */
  z-index: 0;
}

/* White fill — flush to right edge so no gradient bleeds through */
.chat-bubble::after {
  content: "";
  position: absolute;
  inset: 2px 0 2px 2px;
  background: white;
  border-radius: 14px 0 0 14px;
  z-index: 1;
}

.chat-bubble.visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.chat-bubble.visible::before { animation-play-state: running; }

/* Content sits above the pseudo-element layers */
.chat-bubble img,
.chat-bubble-text {
  position: relative;
  z-index: 2;
}

.chat-bubble img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.chat-bubble-text {
  font-size: 9px;
  font-weight: 600;
  color: var(--orange);
  text-align: center;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

/* ── Responsive (mobile) ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .stage { padding: 12px; }

  .chat-widget {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
    height: min(82vh, 640px);
    min-height: 460px;
    border-radius: 20px;
  }

  .watermark img { width: clamp(180px, 56vw, 360px); opacity: 0.045; }

  .user-bubble,
  .companion-bubble { font-size: 13px; }

  .chat-bubble { bottom: 20vh; }
}

/* ── Notification bubbles ───────────────────────────────────────────────────── */

.notification-bubble {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 300px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(34, 35, 35, 0.16);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  animation: notif-slide-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
  cursor: pointer;
}

.notification-bubble:hover { box-shadow: 0 12px 40px rgba(34, 35, 35, 0.22); }

@keyframes notif-slide-in {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.notif-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--orange);
}

.notif-dismiss {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  margin-left: auto;
  opacity: 0.6;
}
.notif-dismiss:hover { opacity: 1; }

.notif-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.notif-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--line);
}

.notif-card-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.notif-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notif-card-sub {
  font-size: 11px;
  color: var(--gray);
}

.notif-card-proof {
  font-size: 11px;
  font-weight: 600;
  color: var(--orange);
}

.notif-card-rating {
  font-size: 11px;
  font-weight: 600;
  color: #f5a623;
}

.notif-text {
  font-size: 12px;
  color: var(--ink);
  line-height: 1.5;
}

@media (max-width: 768px) {
  .notification-bubble {
    right: 12px;
    width: calc(100vw - 24px);
  }
}
