/* © 2026 Juan Pazmino B — Claude Code Digest chat widget.
   Lives only inside public/index.html, so unlike the sibling widget on
   juanpazminob.com this does NOT redefine its own --cb-* palette — it reads
   the page's existing --gold-rgb / --text-rgb / --shadow-rgb tuples and the
   --surface/--gold/--gold-hi/--cream/--muted vars declared in index.html's
   :root and [data-theme="light"] blocks, so both themes stay in sync
   automatically with zero duplicated color logic.
   Typography note: index.html only loads Fraunces at weights 100/300/400,
   non-italic. The source widget (juanpazminob.com) sets message text in
   italic Fraunces 200 — those weights/styles aren't loaded here, so this
   version uses Fraunces 300 upright instead of adding a new font-weight
   axis to the shared Google Fonts import. */

.cb-bubble {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #0A0A0B; /* brand mark stays dark in both themes, like the favicon */
  border: 1px solid rgba(184, 147, 80, 0.30);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 30; /* above .page (z-index 20 in index.html), unlike the source site */
  padding: 0;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.9s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.4s ease;
}
.cb-bubble.cb-in { opacity: 1; transform: translateY(0); }
.cb-bubble:hover { border-color: rgba(212, 176, 104, 0.75); }
.cb-bubble:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }
.cb-bubble svg { width: 32px; height: 32px; display: block; }
.cb-bubble.cb-hidden { display: none; }

/* ── Panel ─────────────────────────────────────────────── */
.cb-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 360px;
  height: min(560px, calc(100vh - 48px));
  /* Near-opaque surface like the juanpazminob.com widget (--cb-surface 0.97/0.98):
     the page's --surface (0.92) lets underlying text bleed through a floating panel */
  background: rgba(13, 13, 15, 0.97);
  border: 1px solid rgba(var(--gold-rgb), 0.16);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(var(--shadow-rgb), 0.55);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 31; /* above .page (z-index 20 in index.html), unlike the source site */
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.cb-panel.cb-open { display: flex; }
.cb-panel.cb-in { opacity: 1; transform: translateY(0); }
[data-theme="light"] .cb-panel { background: rgba(255, 252, 247, 0.98); }

/* ── Header (Art. 50 label + name) ──────────────────────── */
.cb-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 18px 12px 20px;
  border-bottom: 1px solid rgba(var(--gold-rgb), 0.16);
  flex-shrink: 0; /* never compresses when the keyboard shrinks the panel */
}
.cb-chips, .cb-inputrow, .cb-footer { flex-shrink: 0; }
.cb-ai-label {
  display: block;
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(var(--gold-rgb), 0.45);
}
.cb-name {
  display: block;
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 18px;
  color: var(--cream);
  margin-top: 2px;
}
.cb-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: 'Jost', sans-serif;
  font-size: 22px;
  font-weight: 200;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  transition: color 0.3s ease;
}
.cb-close:hover { color: var(--gold); }
.cb-close:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }

/* ── Messages ────────────────────────────────────────────── */
.cb-msgs {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain; /* scroll never chains to the page behind */
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--gold-rgb), 0.30) transparent;
}
.cb-msg {
  max-width: 88%;
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 16px;
  line-height: 1.55;
  color: var(--cream);
  white-space: pre-wrap;
  word-break: break-word;
}
.cb-msg-user {
  align-self: flex-end;
  background: rgba(var(--gold-rgb), 0.10);
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
}
.cb-msg-bot { align-self: flex-start; }

/* Inline links in bot replies */
.cb-link {
  color: var(--gold);
  text-decoration: underline;
  text-decoration-color: rgba(var(--gold-rgb), 0.45);
  text-underline-offset: 3px;
  transition: color 0.3s ease, text-decoration-color 0.3s ease;
}
.cb-link:hover { color: var(--gold-hi); text-decoration-color: var(--gold-hi); }

/* Typing indicator */
.cb-typing { display: flex; gap: 5px; align-self: flex-start; padding: 8px 2px; }
.cb-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(var(--gold-rgb), 0.45);
  animation: cb-pulse 1.2s ease-in-out infinite;
}
.cb-typing span:nth-child(2) { animation-delay: 0.2s; }
.cb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cb-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 0.9; } }

/* ── Chips (BRAND.md pill button pattern) ───────────────── */
.cb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 6px; /* lives inside .cb-msgs, which already has padding */
}
.cb-chip {
  border-radius: 50px;
  border: 1px solid rgba(var(--gold-rgb), 0.30);
  background: transparent;
  color: var(--gold);
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  font-weight: 200;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.4s ease, color 0.4s ease, border-color 0.4s ease, font-weight 0.3s ease;
}
.cb-chip:hover { background: var(--gold); color: var(--bg); font-weight: 400; }
.cb-chip:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }

/* ── Input ───────────────────────────────────────────────── */
.cb-inputrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 10px 20px;
  border-top: 1px solid rgba(var(--gold-rgb), 0.16);
}
.cb-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 16px;
  color: var(--cream);
  min-width: 0;
}
.cb-input::placeholder { color: var(--muted); }
.cb-input:disabled { opacity: 0.45; }
.cb-send {
  background: transparent;
  border: none;
  color: var(--gold);
  font-family: 'Jost', sans-serif;
  font-size: 20px;
  font-weight: 200;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.3s ease;
}
.cb-send:hover { color: var(--gold-hi); }
.cb-send:disabled { opacity: 0.35; cursor: default; }
.cb-send:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }

/* ── Footer ──────────────────────────────────────────────── */
.cb-footer {
  padding: 8px 20px calc(10px + env(safe-area-inset-bottom, 0px));
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: rgba(var(--gold-rgb), 0.45);
}

/* ── Mobile: full-screen panel ──────────────────────────── */
@media (max-width: 600px) {
  .cb-bubble { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .cb-panel {
    inset: 0;
    width: auto;
    /* 100dvh follows the dynamic viewport (URL bar); JS refines it with
       visualViewport when the keyboard opens */
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
    padding-top: env(safe-area-inset-top, 0px);
    overscroll-behavior: contain;
  }
}

/* Background page frozen while the chat is open on mobile. position:fixed on
   body is the only thing iOS respects for touch scroll; JS stores the
   scroll offset in top and restores it on close. */
html.cb-lock { overflow: hidden; }
body.cb-lock { position: fixed; width: 100%; overflow: hidden; }

/* ── Accessibility: no motion if requested ──────────────── */
@media (prefers-reduced-motion: reduce) {
  .cb-bubble, .cb-panel { transition: none; }
  .cb-typing span { animation: none; opacity: 0.6; }
}
