/**
 * Paper Smart Live Chat - Floating Customer Widget Styles
 * Colors sampled from Paper Smart Enterprise custom theme:
 * Primary Green: #3aa935 | Forest: #1f7a2e | Ink: #262626 | Paper: #f7f8f4
 */

:root {
  --ps-chat-primary: #3aa935;
  --ps-chat-primary-hover: #1f7a2e;
  --ps-chat-dark: #262626;
  --ps-chat-paper: #f7f8f4;
  --ps-chat-sage: #e4f1dc;
  --ps-chat-line: #dce3d5;
  --ps-chat-white: #ffffff;
  --ps-chat-gray-text: #666e63;
  --ps-chat-radius: 16px;
  --ps-chat-font: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ps-chat-shadow: 0 10px 35px rgba(0, 0, 0, 0.14), 0 2px 10px rgba(0, 0, 0, 0.06);
}

/* Widget Wrapper */
.ps-chat-widget {
  font-family: var(--ps-chat-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ps-chat-dark);
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

.ps-chat-widget *,
.ps-chat-widget *::before,
.ps-chat-widget *::after {
  box-sizing: border-box;
}

/* Floating Launcher Button */
.ps-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--ps-chat-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 22px rgba(58, 169, 53, 0.4);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s, box-shadow 0.25s;
  z-index: 99998;
  outline: none;
  padding: 0;
}

.ps-chat-launcher:hover {
  background: var(--ps-chat-primary-hover);
  transform: scale(1.06) translateY(-2px);
  box-shadow: 0 10px 28px rgba(31, 122, 46, 0.45);
}

.ps-chat-launcher:active {
  transform: scale(0.96);
}

.ps-launcher-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.2s;
}

.ps-chat-launcher .ps-icon-close {
  display: none;
}

.ps-chat-launcher.ps-active .ps-icon-open {
  display: none;
}

.ps-chat-launcher.ps-active .ps-icon-close {
  display: flex;
}

.ps-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #dc2626;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  animation: psBadgePulse 2s infinite;
}

@keyframes psBadgePulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Chat Window Modal */
.ps-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 590px;
  max-height: calc(100vh - 120px);
  background: var(--ps-chat-white);
  border-radius: var(--ps-chat-radius);
  box-shadow: var(--ps-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  border: 1px solid rgba(38, 38, 38, 0.08);
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.97);
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
}

.ps-chat-window.ps-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.ps-chat-header {
  background: var(--ps-chat-dark);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ps-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ps-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.ps-avatar-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ps-chat-primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.5px;
}

.ps-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ps-chat-dark);
}

.ps-status-dot.ps-online {
  background: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.4);
}

.ps-status-dot.ps-offline {
  background: #9ca3af;
}

.ps-header-meta {
  min-width: 0;
}

.ps-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ps-subtitle {
  margin: 3px 0 0;
  font-size: 11px;
  color: #a3a89f;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ps-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ps-action-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  text-decoration: none;
}

.ps-action-btn:hover {
  background: rgba(255, 255, 255, 0.24);
  transform: scale(1.08);
  color: #ffffff;
}

.ps-action-btn.ps-btn-wa {
  color: #25d366;
}

.ps-action-btn.ps-btn-wa:hover {
  background: rgba(37, 211, 102, 0.25);
  color: #25d366;
}

/* Chat Body */
.ps-chat-body {
  flex: 1;
  background: var(--ps-chat-paper);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  outline: none;
}

/* Welcome Card */
.ps-welcome-card {
  background: #ffffff;
  border: 1px solid var(--ps-chat-line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.ps-welcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ps-chat-primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.ps-welcome-text {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ps-chat-dark);
}

/* Quick Select Options */
.ps-quick-options-wrap {
  border-top: 1px solid var(--ps-chat-line);
  padding-top: 12px;
}

.ps-quick-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--ps-chat-gray-text);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.ps-quick-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ps-quick-btn {
  background: var(--ps-chat-paper);
  border: 1px solid var(--ps-chat-line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ps-chat-dark);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.ps-quick-btn .ps-btn-bullet {
  color: var(--ps-chat-primary);
  font-size: 14px;
  line-height: 1;
}

.ps-quick-btn:hover {
  background: var(--ps-chat-sage);
  border-color: var(--ps-chat-primary);
  color: var(--ps-chat-primary-hover);
  transform: translateX(3px);
}

/* Messages Container */
.ps-messages-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message Bubble */
.ps-message-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  word-break: break-word;
}

.ps-message-row.ps-msg-customer {
  align-self: flex-end;
  align-items: flex-end;
}

.ps-message-row.ps-msg-admin {
  align-self: flex-start;
  align-items: flex-start;
}

.ps-msg-sender {
  font-size: 10px;
  font-weight: 600;
  color: var(--ps-chat-gray-text);
  margin-bottom: 4px;
  padding: 0 4px;
}

.ps-msg-bubble {
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}

.ps-msg-customer .ps-msg-bubble {
  background: var(--ps-chat-primary);
  color: #ffffff;
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 2px 8px rgba(58, 169, 53, 0.2);
}

.ps-msg-admin .ps-msg-bubble {
  background: #ffffff;
  color: var(--ps-chat-dark);
  border: 1px solid var(--ps-chat-line);
  border-radius: 14px 14px 14px 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.ps-msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--ps-chat-gray-text);
  margin-top: 4px;
  padding: 0 4px;
}

.ps-msg-status {
  font-size: 11px;
}

.ps-msg-status.sent {
  color: var(--ps-chat-primary);
}

.ps-msg-status.failed {
  color: #dc2626;
  cursor: pointer;
  text-decoration: underline;
}

/* Inline Lead Card */
.ps-lead-form-card {
  background: #ffffff;
  border: 1.5px solid var(--ps-chat-primary);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 4px 16px rgba(58, 169, 53, 0.12);
  margin-top: 8px;
}

.ps-lead-header h4 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ps-chat-primary-hover);
}

.ps-lead-header p {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--ps-chat-gray-text);
}

.ps-form-group {
  margin-bottom: 8px;
}

.ps-form-group label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ps-chat-dark);
  margin-bottom: 3px;
}

.ps-form-group input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--ps-chat-line);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: var(--ps-chat-paper);
}

.ps-form-group input:focus {
  border-color: var(--ps-chat-primary);
  background: #ffffff;
}

.ps-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.ps-btn-primary {
  flex: 1;
  background: var(--ps-chat-primary);
  color: #ffffff;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.ps-btn-primary:hover {
  background: var(--ps-chat-primary-hover);
}

.ps-btn-skip {
  background: transparent;
  border: none;
  color: var(--ps-chat-gray-text);
  font-size: 11px;
  cursor: pointer;
  padding: 0 6px;
}

.ps-btn-skip:hover {
  text-decoration: underline;
}

/* Network alert */
.ps-network-alert {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 6px;
  text-align: center;
}

/* Footer Composer */
.ps-chat-footer {
  background: #ffffff;
  border-top: 1px solid var(--ps-chat-line);
  padding: 12px 14px 8px;
  flex-shrink: 0;
}

.ps-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--ps-chat-paper);
  border: 1px solid var(--ps-chat-line);
  border-radius: 10px;
  padding: 6px 10px;
  transition: border-color 0.2s;
}

.ps-composer-row:focus-within {
  border-color: var(--ps-chat-primary);
  background: #ffffff;
}

.ps-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
  padding: 4px 0;
  color: var(--ps-chat-dark);
}

.ps-chat-send-btn {
  background: var(--ps-chat-primary);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
  padding: 0;
  flex-shrink: 0;
}

.ps-chat-send-btn:hover:not(:disabled) {
  background: var(--ps-chat-primary-hover);
  transform: scale(1.05);
}

.ps-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ps-footer-subbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 10px;
  color: var(--ps-chat-gray-text);
  padding: 0 4px;
}

.ps-end-chat-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 10px;
  color: #888888;
  cursor: pointer;
  text-decoration: underline;
}

.ps-end-chat-btn:hover {
  color: #dc2626;
}

.ps-branding {
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* ==========================================================================
   Responsive Breakpoints & Safe Mobile Spacing
   ========================================================================== */

/* Mobile viewports */
@media (max-width: 720px) {
  /* Avoid overlapping the floating Call Now bar (height ~68px + safe area) */
  .ps-chat-launcher {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .ps-chat-window {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    left: 12px;
    width: auto;
    height: calc(100vh - 96px - env(safe-area-inset-bottom, 0px));
    max-height: 580px;
  }

  /* When mobile navigation drawer or search overlay is open, hide chat launcher */
  body.menu-open .ps-chat-launcher,
  body.ps-drawer-active .ps-chat-launcher,
  body.ps-search-active .ps-chat-launcher {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }
}

@media (max-width: 480px) {
  .ps-chat-window {
    top: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    right: 8px;
    left: 8px;
    height: auto;
    max-height: none;
    border-radius: 14px;
  }
}
