/* ProxyVerge Live Chat Widget (CSP 'self' compliant, light & dark themes, iOS Chrome/Safari optimized) */
.pv-chat-root {
  position: fixed;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 110;
  font-family: var(--font, "Inter", "Segoe UI", system-ui, -apple-system, sans-serif);
  color: var(--ink, #0f172a);
  -webkit-text-size-adjust: 100%;
}

.pv-chat-root.is-open {
  z-index: 260;
}

body.menu-open .pv-chat-root,
body.nav-drawer-open .pv-chat-root {
  display: none;
}

html.pv-chat-mobile-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body.pv-chat-mobile-open {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.pv-chat-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 50px;
  padding: 0 18px 0 15px;
  border: 0;
  border-radius: 999px;
  background: var(--accent, #2563eb);
  color: #ffffff;
  font: 600 14px/1 var(--font, inherit);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 10px 28px -6px rgba(37, 99, 235, 0.55), 0 2px 6px rgba(15, 23, 42, 0.16);
  transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
  position: relative;
}

.pv-chat-launcher:hover {
  background: var(--accent-hover, #1d4ed8);
  transform: translateY(-2px);
}

.pv-chat-launcher:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 3px;
}

.pv-chat-launcher svg {
  width: 21px;
  height: 21px;
  flex-shrink: 0;
}

.pv-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  font: 700 11px/20px var(--font, inherit);
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg, #ffffff);
}

.pv-chat-root [hidden] {
  display: none !important;
}

.pv-chat-panel {
  width: 372px;
  max-width: calc(100vw - 24px);
  height: 528px;
  max-height: calc(100dvh - 36px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated, #ffffff);
  color: var(--ink, #0f172a);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 18px;
  box-shadow: 0 24px 56px -14px rgba(15, 23, 42, 0.32), 0 4px 12px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  animation: pvChatPop 0.18s ease-out;
}

@keyframes pvChatPop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.pv-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  color: #ffffff;
  flex-shrink: 0;
}

.pv-chat-head-info {
  min-width: 0;
  flex: 1;
}

.pv-chat-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pv-chat-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.28);
  flex-shrink: 0;
}

.pv-chat-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: #ffffff;
}

.pv-chat-sub {
  margin: 3px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.86);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pv-chat-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.15s ease;
}

.pv-chat-close:hover {
  background: rgba(255, 255, 255, 0.26);
}

.pv-chat-close svg {
  width: 18px;
  height: 18px;
  display: block;
}

.pv-chat-email-bar {
  padding: 9px 12px;
  background: var(--bg-subtle, #f1f5f9);
  border-bottom: 1px solid var(--line, #e2e8f0);
  flex-shrink: 0;
}

.pv-chat-email-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pv-chat-email-input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong, #cbd5e1);
  border-radius: 9px;
  background: var(--bg-elevated, #ffffff);
  color: var(--ink, #0f172a);
  font: 400 13px/1.2 var(--font, inherit);
  -webkit-appearance: none;
  appearance: none;
}

.pv-chat-email-input:focus {
  outline: none;
  border-color: var(--accent, #2563eb);
}

.pv-chat-email-btn {
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line-strong, #cbd5e1);
  border-radius: 9px;
  background: var(--bg-elevated, #ffffff);
  color: var(--ink, #0f172a);
  font: 600 12.5px/1 var(--font, inherit);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.pv-chat-email-btn:hover:not(:disabled) {
  border-color: var(--accent, #2563eb);
  color: var(--accent, #2563eb);
}

.pv-chat-email-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.pv-chat-email-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted, #475569);
}

.pv-chat-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg, #f8fafc);
}

.pv-chat-msg {
  max-width: 84%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pv-chat-msg.is-support {
  align-self: flex-start;
}

.pv-chat-msg.is-visitor {
  align-self: flex-end;
}

.pv-chat-bubble {
  padding: 10px 13px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.48;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.pv-chat-msg.is-support .pv-chat-bubble {
  background: var(--bg-elevated, #ffffff);
  color: var(--ink, #0f172a);
  border: 1px solid var(--line, #e2e8f0);
  border-bottom-left-radius: 4px;
}

.pv-chat-msg.is-visitor .pv-chat-bubble {
  background: var(--accent, #2563eb);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.pv-chat-meta {
  font-size: 11px;
  color: var(--muted, #64748b);
  padding: 0 3px;
}

.pv-chat-msg.is-visitor .pv-chat-meta {
  text-align: right;
}

.pv-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.pv-chat-chip {
  padding: 8px 12px;
  border: 1px solid var(--line-strong, #cbd5e1);
  border-radius: 999px;
  background: var(--bg-elevated, #ffffff);
  color: var(--ink, #0f172a);
  font: 500 13px/1.25 var(--font, inherit);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}

.pv-chat-chip:hover:not(:disabled) {
  border-color: var(--accent, #2563eb);
  background: var(--accent-soft, #eff6ff);
  color: var(--accent-ink, #1e40af);
}

.pv-chat-chip:disabled {
  opacity: 0.55;
  cursor: default;
}

.pv-chat-error {
  margin: 0;
  padding: 8px 14px;
  background: #fef2f2;
  color: #b91c1c;
  border-top: 1px solid #fecaca;
  font-size: 12.5px;
  line-height: 1.35;
  flex-shrink: 0;
}

[data-theme="dark"] .pv-chat-error {
  background: #450a0a;
  color: #fca5a5;
  border-top-color: #7f1d1d;
}

.pv-chat-closed-bar {
  padding: 12px 14px;
  border-top: 1px solid var(--line, #e2e8f0);
  background: var(--bg-subtle, #f1f5f9);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 10px;
  flex-shrink: 0;
}

.pv-chat-closed-bar span {
  font-size: 13px;
  color: var(--muted, #475569);
}

.pv-chat-new-btn {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: var(--accent, #2563eb);
  color: #ffffff;
  font: 600 13px/1 var(--font, inherit);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.pv-chat-new-btn:hover {
  background: var(--accent-hover, #1d4ed8);
}

.pv-chat-foot {
  padding: 10px 12px;
  border-top: 1px solid var(--line, #e2e8f0);
  background: var(--bg-elevated, #ffffff);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.pv-chat-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 108px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong, #cbd5e1);
  border-radius: 12px;
  background: var(--bg, #f8fafc);
  color: var(--ink, #0f172a);
  font: 400 14px/1.4 var(--font, inherit);
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}

.pv-chat-input:focus {
  outline: none;
  border-color: var(--accent, #2563eb);
  background: var(--bg-elevated, #ffffff);
}

.pv-chat-send {
  height: 40px;
  min-width: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent, #2563eb);
  color: #ffffff;
  font: 600 13.5px/1 var(--font, inherit);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.14s ease, opacity 0.14s ease;
}

.pv-chat-send:hover:not(:disabled) {
  background: var(--accent-hover, #1d4ed8);
}

.pv-chat-send:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Mobile & iOS Chrome/Safari optimization: compact FAB + full-screen sheet synced to visualViewport + 16px inputs (zero iOS zoom) */
@media (max-width: 640px) {
  .pv-chat-root {
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
  }
  .pv-chat-launcher {
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: 50%;
  }
  .pv-chat-launcher-label {
    display: none;
  }
  .pv-chat-launcher svg {
    width: 24px;
    height: 24px;
  }
  .pv-chat-root.is-open {
    left: 0;
    right: 0;
    top: var(--pv-chat-top, 0px);
    bottom: auto;
    height: var(--pv-chat-h, 100dvh);
  }
  .pv-chat-panel {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    animation: none;
  }
  .pv-chat-head {
    padding: max(12px, env(safe-area-inset-top)) 14px 12px 16px;
  }
  .pv-chat-close {
    width: 42px;
    height: 42px;
    font-size: 24px;
  }
  .pv-chat-email-bar {
    padding: 10px 14px;
  }
  .pv-chat-email-input {
    height: 42px;
    font-size: 16px;
  }
  .pv-chat-email-btn {
    height: 42px;
    padding: 0 14px;
    font-size: 14px;
  }
  .pv-chat-body {
    padding: 14px 14px 16px;
  }
  .pv-chat-msg {
    max-width: 88%;
  }
  .pv-chat-bubble {
    font-size: 15px;
    padding: 10px 14px;
  }
  .pv-chat-chip {
    min-height: 40px;
    padding: 9px 14px;
    font-size: 14px;
  }
  .pv-chat-foot {
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    gap: 8px;
  }
  .pv-chat-input {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 16px;
    line-height: 1.35;
  }
  .pv-chat-send {
    height: 44px;
    padding: 0 16px;
    font-size: 15px;
  }
  .pv-chat-closed-bar {
    padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  }
  .pv-chat-new-btn {
    min-height: 42px;
    font-size: 14px;
  }
}

@media (pointer: coarse) {
  .pv-chat-input,
  .pv-chat-email-input {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pv-chat-panel { animation: none; }
  .pv-chat-launcher { transition: none; }
}
