:root {
  --green-900: #1a4d2e;
  --green-700: #2d6a4f;
  --green-500: #40916c;
  --green-100: #d8f3dc;
  --green-50: #f1faee;
  --earth: #bc6c25;
  --text: #1b1b1b;
  --muted: #6c757d;
  --white: #ffffff;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--green-50) 0%, #e8f5e9 50%, #fff8e1 100%);
  min-height: 100vh;
  color: var(--text);
}

.app {
  max-width: 900px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

header {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 20px;
}

.status.ok { background: var(--green-100); color: var(--green-900); }
.status.err { background: #fee; color: #c00; }

.logo {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.leaf { font-size: 2.5rem; }

header h1 {
  color: var(--green-900);
  font-size: 1.5rem;
}

header p {
  color: var(--muted);
  font-size: 0.9rem;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.chat-gate {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
}

.chat-gate.hidden {
  display: none;
}

.chat-gate-card {
  max-width: 420px;
  width: 100%;
  padding: 1.75rem;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  border: 1px solid var(--green-100);
  text-align: center;
}

.chat-gate-card h2 {
  font-size: 1.15rem;
  color: var(--green-900);
  margin-bottom: 0.75rem;
}

.chat-gate-card p {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 1rem;
}

.chat-gate-card form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-gate-card input[type="password"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #dee2e6;
  border-radius: 12px;
  font-size: 1rem;
}

.chat-gate-card button {
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 12px;
  background: var(--green-700);
  color: var(--white);
  font-weight: 600;
  cursor: pointer;
}

.chat-gate-card button:hover {
  background: var(--green-900);
}

.chat-gate-error {
  color: #c1121f;
  font-size: 0.875rem;
  min-height: 1.25rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 400px;
  max-height: calc(100vh - 220px);
  overflow-anchor: none;
}

.message.assistant .bubble > .reveal-in,
.message.assistant .bubble .product-grid > .reveal-in {
  animation: revealBlock 0.45s ease forwards;
}

@keyframes revealBlock {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.message.assistant .bubble > ol,
.message.assistant .bubble > ul {
  margin: 0.35rem 0 0.5rem 1.1rem;
}

.message.assistant .bubble > ol > li,
.message.assistant .bubble > ul > li {
  margin-bottom: 0.35rem;
}

.product-grid,
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}

.message {
  display: flex;
  max-width: 95%;
}

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.bubble {
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  line-height: 1.6;
}

.message.user .bubble {
  background: var(--green-700);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--green-50);
  border: 1px solid var(--green-100);
  border-bottom-left-radius: 4px;
}

.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem; }

.message ul {
  margin: 0.5rem 0 0 1.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.quick-prompts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  padding: 0.65rem 1.5rem 0.75rem;
  background: #fafafa;
  border-top: 1px solid #eee;
}

.quick-prompts-label {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.quick-menus {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.quick-menu {
  position: relative;
}

.quick-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--white);
  border: 1px solid var(--green-100);
  color: var(--green-900);
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(27, 94, 32, 0.08);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
  white-space: nowrap;
}

.quick-menu-toggle::after {
  content: "▾";
  font-size: 0.75rem;
  opacity: 0.65;
  margin-left: 0.1rem;
}

.quick-menu-toggle:hover,
.quick-menu.is-open .quick-menu-toggle {
  background: var(--green-100);
  border-color: var(--green-500);
  box-shadow: 0 3px 8px rgba(27, 94, 32, 0.12);
}

.quick-menu-list {
  position: absolute;
  left: 0;
  bottom: calc(100% + 0.35rem);
  z-index: 20;
  min-width: min(100%, 280px);
  max-width: min(92vw, 320px);
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  background: var(--white);
  border: 1px solid var(--green-100);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(27, 94, 32, 0.14);
}

.quick-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  color: var(--green-900);
  cursor: pointer;
  font-family: inherit;
  line-height: 1.35;
}

.quick-menu-item:hover {
  background: var(--green-100);
}

.quick-menu-item:disabled,
.quick-menu-toggle:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-input {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid #eee;
  background: #fafafa;
}

.chat-input textarea {
  flex: 1;
  border: 2px solid var(--green-100);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  resize: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.chat-input textarea:focus {
  outline: none;
  border-color: var(--green-500);
}

.chat-input textarea:disabled {
  background: #f4f6f5;
  color: var(--muted);
  cursor: not-allowed;
}

.chat-input.is-waiting textarea,
.chat-input.is-waiting button {
  opacity: 0.65;
}

.quick-prompts.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.chat-input button {
  background: var(--green-700);
  color: var(--white);
  border: none;
  border-radius: 12px;
  padding: 0 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.chat-input button:hover { background: var(--green-900); }
.chat-input button:disabled { opacity: 0.6; cursor: not-allowed; }

.loading-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.typing-label {
  font-size: 0.82rem;
  color: #8a9a8a;
  font-style: italic;
}

.loading {
  display: flex;
  gap: 4px;
  padding: 0.5rem;
}

.loading span {
  width: 8px;
  height: 8px;
  background: var(--green-500);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading span:nth-child(1) { animation-delay: -0.32s; }
.loading span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Product cards from MCP */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.product-card {
  background: var(--white);
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 1rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

.product-card img,
.product-card .product-image img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  display: block;
}

.product-card .product-image {
  display: block;
  text-decoration: none;
}

.product-card .product-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--green-900);
  margin-bottom: 0.35rem;
  line-height: 1.35;
}

.product-card .product-title a {
  color: inherit;
  text-decoration: none;
}

.product-card .product-title a:hover { color: var(--green-500); }

.product-card .product-sku,
.product-card .product-category {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.15rem 0;
  line-height: 1.35;
}

.product-card .product-sku .label,
.product-card .product-category .label {
  font-weight: 600;
  color: #5c6670;
}

.product-card .category {
  font-size: 0.8rem;
  color: var(--muted);
}

.product-card h3 {
  font-size: 0.95rem;
  color: var(--green-900);
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

.product-card .price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--earth);
  margin: 0.25rem 0;
}

.product-card .rating {
  color: #f59e0b;
  font-size: 0.85rem;
}

.product-card .description {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.5rem 0;
  line-height: 1.4;
}

.product-card .buy-link,
.product-card .relevance {
  display: inline-block;
  font-size: 0.85rem;
}

.product-card .buy-link {
  color: var(--green-700);
  font-weight: 600;
  text-decoration: none;
  margin-top: 0.5rem;
}

.product-card .buy-link:hover { text-decoration: underline; }

.rag-card .relevance {
  background: var(--green-100);
  color: var(--green-900);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

.results-meta {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.recommendation-intro {
  font-size: 1rem;
  line-height: 1.55;
  margin-bottom: 1rem;
  color: var(--green-900);
}

.recommendations h2,
.results-meta,
.rag-card .relevance {
  display: none;
}

.more-link {
  margin-top: 0.75rem;
  font-size: 0.95rem;
  color: var(--green-900);
}

.more-link a {
  color: var(--green-700, #2e7d32);
  font-weight: 600;
  text-decoration: none;
}

.more-link a:hover {
  text-decoration: underline;
}


@media (max-width: 600px) {
  .quick-prompts {
    flex-direction: column;
    align-items: stretch;
    padding: 0.5rem 1rem 0.65rem;
  }
  .quick-menus {
    flex-direction: column;
  }
  .quick-menu-toggle {
    width: 100%;
    justify-content: space-between;
    font-size: 0.82rem;
  }
  .quick-menu-list {
    min-width: 100%;
    max-width: none;
  }
  .chat-input { flex-direction: column; }
  .chat-input button { padding: 0.75rem; }
  .products-grid { grid-template-columns: 1fr; }
}

.chat-gate {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
}

.chat-gate.hidden {
  display: none;
}

.chat-gate-panel {
  max-width: 420px;
  width: 100%;
  padding: 1.75rem;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  border: 1px solid var(--green-100);
  text-align: center;
}

.chat-gate-panel h2 {
  font-size: 1.15rem;
  margin-bottom: 0.75rem;
  color: var(--green-900);
}

.chat-gate-panel p {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 1rem;
}

.chat-gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
}

.chat-gate-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #dee2e6;
  border-radius: 12px;
  font-size: 1rem;
}

.chat-gate-form button {
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 12px;
  background: var(--green-700);
  color: var(--white);
  font-weight: 600;
  cursor: pointer;
}

.chat-gate-form button:hover {
  background: var(--green-900);
}

.chat-gate-error {
  color: #c0392b;
  font-size: 0.875rem;
  min-height: 1.25rem;
}
