/* Willow chat widget — self-contained styles, no Tailwind dependency */

/* --- Accessibility: dyslexia font --- */
html.dyslexia-font #willow-panel,
html.dyslexia-font #willow-icon {
  font-family: OpenDyslexic, Arial, sans-serif !important;
}

/* --- Accessibility: high-contrast theme --- */
[data-theme="contrast"] .w-panel {
  border: 2px solid #000;
}
[data-theme="contrast"] .w-header {
  background: #000;
  color: #fff;
}
[data-theme="contrast"] .w-bubble {
  background: #fff;
  color: #000;
  border: 2px solid #000;
}
[data-theme="contrast"] .w-msg-user .w-bubble {
  background: #000;
  color: #fff;
}
[data-theme="contrast"] .w-check-btn,
[data-theme="contrast"] .w-send-btn {
  background: #000;
  color: #fff;
  border: 2px solid #000;
}
[data-theme="contrast"] .w-input {
  border: 2px solid #000;
  color: #000;
}
[data-theme="contrast"] .w-section-header {
  background: #000 !important;
  color: #fff !important;
  border-bottom-color: #000 !important;
}
[data-theme="contrast"] .w-section {
  border-color: #000 !important;
}

/* --- Full-screen mode --- */
.w-panel.w-fullscreen {
  bottom: 0 !important;
  right: 0 !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
}

.w-panel.w-fullscreen .w-messages {
  max-height: none;
  flex: 1;
}

.w-fullscreen-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: .8;
  transition: opacity .15s, background .15s;
}
.w-fullscreen-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,.15);
}

/* --- Layout anchors --- */
#willow-panel,
#willow-icon,
#willow-pill {
  position: fixed;
  z-index: 9999;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  box-sizing: border-box;
}

/* --- Expanded panel --- */
.w-panel {
  bottom: 90px;
  right: 20px;
  width: 450px;
  max-width: calc(100vw - 32px);
  max-height: 650px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.08);
  animation: willow-slide-up .18s ease-out;
}

@keyframes willow-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Header --- */
.w-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #1a6b3a;
  color: #fff;
  flex-shrink: 0;
}

.w-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.w-avatar-img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 15%;
  flex-shrink: 0;
}

.w-name {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
}

.w-tagline {
  font-size: 11px;
  opacity: .75;
}

.w-header-actions {
  display: flex;
  gap: 4px;
}

.w-icon-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: .8;
  transition: opacity .15s, background .15s;
}

.w-icon-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,.15);
}

/* --- Messages --- */
.w-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f9fa;
}

.w-messages::-webkit-scrollbar { width: 4px; }
.w-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

.w-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.w-msg-user    { align-self: flex-end; align-items: flex-end; }
.w-msg-assistant { align-self: flex-start; align-items: flex-start; }

.w-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.w-bubble .w-para {
  margin: 0;
}

.w-bubble .w-para + .w-para {
  margin-top: 7px;
}

.w-msg-user .w-bubble {
  background: #1a6b3a;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.w-msg-assistant .w-bubble {
  background: #fff;
  color: #1a202c;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

/* Sentiment-tinted assistant bubbles */
.w-msg-assistant .w-bubble-low {
  background: #f0fdf4;
  border-color: #86efac;
  border-left: 4px solid #16a34a;
}

.w-msg-assistant .w-bubble-medium {
  background: #fffbeb;
  border-color: #fcd34d;
  border-left: 4px solid #d97706;
}

.w-msg-assistant .w-bubble-high {
  background: #fef2f2;
  border-color: #fca5a5;
  border-left: 4px solid #dc2626;
}

.w-msg-assistant .w-bubble-critical {
  background: #fff1f2;
  border-color: #fda4af;
  border-left: 4px solid #9f1239;
}

.w-msg-assistant .w-bubble-unknown {
  background: #f8fafc;
  border-color: #e2e8f0;
  border-left: 4px solid #94a3b8;
}

/* --- Thinking dots --- */
.w-dots {
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  align-items: center;
}

.w-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: willow-bounce .9s infinite ease-in-out;
}

.w-dots span:nth-child(2) { animation-delay: .15s; }
.w-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes willow-bounce {
  0%, 80%, 100% { transform: scale(1); opacity: .5; }
  40%           { transform: scale(1.25); opacity: 1; }
}

/* --- Check / rerun buttons --- */
.w-check-btn {
  margin-top: 6px;
  padding: 6px 14px;
  background: #1a6b3a;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.w-check-btn:hover { background: #155c31; }

.w-rerun-btn {
  background: #2d6a9f;
}

.w-rerun-btn:hover { background: #245a8a; }

/* Yes / No quick-reply buttons */
.w-qa-btn {
  background: #1a6b3a;
  margin-right: 6px;
}

.w-qa-btn:hover  { background: #155c31; }
.w-qa-btn:disabled { background: #94a3b8; cursor: not-allowed; }

/* "Other" free-text box (unknown 1-2 word phrase) */
.w-other-box {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  width: 100%;
}
.w-other-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}
.w-other-input:focus { outline: none; border-color: #1a6b3a; }

.w-qa-no {
  background: #6b7280;
}

.w-qa-no:hover { background: #4b5563; }

/* --- Risk badge --- */
.w-risk-badge {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.w-risk-low      { background: #d1fae5; color: #065f46; }
.w-risk-medium   { background: #fef3c7; color: #92400e; }
.w-risk-high     { background: #fee2e2; color: #991b1b; }
.w-risk-critical { background: #7f1d1d; color: #fff; }
.w-risk-concerned { background: #fee2e2; color: #991b1b; }
.w-risk-unknown  { background: #e5e7eb; color: #374151; }

/* --- Input row --- */
.w-input-row {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  gap: 8px;
  flex-shrink: 0;
}

.w-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.875rem;
  outline: none;
  color: #1a202c;
  background: #f8f9fa;
  transition: border-color .15s;
  font-family: inherit;
}

.w-input:focus {
  border-color: #1a6b3a;
  background: #fff;
}

.w-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1a6b3a;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

.w-send-btn:hover  { background: #155c31; }
.w-send-btn:active { transform: scale(.93); }
.w-send-btn:disabled { background: #94a3b8; cursor: not-allowed; }

.w-upload-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f8f9fa;
  color: #334155;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}

.w-upload-btn:hover {
  background: #ecfdf5;
  border-color: #86efac;
  color: #166534;
}

.w-upload-btn:active { transform: scale(.94); }

/* --- Breathe animation when Willow has chat history --- */
@keyframes w-willow-breathe {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,.28));
  }
  50% {
    transform: scale(1.07);
    filter:
      drop-shadow(0 6px 14px rgba(0,0,0,.32))
      drop-shadow(0 0 14px rgba(255,255,255,.55));
  }
}

.w-fab.w-has-history .w-fab-rest {
  animation: w-willow-breathe 2.8s ease-in-out infinite;
  transform-origin: bottom center;
}

/* --- Minimised FAB --- */
.w-fab {
  bottom: 80px;
  right: 16px;
  width: 72px;
  height: auto;
  border-radius: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: transform .15s;
  position: fixed;
  padding: 0;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.28));
}

.w-fab { cursor: grab; }
.w-fab:hover { transform: scale(1.05) translateY(-3px); }

.w-fab-img {
  width: 72px;
  height: auto;
  display: block;
  pointer-events: none;
  transition: opacity .2s ease;
}

/* No history: rest visible, help on hover, chat hidden */
.w-fab-rest { opacity: 1; }
.w-fab-help {
  opacity: 0;
  position: absolute;
  bottom: 0;
  left: 0;
}
.w-fab-chat { display: none; }

/* Crossfade rest→help on hover (only when no history) */
.w-fab:not(.w-has-history):hover .w-fab-rest { opacity: 0; }
.w-fab:not(.w-has-history):hover .w-fab-help { opacity: 1; }

/* Has history: chat image with pulsing glow */
@keyframes w-chat-glow {
  0%, 100% {
    filter: drop-shadow(0 4px 8px rgba(0,0,0,.28)) drop-shadow(0 0 6px rgba(255,255,255,0));
  }
  50% {
    filter: drop-shadow(0 4px 12px rgba(0,0,0,.32)) drop-shadow(0 0 16px rgba(255,220,80,.75));
  }
}

.w-fab.w-has-history .w-fab-chat {
  display: block;
  animation: w-chat-glow 2.2s ease-in-out infinite;
}

.w-badge {
  position: absolute;
  top: 4px;
  right: 0;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #e53e3e;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #fff;
}


/* --- Proactive wellbeing bubble --- */
.w-msg-assistant .w-bubble-wellbeing {
  background: #fdf2f8;
  border-color: #f0abcb;
  border-left: 4px solid #db2777;
  color: #831843;
}

/* --- "Willow Says:" header row with avatar --- */
.w-msg-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.w-msg-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 15%;
  flex-shrink: 0;
}

.w-willow-label {
  font-size: 10px;
  font-weight: 700;
  color: #1a6b3a;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- Farewell image --- */
.w-farewell-img {
  margin-top: 8px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 220px;
}

.w-farewell-photo {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
}

/* --- C / R source pill --- */
/* Live-debug: response source badge + host info bar (admin-toggled) */
.w-origin {
  display: inline-block;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  margin: 0 6px 4px 0;
  vertical-align: middle;
  background: #64748b;
}
.w-origin-claude { background: #6d28d9; }
.w-origin-intent { background: #2563eb; }
.w-origin-regex  { background: #64748b; }
.w-origin-live   { background: #16a34a; }
.w-origin-cache  { background: #d97706; }
.w-origin-bank   { background: #0891b2; }
.w-origin-canon  { background: #be123c; }
.w-origin-curated{ background: #be123c; }
.w-debugbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 9px;
  padding: 6px 10px;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 10.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border-bottom: 1px solid #334155;
}
.w-debugbar-tag {
  font-weight: 800;
  letter-spacing: .08em;
  color: #fff;
  background: #4338ca;
  border-radius: 4px;
  padding: 1px 6px;
}
.w-debugbar-item { white-space: nowrap; opacity: .9; }
.w-debugbar-item b { color: #94a3b8; font-weight: 700; margin-right: 2px; }

.w-source-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  margin-left: 7px;
  vertical-align: middle;
  flex-shrink: 0;
}

.w-source-cache {
  background: #e2e8f0;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.w-source-fresh {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

/* --- Section cards (website / company) --- */
.w-section {
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
  margin: 4px 0;
}

.w-section + .w-section {
  margin-top: 8px;
}

.w-section-header {
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.w-section-body {
  padding: 8px 11px 10px;
  font-size: 13px;
  line-height: 1.55;
  background: #fff;
}

.w-section-body .w-para {
  margin: 0;
}

.w-section-body .w-para + .w-para {
  margin-top: 5px;
}

.w-section-website {
  border-color: #cbd5e1;
}

.w-section-website .w-section-header {
  background: #f1f5f9;
  color: #334155;
  border-bottom: 1px solid #cbd5e1;
}

.w-section-company {
  border-color: #cbd5e1;
}

.w-section-company .w-section-header {
  background: #f8fafc;
  color: #334155;
  border-bottom: 1px solid #cbd5e1;
}

.w-section-vehicle {
  border-color: #cbd5e1;
}

.w-section-vehicle .w-section-header {
  background: #f8fafc;
  color: #334155;
  border-bottom: 1px solid #cbd5e1;
}

/* --- Powered by footer --- */
.w-powered-by {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 12px 7px;
  background: #fff;
  border-top: 1px solid #f1f5f9;
}

.w-powered-by-text {
  font-size: 10px;
  color: #94a3b8;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.w-powered-by-img {
  height: 16px;
  width: auto;
  object-fit: contain;
  opacity: 0.7;
}

/* --- Mobile tweaks --- */
@media (max-width: 480px) {
  .w-panel {
    bottom: 80px;
    right: 10px;
    left: 10px;
    width: auto;
    max-height: 70vh;
  }
}
