/* ============================================
   MAMONAKU AI — Chat Widget
   Calm. Quietly present. Honors brand tokens.
   ============================================ */

.mn-chat-launcher,
.mn-chat-panel,
.mn-chat-panel * {
  box-sizing: border-box;
  font-family: 'Satoshi', 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

/* ---------- Launcher (bottom-right) ---------- */
.mn-chat-launcher {
  position: fixed;
  bottom: clamp(1rem, 3vw, 2rem);
  right: clamp(1rem, 3vw, 2rem);
  z-index: 90;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--charcoal, #0D0F13);
  border: none;
  box-shadow: 0 6px 20px rgba(13, 15, 19, 0.18), 0 1px 4px rgba(13, 15, 19, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 360ms cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 360ms cubic-bezier(0.16, 1, 0.3, 1),
              background 360ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 240ms ease-out;
}
.mn-chat-launcher:hover {
  transform: translateY(-2px);
  background: var(--midnight, #26364D);
  box-shadow: 0 12px 32px rgba(13, 15, 19, 0.22), 0 2px 6px rgba(13, 15, 19, 0.10);
}
.mn-chat-launcher:focus-visible {
  outline: 2px solid var(--charcoal, #0D0F13);
  outline-offset: 3px;
}
.mn-chat-launcher object,
.mn-chat-launcher img {
  width: 42px;
  height: 42px;
  pointer-events: none;
}
.mn-chat-launcher[hidden] { display: none !important; }

/* ---------- Panel ---------- */
.mn-chat-panel {
  position: fixed;
  bottom: clamp(1rem, 3vw, 2rem);
  right: clamp(1rem, 3vw, 2rem);
  z-index: 100;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 580px;
  max-height: calc(100vh - 2rem);
  background: var(--off-white, #FBFBFA);
  border: 1px solid var(--light-greige, #E6E4E1);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(13, 15, 19, 0.12), 0 4px 12px rgba(13, 15, 19, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 320ms cubic-bezier(0.16, 1, 0.3, 1),
              transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
}
.mn-chat-panel.mn-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Mobile: full-screen panel */
@media (max-width: 520px) {
  .mn-chat-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
}

/* ---------- Panel header ---------- */
.mn-chat-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.125rem;
  border-bottom: 1px solid var(--light-greige, #E6E4E1);
  background: var(--off-white, #FBFBFA);
  flex-shrink: 0;
}
.mn-chat-head-mark {
  width: 32px;
  height: 35px;
  flex-shrink: 0;
}
.mn-chat-head-text {
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}
.mn-chat-head-name {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--charcoal, #0D0F13);
}
.mn-chat-head-sub {
  font-size: 0.75rem;
  color: var(--stone, #7A8087);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 2px;
}
.mn-chat-head-sub .mn-dot {
  width: 6px;
  height: 6px;
  background: var(--deep-teal, #29636D);
  border-radius: 50%;
  display: inline-block;
  animation: mn-pulse 3.6s ease-in-out infinite;
}
@keyframes mn-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
.mn-chat-leave {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--stone, #7A8087);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 0.375rem 0.625rem;
  border-radius: 6px;
  cursor: pointer;
  transition: color 200ms ease-out, background 200ms ease-out;
}
.mn-chat-leave:hover {
  color: var(--charcoal, #0D0F13);
  background: var(--light-greige, #E6E4E1);
}
.mn-chat-leave:focus-visible {
  outline: 2px solid var(--charcoal, #0D0F13);
  outline-offset: 2px;
}

.mn-chat-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--graphite, #33383F);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 200ms ease-out, color 200ms ease-out;
}
.mn-chat-close:hover {
  background: var(--light-greige, #E6E4E1);
  color: var(--charcoal, #0D0F13);
}
.mn-chat-close:focus-visible {
  outline: 2px solid var(--charcoal, #0D0F13);
  outline-offset: 2px;
}
.mn-chat-close svg { width: 16px; height: 16px; }

/* ---------- Messages area ---------- */
.mn-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.125rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  scroll-behavior: smooth;
}
.mn-chat-body::-webkit-scrollbar { width: 6px; }
.mn-chat-body::-webkit-scrollbar-track { background: transparent; }
.mn-chat-body::-webkit-scrollbar-thumb { background: var(--ash, #B7BDC3); border-radius: 3px; }

/* Intro message (shown before first turn) */
.mn-chat-intro {
  padding: 0.5rem 0 1rem;
  border-bottom: 1px solid var(--light-greige, #E6E4E1);
  margin-bottom: 0.5rem;
}
.mn-chat-intro p {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--graphite, #33383F);
}
.mn-chat-intro .mn-suggest {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.875rem;
}
.mn-chat-intro .mn-suggest button {
  text-align: left;
  font-size: 0.875rem;
  color: var(--charcoal, #0D0F13);
  background: transparent;
  border: 1px solid var(--light-greige, #E6E4E1);
  border-radius: 8px;
  padding: 0.625rem 0.875rem;
  cursor: pointer;
  line-height: 1.4;
  transition: border-color 200ms ease-out, background 200ms ease-out;
}
.mn-chat-intro .mn-suggest button:hover {
  border-color: var(--ash, #B7BDC3);
  background: rgba(13, 15, 19, 0.02);
}

/* Hint text + persistent follow-up suggestions (shown after each answer) */
.mn-suggest-hint {
  font-size: 0.75rem;
  color: var(--stone, #7A8087);
  margin-top: 0.625rem;
}
.mn-suggest-followup {
  align-self: stretch;
  border-top: 1px solid var(--light-greige, #E6E4E1);
  padding-top: 0.75rem;
  margin-top: 0.25rem;
}
.mn-suggest-followup .mn-suggest-hint {
  margin-top: 0;
  margin-bottom: 0.5rem;
}
.mn-suggest-followup .mn-suggest {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.mn-suggest-followup .mn-suggest button {
  text-align: left;
  font-size: 0.875rem;
  color: var(--charcoal, #0D0F13);
  background: transparent;
  border: 1px solid var(--light-greige, #E6E4E1);
  border-radius: 8px;
  padding: 0.625rem 0.875rem;
  cursor: pointer;
  line-height: 1.4;
  transition: border-color 200ms ease-out, background 200ms ease-out;
}
.mn-suggest-followup .mn-suggest button:hover {
  border-color: var(--ash, #B7BDC3);
  background: rgba(13, 15, 19, 0.02);
}

/* Message bubbles */
.mn-msg {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 12px;
  font-size: 0.9375rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.mn-msg-user {
  align-self: flex-end;
  background: var(--charcoal, #0D0F13);
  color: var(--warm-white, #F6F5F2);
  border-bottom-right-radius: 4px;
}
.mn-msg-assistant {
  align-self: flex-start;
  background: var(--light-greige, #E6E4E1);
  color: var(--charcoal, #0D0F13);
  border-bottom-left-radius: 4px;
}
.mn-msg-error {
  align-self: stretch;
  background: transparent;
  color: var(--stone, #7A8087);
  font-size: 0.8125rem;
  font-style: italic;
  border: 1px dashed var(--ash, #B7BDC3);
  border-radius: 6px;
  padding: 0.625rem 0.75rem;
}

/* Typing indicator */
.mn-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.75rem 0.875rem;
  background: var(--light-greige, #E6E4E1);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.mn-typing span {
  width: 6px;
  height: 6px;
  background: var(--stone, #7A8087);
  border-radius: 50%;
  animation: mn-typing 1.4s ease-in-out infinite;
}
.mn-typing span:nth-child(2) { animation-delay: 0.2s; }
.mn-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes mn-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ---------- Input bar ---------- */
.mn-chat-input {
  display: flex;
  gap: 0.5rem;
  padding: 0.875rem 1.125rem 1.125rem;
  border-top: 1px solid var(--light-greige, #E6E4E1);
  background: var(--off-white, #FBFBFA);
  flex-shrink: 0;
}
.mn-chat-input textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.4;
  color: var(--charcoal, #0D0F13);
  background: var(--off-white, #FBFBFA);
  border: 1px solid var(--light-greige, #E6E4E1);
  border-radius: 10px;
  resize: none;
  outline: none;
  transition: border-color 200ms ease-out;
}
.mn-chat-input textarea:focus {
  border-color: var(--charcoal, #0D0F13);
}
.mn-chat-input textarea::placeholder { color: var(--stone, #7A8087); }
.mn-chat-input textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.mn-chat-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  align-self: flex-end;
  border: none;
  background: var(--charcoal, #0D0F13);
  color: var(--warm-white, #F6F5F2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 200ms ease-out, opacity 200ms ease-out;
}
.mn-chat-send:hover:not(:disabled) { background: var(--midnight, #26364D); }
.mn-chat-send:disabled { opacity: 0.35; cursor: not-allowed; }
.mn-chat-send:focus-visible { outline: 2px solid var(--midnight, #26364D); outline-offset: 2px; }
.mn-chat-send svg { width: 16px; height: 16px; }

/* Foot note */
.mn-chat-foot {
  padding: 0.375rem 1.125rem 0.625rem;
  font-size: 0.6875rem;
  color: var(--stone, #7A8087);
  text-align: center;
  background: var(--off-white, #FBFBFA);
}

/* ---------- Inline contact form ---------- */
.mn-chat-form {
  align-self: stretch;
  background: var(--off-white, #FBFBFA);
  border: 1px solid var(--light-greige, #E6E4E1);
  border-radius: 12px;
  padding: 1rem 1rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}
.mn-chat-form-head {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.mn-chat-form-title {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  color: var(--charcoal, #0D0F13);
}
.mn-chat-form-sub {
  font-size: 0.8125rem;
  color: var(--stone, #7A8087);
  margin: 0;
  line-height: 1.45;
}
.mn-chat-form-fields {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.mn-field {
  display: flex;
  flex-direction: column;
  gap: 0.3125rem;
}
.mn-field-label {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--stone, #7A8087);
}
.mn-field input {
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--charcoal, #0D0F13);
  background: var(--off-white, #FBFBFA);
  border: 1px solid var(--light-greige, #E6E4E1);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 200ms ease-out;
}
.mn-field input:focus {
  border-color: var(--charcoal, #0D0F13);
}
.mn-field input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.mn-chat-form-error {
  font-size: 0.8125rem;
  color: var(--copper, #B87A4A);
  line-height: 1.45;
  padding: 0.25rem 0;
}
.mn-chat-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.mn-chat-form-cancel {
  border: none;
  background: transparent;
  color: var(--stone, #7A8087);
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0.5rem 0.5rem;
  border-radius: 6px;
  transition: color 200ms ease-out, background 200ms ease-out;
}
.mn-chat-form-cancel:hover:not(:disabled) {
  color: var(--charcoal, #0D0F13);
  background: var(--light-greige, #E6E4E1);
}
.mn-chat-form-cancel:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.mn-chat-form-submit {
  border: none;
  background: var(--charcoal, #0D0F13);
  color: var(--warm-white, #F6F5F2);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.005em;
  padding: 0.625rem 1.125rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 200ms ease-out, opacity 200ms ease-out;
}
.mn-chat-form-submit:hover:not(:disabled) {
  background: var(--midnight, #26364D);
}
.mn-chat-form-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.mn-chat-form-submit:focus-visible {
  outline: 2px solid var(--midnight, #26364D);
  outline-offset: 2px;
}

/* ---------- Dark theme overrides ---------- */
/* The widget uses var(--token) for nearly everything, so most styles adapt
   automatically when tokens flip. These overrides handle cases where the
   inversion semantics need explicit care. */

/* Launcher inverts: light pill with dark mark for visual contrast on dark canvas */
[data-theme="dark"] .mn-chat-launcher {
  background: #F6F5F2;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 1px 4px rgba(0, 0, 0, 0.2);
}
[data-theme="dark"] .mn-chat-launcher:hover {
  background: #FBFBFA;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Panel header mark — color via attribute, override to light in dark theme */
[data-theme="dark"] .mn-chat-head-mark {
  fill: #F6F5F2;
}

/* Honor motion preferences across the whole widget */
@media (prefers-reduced-motion: reduce) {
  .mn-chat-launcher,
  .mn-chat-panel,
  .mn-chat-close,
  .mn-msg,
  .mn-typing span,
  .mn-chat-input textarea,
  .mn-chat-send {
    transition: none !important;
    animation: none !important;
  }
}
