:root {
  --bg: #f4f7f2;
  --card: #ffffff;
  --ink: #183126;
  --muted: #5b6f64;
  --line: #d9e3dc;
  --primary: #1f5b3b;
  --primary-2: #2d7a50;
  --soft: #edf4ef;
  --warn: #8a3d1f;
  --warn-bg: #fff0e7;
  --ok: #225f49;
  --ok-bg: #e7f6ef;
  --shadow: 0 12px 30px rgba(20, 50, 35, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #eef4ef 0%, var(--bg) 120px);
  color: var(--ink);
  line-height: 1.45;
}
button, input, select, textarea {
  font: inherit;
}
button {
  border: 0;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}
button:active { transform: scale(0.985); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
input, select, textarea {
  width: 100%;
  padding: 0.9rem 0.95rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
.hidden { display: none !important; }
.hidden-input { position: absolute; left: -9999px; }

.app-header {
  padding: calc(1.2rem + env(safe-area-inset-top)) 1rem 1rem;
  display: flex;
  gap: 0.9rem;
  align-items: start;
  justify-content: space-between;
}
.app-header h1 {
  margin: 0.1rem 0 0.3rem;
  font-size: clamp(1.9rem, 5vw, 2.4rem);
}
.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary-2);
  font-size: 0.76rem;
  font-weight: 700;
}
.subhead { margin: 0; color: var(--muted); max-width: 55ch; }

.container {
  padding: 0 1rem calc(2rem + env(safe-area-inset-bottom));
  display: grid;
  gap: 1rem;
  max-width: 980px;
  margin: 0 auto;
}
.card {
  background: var(--card);
  border: 1px solid rgba(12, 52, 31, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}
.inset-card {
  background: #fbfdfb;
  box-shadow: none;
  border: 1px solid var(--line);
  padding: 0.9rem;
}
.collapsible:not(.open) {
  display: none;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}
.section-head h2, .section-head h3 { margin: 0; }

.actions, .compact-actions, .capture-actions, .pill-row, .inline-stack {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.actions { margin-top: 0.9rem; }
.inline-stack { align-items: center; }
.grow { flex: 1 1 220px; }
.primary { background: var(--primary); color: #fff; }
.secondary { background: #dfeee4; color: var(--ink); }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.small { padding: 0.62rem 0.8rem; font-size: 0.92rem; }

.muted { color: var(--muted); }
.latin { font-style: italic; color: #29483a; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.38rem 0.7rem;
  background: #eef4ef;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
}
.pill.success { background: var(--ok-bg); color: var(--ok); }
.pill.warning { background: var(--warn-bg); color: var(--warn); }
.info-box {
  margin-top: 0.8rem;
  background: var(--soft);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
}
.info-box summary { cursor: pointer; font-weight: 700; }
.info-box ul { margin: 0.65rem 0 0 1.1rem; padding: 0; }

.image-tray {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.8rem;
}
.empty-state {
  border: 1px dashed #b9cabf;
  border-radius: 16px;
  padding: 1rem;
  color: var(--muted);
}
.image-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #fafdfb;
}
.tray-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: #e7ece8;
}
.image-controls {
  padding: 0.8rem;
  display: grid;
  gap: 0.6rem;
}
.image-name {
  margin: 0;
  padding: 0 0.8rem 0.8rem;
  color: var(--muted);
  font-size: 0.88rem;
  word-break: break-word;
}

.meta-grid, .knowledge-grid, .compare-grid {
  display: grid;
  gap: 0.8rem;
}
.meta-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 1rem 0;
}
.meta-box {
  background: var(--soft);
  border-radius: 14px;
  padding: 0.8rem;
}
.meta-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}
.knowledge-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.knowledge-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem;
  background: #fbfdfb;
}
.knowledge-card h4 { margin: 0 0 0.45rem; }
.warning-card { background: #fff9f5; }
.edible-card { background: #f7fcf7; }
.medicinal-card { background: #f7fbff; }

.candidate-list, .saved-list {
  display: grid;
  gap: 0.75rem;
}
.candidate-card, .saved-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem;
  background: #fff;
}
.candidate-card.selected {
  border-color: var(--primary-2);
  box-shadow: inset 0 0 0 1px rgba(45, 122, 80, 0.15);
}
.candidate-card h4, .saved-item h4 { margin: 0 0 0.2rem; }
.candidate-meta, .saved-meta {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0.25rem 0 0.5rem;
}
.compare-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.compare-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem;
  background: #fff;
}
.compare-card h4 { margin-top: 0; }
.compare-card p { margin: 0.45rem 0; }

@media (max-width: 680px) {
  .app-header { flex-direction: column; }
  .inline-stack { flex-direction: column; align-items: stretch; }
}
