/* =============================================
   Pergamon Support Widget — v8 Drawer
   ============================================= */

/* ── 1. THEME TOKENS ── */
#pergamon-widget {
  /* Dark (default) */
  --p-strip:       #0b1220;
  --p-drawer:      #0c1322;
  --p-surface:     #111a2c;
  --p-surface2:    #16223a;
  --p-border:      #1b2d44;
  --p-primary:     #0de8d6;
  --p-primary-dim: rgba(13,232,214,0.10);
  --p-primary-glow:rgba(13,232,214,0.30);
  --p-text:        #dde8f4;
  --p-muted:       #52677e;
  --p-dim:         #2e4156;
  --p-shadow:      rgba(0,0,0,0.55);
  --p-overlay:     rgba(7,12,20,0.65);
  --p-badge-bg:    rgba(234,179,8,0.10);
  --p-badge-color: #f0bb2a;
  --p-badge-border:rgba(234,179,8,0.22);
  --p-user-bubble: #16223a;
  --p-input-bg:    #111a2c;
  --p-green:       #22c55e;
  --p-green-glow:  rgba(34,197,94,0.7);

  /* Layout */
  --p-strip-w:   64px;
  --p-drawer-w:  420px;
  --p-radius:    14px;
  --p-transition:0.32s cubic-bezier(0.4,0,0.2,1);

  font-family: 'Inter', 'Noto Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Light override — host sets data-perg-theme="light" OR system prefers light */
#pergamon-widget.perg-light {
  --p-strip:       #ffffff;
  --p-drawer:      #ffffff;
  --p-surface:     #f8fafc;
  --p-surface2:    #f1f5f9;
  --p-border:      #e2e8f0;
  --p-primary:     #0891b2;
  --p-primary-dim: rgba(8,145,178,0.08);
  --p-primary-glow:rgba(8,145,178,0.22);
  --p-text:        #0f172a;
  --p-muted:       #64748b;
  --p-dim:         #94a3b8;
  --p-shadow:      rgba(0,0,0,0.12);
  --p-overlay:     rgba(15,23,42,0.45);
  --p-badge-bg:    rgba(234,179,8,0.08);
  --p-badge-color: #b45309;
  --p-badge-border:rgba(180,83,9,0.20);
  --p-user-bubble: #f1f5f9;
  --p-input-bg:    #f8fafc;
  --p-green:       #16a34a;
  --p-green-glow:  rgba(22,163,74,0.6);
}

/* ── 2. STRIP (desktop nav rail) — hidden by default, triggered externally ── */
.perg-strip {
  display: none;
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: var(--p-strip-w);
  height: 100%;
  z-index: 999;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 16px;
  background: var(--p-strip);
  border-left: 1px solid var(--p-border);
  box-shadow: -4px 0 24px var(--p-shadow);
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.4,0,0.2,1);
}

/* Glow line on the left edge of strip */
.perg-strip::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 15%;
  width: 1px;
  height: 70%;
  background: linear-gradient(180deg,
    transparent,
    var(--p-primary-glow) 30%,
    var(--p-primary) 50%,
    var(--p-primary-glow) 70%,
    transparent
  );
  opacity: 0.6;
}

/* ── 3. ORB ── */
.perg-orb {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--p-primary) 0%, #1a6cf5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin-bottom: 20px;
  transition: transform 0.2s;
  box-shadow:
    0 0 16px var(--p-primary-glow),
    0 0 40px rgba(13,232,214,0.12);
  animation: orb-breathe 4s ease-in-out infinite;
}

.perg-orb:hover { transform: scale(1.08); }

.perg-orb::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1.5px solid var(--p-primary);
  opacity: 0;
  animation: orb-ring 4s ease-in-out infinite;
}

.perg-orb img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.92;
}

@keyframes orb-breathe {
  0%,100% { box-shadow: 0 0 16px var(--p-primary-glow), 0 0 40px rgba(13,232,214,0.10); }
  50%      { box-shadow: 0 0 28px var(--p-primary-glow), 0 0 60px rgba(13,232,214,0.20); }
}

@keyframes orb-ring {
  0%   { transform: scale(1);    opacity: 0.5; }
  60%  { transform: scale(1.28); opacity: 0;   }
  100% { transform: scale(1.28); opacity: 0;   }
}

/* Strip divider */
.perg-strip-divider {
  width: 32px;
  height: 1px;
  background: var(--p-border);
  margin: 8px 0;
  flex-shrink: 0;
}

/* ── 4. STRIP NAV ── */
.perg-strip-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.perg-strip-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--p-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background 0.15s, color 0.15s;
  flex-direction: column;
  gap: 3px;
}

.perg-strip-btn:hover {
  background: var(--p-primary-dim);
  color: var(--p-primary);
}

.perg-strip-btn.active {
  background: var(--p-primary-dim);
  color: var(--p-primary);
}

/* Active indicator dot */
.perg-strip-btn.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--p-primary);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px var(--p-primary-glow);
}

.perg-strip-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.perg-strip-btn-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1;
}

/* Bottom collapse button */
.perg-strip-collapse {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--p-border);
  background: var(--p-surface);
  color: var(--p-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 4px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.perg-strip-collapse:hover {
  border-color: var(--p-primary);
  color: var(--p-primary);
  background: var(--p-primary-dim);
}

.perg-strip-collapse svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
  transition: transform var(--p-transition);
}

/* When drawer is open, flip the collapse arrow */
#pergamon-widget.drawer-open .perg-strip-collapse svg {
  transform: rotate(180deg);
}

/* ── 5. DRAWER SHELL ── */
.perg-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--p-drawer-w);
  height: 100%;
  background: var(--p-drawer);
  border-left: 1px solid var(--p-border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transform: translateX(100%);
  transition: transform var(--p-transition);
  box-shadow: -8px 0 48px var(--p-shadow);
  overflow: hidden;
}

#pergamon-widget.drawer-open .perg-drawer {
  transform: translateX(0);
}

/* ── 6. DRAWER HEADER ── */
.perg-drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--p-border);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--p-surface2) 0%, transparent 100%);
}

.perg-header-orb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--p-primary) 0%, #1a6cf5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 14px var(--p-primary-glow);
  animation: orb-breathe 4s ease-in-out infinite;
}

.perg-header-orb img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.92;
}

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

.perg-header-name {
  font-size: 14px;
  font-weight: 650;
  color: var(--p-text);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 7px;
}

.perg-beta {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--p-primary);
  background: var(--p-primary-dim);
  border: 1px solid rgba(13,232,214,0.2);
  border-radius: 4px;
  padding: 1px 5px;
}

.perg-light .perg-beta {
  border-color: rgba(8,145,178,0.2);
}

.perg-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}

.perg-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--p-green);
  box-shadow: 0 0 6px var(--p-green-glow);
  animation: status-blink 4s ease-in-out infinite;
}

@keyframes status-blink {
  0%,85%,100% { opacity: 1; }
  92%          { opacity: 0.25; }
}

.perg-status-text {
  font-size: 11px;
  color: var(--p-muted);
}

.perg-header-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--p-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.perg-header-btn:hover {
  background: var(--p-surface2);
  color: var(--p-primary);
}

.perg-header-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

/* ── 7. PANEL SYSTEM ── */
.perg-panels {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.perg-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.perg-panel.active {
  display: flex;
}

/* Mode label pill at top of panel */
.perg-panel-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--p-primary);
  border-bottom: 1px solid var(--p-border);
  flex-shrink: 0;
}

.perg-panel-label svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

/* ── 8. HOME PANEL ── */
.perg-home-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--p-border) transparent;
}

.perg-home-body::-webkit-scrollbar { width: 4px; }
.perg-home-body::-webkit-scrollbar-track { background: transparent; }
.perg-home-body::-webkit-scrollbar-thumb { background: var(--p-border); border-radius: 2px; }

/* Hero — cyberpunk / AI aesthetic, always dark */
.perg-home-hero {
  background: linear-gradient(155deg, #040a14 0%, #060e1c 45%, #080d1e 75%, #0a1428 100%);
  padding: 28px 20px 30px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* Dot-grid overlay */
.perg-home-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(13,232,214,0.12) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}

/* Teal bottom-edge glow */
.perg-home-hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: linear-gradient(0deg, rgba(13,232,214,0.07) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

/* Shimmer sweep */
.perg-home-hero-shimmer {
  position: absolute;
  top: 0;
  left: -40%;
  width: 35%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(13,232,214,0.045), transparent);
  animation: hero-shimmer 7s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes hero-shimmer {
  0%   { transform: translateX(0)    skewX(-12deg); }
  100% { transform: translateX(450%) skewX(-12deg); }
}

/* All elements inside hero sit above overlays */
.perg-home-hero > * { position: relative; z-index: 1; }

.perg-home-hero-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.perg-home-hero-brand img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.9;
  flex-shrink: 0;
}

.perg-home-hero-brand-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.perg-home-hero-brand-name {
  font-size: 16px;
  font-weight: 700;
  color: rgba(255,255,255,0.95);
  letter-spacing: 0.01em;
  line-height: 1;
}

.perg-home-hero-brand-status {
  font-size: 10.5px;
  color: #0de8d6;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
}

.perg-home-hero-brand-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0de8d6;
  box-shadow: 0 0 6px rgba(13,232,214,0.9);
  flex-shrink: 0;
}

.perg-home-hero-greeting {
  font-size: 21px;
  font-weight: 750;
  color: #fff;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

.perg-home-hero-sub {
  font-size: 12px;
  color: rgba(255,255,255,0.42);
  line-height: 1.55;
  letter-spacing: 0.01em;
}

.perg-home-cta-btn {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  border-radius: 6px;
  border: 1px solid rgba(13,232,214,0.4);
  background: rgba(13,232,214,0.12);
  color: #0de8d6;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.02em;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  box-shadow: 0 0 16px rgba(13,232,214,0.15), inset 0 0 12px rgba(13,232,214,0.05);
}

.perg-home-cta-btn:hover {
  background: rgba(13,232,214,0.2);
  border-color: rgba(13,232,214,0.7);
  box-shadow: 0 0 24px rgba(13,232,214,0.28), inset 0 0 16px rgba(13,232,214,0.08);
  transform: translateY(-1px);
}

.perg-home-cta-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
  flex-shrink: 0;
}

/* Sections */
.perg-home-section {
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.perg-home-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--p-muted);
  padding: 0 2px 2px;
}

/* Cards */
.perg-home-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
  font-family: inherit;
}

.perg-home-card:hover {
  border-color: var(--p-primary);
  background: var(--p-surface2);
}

.perg-home-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--p-primary-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.perg-home-card-icon svg {
  width: 17px;
  height: 17px;
  fill: var(--p-primary);
}

.perg-home-card-body { flex: 1; min-width: 0; }

.perg-home-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--p-text);
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 2px;
}

.perg-home-card-desc {
  font-size: 11.5px;
  color: var(--p-muted);
  line-height: 1.4;
}

.perg-home-new-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--p-badge-color);
  background: var(--p-badge-bg);
  border: 1px solid var(--p-badge-border);
  border-radius: 4px;
  padding: 1px 5px;
}

.perg-home-card-arrow {
  color: var(--p-muted);
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

/* ── 9. CHAT PANEL ── */
.perg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--p-border) transparent;
}

.perg-messages::-webkit-scrollbar { width: 4px; }
.perg-messages::-webkit-scrollbar-track { background: transparent; }
.perg-messages::-webkit-scrollbar-thumb {
  background: var(--p-border);
  border-radius: 2px;
}

/* Time divider */
.perg-time-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.perg-time-divider::before,
.perg-time-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--p-border);
}

.perg-time-divider span {
  font-size: 10px;
  color: var(--p-dim);
  white-space: nowrap;
  letter-spacing: 0.04em;
}

/* ── 9. MESSAGE BUBBLES ── */
.perg-msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: msg-in 0.22s ease-out both;
}

.perg-msg.user { flex-direction: row-reverse; }

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.perg-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--p-primary) 0%, #1a6cf5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 0 10px rgba(13,232,214,0.18);
}

.perg-msg.user .perg-msg-avatar {
  background: var(--p-surface2);
  color: var(--p-muted);
  box-shadow: none;
  font-size: 10px;
}

.perg-msg-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.perg-msg.user .perg-msg-body { align-items: flex-end; }

.perg-bubble {
  max-width: 100%;
  padding: 11px 15px;
  border-radius: 3px 14px 14px 14px;
  background: var(--p-surface);
  color: var(--p-text);
  font-size: 13px;
  line-height: 1.65;
  border-left: 2px solid var(--p-primary);
  word-break: break-word;
}

.perg-msg.user .perg-bubble {
  background: var(--p-user-bubble);
  border-left: none;
  border-radius: 14px 3px 14px 14px;
}

.perg-bubble strong { font-weight: 650; }

.perg-bubble a {
  color: var(--p-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.perg-msg-time {
  font-size: 10px;
  color: var(--p-dim);
  padding: 0 3px;
}

/* ── 10. RICH CARDS ── */

/* History restore banner */
.perg-restore-banner {
  font-size: 11px;
  color: var(--p-muted);
  text-align: center;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--p-border);
  margin-bottom: 8px;
}
.perg-restore-clear {
  background: none;
  border: none;
  color: var(--p-primary);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.perg-restore-clear:hover { opacity: 0.8; }

/* Ticket card */
.perg-ticket-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-left: 2px solid var(--p-primary);
  border-radius: 3px 12px 12px 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
  animation: msg-in 0.22s ease-out both;
}

.perg-ticket-head {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--p-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.perg-ticket-head svg {
  width: 11px;
  height: 11px;
  fill: var(--p-primary);
}

.perg-ticket-hr {
  height: 1px;
  background: var(--p-border);
}

.perg-ticket-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.perg-ticket-label {
  font-size: 11px;
  color: var(--p-muted);
  flex-shrink: 0;
}

.perg-ticket-val {
  font-size: 12px;
  font-weight: 500;
  color: var(--p-text);
  text-align: right;
}

.perg-ticket-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--p-badge-bg);
  color: var(--p-badge-color);
  border: 1px solid var(--p-badge-border);
  border-radius: 20px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 500;
}

.perg-ticket-badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--p-badge-color);
}

/* Source / KB card */
.perg-source-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-left: 2px solid var(--p-primary);
  border-radius: 3px 10px 10px 10px;
  text-decoration: none;
  max-width: 100%;
  transition: background 0.15s;
  animation: msg-in 0.22s ease-out both;
}

.perg-source-card:hover { background: var(--p-surface2); }

.perg-source-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--p-primary-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.perg-source-icon svg {
  width: 13px;
  height: 13px;
  fill: var(--p-primary);
}

.perg-source-title {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--p-text);
  line-height: 1.4;
}

.perg-source-arrow {
  font-size: 15px;
  color: var(--p-dim);
  flex-shrink: 0;
}

/* ── 11. FEEDBACK ROW ── */
.perg-feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  margin-left: 2px;
}

.perg-feedback-label {
  font-size: 11px;
  color: var(--p-dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
  margin-right: 2px;
}

.perg-fb-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  transition: background 0.15s, transform 0.15s;
  opacity: 0.55;
}
.perg-fb-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.perg-fb-btn:hover {
  opacity: 1;
  transform: scale(1.1);
}
.perg-fb-pos {
  color: #0de8d6;
}
.perg-fb-pos:hover {
  background: rgba(13,232,214,0.12);
}
.perg-fb-neg {
  color: #ff6b6b;
}
.perg-fb-neg:hover {
  background: rgba(255,107,107,0.12);
}

.perg-fb-reason-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  margin-top: 2px;
}
.perg-fb-reason-input {
  flex: 1;
  background: var(--p-surface2);
  border: 1px solid rgba(13,232,214,0.25);
  border-radius: 8px;
  color: var(--p-text);
  font-size: 12px;
  padding: 5px 10px;
  outline: none;
  font-family: inherit;
}
.perg-fb-reason-input:focus {
  border-color: rgba(13,232,214,0.6);
}
.perg-fb-reason-send {
  background: rgba(13,232,214,0.12);
  border: 1px solid rgba(13,232,214,0.35);
  color: var(--p-accent);
  border-radius: 8px;
  font-size: 11px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background 0.2s;
}
.perg-fb-reason-send:hover {
  background: rgba(13,232,214,0.22);
}

.perg-feedback-thanks {
  font-size: 11px;
  color: var(--p-dim);
  font-style: italic;
  margin-top: 6px;
  display: block;
}

/* ── 12. QUICK REPLIES ── */
.perg-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0;
}

.perg-qr-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--p-border);
  background: var(--p-surface);
  color: var(--p-text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  text-decoration: none;
  font-family: inherit;
}

.perg-qr-btn:hover,
.perg-qr-btn:focus-visible {
  border-color: var(--p-primary);
  color: var(--p-primary);
  background: var(--p-primary-dim);
  outline: none;
}

/* Link chips (open in new tab) */
a.perg-qr-btn {
  border-color: rgba(13,232,214,0.22);
  color: var(--p-primary);
}

.perg-light a.perg-qr-btn {
  border-color: rgba(8,145,178,0.22);
}

/* ── 12. CHAT INPUT ── */
.perg-input-area {
  border-top: 1px solid var(--p-border);
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex-shrink: 0;
  background: var(--p-drawer);
}

.perg-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--p-input-bg);
  border: 1px solid var(--p-border);
  border-radius: 12px;
  padding: 9px 10px 9px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.perg-input-wrap:focus-within {
  border-color: rgba(13,232,214,0.45);
  box-shadow: 0 0 0 3px var(--p-primary-dim);
}

.perg-light .perg-input-wrap:focus-within {
  border-color: rgba(8,145,178,0.45);
}

.perg-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--p-text);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  line-height: 1.5;
  max-height: 100px;
  overflow-y: auto;
  scrollbar-width: none;
}

.perg-input::-webkit-scrollbar { display: none; }
.perg-input::placeholder { color: var(--p-dim); }

.perg-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--p-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.perg-icon-btn:hover { color: var(--p-primary); }
.perg-icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.perg-icon-btn svg { width: 16px; height: 16px; fill: currentColor; }

.perg-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: none;
  background: var(--p-primary);
  color: #070c14;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 0 14px var(--p-primary-glow);
  transition: opacity 0.15s, box-shadow 0.15s;
}

.perg-send-btn:disabled {
  background: var(--p-surface2);
  color: var(--p-dim);
  box-shadow: none;
  cursor: not-allowed;
  opacity: 1;
}

.perg-send-btn svg { width: 14px; height: 14px; fill: currentColor; }

.perg-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.perg-search-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--p-dim);
  cursor: pointer;
  transition: color 0.15s;
}

.perg-search-hint:hover { color: var(--p-primary); }

.perg-search-hint svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.perg-footer-brand {
  font-size: 10px;
  color: var(--p-dim);
}

.perg-footer-brand strong {
  color: var(--p-muted);
  font-weight: 500;
}

/* ── 13. TYPING INDICATOR ── */
.perg-typing {
  display: none;
  align-items: flex-start;
  gap: 10px;
}

.perg-typing.visible { display: flex; }

.perg-typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--p-surface);
  border-left: 2px solid var(--p-primary);
  border-radius: 3px 14px 14px 14px;
}

.perg-typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--p-muted);
  animation: tdot 1.3s ease-in-out infinite;
}

.perg-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.perg-typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes tdot {
  0%,60%,100% { transform: translateY(0);   opacity: 0.35; }
  30%          { transform: translateY(-5px); opacity: 1; }
}

/* ── 14. SEARCH PANEL ── */
.perg-search-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--p-border) transparent;
}

.perg-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--p-input-bg);
  border: 1px solid var(--p-border);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 16px 16px 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.perg-search-bar:focus-within {
  border-color: rgba(13,232,214,0.45);
  box-shadow: 0 0 0 3px var(--p-primary-dim);
}

.perg-search-bar svg {
  width: 16px;
  height: 16px;
  fill: var(--p-muted);
  flex-shrink: 0;
}

.perg-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--p-text);
  font-size: 13px;
  font-family: inherit;
}

.perg-search-input::placeholder { color: var(--p-dim); }

.perg-search-submit {
  padding: 4px 10px;
  border-radius: 7px;
  border: none;
  background: var(--p-primary);
  color: #070c14;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.perg-search-suggestions {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.perg-search-suggestions-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--p-muted);
}

.perg-topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.perg-topic-chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--p-border);
  background: var(--p-surface);
  color: var(--p-text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.perg-topic-chip:hover {
  border-color: var(--p-primary);
  color: var(--p-primary);
  background: var(--p-primary-dim);
}

.perg-search-results {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.perg-search-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--p-muted);
  font-size: 13px;
  padding: 20px 0;
  justify-content: center;
}

.perg-search-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--p-border);
  border-top-color: var(--p-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.perg-result-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-left: 2px solid var(--p-primary);
  border-radius: 3px 10px 10px 10px;
  text-decoration: none;
  transition: background 0.15s;
  cursor: default;
}

a.perg-result-card { cursor: pointer; }
a.perg-result-card:hover { background: var(--p-surface2); }

.perg-result-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--p-text);
}

.perg-result-snippet {
  font-size: 12px;
  color: var(--p-muted);
  line-height: 1.5;
}

.perg-result-summary {
  font-size: 13px;
  color: var(--p-text);
  line-height: 1.6;
}

.perg-result-arrow {
  display: flex;
  justify-content: flex-end;
}

.perg-result-arrow svg {
  width: 14px;
  height: 14px;
  fill: var(--p-muted);
}

.perg-search-empty {
  text-align: center;
  color: var(--p-muted);
  font-size: 13px;
  padding: 32px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.perg-search-empty strong {
  color: var(--p-text);
  font-size: 14px;
}

.perg-chat-fallback {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: 10px;
}

.perg-chat-fallback span {
  font-size: 12px;
  color: var(--p-muted);
}

.perg-switch-chat-btn {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--p-primary);
  background: var(--p-primary-dim);
  color: var(--p-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

/* ── 15. FORMS PANEL ── */
.perg-forms-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--p-border) transparent;
}

.perg-forms-intro {
  font-size: 12.5px;
  color: var(--p-muted);
  line-height: 1.6;
  padding: 2px 0 6px;
}

.perg-form-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
  font-family: inherit;
}

.perg-form-card:hover {
  border-color: var(--p-primary);
  background: var(--p-surface2);
}

.perg-form-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--p-primary-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.perg-form-icon svg {
  width: 16px;
  height: 16px;
  fill: var(--p-primary);
}

.perg-form-text { flex: 1; min-width: 0; }

.perg-form-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--p-text);
  margin-bottom: 3px;
}

.perg-form-desc {
  font-size: 11.5px;
  color: var(--p-muted);
  line-height: 1.4;
}

.perg-form-arrow {
  color: var(--p-muted);
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── 16. VOICE OVERLAY ── */
.perg-voice-overlay {
  position: absolute;
  inset: 0;
  background: var(--p-overlay);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 10;
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.perg-voice-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.perg-voice-orb-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--p-primary);
  background: var(--p-primary-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

[data-state="recording"] .perg-voice-orb-btn {
  animation: voice-pulse 1.2s ease-in-out infinite;
  background: rgba(13,232,214,0.2);
}

@keyframes voice-pulse {
  0%,100% { box-shadow: 0 0 0 0 var(--p-primary-glow); }
  50%      { box-shadow: 0 0 0 18px transparent; }
}

.perg-voice-orb-btn svg {
  width: 32px;
  height: 32px;
  fill: var(--p-primary);
}

.perg-voice-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--p-text);
}

.perg-voice-transcript {
  font-size: 13px;
  color: var(--p-muted);
  text-align: center;
  padding: 0 32px;
  min-height: 20px;
}

.perg-voice-actions {
  display: flex;
  gap: 12px;
}

.perg-voice-btn {
  padding: 8px 18px;
  border-radius: 20px;
  border: 1px solid var(--p-border);
  background: var(--p-surface);
  color: var(--p-text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.perg-voice-btn:hover {
  border-color: var(--p-primary);
  color: var(--p-primary);
  background: var(--p-primary-dim);
}

/* ── 17. CONSENT OVERLAY ── */
.perg-consent-overlay {
  position: absolute;
  inset: 0;
  background: var(--p-overlay);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  z-index: 20;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
}

.perg-consent-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.perg-consent-card {
  width: 100%;
  background: var(--p-surface);
  border-top: 1px solid var(--p-border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slide-up 0.25s ease-out both;
}

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.perg-consent-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--p-text);
}

.perg-consent-body {
  font-size: 12.5px;
  color: var(--p-muted);
  line-height: 1.6;
}

.perg-consent-body a {
  color: var(--p-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.perg-consent-actions {
  display: flex;
  gap: 10px;
}

.perg-consent-accept {
  flex: 1;
  padding: 9px;
  border-radius: 10px;
  border: none;
  background: var(--p-primary);
  color: #070c14;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.perg-consent-decline {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--p-border);
  background: transparent;
  color: var(--p-muted);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

/* ── 17b. CHAT EMPTY STATE (inside consent overlay) ── */
.perg-chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 24px 20px;
  text-align: center;
  gap: 10px;
  overflow: hidden;
}

.perg-chat-empty-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--p-text);
}

.perg-chat-empty-desc {
  font-size: 12.5px;
  color: var(--p-muted);
  line-height: 1.6;
  max-width: 280px;
}

.perg-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 6px;
}

.perg-chat-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--p-primary-glow);
  background: var(--p-primary-dim);
  color: var(--p-primary);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.perg-chat-chip:hover {
  background: var(--p-primary);
  color: #070c14;
}

.perg-chat-chip:focus-visible {
  outline: 2px solid var(--p-primary);
  outline-offset: 2px;
}

/* ── 17c. FORMS HELP TEXT ── */
.perg-forms-help {
  margin-top: 14px;
  font-size: 12px;
  color: var(--p-muted);
  text-align: center;
  line-height: 1.5;
  padding: 0 4px;
}

.perg-forms-chat-link {
  background: none;
  border: none;
  color: var(--p-primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: inherit;
}

.perg-forms-chat-link:hover { color: var(--p-text); }

.perg-forms-chat-link:focus-visible {
  outline: 2px solid var(--p-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── 18. MOBILE LAUNCHER ── */
.perg-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--p-primary) 0%, #1a6cf5 100%);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
  box-shadow: 0 0 20px var(--p-primary-glow), 0 4px 20px var(--p-shadow);
  animation: orb-breathe 4s ease-in-out infinite;
  transition: transform 0.2s;
}

.perg-launcher:hover { transform: scale(1.08); }

.perg-launcher .icon-logo {
  position: absolute;
  transition: opacity 0.15s, transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.perg-launcher .icon-logo img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.perg-launcher .icon-close {
  opacity: 0;
  transform: rotate(-90deg);
  position: absolute;
  transition: opacity 0.15s, transform 0.15s;
  width: 22px;
  height: 22px;
  fill: white;
}

.perg-launcher.open .icon-logo { opacity: 0; transform: rotate(90deg); }
.perg-launcher.open .icon-close { opacity: 1; transform: rotate(0deg); }

/* ── 19. SHEET BACKDROP (mobile) ── */
.perg-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--p-overlay);
  backdrop-filter: blur(3px);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--p-transition);
}

/* ── 20. DRAWER TABS (Home / Chat / Submit — shown at bottom of drawer) ── */
.perg-mobile-tabs {
  display: none;
  border-top: 1px solid var(--p-border);
  padding: 0 8px;
  flex-shrink: 0;
  background: var(--p-drawer);
}

.perg-mobile-tab {
  flex: 1;
  padding: 14px 4px 13px;
  border: none;
  background: transparent;
  color: var(--p-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-top: 2px solid transparent;
  margin-top: -1px;
  transition: color 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: inherit;
}

.perg-mobile-tab svg { width: 18px; height: 18px; fill: currentColor; }

.perg-mobile-tab.active {
  color: var(--p-primary);
  border-top-color: var(--p-primary);
  font-weight: 700;
}

.perg-mobile-tab:focus-visible {
  outline: 2px solid var(--p-primary);
  outline-offset: -2px;
}

/* Sheet drag handle */
.perg-sheet-handle {
  display: none;
  width: 36px;
  height: 4px;
  background: var(--p-border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

/* ── 21. RESPONSIVE ── */

/* Desktop ≥ 640px: strip slides in when triggered; off-screen by default */
@media (min-width: 640px) {
  .perg-strip    { display: flex; transform: translateX(100%); }
  #pergamon-widget.strip-visible .perg-strip { transform: translateX(0); }
  .perg-drawer   { display: flex; }
  .perg-launcher { display: none !important; }
  /* Strip is hidden — show drawer tabs so navigation is available */
  .perg-mobile-tabs { display: flex !important; }
  .perg-sheet-backdrop { display: none !important; }
  .perg-sheet-handle { display: none !important; }
  /* Hide panel label — tabs at bottom provide context */
  .perg-panel-label { display: none; }
}

/* Narrower drawer on mid-size screens */
@media (min-width: 640px) and (max-width: 900px) {
  #pergamon-widget {
    --p-drawer-w: min(370px, calc(100vw - var(--p-strip-w) - 20px));
  }
}

/* Mobile < 640px: FAB launcher + bottom sheet drawer */
@media (max-width: 639px) {
  .perg-strip { display: none !important; }
  .perg-launcher { display: flex; }

  /* Drawer becomes a bottom sheet */
  .perg-drawer {
    display: flex;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 88svh;
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-top: 1px solid var(--p-border);
    transform: translateY(calc(100% + 24px));
  }

  #pergamon-widget.drawer-open .perg-drawer {
    transform: translateY(0);
  }

  /* Backdrop shown behind sheet */
  .perg-sheet-backdrop {
    display: block;
  }

  #pergamon-widget.drawer-open .perg-sheet-backdrop {
    opacity: 1;
    pointer-events: all;
  }

  /* Show mobile tabs + handle */
  .perg-mobile-tabs { display: flex; }
  .perg-sheet-handle { display: block; }

  /* Hide desktop panel label on mobile (tabs replace it) */
  .perg-panel-label { display: none; }
}
