/* === Maple chat widget ============================================== */
/* Floating bubble bottom-right + expanding panel. Branded to the existing
   SelfnvestAI palette (rust, paper, ink). Self-contained — does not depend
   on any rule from the main page. */

.cw-root {
  --cw-rust: #a84d2e;
  --cw-rust-deep: #8b3d23;
  --cw-rust-soft: #c8704f;
  --cw-paper: #f5efe6;
  --cw-paper-2: #efe7d9;
  --cw-paper-3: #e8dfcd;
  --cw-ink: #2a1f17;
  --cw-ink-soft: #5a463a;
  --cw-ink-mute: #8a7563;
  --cw-line: rgba(42, 31, 23, 0.14);
  --cw-shadow: 0 24px 60px -28px rgba(80, 40, 20, 0.55);

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--cw-ink);
}

/* === Bubble ========================================================= */

.cw-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--cw-rust);
  color: var(--cw-paper);
  box-shadow: var(--cw-shadow), 0 0 0 1px var(--cw-rust-deep);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.18s ease, background 0.2s ease;
  position: relative;
}
.cw-bubble:hover {
  transform: translateY(-2px);
  background: var(--cw-rust-deep);
}
.cw-bubble:focus-visible {
  outline: 2px solid var(--cw-ink);
  outline-offset: 3px;
}
.cw-bubble svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* gentle rust pulse to draw the eye */
.cw-bubble::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--cw-rust);
  opacity: 0;
  pointer-events: none;
  animation: cwPulse 2.4s ease-out infinite;
}
@keyframes cwPulse {
  0% { opacity: 0.55; transform: scale(0.92); }
  60% { opacity: 0; transform: scale(1.18); }
  100% { opacity: 0; transform: scale(1.18); }
}

/* unread dot when the panel is closed and Maple has unseen content */
.cw-bubble[data-unread="1"]::before {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fde9d8;
  border: 2px solid var(--cw-rust);
}

/* === Panel ========================================================== */

.cw-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 360px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--cw-paper);
  border: 1px solid var(--cw-line);
  border-radius: 16px;
  box-shadow: var(--cw-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: cwPanelIn 0.18s ease-out both;
}
.cw-panel[data-open="1"] {
  display: flex;
}
@keyframes cwPanelIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* === Header ========================================================= */

.cw-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--cw-line);
  background: var(--cw-paper-2);
}
.cw-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cw-rust);
  color: var(--cw-paper);
  font-family: "Newsreader", Georgia, serif;
  font-size: 18px;
  font-weight: 500;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.cw-title-block {
  flex: 1;
  min-width: 0;
}
.cw-title {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  font-size: 16px;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--cw-ink);
}
.cw-subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--cw-ink-mute);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.cw-subtitle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7a8a6c;
  box-shadow: 0 0 0 3px rgba(122, 138, 108, 0.18);
}
.cw-close {
  background: none;
  border: none;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--cw-ink-soft);
  transition: background 0.15s ease, color 0.15s ease;
}
.cw-close:hover {
  background: rgba(42, 31, 23, 0.06);
  color: var(--cw-ink);
}
.cw-close svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* === Message list =================================================== */

.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.cw-messages::-webkit-scrollbar { width: 6px; }
.cw-messages::-webkit-scrollbar-thumb {
  background: rgba(42, 31, 23, 0.18);
  border-radius: 3px;
}

.cw-msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: cwMsgIn 0.2s ease-out both;
}
@keyframes cwMsgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.cw-msg.cw-from-bot {
  align-self: flex-start;
  background: var(--cw-paper-2);
  color: var(--cw-ink);
  border-bottom-left-radius: 4px;
}
.cw-msg.cw-from-user {
  align-self: flex-end;
  background: var(--cw-rust);
  color: var(--cw-paper);
  border-bottom-right-radius: 4px;
}

.cw-msg a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* CTA inside an assistant message */
.cw-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--cw-rust);
  color: var(--cw-paper);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--cw-rust-deep);
  transition: background 0.15s ease;
}
.cw-cta:hover { background: var(--cw-rust-deep); }
.cw-cta svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* error message variant */
.cw-msg.cw-error {
  background: #fbe5dc;
  color: var(--cw-rust-deep);
  border: 1px solid var(--cw-rust-soft);
}

/* typing indicator (3 bouncing dots) */
.cw-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: var(--cw-paper-2);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.cw-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cw-ink-mute);
  animation: cwTyping 1.2s infinite ease-in-out;
}
.cw-typing span:nth-child(2) { animation-delay: 0.15s; }
.cw-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cwTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* === Input ========================================================== */

.cw-input-row {
  border-top: 1px solid var(--cw-line);
  padding: 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--cw-paper);
}
.cw-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--cw-line);
  border-radius: 10px;
  background: var(--cw-paper-2);
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--cw-ink);
  line-height: 1.4;
  max-height: 110px;
  overflow-y: auto;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.cw-input:focus {
  outline: none;
  border-color: var(--cw-rust-soft);
  background: var(--cw-paper);
}
.cw-input::placeholder { color: var(--cw-ink-mute); }
.cw-input:disabled { opacity: 0.6; cursor: not-allowed; }

.cw-send {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 10px;
  border: none;
  background: var(--cw-rust);
  color: var(--cw-paper);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.cw-send:hover:not(:disabled) {
  background: var(--cw-rust-deep);
  transform: translateY(-1px);
}
.cw-send:disabled {
  background: var(--cw-paper-3);
  color: var(--cw-ink-mute);
  cursor: not-allowed;
}
.cw-send svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cw-footer-hint {
  padding: 0 16px 10px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cw-ink-mute);
  text-align: center;
  background: var(--cw-paper);
}

/* === Responsive ===================================================== */

@media (max-width: 600px) {
  .cw-root {
    right: 16px;
    bottom: 16px;
  }
  .cw-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 96px);
    right: 0;
    bottom: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cw-bubble::after,
  .cw-typing span,
  .cw-msg,
  .cw-panel { animation: none !important; }
}
