/* ==========================================================================
   Muse chat — "Powered by Muse" chat experience for naranjodraco.com
   Custom animations throughout. No emojis in this UI.
   Two layouts: modal (default) and full page (body[data-chat-layout="page"]).
   Mobile-first: base = iPhone SE (375px), scales up to 1920x1080.
   ========================================================================== */

/* ---------- Floating chat button ---------- */
.message-btn {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(20px, env(safe-area-inset-right));
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #ff6600 0%, #cc5200 100%);
  color: #fff;
  border: none;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 102, 0, 0.45);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.25s ease;
  /* Minimum 44px touch target already exceeded */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.message-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 24px rgba(255, 102, 0, 0.6);
}
.message-btn:active { transform: scale(0.96); }
.message-btn svg { width: 28px; height: 28px; }
/* Gentle attention pulse ring */
.message-btn::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(255, 102, 0, 0.55);
  animation: muse-pulse 2.6s ease-out infinite;
  pointer-events: none;
}
@keyframes muse-pulse {
  0%   { transform: scale(0.85); opacity: 0.9; }
  70%  { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}

/* ---------- Modal shell ---------- */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0; top: 0;
  width: 100%; height: 100%;
  /* Scaling background: radial glow that grows with viewport */
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(255, 102, 0, 0.08), transparent 70%),
    rgba(8, 6, 4, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal.muse-open { display: block; animation: muse-backdrop-in 0.28s ease-out; }
@keyframes muse-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
/* Prevent body scroll when modal is open */

/* ---------- Chat panel — mobile-first (iPhone SE 375px) ---------- */
.muse-chat-panel {
  background: linear-gradient(150deg, #241610 0%, #17171f 55%, #101016 100%);
  border: 1px solid rgba(255, 102, 0, 0.45);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6),
              0 0 0 1px rgba(0, 0, 0, 0.4),
              0 0 42px rgba(255, 102, 0, 0.12);
  /* Full-screen on mobile for max usable space */
  border-radius: 0;
  border-left: none;
  border-right: none;
  margin: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  /* Respect iPhone notch and home indicator */
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #f5f1ea;
  text-align: left;
  animation: muse-panel-in 0.38s cubic-bezier(0.22, 1.2, 0.36, 1);
}
@keyframes muse-panel-in {
  from { opacity: 0; transform: translateY(26px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Header ---------- */
.muse-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 10px;
  /* Notch-aware top padding */
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(135deg, rgba(255,102,0,0.16), rgba(255,102,0,0.04));
  border-bottom: 1px solid rgba(255, 102, 0, 0.25);
  flex-shrink: 0;
}
.muse-chat-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.muse-chat-title h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.muse-spark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #ff6600, #ff9a3c);
  box-shadow: 0 4px 14px rgba(255, 102, 0, 0.5);
  animation: muse-spark-glow 3s ease-in-out infinite;
}
.muse-spark svg { width: 20px; height: 20px; }
@keyframes muse-spark-glow {
  0%, 100% { box-shadow: 0 4px 14px rgba(255, 102, 0, 0.5); }
  50%      { box-shadow: 0 4px 22px rgba(255, 154, 60, 0.85); }
}

/* "Powered by Muse" badge with shimmer sweep (links to Muse) */
.muse-badge {
  position: relative;
  display: inline-block;
  overflow: hidden;
  margin-top: 2px;
  padding: 3px 10px 3px 8px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: #ffd9b8;
  background: rgba(255, 102, 0, 0.14);
  border: 1px solid rgba(255, 102, 0, 0.4);
  border-radius: 999px;
  white-space: nowrap;
}
.muse-badge-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg,
    transparent 30%, rgba(255, 255, 255, 0.4) 50%, transparent 70%);
  transform: translateX(-110%);
  animation: muse-shimmer 3.4s ease-in-out infinite;
}
@keyframes muse-shimmer {
  0%        { transform: translateX(-110%); }
  55%, 100% { transform: translateX(110%); }
}

.muse-close {
  background: transparent;
  border: none;
  color: #cbb9a6;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  /* 44px minimum touch target */
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 8px;
  flex-shrink: 0;
  transition: color 0.2s ease, background 0.2s ease, transform 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.muse-close:hover { color: #fff; background: rgba(255,255,255,0.08); transform: rotate(90deg); }

/* ---------- Messages ---------- */
.muse-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,102,0,0.5) transparent;
}
.muse-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.5;
  animation: muse-msg-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-wrap: anywhere;
}
@keyframes muse-msg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.muse-msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-left: 3px solid #ff6600;
  border-bottom-left-radius: 4px;
  color: #f2ece2;
}
.muse-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #ff6600, #e05a00);
  border-bottom-right-radius: 4px;
  color: #fff;
  box-shadow: 0 3px 10px rgba(255, 102, 0, 0.3);
}
.muse-msg a { color: #ffb37a; text-decoration: underline; }
.muse-msg.user a { color: #fff; }
.muse-msg.muse-error {
  border-left-color: #e5484d;
  background: rgba(229, 72, 77, 0.1);
}
/* Owner messages — distinct from Muse */
.muse-msg.owner {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-left: 3px solid #fff;
  border-bottom-left-radius: 4px;
  color: #fff;
}
.muse-msg.owner::before {
  content: "Team member";
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #cbb9a6;
  margin-bottom: 4px;
}

/* Typing indicator */
.muse-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 6px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.muse-typing span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ff9a3c;
  animation: muse-dot-bounce 1.1s ease-in-out infinite;
}
.muse-typing span:nth-child(2) { animation-delay: 0.15s; }
.muse-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes muse-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
  30%           { transform: translateY(-7px); opacity: 1; }
}

/* ---------- Quick-reply chips ---------- */
.muse-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 12px 10px;
  flex-shrink: 0;
}
.muse-chip {
  /* 44px min touch target height */
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #ffd9b8;
  background: rgba(255, 102, 0, 0.1);
  border: 1px solid rgba(255, 102, 0, 0.45);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  animation: muse-chip-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.muse-chip:nth-child(2) { animation-delay: 0.06s; }
.muse-chip:nth-child(3) { animation-delay: 0.12s; }
.muse-chip:nth-child(4) { animation-delay: 0.18s; }
@keyframes muse-chip-in {
  from { opacity: 0; transform: translateY(8px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.muse-chip:hover {
  background: rgba(255, 102, 0, 0.28);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 102, 0, 0.25);
}
.muse-chip:active { transform: scale(0.97); }

/* ---------- Input row ---------- */
.muse-input-row {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  /* Home indicator clearance */
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
  align-items: center;
}
.muse-input-row input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  /* 16px prevents iOS auto-zoom on focus */
  font-size: 16px;
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.muse-input-row input::placeholder { color: #9c8d7d; }
.muse-input-row input:focus {
  border-color: #ff6600;
  box-shadow: 0 0 0 3px rgba(255, 102, 0, 0.22);
}
.muse-input-row input:disabled { opacity: 0.65; cursor: wait; }
.muse-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px; height: 48px;
  flex: 0 0 48px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6600, #cc5200);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 102, 0, 0.4);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s ease, opacity 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.muse-send:hover { transform: scale(1.07); }
.muse-send:active { transform: scale(0.94); }
.muse-send:disabled { opacity: 0.5; cursor: default; transform: none; }
.muse-send svg { width: 22px; height: 22px; }

/* ---------- System divider (chat complete) ---------- */
.muse-system {
  align-self: center;
  margin: 6px 0;
  padding: 8px 16px;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: #cbb9a6;
  background: rgba(255, 255, 255, 0.05);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  animation: muse-msg-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  text-align: center;
  max-width: 90%;
}

/* ==========================================================================
   Responsive scale-up
   ========================================================================== */

/* Small tablets and large phones (landscape) */
@media (min-width: 521px) {
  .muse-chat-panel {
    border-radius: 16px;
    border-left: 1px solid rgba(255, 102, 0, 0.45);
    border-right: 1px solid rgba(255, 102, 0, 0.45);
    margin: 5vh auto;
    width: min(92vw, 430px);
    height: min(80vh, 640px);
    max-height: none;
    padding-bottom: 0;
  }
  .muse-chat-header {
    padding: 14px 16px 12px;
  }
  .muse-chat-title h2 { font-size: 1.05rem; }
  .muse-messages { padding: 16px 14px; }
  .muse-msg { font-size: 0.92rem; }
  .muse-input-row { padding: 12px 14px 14px; }
  .muse-input-row input { font-size: 0.92rem; }
}

/* Tablets */
@media (min-width: 768px) {
  .muse-chat-panel {
    width: min(92vw, 460px);
    height: min(78vh, 680px);
  }
  .message-btn {
    width: 64px;
    height: 64px;
    bottom: 24px;
    right: 24px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .muse-chat-panel {
    width: 460px;
    height: min(80vh, 700px);
    margin: 6vh auto;
  }
  .modal {
    background:
      radial-gradient(ellipse 60% 50% at 50% 40%, rgba(255, 102, 0, 0.1), transparent 70%),
      rgba(8, 6, 4, 0.62);
  }
}

/* Large desktop (1920x1080) */
@media (min-width: 1600px) {
  .muse-chat-panel {
    width: 480px;
    height: min(78vh, 720px);
  }
  .muse-chat-title h2 { font-size: 1.1rem; }
  .muse-msg { font-size: 0.95rem; max-width: 80%; }
  .modal {
    background:
      radial-gradient(ellipse 50% 45% at 50% 40%, rgba(255, 102, 0, 0.12), transparent 70%),
      rgba(8, 6, 4, 0.6);
  }
}

/* ---------- Full-page layout (contact.html) ---------- */
body[data-chat-layout="page"] {
  background: #141017;
  color: #f5f1ea;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.muse-page-wrap {
  width: min(94vw, 720px);
  margin: 0 auto;
  padding: 24px 0 40px;
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
  flex: 1;
  display: flex;
  flex-direction: column;
}
.muse-page-head { text-align: center; margin-bottom: 20px; padding: 0 16px; }
.muse-page-head h1 { margin: 0 0 8px; font-size: 1.6rem; color: #fff; }
.muse-page-head p { color: #cbb9a6; margin: 0 0 12px; font-size: 0.95rem; }
.muse-page-head .muse-badge { font-size: 0.75rem; }
body[data-chat-layout="page"] .muse-chat-panel {
  margin: 0;
  width: 100%;
  height: min(72vh, 620px);
  border-radius: 16px;
  border-left: 1px solid rgba(255, 102, 0, 0.45);
  border-right: 1px solid rgba(255, 102, 0, 0.45);
  padding-bottom: 0;
}
@media (min-width: 768px) {
  .muse-page-wrap { padding: 32px 0 48px; }
  .muse-page-head h1 { font-size: 1.9rem; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .muse-chat-panel, .muse-msg, .muse-chip,
  .message-btn::after,
  .muse-typing span, .muse-spark { animation: none !important; }
  .message-btn, .muse-badge-shimmer,
  .muse-send, .muse-chip, .muse-close { transition: none; }
}
