/* ── CHAT WIDGET ─────────────────────────────────────────────────────────── */

#chat-launcher {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Fun facts ticker */
#fun-facts-ticker {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  max-width: 300px;
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  pointer-events: none;
}
#fun-facts-ticker.visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
#fun-facts-ticker.fading {
  opacity: 0;
  transform: translateX(6px);
}
.fun-facts-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  flex-shrink: 0;
}
#fun-facts-text {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
}

#chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(125, 171, 90, 0.35);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
#chat-toggle:hover {
  background: #8fbc6a;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(125, 171, 90, 0.45);
}
#chat-toggle svg {
  width: 24px;
  height: 24px;
  fill: #1a1f14;
  transition: opacity 0.15s;
}
#chat-toggle .icon-close { display: none; }
#chat-toggle.open .icon-chat  { display: none; }
#chat-toggle.open .icon-close { display: block; }

/* Panel */
#chat-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 2rem;
  z-index: 199;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 520px;
  max-height: calc(100vh - 8rem);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  transform: translateY(12px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
#chat-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.chat-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
}
.chat-header-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  flex-shrink: 0;
}
.chat-header-title {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.chat-header-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-left: auto;
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 2px; }

/* Message bubbles */
.chat-msg {
  max-width: 88%;
  font-size: 0.88rem;
  line-height: 1.65;
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  word-break: break-word;
}
.chat-msg-user {
  align-self: flex-end;
  background: rgba(125, 171, 90, 0.15);
  border: 1px solid rgba(125, 171, 90, 0.25);
  color: var(--text);
}
.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg-card2);
  border: 1px solid var(--border-subtle);
  color: rgba(240, 236, 224, 0.85);
}
.chat-msg-assistant.streaming::after {
  content: '▋';
  display: inline-block;
  color: var(--accent);
  animation: blink 0.8s step-end infinite;
  margin-left: 1px;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Thinking indicator */
.chat-thinking {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.65rem 0.9rem;
  background: var(--bg-card2);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}
.chat-thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s ease-in-out infinite;
}
.chat-thinking span:nth-child(2) { animation-delay: 0.2s; }
.chat-thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Intro message */
.chat-intro {
  align-self: flex-start;
  font-size: 0.88rem;
  line-height: 1.65;
  color: rgba(240, 236, 224, 0.85);
  background: var(--bg-card2);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  max-width: 88%;
}

/* Suggested prompts */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.chat-suggestion {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--accent);
  border: 1px solid rgba(125, 171, 90, 0.3);
  background: rgba(125, 171, 90, 0.07);
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: left;
}
.chat-suggestion:hover {
  background: rgba(125, 171, 90, 0.15);
  border-color: var(--accent);
}

/* Input area */
.chat-input-area {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.8rem;
  color: var(--text);
  resize: none;
  min-height: 38px;
  max-height: 96px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
}
#chat-input::placeholder { color: var(--muted); }
#chat-input:focus { border-color: var(--border); }
#chat-input:disabled { opacity: 0.5; cursor: not-allowed; }

#chat-send {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}
#chat-send:hover { background: #8fbc6a; }
#chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
#chat-send svg {
  width: 16px;
  height: 16px;
  fill: #1a1f14;
}

/* Drag & resize handles — injected via JS */
.chat-resize {
  position: absolute;
  z-index: 20;
}
.chat-resize-n  { top: 0;    left: 14px; right: 14px; height: 8px;  cursor: ns-resize; }
.chat-resize-s  { bottom: 0; left: 14px; right: 14px; height: 8px;  cursor: ns-resize; }
.chat-resize-e  { right: 0;  top: 14px;  bottom: 14px; width: 8px;  cursor: ew-resize; }
.chat-resize-w  { left: 0;   top: 14px;  bottom: 14px; width: 8px;  cursor: ew-resize; }
.chat-resize-nw { top: 0;    left: 0;    width: 14px; height: 14px; cursor: nwse-resize; }
.chat-resize-ne { top: 0;    right: 0;   width: 14px; height: 14px; cursor: nesw-resize; }
.chat-resize-sw { bottom: 0; left: 0;    width: 14px; height: 14px; cursor: nesw-resize; }
.chat-resize-se { bottom: 0; right: 0;   width: 14px; height: 14px; cursor: nwse-resize; }

/* Subtle grip dots on se/nw corner hints */
.chat-resize-se::after,
.chat-resize-nw::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid rgba(125, 171, 90, 0.25);
  border-bottom: 1.5px solid rgba(125, 171, 90, 0.25);
}
.chat-resize-se::after { bottom: 3px; right: 3px; }
.chat-resize-nw::after { top: 3px; left: 3px; transform: rotate(180deg); }

@media (max-width: 480px) {
  #chat-panel { right: 0; bottom: 0; width: 100%; max-width: 100%; border-radius: 16px 16px 0 0; height: 70vh; }
  #chat-launcher { bottom: 1.25rem; right: 1.25rem; }
  #fun-facts-ticker { display: none; }
}

/* ── WATER FOOTPRINT FOOTER (inside chat panel) ───────────────────────── */

#water-widget {
  border-top: 1px solid var(--border-subtle);
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  transition: background 0.15s;
}
#water-widget:hover {
  background: rgba(255,255,255,0.015);
}

.water-compact {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.water-drop-icon {
  width: 12px;
  height: 12px;
  fill: var(--water);
  flex-shrink: 0;
  opacity: 0.85;
}
.water-compact-amount,
.water-compact-unit {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--water);
}
.water-compact-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-left: auto;
}

.water-expanded-panel {
  display: none;
  padding-top: 0.6rem;
}
#water-widget.water-open .water-expanded-panel {
  display: block;
}

.water-exp-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.water-exp-title {
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  color: var(--water);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.water-exp-total {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  margin-bottom: 0.1rem;
}
#water-total-amount {
  font-family: 'DM Mono', monospace;
  font-size: 1.2rem;
  color: var(--water);
}
.water-exp-unit {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--water);
}
.water-exp-sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.water-exp-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 0.35rem 0;
}
.water-breakdown { display: flex; flex-direction: column; gap: 0.15rem; }
.water-row {
  display: flex;
  justify-content: space-between;
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--muted);
}
.water-exp-note {
  font-size: 0.62rem;
  color: var(--muted);
  opacity: 0.65;
  line-height: 1.6;
}

@keyframes water-pulse-anim {
  0%, 100% { fill: var(--water); }
  50%       { fill: #93d4f5; }
}
#water-widget.water-pulse .water-drop-icon {
  animation: water-pulse-anim 0.5s ease;
}
