/* ═══════════════════════════════════════════════════════════════
   Pulsessivo WP Chatbot - Styles
   Design: North Star — dark navy + orange accent
   ═══════════════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties (Light theme) ────────── */

#pulsessivo-chatbot {
  --pcb-primary: #0c2340;
  --pcb-primary-light: #163a5f;
  --pcb-accent: #e87722;
  --pcb-accent-hover: #d0681c;
  --pcb-bg-window: #ffffff;
  --pcb-bg-messages: #f0f4f8;
  --pcb-bg-header: #0c2340;
  --pcb-bg-input: #ffffff;
  --pcb-bg-bubble-user: #e87722;
  --pcb-bg-bubble-ai: #ffffff;
  --pcb-text-primary: #0c2340;
  --pcb-text-secondary: #4a6278;
  --pcb-text-header: #ffffff;
  --pcb-text-bubble-user: #ffffff;
  --pcb-text-bubble-ai: #1a2b3c;
  --pcb-text-placeholder: #8899aa;
  --pcb-border: #cdd8e3;
  --pcb-border-header: rgba(255, 255, 255, 0.1);
  --pcb-shadow: rgba(12, 35, 64, 0.25);
  --pcb-icon-header: rgba(255, 255, 255, 0.8);
  --pcb-icon-header-hover: rgba(255, 255, 255, 0.15);
  --pcb-contact-bg: #eaf0f7;
  --pcb-contact-border: #cdd8e3;
  --pcb-scrollbar: #b0bec5;
}

/* ─── Dark theme overrides ───────────────────────── */

#pulsessivo-chatbot.pcb-dark {
  --pcb-primary: #0c2340;
  --pcb-primary-light: #163a5f;
  --pcb-accent: #e87722;
  --pcb-accent-hover: #f09040;
  --pcb-bg-window: #0a1929;
  --pcb-bg-messages: #0e2236;
  --pcb-bg-header: #081625;
  --pcb-bg-input: #0e2236;
  --pcb-bg-bubble-user: #e87722;
  --pcb-bg-bubble-ai: #152d45;
  --pcb-text-primary: #e0e8f0;
  --pcb-text-secondary: #8aa0b8;
  --pcb-text-header: #ffffff;
  --pcb-text-bubble-user: #ffffff;
  --pcb-text-bubble-ai: #d8e4f0;
  --pcb-text-placeholder: #5a7a96;
  --pcb-border: #1c3a56;
  --pcb-border-header: rgba(255, 255, 255, 0.06);
  --pcb-shadow: rgba(0, 0, 0, 0.5);
  --pcb-icon-header: rgba(255, 255, 255, 0.75);
  --pcb-icon-header-hover: rgba(255, 255, 255, 0.1);
  --pcb-contact-bg: #122a40;
  --pcb-contact-border: #1c3a56;
  --pcb-scrollbar: #1c3a56;
}

/* ─── Reset & container ──────────────────────────── */

#pulsessivo-chatbot *,
#pulsessivo-chatbot *::before,
#pulsessivo-chatbot *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#pulsessivo-chatbot {
  position: fixed;
  bottom: 24px;
  right: 12px;
  z-index: 99999;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  direction: ltr;
}

/* ─── Toggle Button (FAB) ────────────────────────── */

.pcb-toggle-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--pcb-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px var(--pcb-shadow);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  background: var(--pcb-primary);
  color: var(--pcb-accent);
}

.pcb-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 30px var(--pcb-shadow);
}

.pcb-toggle-btn svg {
  width: 30px;
  height: 30px;
}

/* ─── Chat Window ────────────────────────────────── */

.pcb-window {
  display: flex;
  flex-direction: column;
  background: var(--pcb-bg-window);
  border: 1px solid var(--pcb-border);
  border-radius: 10px;
  box-shadow: 0 10px 32px var(--pcb-shadow);
  transition: all 0.3s ease-in-out;
  overflow: hidden;
}

.pcb-window.pcb-normal {
  width: min(384px, calc(100vw - 24px));
  height: 520px;
}

.pcb-window.pcb-expanded {
  width: min(90vw, calc(100vw - 24px));
  max-width: 768px;
  height: min(80vh, calc(100vh - 24px));
}

@media (max-width: 640px) {
  #pulsessivo-chatbot {
    bottom: 20px;
    right: 8px;
  }

  .pcb-header-title {
    font-size: 10px;
    max-width: 140px;
  }

  .pcb-window.pcb-normal {
    width: calc(100vw - 16px);
    height: min(500px, calc(100vh - 16px));
  }

  .pcb-window.pcb-expanded {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
  }
}

/* ─── Header ─────────────────────────────────────── */

.pcb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 56px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--pcb-border-header);
  background: var(--pcb-bg-header);
}

.pcb-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pcb-header-logo {
  width: 28px;
  height: auto;
}

.pcb-header-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--pcb-text-header);
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.pcb-header-right {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
}

.pcb-icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pcb-icon-header);
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.pcb-icon-btn:hover {
  background: var(--pcb-icon-header-hover);
  color: #ffffff;
}

.pcb-icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ─── Theme Toggle Switch ────────────────────────── */

.pcb-theme-toggle {
  position: relative;
  width: 48px;
  height: 28px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: background 0.25s ease;
  display: flex;
  align-items: center;
  padding: 0 4px;
  flex-shrink: 0;
}

.pcb-theme-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
}

.pcb-theme-toggle-knob {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--pcb-accent);
  transition: transform 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.pcb-theme-toggle-knob svg {
  width: 11px;
  height: 11px;
  color: #fff;
}

.pcb-dark .pcb-theme-toggle-knob {
  transform: translateX(20px);
}

.pcb-theme-separator {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
  margin: 0 2px;
}

/* ─── Messages Area ──────────────────────────────── */

.pcb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--pcb-bg-messages);
}

.pcb-messages-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--pcb-text-placeholder);
  font-size: 14px;
}

/* ─── Message Row ────────────────────────────────── */

.pcb-msg-row {
  display: flex;
  width: 100%;
  padding: 0 1px;
}

.pcb-msg-row.pcb-user {
  justify-content: flex-end;
}

.pcb-msg-row.pcb-ai {
  justify-content: flex-start;
}

.pcb-msg-avatar {
  min-width: 30px;
  margin-right: 4px;
  display: flex;
  align-items: flex-start;
  padding-top: 1px;
}

.pcb-msg-avatar img {
  width: 24px;
  height: auto;
  border-radius: 4px;
}

.pcb-msg-spacer {
  min-width: 6px;
}

/* ─── Message Bubble ─────────────────────────────── */

.pcb-bubble {
  display: inline-block;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 90%;
  hyphens: auto;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.pcb-bubble.pcb-bubble-user {
  background: var(--pcb-bg-bubble-user);
  color: var(--pcb-text-bubble-user);
  border-bottom-right-radius: 4px;
}

.pcb-bubble.pcb-bubble-ai {
  background: var(--pcb-bg-bubble-ai);
  color: var(--pcb-text-bubble-ai);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--pcb-border);
}

/* RTL support */
[dir="rtl"] .pcb-bubble {
  font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
  text-align: right;
  max-width: 100%;
  unicode-bidi: plaintext;
}

/* ─── Markdown Content ───────────────────────────── */

.pcb-markdown p {
  margin-bottom: 8px;
}

.pcb-markdown p:last-child {
  margin-bottom: 0;
}

.pcb-markdown strong {
  font-weight: 700;
}

.pcb-markdown em {
  font-style: italic;
}

.pcb-markdown h1,
.pcb-markdown h2,
.pcb-markdown h3,
.pcb-markdown h4 {
  font-weight: 700;
  margin-top: 12px;
  margin-bottom: 8px;
}

.pcb-markdown h1:first-child,
.pcb-markdown h2:first-child,
.pcb-markdown h3:first-child,
.pcb-markdown h4:first-child {
  margin-top: 0;
}

.pcb-markdown h1 {
  font-size: 1.25em;
}
.pcb-markdown h2 {
  font-size: 1.125em;
}
.pcb-markdown h3 {
  font-size: 1em;
}

.pcb-markdown ul,
.pcb-markdown ol {
  margin: 8px 0;
  padding-left: 20px;
}

.pcb-markdown ul {
  list-style-type: disc;
}
.pcb-markdown ol {
  list-style-type: decimal;
}

.pcb-markdown li {
  margin-bottom: 4px;
}

.pcb-markdown code {
  background: rgba(12, 35, 64, 0.08);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

.pcb-markdown pre {
  background: rgba(12, 35, 64, 0.06);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--pcb-border);
}

.pcb-markdown a {
  color: var(--pcb-accent);
  text-decoration: underline;
  font-weight: 500;
}

.pcb-markdown a:hover {
  color: var(--pcb-accent-hover);
  text-decoration: none;
}

.pcb-markdown blockquote {
  border-left: 3px solid var(--pcb-accent);
  padding-left: 16px;
  font-style: italic;
  margin: 8px 0;
  color: var(--pcb-text-secondary);
}

.pcb-markdown table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  font-size: 0.97em;
}

.pcb-markdown th,
.pcb-markdown td {
  border: 1px solid var(--pcb-border);
  padding: 6px 10px;
}

.pcb-markdown th {
  background: var(--pcb-contact-bg);
  font-weight: bold;
}

/* ─── Typing Animation ───────────────────────────── */

.pcb-dot-typing {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 12px;
  padding: 0 2px;
}

.pcb-dot-typing::before,
.pcb-dot-typing::after {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--pcb-accent);
  margin: 0 2px;
  animation: pcb-blink-dots 1.4s infinite both;
}

.pcb-dot-typing::before {
  animation-delay: 0s;
}

.pcb-dot-typing-middle {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--pcb-accent);
  margin: 0 2px;
  animation: pcb-blink-dots 1.4s infinite both;
  animation-delay: 0.2s;
}

.pcb-dot-typing::after {
  animation-delay: 0.4s;
}

@keyframes pcb-blink-dots {
  0%,
  80%,
  100% {
    opacity: 0;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ─── Input Area ─────────────────────────────────── */

.pcb-input-area {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--pcb-border);
  background: var(--pcb-bg-window);
}

.pcb-input {
  flex: 1;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--pcb-border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  background: var(--pcb-bg-input);
  color: var(--pcb-text-primary);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.pcb-input::placeholder {
  color: var(--pcb-text-placeholder);
}

.pcb-input:focus {
  border-color: var(--pcb-accent);
  box-shadow: 0 0 0 2px rgba(232, 119, 34, 0.15);
}

.pcb-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pcb-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  background: var(--pcb-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  transition:
    background 0.15s ease,
    transform 0.1s ease;
}

.pcb-send-btn:hover {
  background: var(--pcb-accent-hover);
}

.pcb-send-btn:active {
  transform: scale(0.96);
}

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

.pcb-send-btn svg {
  width: 20px;
  height: 20px;
}

@media (max-width: 640px) {
  .pcb-header {
    padding: 8px 10px;
  }

  .pcb-messages {
    padding: 10px 8px 8px;
  }

  .pcb-input-area {
    padding: 8px;
  }
}

/* ─── Clear Confirmation Modal ───────────────────── */

#pulsessivo-chatbot .pcb-clear-modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: rgba(6, 18, 31, 0.56);
  backdrop-filter: blur(2px);
}

#pulsessivo-chatbot .pcb-clear-modal {
  width: min(100%, 290px);
  background: var(--pcb-bg-window);
  border: 1px solid var(--pcb-border);
  border-radius: 10px;
  box-shadow: 0 10px 30px var(--pcb-shadow);
  padding: 12px;
}

#pulsessivo-chatbot .pcb-clear-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--pcb-text-primary);
  margin-bottom: 6px;
}

#pulsessivo-chatbot .pcb-clear-modal-text {
  font-size: 13px;
  line-height: 1.45;
  color: var(--pcb-text-secondary);
  margin-bottom: 12px;
}

#pulsessivo-chatbot .pcb-clear-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#pulsessivo-chatbot .pcb-clear-modal-btn {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--pcb-border);
  background: var(--pcb-bg-input);
  color: var(--pcb-text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

#pulsessivo-chatbot .pcb-clear-modal-cancel:hover {
  background: rgba(12, 35, 64, 0.05);
}

#pulsessivo-chatbot .pcb-clear-modal-confirm {
  border-color: var(--pcb-accent);
  background: var(--pcb-accent);
  color: #ffffff;
}

#pulsessivo-chatbot .pcb-clear-modal-confirm:hover {
  background: var(--pcb-accent-hover);
  border-color: var(--pcb-accent-hover);
}

#pulsessivo-chatbot.pcb-dark .pcb-clear-modal-cancel:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* ─── Contact Form (inline in chat) ──────────────── */

#pulsessivo-chatbot .pcb-contact-row {
  align-items: flex-start;
}

#pulsessivo-chatbot .pcb-contact-card {
  flex: 1;
  max-width: 90%;
  background: var(--pcb-bg-bubble-ai);
  color: var(--pcb-text-bubble-ai);
  border: 1px solid var(--pcb-border);
  border-radius: 10px;
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

#pulsessivo-chatbot .pcb-contact-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--pcb-text-bubble-ai);
  line-height: 1.4;
}

#pulsessivo-chatbot .pcb-contact-desc {
  font-size: 13px;
  color: var(--pcb-text-secondary);
  margin-bottom: 14px;
  line-height: 1.45;
}

#pulsessivo-chatbot .pcb-contact-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#pulsessivo-chatbot .pcb-contact-field {
  margin-bottom: 10px;
}

#pulsessivo-chatbot .pcb-contact-field:last-of-type {
  margin-bottom: 0;
}

#pulsessivo-chatbot .pcb-contact-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--pcb-text-bubble-ai);
  margin-bottom: 5px;
  letter-spacing: 0.01em;
}

#pulsessivo-chatbot .pcb-contact-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--pcb-border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  background: var(--pcb-bg-messages);
  color: var(--pcb-text-primary);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

#pulsessivo-chatbot .pcb-contact-input::placeholder {
  color: var(--pcb-text-placeholder);
}

#pulsessivo-chatbot .pcb-contact-input:focus {
  border-color: var(--pcb-accent);
  box-shadow: 0 0 0 2px rgba(232, 119, 34, 0.15);
  background: var(--pcb-bg-input);
}

#pulsessivo-chatbot .pcb-contact-error {
  color: #f87171;
  font-size: 12px;
  margin-top: 10px;
  margin-bottom: 0;
  line-height: 1.4;
}

#pulsessivo-chatbot .pcb-contact-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin-top: 14px;
}

#pulsessivo-chatbot .pcb-contact-btn-submit {
  width: 100%;
  min-height: 42px;
  padding: 0 16px;
  background: var(--pcb-accent);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition:
    background 0.15s ease,
    transform 0.1s ease;
}

#pulsessivo-chatbot .pcb-contact-btn-submit:hover {
  background: var(--pcb-accent-hover);
}

#pulsessivo-chatbot .pcb-contact-btn-submit:active {
  transform: scale(0.98);
}

#pulsessivo-chatbot .pcb-contact-btn-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#pulsessivo-chatbot .pcb-contact-btn-skip {
  align-self: flex-end;
  padding: 4px 8px;
  background: transparent;
  color: var(--pcb-text-secondary);
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}

#pulsessivo-chatbot .pcb-contact-btn-skip:hover {
  color: var(--pcb-text-bubble-ai);
  background: rgba(12, 35, 64, 0.05);
  text-decoration: none;
}

#pulsessivo-chatbot.pcb-dark .pcb-contact-btn-skip:hover {
  color: var(--pcb-text-bubble-ai);
  background: rgba(255, 255, 255, 0.06);
}

.pcb-dark .pcb-markdown code {
  background: rgba(255, 255, 255, 0.08);
}

.pcb-dark .pcb-markdown pre {
  background: rgba(255, 255, 255, 0.06);
}

/* ─── Scrollbar ──────────────────────────────────── */

.pcb-messages::-webkit-scrollbar {
  width: 6px;
}

.pcb-messages::-webkit-scrollbar-track {
  background: transparent;
}

.pcb-messages::-webkit-scrollbar-thumb {
  background: var(--pcb-scrollbar);
  border-radius: 3px;
}

.pcb-messages::-webkit-scrollbar-thumb:hover {
  background: var(--pcb-accent);
}

/* ─── Layout Safeguards ──────────────────────────── */

#pulsessivo-chatbot .pcb-window {
  overflow: hidden;
}

#pulsessivo-chatbot .pcb-header {
  min-height: 56px;
  padding: 8px 10px;
}

#pulsessivo-chatbot .pcb-header-left {
  gap: 8px;
}

#pulsessivo-chatbot .pcb-header-right {
  gap: 3px;
  margin-left: 6px;
}

#pulsessivo-chatbot .pcb-messages {
  padding: 10px 8px 8px;
  gap: 6px;
}

#pulsessivo-chatbot .pcb-msg-row {
  padding: 0 1px;
}

#pulsessivo-chatbot .pcb-bubble {
  padding: 8px 10px;
}

#pulsessivo-chatbot .pcb-input-area {
  gap: 6px;
  padding: 8px;
}

#pulsessivo-chatbot .pcb-input {
  min-height: 42px;
  padding: 8px 10px;
}

#pulsessivo-chatbot .pcb-send-btn {
  min-width: 42px;
  min-height: 42px;
}

@media (max-width: 640px) {
  #pulsessivo-chatbot .pcb-header {
    padding: 8px 10px;
  }

  #pulsessivo-chatbot .pcb-header-title {
    font-size: 10px;
    max-width: 140px;
  }

  #pulsessivo-chatbot .pcb-messages {
    padding: 10px 8px 8px;
  }

  #pulsessivo-chatbot .pcb-input-area {
    padding: 8px;
  }
}
