.juan-chat {
  --chat-bg: #fffaf2;
  --chat-ink: #433629;
  --chat-muted: #847360;
  --chat-line: #e9dece;
  --chat-bubble: #f3ebdf;
  color: var(--chat-ink);
  font-size: 14px;
  line-height: 1.6;
}
[data-user-color-scheme="dark"] .juan-chat {
  --chat-bg: #282923;
  --chat-ink: #f0e8db;
  --chat-muted: #bbae9a;
  --chat-line: #49463c;
  --chat-bubble: #36372e;
}
.juan-chat [hidden] { display: none !important; }
.juan-chat button { font: inherit; cursor: pointer; }
.juan-chat-launcher {
  position: fixed;
  z-index: 1050;
  width: 72px;
  height: 76px;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: none;
  user-select: none;
  filter: drop-shadow(0 5px 7px #43362938);
  cursor: grab !important;
}
.juan-chat-launcher:active { cursor: grabbing !important; }
.juan-chat-launcher svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.juan-chat-launcher:hover svg { transform: rotate(-7deg); }
.juan-chat-panel {
  position: fixed;
  z-index: 1051;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 24px));
  height: min(540px, calc(100dvh - 32px));
  border: 1px solid var(--chat-line);
  border-radius: 20px;
  background: var(--chat-bg);
  box-shadow: 0 16px 60px #0003;
  overflow: hidden;
}
.juan-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--chat-line);
}
.juan-chat-heading { margin: 0; font-size: 17px; font-weight: 700; }
.juan-chat-caption { margin: 3px 0 0; font-size: 12px; color: var(--chat-muted); }
.juan-chat-close {
  border: 0;
  border-radius: 50%;
  background: var(--chat-bubble);
  color: var(--chat-ink);
  width: 36px;
  height: 36px;
  font-size: 24px !important;
  flex-shrink: 0;
}
.juan-chat-messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px; }
.juan-chat-welcome { margin-bottom: 20px; }
.juan-chat-welcome strong { font-size: 18px; }
.juan-chat-welcome p { color: var(--chat-muted); margin: 8px 0 12px; }
.juan-chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.juan-chat-suggestions button {
  padding: 6px 10px;
  border: 1px solid var(--chat-line);
  border-radius: 12px;
  background: transparent;
  color: var(--chat-ink);
}
.juan-chat-message { margin: 0 0 16px; }
.juan-chat-message-label { margin: 0 0 4px; font-size: 11px; color: var(--chat-muted); }
.juan-chat-message-text {
  border-radius: 14px 14px 14px 3px;
  padding: 10px 12px;
  background: var(--chat-bubble);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.juan-chat-message.is-user { margin-left: 28px; }
.juan-chat-message.is-user .juan-chat-message-label { text-align: right; }
.juan-chat-message.is-user .juan-chat-message-text { background: #ead5ad; color: #433629; border-radius: 14px 14px 3px 14px; }
.juan-chat-message-note { font-size: 12px; color: var(--chat-muted); margin: 5px 0 0; }
.juan-chat-form { border-top: 1px solid var(--chat-line); padding: 12px 16px 14px; }
.juan-chat-input {
  display: block;
  width: 100%;
  resize: none;
  min-height: 66px;
  padding: 10px 12px;
  border: 1px solid var(--chat-line);
  border-radius: 12px;
  background: var(--chat-bg);
  color: var(--chat-ink);
  font: inherit;
}
.juan-chat-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.juan-chat-status { color: var(--chat-muted); font-size: 11px; }
.juan-chat-send, .juan-chat-stop { border: 0; border-radius: 10px; background: #68543b; color: #fffaf2; padding: 7px 14px; flex-shrink: 0; }
.juan-chat button:disabled { opacity: .55; cursor: default; }
@media (max-width: 600px) {
  .juan-chat-panel { left: 12px !important; right: 12px; top: auto !important; bottom: max(12px, env(safe-area-inset-bottom)); width: auto; height: min(580px, calc(100dvh - 24px)); }
  .juan-chat-input { font-size: 16px; }
}

/* Shared account, history and wall controls. */
.juan-community { color: var(--text-color, #433629); font-size: 14px; line-height: 1.7; }
.juan-community [hidden] { display: none !important; }
.juan-community button, .chat-tools button, .chat-copy { font: inherit; color: inherit; border: 1px solid #a7947566; border-radius: 9px; background: transparent; padding: 5px 10px; cursor: pointer; }
.juan-community button:disabled { opacity: .5; cursor: default; }
.juan-community button:hover, .chat-tools button[aria-pressed="true"] { background: #b89a6433; }
.juan-community label { display: block; margin-top: 12px; }
.juan-community input, .juan-community textarea { display: block; width: 100%; border: 1px solid #a7947580; border-radius: 10px; padding: 10px; background: transparent; color: inherit; font: inherit; }
.juan-community textarea { resize: vertical; }
.juan-community small { display: block; opacity: .8; }
.community-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0; }
.juan-account { width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 28px; background: var(--board-bg-color, #fffaf2); border: 1px solid #a7947566; border-radius: 18px; box-shadow: 0 16px 60px #0003; }
.juan-account::backdrop { background: #0008; }
.juan-account h2 { font-size: 20px; padding-right: 24px; }
.juan-account .account-close { position: absolute; top: 12px; right: 12px; }
.community-record { border-bottom: 1px solid #a7947544; padding: 16px 0; overflow-wrap: anywhere; }
.community-record p { white-space: pre-wrap; margin: 10px 0; }
.community-record a { display: block; margin: 8px 0; }
.community-record summary { cursor: pointer; white-space: pre-wrap; }
.community-record button { margin: 8px 8px 0 0; }
.chat-tools { display: flex; gap: 6px; padding: 8px 16px 0; }
.chat-tools button { font-size: 12px; }
.chat-account-note { font-size: 11px; color: var(--chat-muted); margin: 6px 16px; }
.chat-history { flex: 1; min-height: 0; overflow-y: auto; padding: 0 18px 18px; color: var(--chat-ink); }
.chat-copy { font-size: 11px; margin-top: 5px; }
@media (max-width: 600px) {
  .juan-community input, .juan-community textarea { font-size: 16px; }
}
.juan-chat-message-text p { margin: 0 0 8px; }
.juan-chat-message-text p:last-child { margin-bottom: 0; }
.juan-chat-message-text:has(p) { white-space: normal; }
.juan-chat-message-text pre, .community-record pre { white-space: pre; overflow-x: auto; padding: 10px; background: #8882; border-radius: 8px; }
.juan-chat-message-text code, .community-record code { font-size: .9em; color: inherit; background: #8882; }
.juan-chat-message-text h4 { font-size: 16px; }

.wall-replies { border-top: 1px solid #a7947544; margin-top: 12px; }
[data-reply-context] { padding: 10px 12px; border-left: 3px solid #a79475; background: #b89a6414; overflow-wrap: anywhere; }
