/* QUICKSALES.AI Proposal — floating AI support widget */
.psw-root {
  --psw-primary: var(--qs-primary, #059669);
  --psw-primary-dark: var(--qs-primary-dark, #065f46);
  --psw-accent: var(--qs-accent, #f97316);
  --psw-surface: var(--qs-surface, #ffffff);
  --psw-text: var(--qs-text, #0f172a);
  --psw-muted: var(--qs-muted, #64748b);
  --psw-border: var(--qs-border, #e2e8f0);
  --psw-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  --psw-width: 380px;
  --psw-height: 520px;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  z-index: 99990;
}

.psw-launcher {
  position: fixed;
  right: 1.25rem;
  bottom: calc(var(--footer-height, 0px) + 1.25rem);
  width: 3.5rem;
  height: 3.5rem;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--psw-primary), var(--psw-primary-dark));
  color: #fff;
  cursor: pointer;
  box-shadow: var(--psw-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 99991;
}

.psw-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 16px 48px rgba(5, 150, 105, 0.35);
}

.psw-launcher svg { width: 1.5rem; height: 1.5rem; }

.psw-launcher[aria-expanded="true"] {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

.psw-panel {
  position: fixed;
  right: 1.25rem;
  bottom: calc(var(--footer-height, 0px) + 1.25rem);
  width: var(--psw-width);
  height: var(--psw-height);
  min-width: 300px;
  min-height: 360px;
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 2rem);
  background: var(--psw-surface);
  border: 1px solid var(--psw-border);
  border-radius: 16px;
  box-shadow: var(--psw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 99992;
}

.psw-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.psw-panel.is-fullscreen {
  inset: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  border: none;
}

.psw-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  background: linear-gradient(135deg, var(--psw-primary), var(--psw-primary-dark));
  color: #fff;
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}

.psw-header-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.psw-header-text { flex: 1; min-width: 0; }

.psw-header-text strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.2;
}

.psw-header-text span {
  display: block;
  font-size: 0.7rem;
  opacity: 0.85;
  margin-top: 0.125rem;
}

.psw-header-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.psw-icon-btn {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.psw-icon-btn:hover { background: rgba(255, 255, 255, 0.22); }
.psw-icon-btn svg { width: 1rem; height: 1rem; }

.psw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--qs-bg, #f8fafc);
}

.psw-msg {
  max-width: 88%;
  padding: 0.625rem 0.875rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.psw-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--psw-border);
  color: var(--psw-text);
}

.psw-msg--user {
  align-self: flex-end;
  background: var(--psw-primary);
  color: #fff;
}

.psw-msg--system {
  align-self: center;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  font-size: 0.8rem;
  max-width: 95%;
  text-align: center;
}

.psw-msg--typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--psw-border);
  color: var(--psw-muted);
  font-style: italic;
}

.psw-msg strong { font-weight: 600; }
.psw-msg ul, .psw-msg ol { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.psw-msg li { margin: 0.25rem 0; }

.psw-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 1rem 0.75rem;
  background: var(--qs-bg, #f8fafc);
}

.psw-suggestion {
  border: 1px solid var(--psw-border);
  background: #fff;
  color: var(--psw-primary);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.psw-suggestion:hover {
  background: var(--qs-primary-light, #d1fae5);
  border-color: var(--psw-primary);
}

.psw-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--psw-border);
  background: #fff;
  flex-shrink: 0;
}

.psw-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 0.375rem;
  border: 1px solid var(--psw-border);
  border-radius: 12px;
  padding: 0.5rem 0.625rem;
  background: var(--qs-bg, #f8fafc);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.psw-input-wrap:focus-within {
  border-color: var(--psw-primary);
  box-shadow: var(--focus-ring, 0 0 0 3px rgba(5, 150, 105, 0.15));
  background: #fff;
}

.psw-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  max-height: 120px;
  min-height: 1.4em;
  outline: none;
  color: var(--psw-text);
}

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

.psw-mic-btn:hover { color: var(--psw-primary); background: var(--qs-primary-light, #d1fae5); }
.psw-mic-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.psw-mic-btn.is-listening {
  color: #dc2626;
  background: #fee2e2;
  animation: psw-pulse 1.2s ease infinite;
}

@keyframes psw-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

.psw-send-btn {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 12px;
  background: var(--psw-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.psw-send-btn:hover:not(:disabled) { background: var(--qs-primary-hover, #047857); }
.psw-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.psw-send-btn svg { width: 1.125rem; height: 1.125rem; }

.psw-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 2;
}

.psw-resize-handle::after {
  content: '';
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--psw-muted);
  border-bottom: 2px solid var(--psw-muted);
  opacity: 0.5;
}

.psw-panel.is-fullscreen .psw-resize-handle { display: none; }

.psw-msg-media {
  margin-top: 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.psw-msg-image {
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--psw-border);
  background: #fff;
}

.psw-msg-video {
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--psw-border);
  background: #000;
}

.psw-msg-video-pending {
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--qs-primary-muted, #ecfdf5);
  border: 1px dashed var(--psw-primary);
  color: var(--psw-primary-dark);
  font-size: 0.8rem;
  position: relative;
  padding-left: 2rem;
}

.psw-msg-video-pending::before {
  content: '';
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 0.75rem;
  height: 0.75rem;
  margin-top: -0.375rem;
  border: 2px solid var(--psw-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: psw-spin 0.8s linear infinite;
}

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

.psw-msg-video-pending.is-error {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #b91c1c;
}

.psw-panel.is-fullscreen .psw-msg-image,
.psw-panel.is-fullscreen .psw-msg-video {
  max-height: 60vh;
  object-fit: contain;
}

.psw-status-bar {
  display: none;
  padding: 0.35rem 0.75rem;
  font-size: 0.65rem;
  color: var(--psw-muted);
  background: #f1f5f9;
  border-top: 1px solid var(--psw-border);
  text-align: center;
  flex-shrink: 0;
}

.psw-status-bar.is-visible { display: block; }

.psw-status-bar.is-error { color: #b91c1c; background: #fef2f2; }

@media (max-width: 480px) {
  .psw-panel:not(.is-fullscreen) {
    right: 0.5rem;
    bottom: 0.5rem;
    width: calc(100vw - 1rem);
    height: min(70vh, 520px);
  }
  .psw-launcher { right: 0.75rem; bottom: 0.75rem; }
}

@media print {
  .psw-root, .psw-launcher, .psw-panel { display: none !important; }
}
