.app, .launcher-btn {
  /* Single brand red (#C0392B) used throughout — header, buttons, active
     states, links, and the outgoing chat bubble. */
  --ink: #C0392B;          /* header bar, dark UI chrome, borders */
  --ink-soft: #8E4A40;     /* muted red-brown — secondary text */
  --bg: #ECE5DD;           /* WhatsApp's signature tan/beige chat wallpaper */
  --panel: #FFFFFF;
  --accent: #C0392B;       /* send button, active states — same red as --ink */
  --accent-soft: #F7D9D5;  /* pale red — highlights */
  --user-bubble: #FFFFFF;  /* same white as the bot bubble — user asked for */
  --user-text: #1B1B1B;    /* both sides to look/read the same way. */
  --bot-bubble: #FFFFFF;   /* white — incoming bubble, like WhatsApp */
  --bot-text: #1B1B1B;
  --radius: 10px;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app, .app * { box-sizing: border-box; }

.app {
  margin: 0;
  font-family: var(--font-body);
  background: transparent;
  color: var(--bot-text);
}

/* Fixed-size floating chat widget — same footprint everywhere it's used
   (this page, or the dashboard's page-reader widget). Hidden by default;
   the launcher icon toggles it open, the ➖ button minimizes it again. */
.widget-width { width: 380px; }
.widget-height { height: 560px; }

.app {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 380px;
  height: 560px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  background: var(--bg);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  display: none; /* shown via .app.open */
}
.app.open { display: flex; }

/* Floating launcher icon */
.launcher-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #fff;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.15s ease;
}
.launcher-icon { width: 34px; height: 34px; display: block; }
.launcher-btn:hover { transform: scale(1.06); }
.launcher-btn.hidden { display: none; }

/* Language gate — shown once before the chat starts */
.lang-gate {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.lang-gate[hidden] { display: none; }
.lang-gate-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  text-align: center;
}
.lang-gate-emoji { font-size: 40px; margin-bottom: 4px; }
.lang-gate-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--bot-text);
  margin-bottom: 8px;
  line-height: 1.5;
}
.lang-btn {
  border: none;
  border-radius: 22px;
  padding: 12px 16px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.lang-btn:hover { filter: brightness(0.95); }
.lang-btn + .lang-btn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--accent);
}

.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat-body[hidden] { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  background: var(--ink);
  color: #fff;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand-dot {
  height: 36px; width: 36px; padding: 5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-logo { height: 100%; width: auto; display: block; }
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.status { font-size: 11px; opacity: 0.85; }
.status.online { color: #DFF5C4; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.icon-btn.small {
  width: 28px; height: 28px;
  font-size: 13px;
  background: rgba(255,255,255,0.18);
  color: #fff;
}
.icon-btn.small.muted { opacity: 0.4; }

.reg-form {
  margin: 10px 10px 0;
  border: 1px solid #E4D9CB;
  border-radius: 10px;
  background: var(--panel);
  overflow: hidden;
  flex-shrink: 0;
}

.reg-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--ink);
  color: #fff;
}
.reg-form-title { font-weight: 700; font-size: 12px; }
.reg-form-step { font-size: 10px; opacity: 0.85; }

.reg-form-body { padding: 6px; display: flex; flex-direction: column; gap: 4px; }

.reg-field {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid transparent;
  color: var(--ink-soft);
}
.reg-field.pending { opacity: 0.55; }
.reg-field.done { color: var(--bot-text); }
.reg-field.done .reg-field-icon { color: #2E9E6C; font-weight: 700; }
.reg-field.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
}
.reg-field-icon { text-align: center; font-size: 12px; }
.reg-field-label { white-space: nowrap; }
.reg-field-value {
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
}
.reg-field.active .reg-field-value { color: var(--accent); }

/* Faint repeating dot pattern over the wallpaper, like WhatsApp's chat background */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(0,0,0,0.035) 1px, transparent 1px);
  background-size: 18px 18px;
}

.msg { display: flex; gap: 6px; align-items: flex-end; max-width: 82%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  border-radius: 50%;
  background: var(--accent-soft);
  flex-shrink: 0;
}

/* Message bubble with a small WhatsApp-style tail */
.bubble {
  position: relative;
  padding: 7px 9px 8px;
  border-radius: var(--radius);
  font-size: 14.2px;
  line-height: 1.4;
  white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.msg.bot .bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border-top-left-radius: 2px;
}
.msg.bot .bubble::before {
  content: "";
  position: absolute;
  left: -6px; top: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 8px 8px 0;
  border-color: transparent var(--bot-bubble) transparent transparent;
}

.dashboard-link {
  display: inline-block;
  margin-top: 2px;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}
.dashboard-link:hover { text-decoration: underline; }

.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-top-right-radius: 2px;
}
.msg.user .bubble::before {
  content: "";
  position: absolute;
  right: -6px; top: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 0 8px 8px;
  border-color: transparent transparent var(--user-bubble) transparent;
}

.msg.typing .bubble {
  display: flex;
  gap: 4px;
  align-items: center;
}
.dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--ink-soft);
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.15s; }
.dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #E4D9CB;
  background: var(--panel);
  flex-shrink: 0;
}

#input {
  flex: 1;
  font-size: 14px;
  padding: 9px 14px;
  border: 1px solid #E4D9CB;
  border-radius: 20px;
  outline: none;
  background: var(--bg);
}
#input:focus { border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn:hover { filter: brightness(0.95); }
.send-btn:focus-visible, .icon-btn:focus-visible, #input:focus-visible {
  outline: 3px solid var(--ink-soft);
  outline-offset: 2px;
}

.icon-btn {
  background: var(--bg);
  border: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.recording { background: var(--accent-soft); }
.mic-icon { width: 19px; height: 19px; }

@media (max-width: 420px) {
  .app {
    right: 0; bottom: 0; left: 0; top: 0;
    width: 100%; height: 100%;
    max-width: 100%; max-height: 100%;
    border-radius: 0;
  }
  .launcher-btn { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; }
}

/* Inline dropdown picker shown in chat for fields chosen from a fixed
   list (state, district) instead of typed freely. */
.field-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
}
.field-picker-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #E4D9CB;
  border-radius: 8px;
  font-size: 13.5px;
  background: #fff;
  color: var(--bot-text);
  font-family: inherit;
}
.field-picker-select:focus {
  outline: none;
  border-color: var(--accent);
}
.field-picker-btn {
  align-self: flex-end;
  padding: 7px 16px;
  border: none;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.field-picker-btn:hover:not(:disabled) { filter: brightness(0.95); }
.field-picker-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Quick-reply buttons (Login / Register / Explore, etc.) */
.quick-replies {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin: 4px 0 10px 0;
  overflow-x: auto;
}
.quick-reply-btn {
  border: 1px solid var(--accent);
  border-radius: 18px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--panel);
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}
.quick-reply-btn:hover:not(:disabled) { background: var(--accent); color: #fff; }
.quick-reply-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Course cards with an Enroll button */
.course-cards { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px 0; }
.course-card {
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
}
.course-card-info { display: flex; flex-direction: column; gap: 2px; }
.course-card-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.course-card-price { font-size: 12.5px; color: var(--bot-text); }
.course-card-btn {
  flex-shrink: 0;
  border: none;
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.course-card-btn:hover:not(:disabled) { filter: brightness(0.95); }
.course-card-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Course payment status — shown after "Enroll" (pending, while we wait for
   the user to pay on the real checkout page) and after "I've completed
   payment" (confirmed success, or not-confirmed-yet). */
.payment-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
}
.payment-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.payment-link:hover { text-decoration: underline; }

.payment-badge {
  display: inline-block;
  width: 16px; height: 16px;
  flex-shrink: 0;
  border-radius: 50%;
  position: relative;
}

/* Pending: a spinning ring while we're waiting on the checkout page. */
.payment-badge-pending,
.payment-badge-checking {
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: payment-spin 0.8s linear infinite;
}

/* Success: a small green check that pops in. */
.payment-badge-success {
  background: #2E8B57;
  animation: payment-pop 0.35s ease-out;
}
.payment-badge-success::after {
  content: "";
  position: absolute;
  left: 4px; top: 2px;
  width: 5px; height: 8px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg);
}

/* Failure / not-confirmed-yet: an amber alert that gives a short shake to
   draw the eye without being alarming. */
.payment-badge-fail {
  background: #D97706;
  animation: payment-shake 0.4s ease-in-out;
}
.payment-badge-fail::after {
  content: "!";
  position: absolute;
  inset: 0;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

@keyframes payment-spin {
  to { transform: rotate(360deg); }
}
@keyframes payment-pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes payment-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@media (prefers-reduced-motion: reduce) {
  .payment-badge-pending,
  .payment-badge-checking,
  .payment-badge-success,
  .payment-badge-fail { animation: none; }
}

/* A brief highlight pop on the bot's own bubble when it reports a
   successful payment/enrollment — draws the eye to the good news. */
.payment-success-pop {
  animation: payment-success-glow 1s ease-out;
}
@keyframes payment-success-glow {
  0% { box-shadow: 0 0 0 0 rgba(46, 139, 87, 0.45); }
  100% { box-shadow: 0 0 0 10px rgba(46, 139, 87, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .payment-success-pop { animation: none; }
}
/* Keep user and bot messages visually consistent: same width behaviour,
   padding, radius and shadow. Colour alone indicates who sent the message. */
.msg { width: fit-content; min-width: 0; }
.msg .bubble { border-radius: 14px; border-top-left-radius: 14px; border-top-right-radius: 14px; }
.msg.bot .bubble, .msg.user .bubble { border-top-left-radius: 14px; border-top-right-radius: 14px; }
.msg.bot .bubble::before, .msg.user .bubble::before { display: none; }
