/* ══════════════════════════════════════════════════════════════════════════
   Journal AI Chatbot v3 — Clean & Modern
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  --cb-primary:   #2563eb;        /* overridden by JS with actual theme color */
  --cb-bg:        #ffffff;
  --cb-surface:   #f8fafc;
  --cb-border:    #e2e8f0;
  --cb-text:      #1e293b;
  --cb-muted:     #94a3b8;
  --cb-bot-bg:    #f1f5f9;
  --cb-user-bg:   var(--cb-primary);
  --cb-user-text: #ffffff;
  --cb-radius:    18px;
  --cb-font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --cb-z:         99999;
  --cb-shadow:    0 16px 48px rgba(0,0,0,.16), 0 4px 16px rgba(0,0,0,.08);
}

/* ── FAB ──────────────────────────────────────────────────────────────────── */

.cb-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--cb-z);
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--cb-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, box-shadow .2s, background .15s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.cb-fab:hover  { transform: scale(1.07); box-shadow: 0 6px 28px rgba(0,0,0,.28); }
.cb-fab:active { transform: scale(.95); }
.cb-fab:focus-visible { outline: 3px solid var(--cb-primary); outline-offset: 3px; }

/* Badge */
.cb-badge {
  position: absolute;
  top: 0; right: 0;
  width: 19px; height: 19px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid white;
  font: 700 10px/1 var(--cb-font);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0);
  opacity: 0;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .15s;
}
.cb-badge-show { transform: scale(1) !important; opacity: 1 !important; }

/* ── Panel ────────────────────────────────────────────────────────────────── */

.cb-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: var(--cb-z);
  width: 360px;
  max-height: 560px;
  background: var(--cb-bg);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--cb-font);
  border: 1px solid rgba(0,0,0,.07);
  /* closed */
  transform: scale(.88) translateY(14px);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: transform .28s cubic-bezier(.32,.72,0,1), opacity .22s;
  will-change: transform, opacity;
}

.cb-open {
  transform: scale(1) translateY(0) !important;
  opacity: 1 !important;
  pointer-events: all !important;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.cb-hdr {
  background: var(--cb-primary);
  padding: 13px 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.cb-logo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.22);
}

.cb-meta { flex: 1; min-width: 0; }

.cb-name {
  font-size: 14px;
  font-weight: 700;
  color: white;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cb-stat {
  font-size: 11.5px;
  color: rgba(255,255,255,.8);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.cb-dot {
  width: 6px; height: 6px;
  background: #4ade80;
  border-radius: 50%;
  flex-shrink: 0;
  animation: cbPulse 2.5s infinite;
}
@keyframes cbPulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .45; }
}

.cb-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.8);
  transition: background .15s;
  flex-shrink: 0;
  padding: 0;
}
.cb-close:hover { background: rgba(255,255,255,.18); color: white; }

/* ── Messages ─────────────────────────────────────────────────────────────── */

.cb-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px 13px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
}

.cb-msgs::-webkit-scrollbar { width: 4px; }
.cb-msgs::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Message rows */
.cb-row { display: flex; animation: cbUp .18s ease both; }
@keyframes cbUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.cb-bot { justify-content: flex-start; }
.cb-user { justify-content: flex-end; }

/* Bubbles */
.cb-bub {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
}

.cb-bot .cb-bub {
  background: var(--cb-bot-bg);
  color: var(--cb-text);
  border-bottom-left-radius: 4px;
}

.cb-user .cb-bub {
  background: var(--cb-user-bg);
  color: var(--cb-user-text);
  border-bottom-right-radius: 4px;
}

.cb-bot-err .cb-bub {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-bottom-left-radius: 4px;
}

/* Links inside bot bubbles */
.cb-bot .cb-bub a { color: var(--cb-primary); font-weight: 500; }
.cb-bot .cb-bub a:hover { text-decoration: underline; }

/* Numbered list items */
.cb-li {
  display: flex;
  gap: 7px;
  margin: 3px 0;
}
.cb-li b {
  color: var(--cb-primary);
  min-width: 16px;
  font-size: 12px;
  flex-shrink: 0;
  padding-top: 2px;
}

/* ── Typing dots ──────────────────────────────────────────────────────────── */

.cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 11px 14px;
}
.cb-typing b {
  width: 6px; height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  font-size: 0;
  display: inline-block;
  animation: cbDot 1.2s ease-in-out infinite;
}
.cb-typing b:nth-child(2) { animation-delay: .16s; }
.cb-typing b:nth-child(3) { animation-delay: .32s; }

@keyframes cbDot {
  0%,60%,100% { transform: translateY(0); opacity: .5; }
  30%         { transform: translateY(-5px); opacity: 1; background: var(--cb-primary); }
}

/* ── Quick chips ──────────────────────────────────────────────────────────── */

.cb-chips {
  padding: 2px 13px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cb-chip {
  padding: 5px 12px;
  background: transparent;
  color: var(--cb-primary);
  border: 1.5px solid var(--cb-primary);
  border-radius: 20px;
  font: 500 12px/1.4 var(--cb-font);
  cursor: pointer;
  transition: background .14s, color .14s, transform .1s;
  white-space: nowrap;
  opacity: .85;
}
.cb-chip:hover {
  background: var(--cb-primary);
  color: white;
  opacity: 1;
  transform: translateY(-1px);
}

/* ── Input footer ─────────────────────────────────────────────────────────── */

.cb-footer {
  padding: 10px 12px 11px;
  border-top: 1px solid var(--cb-border);
  background: var(--cb-bg);
  flex-shrink: 0;
}

.cb-inputwrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--cb-surface);
  border: 1.5px solid var(--cb-border);
  border-radius: 13px;
  padding: 7px 7px 7px 13px;
  transition: border-color .15s, box-shadow .15s;
}
.cb-inputwrap:focus-within {
  border-color: var(--cb-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cb-primary) 12%, transparent);
}

#cb-input {
  flex: 1;
  border: none;
  background: transparent;
  font: 13.5px/1.5 var(--cb-font);
  color: var(--cb-text);
  resize: none;
  max-height: 96px;
  outline: none;
  padding: 2px 0;
}
#cb-input::placeholder { color: var(--cb-muted); }

/* ── Send button — filled paper-plane icon ─────────────────────────────── */
.cb-sendbtn {
  width: 36px;
  height: 36px;
  min-width: 36px;   /* prevent shrinking */
  border-radius: 10px;
  background: var(--cb-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  transition: background .14s, transform .1s;
  padding: 0;
  flex-shrink: 0;
}
.cb-sendbtn:hover:not(:disabled) { filter: brightness(1.1); }
.cb-sendbtn:active:not(:disabled) { transform: scale(.92); }
.cb-sendbtn:disabled { opacity: .4; cursor: not-allowed; }

/* Ensure inner SVG fills the button correctly */
.cb-sendbtn svg {
  display: block;
  flex-shrink: 0;
  overflow: visible;
}

.cb-pw {
  font: 11px/1 var(--cb-font);
  color: var(--cb-muted);
  text-align: center;
  margin-top: 7px;
  opacity: .65;
}

/* ── Scroll-to-bottom pill ────────────────────────────────────────────────── */

.cb-pill {
  position: absolute;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: white;
  border: 1.5px solid var(--cb-border);
  border-radius: 20px;
  padding: 4px 13px;
  font: 500 12px/1.4 var(--cb-font);
  color: var(--cb-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 10px rgba(0,0,0,.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 1;
}
.cb-pill-show {
  opacity: 1 !important;
  pointer-events: all !important;
  transform: translateX(-50%) translateY(0) !important;
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .cb-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%;
    max-height: 88svh;
    border-radius: var(--cb-radius) var(--cb-radius) 0 0;
  }
  .cb-fab { bottom: 18px; right: 18px; }
}
