/* Sales Assistant Widget — Redesigned */
:root {
  --sa-color: #2563eb;
  --sa-color-rgb: 37, 99, 235;
  --sa-radius: 12px;
  --sa-panel-width: 380px;
  --sa-panel-height: 560px;
  --sa-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* --- Trigger Button --- */
#sales-assistant-widget {
  font-family: var(--sa-font);
}
#sales-assistant-trigger {
  position: fixed; bottom: 24px; z-index: 9999;
  background: var(--sa-color); color: #fff;
  border-radius: 50px; padding: 14px 24px;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: none; outline: none;
}
#sales-assistant-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
#sales-assistant-trigger:active {
  transform: translateY(0);
}
#sales-assistant-trigger .sa-trigger-icon {
  width: 22px; height: 22px; flex-shrink: 0;
}
#sales-assistant-trigger .sa-trigger-label {
  font-size: 14px; font-weight: 600;
}

/* --- Panel --- */
#sales-assistant-panel {
  position: fixed; bottom: 24px; z-index: 9999;
  width: var(--sa-panel-width); max-height: var(--sa-panel-height);
  background: #fff; border-radius: var(--sa-radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.14);
  flex-direction: column; overflow: hidden;
  display: none;
  transform: translateY(20px); opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
#sales-assistant-panel.sa-open {
  display: flex;
  transform: translateY(0); opacity: 1;
}
#sales-assistant-panel.sa-minimized {
  display: none;
}

/* --- Header --- */
#sales-assistant-header {
  background: var(--sa-color); color: #fff;
  padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.sa-header-left {
  display: flex; align-items: center; gap: 10px; min-width: 0;
}
.sa-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.sa-header-info {
  display: flex; flex-direction: column; min-width: 0;
}
.sa-header-name {
  font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sa-header-status {
  font-size: 11px; opacity: 0.75; display: flex; align-items: center; gap: 4px;
}
.sa-status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #22c55e; display: inline-block;
}
.sa-header-actions {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.sa-header-btn {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.2);
  color: #fff; border-radius: 6px; padding: 4px 8px; font-size: 12px;
  cursor: pointer; transition: background 0.15s; line-height: 1;
}
.sa-header-btn:hover { background: rgba(255,255,255,0.25); }
.sa-header-close {
  background: none; border: none; color: #fff; font-size: 20px;
  cursor: pointer; line-height: 1; padding: 4px; opacity: 0.8;
}
.sa-header-close:hover { opacity: 1; }

/* --- Messages Area --- */
#sales-assistant-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.sa-message {
  padding: 10px 14px; border-radius: 10px;
  max-width: 85%; line-height: 1.5; font-size: 14px;
  animation: sa-fadeIn 0.25s ease;
}
@keyframes sa-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.sa-user {
  background: var(--sa-color); color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.sa-assistant {
  background: #f1f5f9; color: #1e293b;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.sa-assistant p { margin: 6px 0; }
.sa-assistant p:first-child { margin-top: 0; }
.sa-assistant p:last-child { margin-bottom: 0; }
.sa-assistant code {
  background: #e2e8f0; border-radius: 3px; padding: 1px 5px;
  font-size: 0.85em;
}
.sa-assistant strong { font-weight: 700; }
.sa-assistant a { color: #2563eb; text-decoration: underline; }
.sa-assistant a:hover { color: #1d4ed8; }

.sa-agent {
  background: #ecfdf5; color: #065f46;
  align-self: flex-start;
  border: 1px solid #a7f3d0;
  border-bottom-left-radius: 4px;
}

/* --- Typing Indicator --- */
.sa-typing {
  display: flex; align-items: center; gap: 5px; padding: 14px 18px;
}
.sa-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #94a3b8;
  display: inline-block;
  animation: sa-bounce 1.3s ease-in-out infinite;
}
.sa-dot:nth-child(2) { animation-delay: 0.15s; }
.sa-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes sa-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Quick Replies --- */
.sa-quick-replies {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0;
  align-self: flex-start; max-width: 100%;
}
.sa-quick-btn {
  background: #fff; border: 1.5px solid var(--sa-color);
  color: var(--sa-color); border-radius: 20px;
  padding: 8px 18px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: all 0.15s ease;
}
.sa-quick-btn:hover {
  background: var(--sa-color); color: #fff;
  transform: scale(1.02);
}

/* --- Category Buttons --- */
.sa-categories {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 4px 0; align-self: flex-start; width: 100%;
}
.sa-cat-btn {
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1.5px solid var(--sa-color);
  color: var(--sa-color); border-radius: 8px;
  padding: 12px 14px; font-size: 13px; font-weight: 600;
  text-decoration: none; text-align: center;
  transition: all 0.15s ease;
}
.sa-cat-btn:hover {
  background: var(--sa-color); color: #fff;
  transform: translateY(-1px);
}

/* --- Action Buttons --- */
.sa-action { background: transparent; padding: 4px 0; }
.sa-checkout-btn {
  display: inline-block; background: #22c55e; color: #fff;
  padding: 10px 20px; border-radius: 8px; text-decoration: none;
  font-weight: 700; font-size: 14px;
  transition: background 0.15s;
}
.sa-checkout-btn:hover { background: #16a34a; }

/* --- Deal Card --- */
.sa-deal-card {
  background: #f0fdf4; border: 1px solid #bbf7d0;
  border-radius: 12px; padding: 12px 16px; margin: 4px 0;
  align-self: flex-start; max-width: 90%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  animation: sa-fadeIn 0.3s ease;
}
.sa-deal-card-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.sa-deal-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: #22c55e; color: #fff; font-size: 12px;
  font-weight: 700; flex-shrink: 0;
}
.sa-deal-title { font-weight: 700; font-size: 13px; color: #065f46; flex: 1; }
.sa-deal-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 10px; border-radius: 20px; letter-spacing: 0.3px;
}
.sa-deal-type-customer { background: #dbeafe; color: #1e40af; }
.sa-deal-type-fresh { background: #d1fae5; color: #065f46; }
.sa-deal-type-existing { background: #fef3c7; color: #92400e; }
.sa-deal-card-body { display: flex; flex-direction: column; gap: 6px; }
.sa-deal-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.sa-deal-label { color: #6b7280; }
.sa-deal-value { color: #1f2937; font-weight: 600; }
.sa-deal-stage { color: var(--sa-color); }

/* --- Pipeline Chooser --- */
#sa-pipeline-chooser {
  display: none; padding: 20px 16px; text-align: center;
  border-top: 1px solid #e2e8f0;
}
#sa-pipeline-chooser.sa-active { display: block; }
.sa-chooser-text {
  margin: 0 0 6px; font-size: 15px; color: #374151; font-weight: 700;
}
.sa-chooser-sub {
  margin: 0 0 16px; font-size: 13px; color: #6b7280;
}
.sa-chooser-buttons {
  display: flex; flex-direction: column; gap: 10px; max-width: 280px; margin: 0 auto;
}
.sa-chooser-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border: 1px solid #e5e7eb;
  border-radius: 12px; background: #fff;
  cursor: pointer; font-size: 14px; text-align: left;
  color: #1f2937; font-weight: 600;
  transition: all 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.sa-chooser-btn:hover {
  border-color: var(--sa-color);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}
.sa-chooser-btn:active { transform: translateY(0); }
.sa-chooser-icon {
  width: 24px; height: 24px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

/* --- Guest Form --- */
#sales-assistant-guest-form {
  display: none; flex-direction: column; gap: 10px;
  padding: 20px 16px; border-top: 1px solid #e2e8f0;
}
#sales-assistant-guest-form.sa-active { display: flex; }
#sa-guest-form-text {
  margin: 0 0 4px; font-size: 14px; color: #374151; font-weight: 600;
}
#sales-assistant-guest-form input {
  border: 1px solid #d1d5db; border-radius: 8px;
  padding: 10px 14px; font-size: 14px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#sales-assistant-guest-form input:focus {
  border-color: var(--sa-color);
  box-shadow: 0 0 0 3px rgba(var(--sa-color-rgb), 0.12);
}
#sa-guest-submit {
  background: var(--sa-color); color: #fff; border: none;
  border-radius: 8px; padding: 11px; font-size: 15px;
  font-weight: 700; cursor: pointer;
  transition: opacity 0.15s;
}
#sa-guest-submit:hover { opacity: 0.9; }
#sa-guest-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.sa-guest-back {
  background: none; border: none; color: #6b7280;
  font-size: 13px; cursor: pointer; padding: 4px 0;
  text-decoration: underline; align-self: flex-start;
}
.sa-guest-back:hover { color: #374151; }

/* --- Bottom Bar --- */
#sa-bottom-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; border-top: 1px solid #e2e8f0;
  background: #f8fafc; flex-shrink: 0;
}
.sa-bottom-btn {
  display: flex; align-items: center; gap: 4px;
  background: none; border: 1px solid #e2e8f0;
  color: #6b7280; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.sa-bottom-btn:hover {
  border-color: #ef4444; color: #ef4444;
  background: #fef2f2;
}
#sa-bottom-bar .sa-lang-btn {
  padding: 4px 8px; font-size: 11px;
}
#sa-talk-human-btn:hover {
  border-color: #059669; color: #059669;
  background: #ecfdf5;
}

/* --- Input Area --- */
#sales-assistant-input-area {
  display: flex; padding: 12px 16px;
  border-top: 1px solid #e2e8f0; gap: 8px;
  background: #fafbfc;
}
#sales-assistant-input {
  flex: 1; border: 1px solid #d1d5db; border-radius: 24px;
  padding: 10px 16px; font-size: 14px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#sales-assistant-input:focus {
  border-color: var(--sa-color);
  box-shadow: 0 0 0 3px rgba(var(--sa-color-rgb), 0.12);
}
#sales-assistant-send {
  background: var(--sa-color); color: #fff; border: none;
  border-radius: 50%; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
#sales-assistant-send:hover {
  opacity: 0.9; transform: scale(1.05);
}
#sales-assistant-send:active { transform: scale(0.95); }
#sales-assistant-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#sales-assistant-send svg {
  width: 18px; height: 18px;
}
.sa-lang-btn {
  background: none; border: 1px solid #d1d5db;
  color: #6b7280; border-radius: 6px;
  padding: 4px 8px; font-size: 11px; font-weight: 700;
  cursor: pointer; letter-spacing: 0.5px;
  transition: all 0.15s;
}
.sa-lang-btn:hover { border-color: var(--sa-color); color: var(--sa-color); }

/* --- Rating Widget --- */
#sa-rating-widget {
  display: none; flex-direction: column; align-items: center;
  gap: 12px; padding: 24px 16px;
  border-top: 1px solid #e2e8f0;
}
#sa-rating-widget.sa-active { display: flex; }
.sa-rating-title {
  font-size: 15px; font-weight: 700; color: #374151; margin: 0;
}
.sa-rating-stars {
  display: flex; gap: 8px;
}
.sa-star-btn {
  background: none; border: none; font-size: 32px;
  cursor: pointer; color: #d1d5db;
  transition: transform 0.15s, color 0.15s;
  padding: 0; line-height: 1;
}
.sa-star-btn:hover { transform: scale(1.2); }
.sa-star-btn.sa-active { color: #f59e0b; }
.sa-rating-submit {
  background: var(--sa-color); color: #fff; border: none;
  border-radius: 8px; padding: 10px 32px; font-size: 14px;
  font-weight: 700; cursor: pointer;
}
.sa-rating-submit:hover { opacity: 0.9; }

/* --- Reset / Start New Chat --- */
.sa-reset-btn {
  background: none; border: 1px solid #d1d5db;
  color: #6b7280; border-radius: 8px; padding: 10px 24px;
  font-size: 14px; cursor: pointer; font-weight: 600;
  margin-top: 4px;
}
.sa-reset-btn:hover { border-color: var(--sa-color); color: var(--sa-color); }

/* --- Utility --- */
.sa-loading { padding: 20px; text-align: center; color: #94a3b8; font-size: 13px; }
.sa-message-timestamp {
  font-size: 10px; color: #94a3b8; margin-top: 4px; opacity: 0;
  transition: opacity 0.15s;
}
.sa-message:hover .sa-message-timestamp { opacity: 1; }
.sa-user .sa-message-timestamp { color: rgba(255,255,255,0.6); text-align: right; }

/* --- Confirmation Dialog --- */
#sa-confirm-dialog {
  display: none; flex-direction: column; align-items: center;
  gap: 12px; padding: 24px 16px; text-align: center;
  border-top: 1px solid #e2e8f0;
}
#sa-confirm-dialog.sa-active { display: flex; }
.sa-confirm-title { font-size: 15px; font-weight: 700; color: #374151; margin: 0; }
.sa-confirm-text { font-size: 13px; color: #6b7280; margin: 0; }
.sa-confirm-actions { display: flex; gap: 12px; }
.sa-confirm-yes {
  background: #ef4444; color: #fff; border: none;
  border-radius: 8px; padding: 10px 24px; font-size: 14px;
  font-weight: 700; cursor: pointer;
}
.sa-confirm-yes:hover { background: #dc2626; }
.sa-confirm-no {
  background: #fff; border: 1px solid #d1d5db; color: #374151;
  border-radius: 8px; padding: 10px 24px; font-size: 14px;
  font-weight: 600; cursor: pointer;
}
.sa-confirm-no:hover { border-color: #9ca3af; }

/* --- Mobile Responsive --- */
@media (max-width: 639px) {
  #sales-assistant-panel {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; max-height: 100%; border-radius: 0;
    bottom: 0; z-index: 99999;
  }
  #sales-assistant-trigger {
    bottom: 16px; padding: 12px 16px;
  }
  #sales-assistant-trigger .sa-trigger-label { display: none; }
  .sa-categories { grid-template-columns: 1fr; }
  #sa-rating-widget { padding: 32px 16px; }
  .sa-star-btn { font-size: 40px; }
  #sales-assistant-messages { padding: 12px; }
}
