/* PICPACS SITE CHAT WIDGET
   Self-hosted, backed by src/chat.js + a private Telegram bot (see
   13-Site-Chat-Widget.md). Matches the "stoic." design tokens from
   style.css (black/white/gray, pill buttons, soft-shadow circle badges);
   falls back to the same literal values so this file also works standalone
   if style.css isn't on the page. Scoped entirely under #picpac-chat so it
   never leaks into the rest of the site. To disable the widget, remove the
   <link>/<script> tags that load this file - nothing else changes. */

#picpac-chat, #picpac-chat * { box-sizing: border-box; }
/* .pp-panel/.pp-badge/.pp-contact each set an explicit `display` below to
   lay themselves out when shown; toggling the `hidden` attribute doesn't
   ask the browser to fight its own default [hidden]{display:none} rule
   unless we say so explicitly - author CSS beats the UA stylesheet at
   equal specificity, so without this line these three would stay visible
   even with .hidden = true. Keep this ahead of any specificity questions. */
#picpac-chat .pp-panel[hidden],
#picpac-chat .pp-badge[hidden],
#picpac-chat .pp-contact[hidden],
#picpac-chat .pp-teaser[hidden] { display: none; }
#picpac-chat {
  --pc-ground: var(--ground, #F3F3F3);
  --pc-surface: var(--surface, #FFFFFF);
  --pc-surface-2: var(--surface-2, #E9E9E9);
  --pc-ink: var(--ink, #0E0E0E);
  --pc-ink-2: var(--ink-2, #4A4A4A);
  --pc-muted: var(--muted, #8A8A8A);
  --pc-line: var(--line, #E2E2E2);
  --pc-shadow: var(--shadow, 0 10px 30px rgba(14,14,14,0.08));
  --pc-shadow-badge: var(--shadow-badge, 0 8px 20px rgba(14,14,14,0.12));
  --pc-radius: var(--radius, 20px);
  --pc-radius-sm: var(--radius-sm, 12px);
  --pc-radius-pill: var(--radius-pill, 999px);
  --pc-bubble-bg: var(--ink, #0E0E0E);
  --pc-bubble-ink: var(--ground, #F3F3F3);
  --pc-font: "Inter", "Helvetica Neue", Arial, sans-serif;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999999;
  font-family: var(--pc-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--pc-ink);
}
@media (prefers-color-scheme: dark) {
  #picpac-chat:not([data-theme="light"]) {
    --pc-bubble-bg: var(--ink, #F3F3F3);
    --pc-bubble-ink: var(--ground, #0E0E0E);
  }
}
#picpac-chat[data-theme="dark"] {
  --pc-bubble-bg: var(--ink, #F3F3F3);
  --pc-bubble-ink: var(--ground, #0E0E0E);
}

/* Bubble */
.pp-bubble {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--pc-bubble-bg); color: var(--pc-bubble-ink);
  border: none; cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--pc-shadow-badge);
  transition: transform 0.15s ease, opacity 0.15s ease;
  position: relative; padding: 0;
}
.pp-bubble:hover { transform: translateY(-2px); opacity: 0.92; }
.pp-bubble:focus-visible { outline: 2px solid var(--pc-ink); outline-offset: 3px; }
.pp-bubble svg { width: 24px; height: 24px; display: block; }
.pp-bubble .pp-icon-close { display: none; }
#picpac-chat[data-open="1"] .pp-bubble .pp-icon-chat { display: none; }
#picpac-chat[data-open="1"] .pp-bubble .pp-icon-close { display: block; }
.pp-badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px;
  border-radius: var(--pc-radius-pill); background: var(--pc-ink); color: var(--pc-ground);
  font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 5px;
  border: 2px solid var(--pc-ground);
}
@media (prefers-color-scheme: dark) {
  #picpac-chat:not([data-theme="light"]) .pp-badge { background: var(--pc-ink); color: var(--pc-ground); border-color: var(--pc-ground); }
}

/* Proactive auto-open teaser (site/chat.js doAutoOpen) - mobile-only
   low-key alternative to opening the full-screen panel: a small pill next
   to the bubble plus the existing .pp-badge unread count. */
.pp-teaser {
  position: absolute;
  right: 60px;
  bottom: 14px;
  max-width: 170px;
  background: var(--pc-surface);
  color: var(--pc-ink);
  border: 1px solid var(--pc-line);
  border-radius: var(--pc-radius-pill);
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: var(--pc-shadow-badge);
  cursor: pointer;
  white-space: nowrap;
  animation: pp-teaser-in 0.2s ease;
}
.pp-teaser:hover { opacity: 0.9; }
@media (min-width: 640px) {
  /* Desktop auto-opens the panel itself (see doAutoOpen) - the teaser is a
     mobile-only fallback and should never appear on wider viewports even
     if something toggles its hidden attribute unexpectedly. */
  .pp-teaser { display: none !important; }
}
@keyframes pp-teaser-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Panel */
.pp-panel {
  position: absolute; right: 0; bottom: 68px;
  width: 360px; max-width: calc(100vw - 24px); height: 520px; max-height: calc(100vh - 100px);
  background: var(--pc-surface); border-radius: var(--pc-radius);
  box-shadow: var(--pc-shadow); border: 1px solid var(--pc-line);
  display: flex; flex-direction: column; overflow: hidden;
}
@media (max-width: 520px) {
  .pp-panel {
    position: fixed; inset: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%;
    border-radius: 0; border: none;
  }
}
.pp-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--pc-line); background: var(--pc-surface); flex: none;
}
.pp-head-title { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.pp-head-sub { font-size: 12.5px; color: var(--pc-muted); margin-top: 2px; }
.pp-head-close {
  background: transparent; border: none; cursor: pointer; color: var(--pc-muted);
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; flex: none;
}
.pp-head-close:hover { background: var(--pc-surface-2); color: var(--pc-ink); }
.pp-head-close:focus-visible { outline: 2px solid var(--pc-ink); outline-offset: 2px; }
.pp-head-close svg { width: 16px; height: 16px; }

.pp-messages {
  flex: 1 1 auto; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px;
  background: var(--pc-ground);
  overscroll-behavior: contain;
}
.pp-msg { max-width: 82%; padding: 10px 13px; border-radius: 16px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.pp-msg-visitor { align-self: flex-end; background: var(--pc-ink); color: var(--pc-ground); border-bottom-right-radius: 4px; }
.pp-msg-ava { align-self: flex-start; background: var(--pc-surface-2); color: var(--pc-ink); border-bottom-left-radius: 4px; }
.pp-msg-system { align-self: center; background: transparent; color: var(--pc-muted); font-size: 12.5px; text-align: center; max-width: 92%; padding: 4px 8px; }
.pp-msg time { display: none; }

.pp-status {
  font-size: 12px; color: var(--pc-muted); text-align: center; padding: 6px 10px; flex: none;
}

.pp-contact { padding: 10px 14px; border-top: 1px solid var(--pc-line); display: flex; flex-direction: column; gap: 8px; flex: none; }
.pp-contact-row { display: flex; gap: 8px; }
.pp-contact input {
  flex: 1 1 0; min-width: 0; font: inherit; font-size: 13.5px; padding: 9px 11px;
  border: 1px solid var(--pc-line); border-radius: var(--pc-radius-sm);
  background: var(--pc-surface); color: var(--pc-ink);
}
.pp-contact input:focus-visible { outline: 2px solid var(--pc-ink); outline-offset: 1px; }
.pp-contact-actions { display: flex; justify-content: flex-end; gap: 8px; }
.pp-contact-actions button {
  font: inherit; font-size: 13px; font-weight: 600; padding: 8px 16px; border-radius: var(--pc-radius-pill);
  cursor: pointer; border: 1px solid transparent;
}
.pp-contact-skip { background: transparent; color: var(--pc-muted); border-color: var(--pc-line); }
.pp-contact-skip:hover { background: var(--pc-surface-2); }
.pp-contact-go { background: var(--pc-ink); color: var(--pc-ground); }
.pp-contact-go:hover { opacity: 0.85; }

.pp-composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--pc-line); flex: none; background: var(--pc-surface); }
.pp-composer textarea {
  flex: 1 1 auto; resize: none; font: inherit; font-size: 14px; padding: 10px 13px; max-height: 100px;
  border: 1px solid var(--pc-line); border-radius: 16px; background: var(--pc-ground); color: var(--pc-ink);
}
.pp-composer textarea:focus-visible { outline: 2px solid var(--pc-ink); outline-offset: 1px; }
.pp-send {
  width: 38px; height: 38px; border-radius: 50%; background: var(--pc-ink); color: var(--pc-ground);
  border: none; cursor: pointer; display: grid; place-items: center; flex: none;
}
.pp-send:hover { opacity: 0.85; }
.pp-send:disabled { opacity: 0.4; cursor: default; }
.pp-send svg { width: 16px; height: 16px; }

@media (prefers-reduced-motion: reduce) {
  #picpac-chat, #picpac-chat * { transition: none !important; scroll-behavior: auto !important; animation: none !important; }
}
