/* ==========================================================================
   Scrap Chat Widget — PowerScraper Pro
   Matches the site's dark indigo design system
   ========================================================================== */

/* --- Chat Toggle Button --- */
.scrap-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(99, 102, 241, 0.3);
  background: linear-gradient(135deg, #111116 0%, #1a1a28 100%);
  color: #818cf8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 40px rgba(99, 102, 241, 0.1);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.3s,
              box-shadow 0.3s;
}

.scrap-toggle:hover {
  transform: scale(1.08);
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 60px rgba(99, 102, 241, 0.2);
}

.scrap-toggle svg {
  width: 24px;
  height: 24px;
  transition: transform 0.3s;
}

.scrap-toggle--open svg {
  transform: rotate(90deg);
}

/* Notification dot */
.scrap-toggle__dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #6366f1;
  border: 2px solid #111116;
  animation: scrap-pulse 2s ease-in-out infinite;
}

.scrap-toggle--open .scrap-toggle__dot {
  display: none;
}

@keyframes scrap-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.2); }
}

/* --- Chat Window --- */
.scrap-chat {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9999;
  width: 380px;
  max-height: 520px;
  border-radius: 16px;
  border: 1px solid rgba(99, 102, 241, 0.15);
  background: #0c0c10;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.scrap-chat--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* --- Header --- */
.scrap-chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: #111116;
  border-bottom: 1px solid rgba(99, 102, 241, 0.1);
  flex-shrink: 0;
}

.scrap-chat__avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(167, 139, 250, 0.2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.scrap-chat__info {
  flex: 1;
  min-width: 0;
}

.scrap-chat__name {
  font-size: 14px;
  font-weight: 600;
  color: #f0f0f3;
  letter-spacing: -0.01em;
}

.scrap-chat__status {
  font-size: 11px;
  color: #5a5a6e;
  display: flex;
  align-items: center;
  gap: 5px;
}

.scrap-chat__status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
}

.scrap-chat__close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #5a5a6e;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}

.scrap-chat__close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #8a8a9a;
}

/* --- Messages Area --- */
.scrap-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
  max-height: 340px;
  scrollbar-width: thin;
  scrollbar-color: rgba(99, 102, 241, 0.2) transparent;
}

.scrap-chat__messages::-webkit-scrollbar {
  width: 4px;
}

.scrap-chat__messages::-webkit-scrollbar-track {
  background: transparent;
}

.scrap-chat__messages::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.2);
  border-radius: 4px;
}

/* --- Message Bubbles --- */
.scrap-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: scrap-msg-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes scrap-msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.scrap-msg--bot {
  align-self: flex-start;
  background: #16161d;
  color: #d0d0da;
  border: 1px solid rgba(99, 102, 241, 0.08);
  border-bottom-left-radius: 4px;
}

.scrap-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, #4338ca, #6366f1);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Markdown-like formatting in bot messages */
.scrap-msg--bot strong {
  color: #f0f0f3;
  font-weight: 600;
}

.scrap-msg--bot code {
  background: rgba(99, 102, 241, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: #a78bfa;
}

.scrap-msg--bot a {
  color: #818cf8;
  text-decoration: underline;
  text-decoration-color: rgba(129, 140, 248, 0.3);
  text-underline-offset: 2px;
}

.scrap-msg--bot a:hover {
  text-decoration-color: #818cf8;
}

/* --- Typing Indicator --- */
.scrap-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #16161d;
  border-radius: 14px;
  border: 1px solid rgba(99, 102, 241, 0.08);
  border-bottom-left-radius: 4px;
}

.scrap-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5a5a6e;
  animation: scrap-typing-bounce 1.2s ease-in-out infinite;
}

.scrap-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.scrap-typing__dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes scrap-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Input Area --- */
.scrap-chat__input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgba(99, 102, 241, 0.08);
  background: #0a0a0e;
  flex-shrink: 0;
}

.scrap-chat__input {
  flex: 1;
  background: #16161d;
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #f0f0f3;
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
}

.scrap-chat__input::placeholder {
  color: #5a5a6e;
}

.scrap-chat__input:focus {
  border-color: rgba(99, 102, 241, 0.35);
}

.scrap-chat__send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: #6366f1;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
}

.scrap-chat__send:hover {
  background: #4f46e5;
}

.scrap-chat__send:active {
  transform: scale(0.94);
}

.scrap-chat__send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.scrap-chat__send svg {
  width: 16px;
  height: 16px;
}

/* --- Powered By --- */
.scrap-chat__footer {
  padding: 6px 16px 10px;
  text-align: center;
  font-size: 10px;
  color: #3a3a4e;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

/* --- Responsive: Tablets (portrait & landscape) --- */
@media (max-width: 1024px) and (min-width: 481px) {
  .scrap-chat {
    width: 360px;
    max-height: 480px;
    bottom: 88px;
    right: 20px;
  }

  .scrap-chat__messages {
    max-height: 300px;
  }

  .scrap-toggle {
    bottom: 20px;
    right: 20px;
  }
}

/* --- Responsive: Mobile phones --- */
@media (max-width: 480px) {
  .scrap-chat {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    z-index: 10000;
  }

  .scrap-chat__header {
    padding: 14px 16px;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .scrap-chat__messages {
    max-height: none;
    flex: 1;
    min-height: 0;
    padding: 12px 12px 8px;
  }

  .scrap-msg {
    max-width: 90%;
    font-size: 15px;
    padding: 12px 16px;
    line-height: 1.5;
  }

  .scrap-chat__input-area {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .scrap-chat__input {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 12px 14px;
    border-radius: 12px;
  }

  .scrap-chat__send {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }

  .scrap-chat__send svg {
    width: 18px;
    height: 18px;
  }

  .scrap-toggle {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .scrap-chat__footer {
    padding: 4px 12px 6px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .scrap-chat__avatar {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .scrap-chat__name {
    font-size: 15px;
  }

  .scrap-chat__close {
    width: 36px;
    height: 36px;
  }
}

/* --- Small phones (iPhone SE, Galaxy S8, etc.) --- */
@media (max-width: 375px) {
  .scrap-msg {
    font-size: 14px;
    padding: 10px 14px;
  }

  .scrap-chat__header {
    gap: 10px;
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
  }
}

/* --- Landscape phones --- */
@media (max-height: 500px) and (orientation: landscape) {
  .scrap-chat {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: 50vw;
    max-width: 400px;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .scrap-chat__messages {
    max-height: none;
    flex: 1;
    min-height: 0;
  }

  .scrap-toggle {
    bottom: 12px;
    right: 12px;
    width: 48px;
    height: 48px;
  }
}

/* --- Print: hide chat --- */
@media print {
  .scrap-toggle,
  .scrap-chat {
    display: none !important;
  }
}
