:root {
  --primary: #96c726;
  --primary-dark: #658f1b;
  --primary-soft: #f4f9e8;
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --brand-gradient: linear-gradient(145deg, #96c726 0%, #658f1b 100%);
  --shadow-panel: 0 8px 30px rgba(15, 23, 42, 0.1), 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-launcher: 0 2px 10px rgba(15, 23, 42, 0.14), 0 1px 3px rgba(15, 23, 42, 0.06);
  --whatsapp: #25d366;
  --whatsapp-dark: #1ebe57;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: transparent;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

#root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  --tb-launcher-size: 56px;
  --tb-launcher-gap: 12px;
  --tb-launcher-inset: 8px;
  --tb-panel-width: 392px;
  --tb-panel-height: 560px;
  --tb-font-title: 1rem;
  --tb-font-subtitle: 0.75rem;
  --tb-font-body: 0.875rem;
  --tb-font-small: 0.8125rem;
  --tb-font-meta: 0.6875rem;
  --tb-avatar: 38px;
  --tb-icon-btn: 36px;
  --tb-send: 44px;
}

#root.a11y-large {
  --tb-launcher-size: 64px;
  --tb-panel-width: 448px;
  --tb-panel-height: 640px;
  --tb-font-title: 1.1875rem;
  --tb-font-subtitle: 0.9375rem;
  --tb-font-body: 1.0625rem;
  --tb-font-small: 0.9375rem;
  --tb-font-meta: 0.8125rem;
  --tb-avatar: 46px;
  --tb-icon-btn: 42px;
  --tb-send: 52px;
}

#launcher,
#panel {
  pointer-events: auto;
}

/* ---------- Launcher (same as plant .snf-chat-popup-button) ---------- */
#launcher {
  position: absolute;
  bottom: var(--tb-launcher-inset);
  right: var(--tb-launcher-inset);
  width: var(--tb-launcher-size);
  height: var(--tb-launcher-size);
  border-radius: 50%;
  border: none;
  background: var(--brand-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-launcher);
  transform-origin: bottom right;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 2;
}

#launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16), 0 2px 4px rgba(15, 23, 42, 0.08);
}

#launcher:active {
  transform: scale(1.02);
}

#launcher svg {
  width: 26px;
  height: 26px;
}

/* ---------- Panel (same as plant .snf-chat-popup-panel) ---------- */
#panel {
  position: absolute;
  bottom: calc(var(--tb-launcher-size) + var(--tb-launcher-gap) + var(--tb-launcher-inset));
  right: var(--tb-launcher-inset);
  display: none;
  flex-direction: column;
  width: var(--tb-panel-width);
  max-width: calc(100vw - 24px);
  height: var(--tb-panel-height);
  max-height: calc(100% - var(--tb-launcher-size) - var(--tb-launcher-gap) - var(--tb-launcher-inset));
  background: var(--bg);
  border-radius: 16px;
  box-shadow: var(--shadow-panel);
  border: 1px solid rgba(101, 143, 27, 0.08);
  overflow: hidden;
  z-index: 1;
}

#panel.open {
  display: flex;
  animation: panel-in 0.25s ease;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- Header (Trading Buddy branding, plant layout) ---------- */
.panel-header {
  padding: 14px 16px;
  background: var(--brand-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: var(--tb-avatar);
  height: var(--tb-avatar);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.title {
  font-weight: 700;
  font-size: var(--tb-font-title);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.subtitle {
  font-size: var(--tb-font-subtitle);
  opacity: 0.85;
  font-weight: 400;
  margin-top: 2px;
}

.icon-btn {
  width: var(--tb-icon-btn);
  height: var(--tb-icon-btn);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.icon-btn.is-active {
  background: rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ---------- Chat body (same as plant .snf-rag-chat--popup) ---------- */
.chat-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-soft);
}

/* ---------- Messages (same as plant .snf-rag-chat-messages) ---------- */
.messages {
  flex: 1;
  min-height: 140px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.bubble {
  max-width: 85%;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: var(--tb-font-body);
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.bubble.bot {
  align-self: flex-start;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--brand-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

.bubble.user a {
  color: #fff;
}

/* ---------- Option buttons ---------- */
.options {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 85%;
}

.option-btn {
  text-align: left;
  background: #fff;
  color: var(--primary-dark);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: var(--tb-font-body);
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.option-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(101, 143, 27, 0.12);
}

.option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.options.is-locked .option-btn {
  pointer-events: none;
}

/* ---------- Action buttons ---------- */
.actions {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 85%;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: var(--tb-font-small);
  font-weight: 500;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  border-color: var(--primary);
}

.action-btn .icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.action-btn[data-kind="whatsapp_group"] .icon,
.action-btn[data-kind="whatsapp_personal"] .icon {
  background: rgba(37, 211, 102, 0.15);
  color: var(--whatsapp-dark);
}

.action-btn[data-kind="webinar"] .icon {
  background: rgba(150, 199, 38, 0.15);
  color: var(--primary-dark);
}

.action-btn[data-kind="video"] .icon {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
}

.action-btn .label {
  flex: 1;
  line-height: 1.3;
}

/* ---------- Typing indicator (same as plant) ---------- */
.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typing-bounce 1.4s ease-in-out infinite both;
}

.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.1);
    opacity: 1;
  }
}

/* ---------- Video card (same rhythm as plant product cards) ---------- */
.video-card {
  align-self: flex-start;
  max-width: 85%;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.video-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.video-card .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000 center / cover no-repeat;
  position: relative;
}

.video-card .play {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-dark);
  z-index: 1;
}

.video-card .meta {
  padding: 10px;
  font-size: var(--tb-font-small);
  font-weight: 600;
  color: var(--primary-dark);
  line-height: 1.3;
}

/* ---------- Composer (same as plant .snf-rag-chat-input-wrap) ---------- */
.composer {
  padding: 12px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.composer-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

#message-input {
  flex: 1;
  min-width: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 14px;
  font-size: var(--tb-font-body);
  background: var(--bg-soft);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  resize: none;
  font-family: inherit;
  line-height: 1.4;
  max-height: 110px;
  overflow-y: auto;
}

#message-input::placeholder {
  color: #94a3b8;
}

#message-input:focus {
  border-color: var(--primary-dark);
  box-shadow: 0 0 0 3px rgba(150, 199, 38, 0.18);
}

#message-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#send-btn {
  width: var(--tb-send);
  height: var(--tb-send);
  border-radius: 12px;
  background: var(--brand-gradient);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}

#send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(101, 143, 27, 0.2);
}

#send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#send-btn svg {
  width: 20px;
  height: 20px;
}

.composer-meta {
  display: flex;
  justify-content: flex-end;
}

.char-counter {
  font-size: var(--tb-font-meta);
  color: var(--text-muted);
}

.char-counter.is-warn {
  color: #d97706;
}

.char-counter.is-error {
  color: #dc2626;
  font-weight: 600;
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  #panel {
    width: 100%;
    max-width: 100%;
    height: calc(100% - var(--tb-launcher-size) - var(--tb-launcher-gap) - var(--tb-launcher-inset));
    max-height: calc(100% - var(--tb-launcher-size) - var(--tb-launcher-gap) - var(--tb-launcher-inset));
    border-radius: 16px;
    right: 0;
  }
}

/* ---------- Large accessibility mode extras ---------- */
#root.a11y-large .bubble,
#root.a11y-large .option-btn {
  padding: 12px 16px;
}

#root.a11y-large .action-btn {
  padding: 12px 14px;
}

#root.a11y-large .action-btn .icon {
  width: 40px;
  height: 40px;
}

#root.a11y-large .typing {
  padding: 14px 16px;
}

#root.a11y-large .typing span {
  width: 7px;
  height: 7px;
}

#root.a11y-large #launcher svg {
  width: 30px;
  height: 30px;
}

#root.a11y-large #send-btn svg {
  width: 22px;
  height: 22px;
}

#root.a11y-large .icon-btn svg {
  width: 20px;
  height: 20px;
}

#root.a11y-large .messages {
  gap: 14px;
  padding: 18px;
}

#root.a11y-large #message-input {
  padding: 12px 16px;
}
