:root {
  --ai-bg: #ffffff;
  --ai-surface: #1b5e20;
  --ai-header-text: #ffffff;
  --ai-header-sub: #bbf7d0;
  --ai-border: #cbd5e1;
  --ai-text: #1e293b;
  --ai-muted: #64748b;
  --ai-accent: #1b5e20;
  --ai-accent-ink: #ffffff;
  --ai-user-bg: #1b5e20;
  --ai-bot-bg: #f0fdf4;
  --ai-radius: 12px;
  --ai-z: 2600; /* above the household profile panel (2500), below modal dialogs (3000) */
}

.ai-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--ai-z);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  color: #ffffff;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(27, 94, 32, 0.35);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.ai-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(27, 94, 32, 0.45);
}

.ai-fab svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: #bbf7d0;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-drawer {
  position: fixed;
  right: 20px;
  bottom: 74px;
  z-index: calc(var(--ai-z) + 1);
  width: min(410px, calc(100vw - 24px));
  height: min(580px, calc(100vh - 100px));
  display: none;
  flex-direction: column;
  background: var(--ai-bg);
  color: var(--ai-text);
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius);
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.22);
  overflow: hidden;
  font-family: inherit;
}

.ai-drawer.open {
  display: flex;
}

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  background: var(--ai-surface);
  color: var(--ai-header-text);
}

.ai-header-title {
  font-size: 14px;
  font-weight: 700;
}

.ai-header-sub {
  font-size: 11px;
  color: var(--ai-header-sub);
  margin-top: 2px;
}

.ai-header-actions {
  display: flex;
  gap: 6px;
}

.ai-icon-btn {
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ai-icon-btn:hover {
  background: #ffffff;
  color: var(--ai-accent);
}

.ai-settings {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--ai-border);
  font-size: 12px;
}

.ai-settings.open {
  display: flex;
}

.ai-settings-label {
  font-weight: 700;
  color: var(--ai-accent);
}

.ai-settings input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--ai-border);
  background: #ffffff;
  color: var(--ai-text);
  font-size: 12px;
}

.ai-settings-btns {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.ai-quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  max-height: 115px;
  overflow-y: auto;
}

.ai-chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid #86efac;
  background: #f0fdf4;
  color: #166534;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.ai-chip:hover {
  background: #dcfce7;
}

.ai-messages {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #ffffff;
}

.ai-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.48;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg.user {
  align-self: flex-end;
  background: var(--ai-user-bg);
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

.ai-msg.bot {
  align-self: flex-start;
  background: var(--ai-bot-bg);
  border: 1px solid #bbf7d0;
  color: var(--ai-text);
  border-bottom-left-radius: 3px;
}

.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border-top: 1px solid var(--ai-border);
}

.ai-input-row input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--ai-border);
  background: #ffffff;
  color: var(--ai-text);
  font-size: 13px;
  outline: none;
}

.ai-btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.ai-btn-primary {
  background: var(--ai-accent);
  color: var(--ai-accent-ink);
}

.ai-btn-outline {
  background: #ffffff;
  border-color: var(--ai-border);
  color: var(--ai-text);
}

@media (max-width: 520px) {
  .ai-drawer {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 70px;
    height: min(72vh, 540px);
  }
  .ai-fab {
    right: 12px;
    bottom: 14px;
  }
}
