/* ================================================================
   Marco Polo — AI Chat Widget Styles
   Theme-aware via CSS custom properties from themes.css
   All classes prefixed with mp- to avoid conflicts
   ================================================================ */

/* ─── Floating Bubble ───────────────────────────────────────── */
.mp-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c8963e 0%, #d4a64e 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(200, 150, 62, 0.45), 0 0 0 3px rgba(200, 150, 62, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.mp-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(200, 150, 62, 0.6), 0 0 0 4px rgba(200, 150, 62, 0.2);
}

.mp-bubble:active {
  transform: scale(0.95);
}

.mp-bubble svg {
  width: 30px;
  height: 30px;
  fill: #fff;
  stroke: none;
}

.mp-bubble.mp-hidden {
  display: none;
}

/* Pulse animation for unread messages */
.mp-bubble.mp-pulse {
  animation: mp-bubble-glow 2s ease-in-out infinite;
}

.mp-bubble.mp-pulse::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(200, 150, 62, 0.6);
  opacity: 0;
  animation: mp-pulse-ring 2s ease-out infinite;
}

@keyframes mp-bubble-glow {
  0%, 100% { box-shadow: 0 4px 20px rgba(200, 150, 62, 0.45), 0 0 0 3px rgba(200, 150, 62, 0.15); }
  50% { box-shadow: 0 4px 28px rgba(200, 150, 62, 0.7), 0 0 0 5px rgba(200, 150, 62, 0.25); }
}

@keyframes mp-pulse-ring {
  0% { transform: scale(1); opacity: 0.6; }
  70% { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* ─── Unread Badge ──────────────────────────────────────────── */
.mp-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  padding: 0 6px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
  border: 2px solid var(--theme-bg, #f8fafc);
}

/* ─── Proactive Suggestion Tooltip ──────────────────────────── */
.mp-proactive {
  position: fixed;
  bottom: 96px;
  right: 24px;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid rgba(200, 150, 62, 0.3);
  border-radius: 12px;
  padding: 12px 36px 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 280px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 9998;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
}

.mp-proactive.mp-show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.mp-proactive::after {
  content: "";
  position: absolute;
  bottom: -7px;
  right: 24px;
  width: 12px;
  height: 12px;
  background: #1e293b;
  border-right: 1px solid rgba(200, 150, 62, 0.3);
  border-bottom: 1px solid rgba(200, 150, 62, 0.3);
  transform: rotate(45deg);
}

.mp-proactive-close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}

.mp-proactive-close:hover {
  color: #fff;
}

/* ─── Chat Panel ────────────────────────────────────────────── */
.mp-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  height: 600px;
  max-height: 80vh;
  background: #0f172a;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(200, 150, 62, 0.15);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.mp-panel.mp-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ─── Panel Header ──────────────────────────────────────────── */
.mp-header {
  height: 60px;
  min-height: 60px;
  background: linear-gradient(135deg, #c8963e 0%, #b8862e 100%);
  color: #fff;
  padding: 0 12px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-radius: 15px 15px 0 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  position: relative;
  z-index: 1;
}

.mp-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.mp-header-icon svg {
  width: 20px;
  height: 20px;
  fill: #fff;
  stroke: none;
}

.mp-header-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.mp-header-status {
  font-size: 11px;
  opacity: 0.8;
  font-weight: 400;
  margin-top: 2px;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 4px;
}

.mp-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  box-shadow: 0 0 4px rgba(34, 197, 94, 0.6);
}

.mp-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mp-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  padding: 0;
  line-height: 1;
}

.mp-header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.mp-header-btn:active {
  background: rgba(255, 255, 255, 0.35);
}

.mp-header-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Messages Area ─────────────────────────────────────────── */
.mp-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  background: #0f172a;
}

/* Scrollbar styling */
.mp-messages::-webkit-scrollbar {
  width: 5px;
}

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

.mp-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.mp-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ─── Message Wrappers ──────────────────────────────────────── */
.mp-msg {
  display: flex;
  flex-direction: column;
  animation: mp-msg-in 0.3s ease forwards;
}

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

.mp-msg-user {
  align-items: flex-end;
}

.mp-msg-assistant {
  align-items: flex-start;
}

/* ─── User Message Bubble ───────────────────────────────────── */
.mp-msg-user .mp-bubble-text {
  max-width: 80%;
  background: linear-gradient(135deg, #c8963e, #b8862e);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 2px 8px rgba(200, 150, 62, 0.25);
}

/* ─── Assistant Message Bubble ──────────────────────────────── */
.mp-msg-assistant .mp-msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 88%;
}

.mp-msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c8963e, #d4a64e);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(200, 150, 62, 0.3);
}

.mp-msg-avatar svg {
  width: 16px;
  height: 16px;
  fill: #fff;
  stroke: none;
}

.mp-msg-assistant .mp-bubble-text {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Markdown-like formatting inside assistant bubbles */
.mp-bubble-text strong {
  font-weight: 700;
  color: #f1f5f9;
}

.mp-bubble-text em {
  font-style: italic;
  color: #cbd5e1;
}

.mp-bubble-text code {
  background: rgba(200, 150, 62, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  color: #d4a64e;
  border: 1px solid rgba(200, 150, 62, 0.15);
}

.mp-bubble-text ul {
  margin: 8px 0 4px 0;
  padding-left: 18px;
}

.mp-bubble-text ul li {
  margin-bottom: 4px;
}

.mp-bubble-text ul li::marker {
  color: #c8963e;
}

/* Timestamp */
.mp-msg-time {
  font-size: 10px;
  color: #64748b;
  margin-top: 4px;
  padding: 0 4px;
}

.mp-msg-user .mp-msg-time {
  text-align: right;
}

/* ─── Quick Action Buttons ──────────────────────────────────── */
.mp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding-left: 36px;
  max-width: 88%;
  align-self: flex-start;
}

.mp-action-btn {
  background: rgba(200, 150, 62, 0.1);
  border: 1px solid rgba(200, 150, 62, 0.35);
  color: #d4a64e;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.mp-action-btn:hover {
  background: #c8963e;
  border-color: #c8963e;
  color: #fff;
}

.mp-action-btn:active {
  transform: scale(0.96);
}

/* ─── Typing Indicator ──────────────────────────────────────── */
.mp-typing-wrap {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  align-self: flex-start;
}

.mp-typing-dots {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px 16px 16px 4px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.mp-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c8963e;
  animation: mp-dot-bounce 1.2s ease-in-out infinite;
}

.mp-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.mp-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes mp-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input Area ────────────────────────────────────────────── */
.mp-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: #0d1526;
  flex-shrink: 0;
  border-radius: 0 0 16px 16px;
}

.mp-input {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
  resize: none;
  font-size: 14px;
  line-height: 1.5;
  padding: 9px 14px;
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
  border-radius: 12px;
  outline: none;
  max-height: 80px;
  overflow-y: auto;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mp-input::placeholder {
  color: #64748b;
}

.mp-input:focus {
  border-color: rgba(200, 150, 62, 0.5);
  box-shadow: 0 0 0 3px rgba(200, 150, 62, 0.1);
  background: rgba(255, 255, 255, 0.07);
}

.mp-send-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c8963e, #b8862e);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(200, 150, 62, 0.3);
}

.mp-send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #d4a64e, #c8963e);
  box-shadow: 0 4px 12px rgba(200, 150, 62, 0.45);
}

.mp-send-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.mp-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.mp-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Welcome / Empty State ─────────────────────────────────── */
.mp-welcome {
  text-align: center;
  padding: 32px 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.mp-welcome-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 8px;
  background: rgba(200, 150, 62, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(200, 150, 62, 0.2);
}

.mp-welcome-icon svg {
  width: 32px;
  height: 32px;
  fill: #c8963e;
  stroke: none;
}

.mp-welcome-title {
  font-size: 20px;
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 2px;
  letter-spacing: 0.3px;
}

.mp-welcome-text {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.6;
  max-width: 300px;
}

/* ─── Error Message ─────────────────────────────────────────── */
.mp-error-wrap {
  text-align: center;
  padding: 8px 14px;
}

.mp-error-text {
  color: #f87171;
  font-size: 13px;
}

.mp-retry-btn {
  background: none;
  border: 1px solid #f87171;
  color: #f87171;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.mp-retry-btn:hover {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

/* ─── Responsive: Mobile (<480px) ───────────────────────────── */
@media (max-width: 480px) {
  .mp-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    max-height: calc(100vh - 16px);
    bottom: 8px;
    right: 8px;
    border-radius: 12px;
  }

  .mp-header {
    border-radius: 11px 11px 0 0;
  }

  .mp-input-area {
    border-radius: 0 0 11px 11px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .mp-bubble {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
  }

  .mp-bubble svg {
    width: 24px;
    height: 24px;
  }

  .mp-proactive {
    right: 16px;
    bottom: 84px;
    max-width: calc(100vw - 80px);
  }

  .mp-proactive::after {
    right: 18px;
  }

  .mp-messages {
    padding: 12px;
  }
}

/* ─── Reduced Motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .mp-panel,
  .mp-bubble,
  .mp-proactive,
  .mp-input {
    transition: none;
  }

  .mp-bubble.mp-pulse,
  .mp-bubble.mp-pulse::after {
    animation: none;
  }

  .mp-typing-dot {
    animation: none;
    opacity: 0.5;
  }

  .mp-msg {
    animation: none;
  }
}
