/* MOPEL public assistant. All rules are scoped to the two widget roots. */
#mopel-chat-open,
#mopel-chat,
#mopel-chat * {
  box-sizing: border-box;
}

#mopel-chat-open,
#mopel-chat {
  --mc-cream: #faf5ee;
  --mc-plum: #653d5b;
  --mc-ink: #30212d;
  --mc-muted: #5e4d59;
  --mc-line: #dfd1d7;
  font-family: Grotesk, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--mc-ink);
}

#mopel-chat-open {
  position: fixed;
  z-index: 39;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 7px 19px 7px 7px;
  border: 1px solid #c9b3c1;
  border-radius: 999px;
  background: var(--mc-cream);
  box-shadow: 0 6px 26px #30212d26;
  color: var(--mc-plum);
  cursor: pointer;
  font-weight: 650;
}
#mopel-chat-open img { display: block; width: 44px; height: 44px; border-radius: 50%; }
#mopel-chat-open:hover { background: #f0e6ed; }
#mopel-chat-open:focus-visible,
#mopel-chat :focus-visible { outline: 3px solid #875879; outline-offset: 3px; }

#mopel-chat {
  position: fixed;
  inset: auto max(16px, env(safe-area-inset-right)) calc(16px + var(--mopel-chat-keyboard, 0px)) auto;
  width: min(450px, calc(100vw - 32px));
  height: min(744px, calc(100dvh - 32px), calc(var(--mopel-chat-vh, 100dvh) - 32px));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--mc-line);
  border-radius: 22px;
  background: var(--mc-cream);
  box-shadow: 0 24px 80px #30212d40;
  overflow: auto;
  overscroll-behavior: contain;
  color-scheme: light;
}
#mopel-chat:not([open]) { display: none; }
#mopel-chat[open] { display: grid; grid-template-rows: auto auto minmax(90px, 1fr) auto auto auto; }
#mopel-chat::backdrop { background: #30212d66; }
#mopel-chat button,
#mopel-chat textarea { font: inherit; }
#mopel-chat button { cursor: pointer; }
#mopel-chat button:disabled { cursor: default; opacity: .6; }
#mopel-chat .mopel-chat-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--mc-line);
  background: var(--mc-cream);
}
#mopel-chat .mopel-chat-header img { flex: none; width: 44px; height: 44px; border-radius: 12px; }
#mopel-chat .mopel-chat-header > div { flex: 1; min-width: 0; }
#mopel-chat .mopel-chat-eyebrow { display: block; font-size: 9px; font-weight: 650; letter-spacing: .1em; color: var(--mc-plum); }
#mopel-chat #mopel-chat-title { margin: 3px 0 0; font: 650 22px/1.2 Grotesk, system-ui, sans-serif; letter-spacing: -.04em; color: var(--mc-ink); }
#mopel-chat #mopel-chat-close {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--mc-line);
  border-radius: 50%;
  background: transparent;
  color: var(--mc-plum);
  font-size: 28px;
  line-height: 1;
}
#mopel-chat #mopel-chat-close:hover { background: #f0e6ed; }
#mopel-chat #mopel-chat-privacy { margin: 0; padding: 12px 18px; background: #f3ece3; color: var(--mc-muted); font-size: 11px; line-height: 1.55; }
#mopel-chat #mopel-chat-log {
  min-height: 90px;
  margin: 0;
  padding: 18px;
  list-style: none;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #c9b3c1 transparent;
}
#mopel-chat #mopel-chat-log li { width: fit-content; max-width: 94%; margin: 0 0 14px; padding: 12px 14px; border: 1px solid #e8ded1; border-radius: 3px 15px 15px; background: #fffdf9; }
#mopel-chat #mopel-chat-log li:last-child { margin-bottom: 0; }
#mopel-chat #mopel-chat-log [data-role="user"] { margin-left: auto; border-color: var(--mc-plum); border-radius: 15px 3px 15px 15px; background: var(--mc-plum); color: var(--mc-cream); }
#mopel-chat .mopel-chat-author { display: block; margin-bottom: 5px; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
#mopel-chat #mopel-chat-log p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }
#mopel-chat .mopel-chat-chips { display: flex; gap: 7px; padding: 4px 18px 12px; flex-wrap: wrap; }
#mopel-chat .mopel-chat-chips button { min-height: 44px; padding: 8px 13px; border: 1px solid #c9b3c1; border-radius: 999px; background: transparent; color: var(--mc-plum); font-size: 12px; font-weight: 600; }
#mopel-chat .mopel-chat-chips button:hover:not(:disabled) { background: #f0e6ed; }
#mopel-chat .mopel-chat-form { margin: 0; padding: 0 18px 12px; }
#mopel-chat .mopel-chat-label { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 7px; font-size: 12px; }
#mopel-chat .mopel-chat-label label { font-weight: 650; }
#mopel-chat #mopel-chat-count { color: var(--mc-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#mopel-chat .mopel-chat-compose { display: flex; align-items: stretch; gap: 8px; }
#mopel-chat #mopel-chat-input { display: block; width: 100%; min-width: 0; min-height: 68px; max-height: 140px; resize: vertical; padding: 11px 12px; border: 1px solid #b69ba9; border-radius: 12px; background: #fffdf9; color: var(--mc-ink); font-size: 16px; line-height: 1.4; }
#mopel-chat #mopel-chat-input::placeholder { color: #786570; opacity: 1; }
#mopel-chat #mopel-chat-input[aria-invalid="true"] { border-color: #9b3048; }
#mopel-chat #mopel-chat-send { flex: none; min-width: 84px; min-height: 44px; padding: 10px; border: 1px solid var(--mc-plum); border-radius: 12px; background: var(--mc-plum); color: var(--mc-cream); font-size: 13px; font-weight: 650; }
#mopel-chat #mopel-chat-send:hover:not(:disabled) { background: #52314a; }
#mopel-chat #mopel-chat-status { margin: 9px 0 0; color: var(--mc-muted); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
#mopel-chat #mopel-chat-status:empty { display: none; }
#mopel-chat #mopel-chat-status[data-state="error"] { color: #8d2532; }
#mopel-chat .mopel-chat-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 20px; padding: 8px 18px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--mc-line); }
#mopel-chat .mopel-chat-links a { display: flex; justify-content: center; align-items: center; min-height: 44px; color: var(--mc-plum); font-size: 12px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
#mopel-chat .mopel-chat-links .mopel-chat-human { flex-basis: 100%; border: 1px solid #c9b3c1; border-radius: 10px; text-decoration: none; }
#mopel-chat .mopel-chat-links a:hover { color: #30212d; }

@media (max-width: 600px) {
  #mopel-chat-open { right: max(16px, env(safe-area-inset-right)); bottom: calc(88px + env(safe-area-inset-bottom)); width: 56px; height: 56px; min-height: 56px; padding: 5px; gap: 0; }
  #mopel-chat-open > span { display: none; }
  #mopel-chat { right: 12px; bottom: calc(12px + var(--mopel-chat-keyboard, 0px)); width: calc(100vw - 24px); height: min(744px, calc(100dvh - 24px), calc(var(--mopel-chat-vh, 100dvh) - 24px)); border-radius: 18px; }
  #mopel-chat .mopel-chat-header { gap: 9px; padding: 12px; }
  #mopel-chat #mopel-chat-title { font-size: 21px; }
  #mopel-chat .mopel-chat-header img { width: 38px; height: 38px; }
  #mopel-chat .mopel-chat-eyebrow { font-size: 8px; }
  #mopel-chat #mopel-chat-privacy { padding: 10px 14px; }
  #mopel-chat #mopel-chat-log { padding: 14px; }
  #mopel-chat .mopel-chat-chips { padding-right: 14px; padding-left: 14px; gap: 6px; }
  #mopel-chat .mopel-chat-chips button { padding-right: 11px; padding-left: 11px; }
  #mopel-chat .mopel-chat-form { padding-right: 14px; padding-left: 14px; }
  #mopel-chat .mopel-chat-links { padding-right: 14px; padding-left: 14px; }
}

/* Scrolling the panel keeps every control reachable with the keyboard open. */
@media (max-height: 600px) {
  #mopel-chat[open] { display: block; }
  #mopel-chat #mopel-chat-log { height: 130px; }
}

@media (prefers-reduced-motion: no-preference) {
  #mopel-chat[open] { animation: mopel-chat-appear 150ms ease-out; }
  @keyframes mopel-chat-appear { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
}

#mopel-chat #mopel-chat-log a { color: var(--mc-plum); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
