/* ==========================================================================
   EASTC AI CHATBOT — Phase 0 Widget Styles
   - Vanilla CSS, no dependencies
   - Isolated: all selectors prefixed with .eastc-cb-
   - Matches EASTC design tokens from eastc.ac.tz (navy/gold/ivory)
   ========================================================================== */

/* Tokens (scoped to widget to avoid polluting site) */
.eastc-cb-root {
  --cb-navy: #06111f;
  --cb-navy-mid: #0b1d35;
  --cb-navy-panel: #0d2141;
  --cb-navy-soft: #1a3560;
  --cb-gold: #c8922a;
  --cb-gold-light: #dda94a;
  --cb-gold-pale: rgba(200, 146, 42, 0.12);
  --cb-gold-glow: rgba(200, 146, 42, 0.18);
  --cb-ivory: #faf9f6;
  --cb-ivory-dark: #f0ede6;
  --cb-smoke: #e4e0d8;
  --cb-ink: #1a1612;
  --cb-ink-mid: #3d3830;
  --cb-ink-soft: #7a7268;
  --cb-white: #ffffff;
  --cb-border: #ece8e0;
  --cb-shadow-lg: 0 20px 60px rgba(6, 17, 31, 0.22), 0 8px 20px rgba(6, 17, 31, 0.12);
  --cb-shadow-md: 0 8px 24px rgba(6, 17, 31, 0.14);
  --cb-radius-xl: 18px;
  --cb-radius-lg: 14px;
  --cb-radius-md: 10px;
  --cb-radius-pill: 999px;
  --cb-font-display: 'Playfair Display', Georgia, serif;
  --cb-font-body: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --cb-ease: cubic-bezier(0.16, 1, 0.3, 1);
  font-family: var(--cb-font-body);
  color: var(--cb-ink);
}

/* Root container fixed */
.eastc-cb-root {
  position: fixed;
  inset: auto 24px 24px auto;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  pointer-events: none; /* allow clicks through when closed; children re-enable */
}
.eastc-cb-root * { box-sizing: border-box; }
.eastc-cb-root button { font-family: var(--cb-font-body); }

/* ---------- Floating Button ---------- */
.eastc-cb-fab {
  pointer-events: auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  background: linear-gradient(135deg, var(--cb-navy-panel) 0%, var(--cb-navy-mid) 100%);
  color: var(--cb-white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(6,17,31,0.28), 0 2px 8px rgba(6,17,31,0.18);
  transition: transform 180ms var(--cb-ease), box-shadow 180ms var(--cb-ease), background 180ms;
  position: relative;
  flex-shrink: 0;
}
.eastc-cb-fab:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 16px 36px rgba(6,17,31,0.32);
}
.eastc-cb-fab:active { transform: scale(0.98); }
.eastc-cb-fab:focus-visible {
  outline: 3px solid var(--cb-gold);
  outline-offset: 2px;
}
.eastc-cb-fab__icon,
.eastc-cb-fab__close {
  position: absolute;
  transition: opacity 160ms, transform 160ms var(--cb-ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
}
.eastc-cb-fab__close { opacity: 0; transform: scale(0.6) rotate(-90deg); }
.eastc-cb-root.eastc-cb--open .eastc-cb-fab__icon { opacity: 0; transform: scale(0.6) rotate(90deg); }
.eastc-cb-root.eastc-cb--open .eastc-cb-fab__close { opacity: 1; transform: scale(1) rotate(0); }

/* gold pulse dot */
.eastc-cb-fab__dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: var(--cb-gold);
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--cb-gold-glow);
}

/* label next to FAB on desktop */
.eastc-cb-fab-label {
  pointer-events: none;
  position: absolute;
  right: 72px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--cb-navy);
  color: white;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: var(--cb-shadow-md);
  opacity: 0;
  transition: opacity 160ms;
}
.eastc-cb-fab:hover .eastc-cb-fab-label { opacity: 1; }
@media (max-width: 640px) { .eastc-cb-fab-label { display: none; } }

/* ---------- Chat Panel ---------- */
.eastc-cb-panel {
  pointer-events: auto;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--cb-white);
  border-radius: var(--cb-radius-xl);
  box-shadow: var(--cb-shadow-lg);
  border: 1px solid var(--cb-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  visibility: hidden;
  transition: opacity 220ms var(--cb-ease), transform 280ms var(--cb-ease), visibility 220ms;
  transform-origin: bottom right;
}
.eastc-cb-root.eastc-cb--open .eastc-cb-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
}

/* Mobile: full screen sheet */
@media (max-width: 640px) {
  .eastc-cb-root { inset: auto 0 0 0; align-items: stretch; padding: 0; }
  .eastc-cb-panel {
    width: 100%;
    max-width: 100%;
    height: calc(100vh - 0px);
    max-height: 100dvh;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  .eastc-cb-fab { position: fixed; right: 16px; bottom: 16px; }
  .eastc-cb-root.eastc-cb--open .eastc-cb-fab { display: none; } /* hide fab when open on mobile */
}

/* ---------- Header ---------- */
.eastc-cb-header {
  background: linear-gradient(135deg, var(--cb-navy-panel) 0%, var(--cb-navy-mid) 100%);
  color: white;
  padding: 16px 16px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  border-bottom: 3px solid var(--cb-gold);
  position: relative;
  overflow: hidden;
}
.eastc-cb-header::after {
  content: '';
  position: absolute;
  inset: -40px -40px auto auto;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(200,146,42,0.18) 0%, transparent 70%);
  pointer-events: none;
}
.eastc-cb-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1.5px solid rgba(255,255,255,0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.eastc-cb-header__text { flex: 1; min-width: 0; position: relative; z-index: 1; }
.eastc-cb-header__title {
  font-family: var(--cb-font-display);
  font-weight: 800;
  font-size: 15px;
  line-height: 1.1;
  margin: 0;
  letter-spacing: -0.2px;
}
.eastc-cb-header__subtitle {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  opacity: 0.72;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.eastc-cb-header__dot {
  width: 7px; height: 7px;
  background: #2ecc71;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(46,204,113,0.2);
  display: inline-block;
}
.eastc-cb-header__actions {
  display: flex;
  gap: 6px;
  position: relative;
  z-index: 1;
}
.eastc-cb-icon-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.86);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: background 160ms, color 160ms;
}
.eastc-cb-icon-btn:hover { background: rgba(255,255,255,0.14); color: white; }
.eastc-cb-icon-btn:focus-visible { outline: 2px solid var(--cb-gold); outline-offset: 2px; }

/* ---------- Body ---------- */
.eastc-cb-body {
  flex: 1;
  overflow-y: auto;
  background: var(--cb-ivory);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.eastc-cb-body::-webkit-scrollbar { width: 6px; }
.eastc-cb-body::-webkit-scrollbar-thumb { background: #d8d2c4; border-radius: 99px; }
.eastc-cb-body::-webkit-scrollbar-track { background: transparent; }

/* welcome */
.eastc-cb-welcome {
  background: white;
  border: 1px solid var(--cb-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 2px 10px rgba(6,17,31,0.06);
}
.eastc-cb-welcome__title {
  font-family: var(--cb-font-display);
  font-weight: 800;
  font-size: 15px;
  color: var(--cb-navy-panel);
  margin: 0 0 6px;
}
.eastc-cb-welcome__text {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--cb-ink-mid);
  margin: 0;
}
.eastc-cb-welcome__badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--cb-navy-panel);
  background: var(--cb-gold-pale);
  border: 1px solid rgba(200,146,42,0.22);
  padding: 5px 9px;
  border-radius: 99px;
}

/* suggested chips */
.eastc-cb-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.eastc-cb-chip {
  font-size: 13px;
  font-weight: 500;
  color: var(--cb-navy-panel);
  background: white;
  border: 1px solid var(--cb-border);
  padding: 7px 12px;
  border-radius: 99px;
  cursor: pointer;
  transition: border-color 160ms, background 160ms, transform 160ms;
  line-height: 1.3;
}
.eastc-cb-chip:hover { border-color: var(--cb-gold); background: var(--cb-ivory-dark); transform: translateY(-1px); }
.eastc-cb-chip:focus-visible { outline: 2px solid var(--cb-gold); outline-offset: 2px; }

/* ---------- Messages ---------- */
.eastc-cb-messages { display: flex; flex-direction: column; gap: 12px; }

.eastc-cb-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 92%;
}
.eastc-cb-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.eastc-cb-msg--bot  { align-self: flex-start; }

.eastc-cb-msg__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.eastc-cb-msg--bot .eastc-cb-msg__avatar { background: var(--cb-navy-panel); color: white; border: 1px solid rgba(255,255,255,0.2); }
.eastc-cb-msg--user .eastc-cb-msg__avatar { background: var(--cb-gold); color: white; }

.eastc-cb-bubble {
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  position: relative;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(6,17,31,0.06);
}
.eastc-cb-msg--bot .eastc-cb-bubble {
  background: white;
  border: 1px solid var(--cb-border);
  border-bottom-left-radius: 6px;
  color: var(--cb-ink-mid);
}
.eastc-cb-msg--user .eastc-cb-bubble {
  background: var(--cb-navy-panel);
  color: white;
  border-bottom-right-radius: 6px;
}
.eastc-cb-bubble p { margin: 0 0 6px; }
.eastc-cb-bubble p:last-child { margin-bottom: 0; }

.eastc-cb-time {
  font-size: 11px;
  color: var(--cb-ink-soft);
  margin-top: 4px;
  padding: 0 2px;
}
.eastc-cb-msg--user .eastc-cb-time { text-align: right; }

/* sources inside bot bubble */
.eastc-cb-sources {
  margin-top: 10px;
  border-top: 1px solid var(--cb-ivory-dark);
  padding-top: 10px;
}
.eastc-cb-sources__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--cb-ink-soft);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.eastc-cb-source {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--cb-ivory);
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  padding: 8px 10px;
  text-decoration: none;
  transition: border-color 160ms, background 160ms;
}
.eastc-cb-source:hover { border-color: var(--cb-gold); background: white; }
.eastc-cb-source__icon {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: white;
  border: 1px solid var(--cb-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.eastc-cb-source__title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--cb-navy-panel);
  line-height: 1.3;
}
.eastc-cb-source__url {
  font-size: 11px;
  color: var(--cb-ink-soft);
  word-break: break-all;
  margin-top: 1px;
}
.eastc-cb-source__arrow {
  margin-left: auto;
  font-size: 11px;
  color: var(--cb-ink-soft);
  align-self: center;
}

/* feedback */
.eastc-cb-feedback {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.eastc-cb-feedback__btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--cb-border);
  background: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: border-color 160ms, background 160ms;
}
.eastc-cb-feedback__btn:hover { border-color: var(--cb-gold); background: var(--cb-ivory); }
.eastc-cb-feedback__btn.is-active { background: var(--cb-navy-panel); color: white; border-color: var(--cb-navy-panel); }

/* ---------- Typing indicator ---------- */
.eastc-cb-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  background: white;
  border: 1px solid var(--cb-border);
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 8px rgba(6,17,31,0.06);
}
.eastc-cb-typing__dots { display: inline-flex; gap: 4px; }
.eastc-cb-typing__dots span {
  width: 6px; height: 6px;
  background: #c9c3b8;
  border-radius: 50%;
  animation: eastc-cb-bounce 1.2s infinite;
}
.eastc-cb-typing__dots span:nth-child(2) { animation-delay: 0.15s; }
.eastc-cb-typing__dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes eastc-cb-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.6; }
  40% { transform: translateY(-5px); opacity: 1; background: var(--cb-gold); }
}
.eastc-cb-typing__text { font-size: 12px; color: var(--cb-ink-soft); }

/* ---------- Error banner ---------- */
.eastc-cb-error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: #9b2c2c;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.5;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.eastc-cb-error__retry {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #9b2c2c;
  background: white;
  border: 1px solid #fed7d7;
  padding: 6px 10px;
  border-radius: 99px;
  cursor: pointer;
}
.eastc-cb-error__retry:hover { background: #fff0f0; }

/* ---------- Footer ---------- */
.eastc-cb-footer {
  border-top: 1px solid var(--cb-border);
  background: white;
  padding: 10px 10px 10px;
  flex-shrink: 0;
}
.eastc-cb-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--cb-ivory);
  border: 1.5px solid var(--cb-border);
  border-radius: 14px;
  padding: 6px 6px 6px 12px;
  transition: border-color 160ms, box-shadow 160ms, background 160ms;
}
.eastc-cb-input-row:focus-within {
  border-color: var(--cb-gold);
  background: white;
  box-shadow: 0 0 0 4px var(--cb-gold-pale);
}
.eastc-cb-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 13.5px;
  line-height: 1.5;
  max-height: 96px;
  min-height: 22px;
  padding: 6px 0;
  color: var(--cb-ink);
}
.eastc-cb-input::placeholder { color: #a8a29a; }
.eastc-cb-send {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--cb-navy-panel);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 15px;
  transition: background 160ms, transform 120ms, opacity 160ms;
}
.eastc-cb-send:hover { background: var(--cb-navy-mid); }
.eastc-cb-send:active { transform: scale(0.96); }
.eastc-cb-send:disabled { opacity: 0.45; cursor: not-allowed; }
.eastc-cb-send:focus-visible { outline: 2px solid var(--cb-gold); outline-offset: 2px; }

.eastc-cb-footer__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
  padding: 0 2px;
}
.eastc-cb-footer__hint {
  font-size: 11px;
  color: var(--cb-ink-soft);
  line-height: 1.3;
}
.eastc-cb-footer__count {
  font-size: 11px;
  color: var(--cb-ink-soft);
  font-variant-numeric: tabular-nums;
}
.eastc-cb-footer__count.is-warn { color: #c53030; }
.eastc-cb-footer__links {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.eastc-cb-link-btn {
  font-size: 11px;
  font-weight: 600;
  color: var(--cb-ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.eastc-cb-link-btn:hover { color: var(--cb-navy-panel); }

/* ---------- Utilities ---------- */
.eastc-cb-hidden { display: none !important; }
.eastc-cb-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Motion reduce ---------- */
@media (prefers-reduced-motion: reduce) {
  .eastc-cb-panel, .eastc-cb-fab, .eastc-cb-typing__dots span { transition: none; animation: none; }
}
