/* ==========================================================================
   SS Medical Foundation — AI Admission Chatbot Widget
   Floating chatbot with conversational UI, quick actions, admin panel.
   Reuses design tokens from styles.css.
   ========================================================================== */

/* ---- Trigger Button ---------------------------------------------------- */
#ssmf-chatbot {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: var(--font-body);
}

#cb-trigger {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 24px -4px rgba(239, 106, 77, 0.65);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  position: relative;
}
#cb-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 30px -4px rgba(239, 106, 77, 0.8);
}
#cb-trigger svg { width: 28px; height: 28px; pointer-events: none; }

#cb-trigger .cb-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--ink);
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: none;
  line-height: 20px;
  text-align: center;
}

/* Pulse ring */
#cb-trigger::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--coral);
  animation: cb-pulse 2s ease-out infinite;
}
@keyframes cb-pulse {
  0% { opacity: 0.6; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.45); }
}
#cb-trigger.cb-open::after { animation: none; opacity: 0; }

/* ---- Chat Window ------------------------------------------------------- */
#cb-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}
#cb-window.cb-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Mobile: full screen */
@media (max-width: 640px) {
  #ssmf-chatbot { bottom: 0; right: 0; }
  #cb-trigger { bottom: 16px; right: 16px; width: 54px; height: 54px; }
  #cb-trigger svg { width: 24px; height: 24px; }
  #cb-window {
    position: fixed;
    inset: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
}

/* ---- Header ----------------------------------------------------------- */
.cb-header {
  background: var(--ink);
  color: #fff;
  padding: 0.9rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-shrink: 0;
  position: relative;
}
.cb-header img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  padding: 2px;
}
.cb-header-info { flex: 1; min-width: 0; }
.cb-header-info h4 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  margin: 0;
  line-height: 1.2;
}
.cb-header-info span {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--on-dark-mut);
}
.cb-header-info .cb-online-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 4px;
  vertical-align: middle;
}
.cb-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: var(--on-dark);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.cb-header-btn:hover { background: rgba(255,255,255,0.2); }
.cb-header-btn svg { width: 16px; height: 16px; }

/* Admin toggle (gear icon) */
#cb-admin-toggle {
  display: none;
}
body.cb-admin-mode #cb-admin-toggle {
  display: grid;
}

/* ---- Messages Area ----------------------------------------------------- */
#cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scroll-behavior: smooth;
  background: var(--paper);
}
#cb-messages::-webkit-scrollbar { width: 5px; }
#cb-messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* ---- Message Bubbles --------------------------------------------------- */
.cb-msg {
  display: flex;
  gap: 0.5rem;
  max-width: 92%;
  animation: cb-fadeIn 0.3s ease;
}
@keyframes cb-fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.cb-msg.bot { align-self: flex-start; }
.cb-msg.user { align-self: flex-end; flex-direction: row-reverse; }

.cb-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  margin-top: 2px;
}
.cb-msg.bot .cb-msg-avatar {
  background: var(--forest);
  color: #fff;
}
.cb-msg.user .cb-msg-avatar {
  background: var(--coral);
  color: #fff;
}

.cb-bubble {
  padding: 0.7rem 1rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.55;
  word-wrap: break-word;
}
.cb-msg.bot .cb-bubble {
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.cb-msg.user .cb-bubble {
  background: var(--coral);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.cb-bubble strong { font-weight: 600; }
.cb-bubble a { color: var(--emerald); font-weight: 600; }
.cb-msg.user .cb-bubble a { color: #fff; text-decoration: underline; }

/* Typing indicator */
.cb-typing {
  display: flex;
  gap: 4px;
  padding: 0.7rem 1rem;
  align-items: center;
}
.cb-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sage);
  animation: cb-bounce 1.2s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: 0.15s; }
.cb-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cb-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* ---- Card Message ------------------------------------------------------ */
.cb-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 0.3rem;
}
.cb-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.cb-card-header h5 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}
.cb-card .cb-tag {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2em 0.6em;
  border-radius: 6px;
  font-weight: 600;
}
.cb-tag--green { background: rgba(30,122,94,.14); color: #14573f; }
.cb-tag--gold { background: rgba(216,162,74,.18); color: #8a5f12; }
.cb-tag--coral { background: rgba(239,106,77,.14); color: var(--coral-dk); }
.cb-tag--purple { background: rgba(100,80,180,.12); color: #4a3a8a; }

.cb-card p {
  font-size: 0.85rem;
  color: var(--sage);
  margin: 0.3rem 0;
  line-height: 1.5;
}
.cb-card .cb-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}
.cb-pill {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  background: var(--mint-2);
  color: var(--forest);
  border-radius: 999px;
  padding: 0.3em 0.7em;
  font-weight: 500;
}
.cb-pill--gold {
  background: rgba(216,162,74,.14);
  color: #9a6f1e;
}

/* College recommendation card */
.cb-college-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin-top: 0.4rem;
  transition: border-color 0.15s;
}
.cb-college-card:hover { border-color: var(--emerald); }
.cb-college-card .cb-college-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
}
.cb-college-card .cb-college-city {
  font-size: 0.78rem;
  color: var(--sage);
  margin-top: 0.1rem;
}
.cb-college-card .cb-college-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.cb-chance {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.25em 0.65em;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cb-chance--safe { background: rgba(30,122,94,.16); color: #14573f; }
.cb-chance--likely { background: rgba(120,170,90,.18); color: #4f6b1f; }
.cb-chance--reach { background: rgba(216,162,74,.2); color: #8a5f12; }
.cb-chance--ambitious { background: rgba(239,106,77,.16); color: var(--coral-dk); }

/* Fee breakdown card */
.cb-fee-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 0.5rem;
}
.cb-fee-table td {
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--line);
}
.cb-fee-table td:last-child {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink);
}
.cb-fee-table tr.cb-fee-total td {
  border-bottom: none;
  border-top: 2px solid var(--emerald);
  font-weight: 700;
  color: var(--forest);
  padding-top: 0.6rem;
}

/* Comparison table */
.cb-compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin-top: 0.5rem;
}
.cb-compare-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sage);
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--mint-2);
}
.cb-compare-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.cb-compare-table tr:last-child td { border-bottom: none; }

/* Checklist */
.cb-checklist {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
}
.cb-checklist li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.35rem 0;
  font-size: 0.85rem;
  color: var(--ink);
}
.cb-checklist li .cb-ck {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--mint-2);
  color: var(--emerald);
  display: grid;
  place-items: center;
  font-size: 0.6rem;
  margin-top: 2px;
}

/* Timeline */
.cb-timeline {
  position: relative;
  margin: 0.5rem 0;
  padding-left: 28px;
}
.cb-timeline::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: linear-gradient(var(--gold), var(--emerald));
}
.cb-tl-step {
  position: relative;
  padding: 0.35rem 0;
  font-size: 0.85rem;
}
.cb-tl-step::before {
  content: "";
  position: absolute;
  left: -23px;
  top: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--paper-2);
  border: 2px solid var(--emerald);
}
.cb-tl-step strong {
  color: var(--ink);
  font-weight: 600;
}

/* ---- Quick Actions ----------------------------------------------------- */
#cb-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0;
}
.cb-qa-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.45em 0.85em;
  border-radius: 999px;
  border: 1.5px solid var(--emerald);
  background: var(--mint-2);
  color: var(--forest);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.cb-qa-btn:hover {
  background: var(--emerald);
  color: #fff;
  border-color: var(--emerald);
}
.cb-qa-btn .cb-qa-icon { font-size: 0.9em; }

/* Back / Home button */
.cb-qa-btn.cb-back {
  border-color: var(--line);
  background: var(--paper-2);
  color: var(--sage);
}
.cb-qa-btn.cb-back:hover {
  border-color: var(--sage);
  background: var(--mint-2);
  color: var(--forest);
}

/* ---- Input Area -------------------------------------------------------- */
.cb-input-area {
  border-top: 1px solid var(--line);
  background: var(--paper-2);
  flex-shrink: 0;
}
.cb-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
}
#cb-text-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#cb-text-input:focus {
  border-color: var(--emerald);
  box-shadow: var(--ring);
}
#cb-text-input::placeholder { color: var(--sage); }

#cb-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--coral);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}
#cb-send:hover { background: var(--coral-dk); transform: scale(1.05); }
#cb-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#cb-send svg { width: 18px; height: 18px; }

/* Number input for scores */
.cb-number-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
}
.cb-number-input input {
  width: 120px;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.5rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}
.cb-number-input input:focus { border-color: var(--emerald); }
.cb-number-input .cb-num-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}
.cb-number-input .cb-num-btn:hover { background: var(--mint-2); }

/* ---- Inline Form (lead capture) ---------------------------------------- */
.cb-form {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem;
  margin-top: 0.3rem;
}
.cb-form .cb-field {
  margin-bottom: 0.6rem;
}
.cb-form .cb-field:last-child { margin-bottom: 0; }
.cb-form label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.25rem;
}
.cb-form label .cb-req { color: var(--coral); }
.cb-form input,
.cb-form select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.cb-form input:focus,
.cb-form select:focus {
  border-color: var(--emerald);
  box-shadow: var(--ring);
}
.cb-form .cb-form-submit {
  margin-top: 0.6rem;
  width: 100%;
}
.cb-form .cb-form-note {
  font-size: 0.72rem;
  color: var(--sage);
  margin-top: 0.3rem;
}

/* ---- Success / Error States -------------------------------------------- */
.cb-success-msg {
  background: var(--mint);
  border: 1px solid #bcdccd;
  color: var(--forest);
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  margin-top: 0.3rem;
}
.cb-error-msg {
  background: #fde7e1;
  border: 1px solid #f4c4b6;
  color: var(--coral-dk);
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  margin-top: 0.3rem;
}

/* ---- Live Agent Bar ---------------------------------------------------- */
.cb-live-agent {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.cb-live-agent a {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5em 1em;
  border-radius: 999px;
  text-decoration: none;
  transition: transform 0.15s;
}
.cb-live-agent a:hover { transform: translateY(-1px); text-decoration: none; }
.cb-live-agent .cb-call {
  background: var(--coral);
  color: #fff;
}
.cb-live-agent .cb-whatsapp {
  background: #25d366;
  color: #fff;
}
.cb-live-agent .cb-appointment {
  background: var(--forest);
  color: #fff;
}

/* ---- Admin Panel ------------------------------------------------------- */
#cb-admin-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
body.cb-admin-mode #cb-admin-panel { display: flex; }
body.cb-admin-mode #cb-user-panel { display: none; }

.cb-admin-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
  flex-shrink: 0;
  overflow-x: auto;
}
.cb-admin-tab {
  flex: 1;
  padding: 0.6rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  border: none;
  background: none;
  color: var(--sage);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.cb-admin-tab:hover { color: var(--forest); }
.cb-admin-tab.active {
  color: var(--forest);
  border-bottom-color: var(--coral);
}

.cb-admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}
.cb-admin-content::-webkit-scrollbar { width: 5px; }
.cb-admin-content::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* Admin stat cards */
.cb-admin-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.cb-admin-stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  text-align: center;
}
.cb-admin-stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--ink);
  line-height: 1;
}
.cb-admin-stat span {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sage);
  margin-top: 0.3rem;
  display: block;
}

/* Admin list items */
.cb-admin-list { display: flex; flex-direction: column; gap: 0.5rem; }
.cb-admin-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.cb-admin-item:hover { border-color: var(--emerald); }
.cb-admin-item h6 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}
.cb-admin-item p {
  font-size: 0.75rem;
  color: var(--sage);
  margin: 0.2rem 0 0;
}
.cb-admin-item .cb-admin-meta {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.3rem;
}
.cb-admin-item .cb-admin-meta span {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--sage);
}

/* Admin status badges */
.cb-status {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 600;
  padding: 0.2em 0.55em;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cb-status--new { background: rgba(216,162,74,.18); color: #8a5f12; }
.cb-status--contacted { background: rgba(30,122,94,.14); color: #14573f; }
.cb-status--enrolled { background: rgba(100,80,180,.12); color: #4a3a8a; }
.cb-status--closed { background: var(--line); color: var(--sage); }

/* Admin section headings */
.cb-admin-section {
  margin-bottom: 1rem;
}
.cb-admin-section h5 {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.6rem;
}

/* ---- Scrollbar for messages -------------------------------------------- */
#cb-messages { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .cb-msg { animation: none; }
  .cb-typing span { animation: none; }
  #cb-trigger::after { animation: none; }
  #cb-window { transition: none; }
}
