:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1f2318;
  --ink-soft: #5b6156;
  --accent: #2f6b3f;
  --accent-soft: #e6f0e6;
  --line: #e2e0d8;
  --warn: #b3541e;
  --warn-soft: #fbe9dd;
  --agent: #4356a8;
  --agent-soft: #e8ebfa;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

a { color: var(--accent); }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-icon { font-size: 2rem; }
.brand h1 { margin: 0; font-size: 1.4rem; }
.tagline { margin: 0.1rem 0 0; color: var(--ink-soft); font-size: 0.9rem; }

.webmcp-status {
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  white-space: nowrap;
}
.webmcp-status.inactive {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: var(--warn);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.6rem 1.5rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab-btn {
  border: none;
  background: transparent;
  padding: 0.6rem 1rem;
  font-size: 0.92rem;
  cursor: pointer;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 1.5rem; max-width: 1080px; margin: 0 auto; }
.tab-panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.panel-header h2 { margin: 0; font-size: 1.15rem; }
.hint { color: var(--ink-soft); font-size: 0.85rem; margin: 0 0 0.75rem; }

.week-cost { font-weight: 600; color: var(--accent); }

.dietary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.diet-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.diet-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.plan-toolbar, .recipe-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}
.plan-toolbar label, .recipe-toolbar label { font-size: 0.82rem; color: var(--ink-soft); }
#budget-input { width: 90px; padding: 0.4rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; }
#sort-select { padding: 0.35rem 0.5rem; border: 1px solid var(--line); border-radius: 8px; }
.budget-status { font-size: 0.85rem; margin-bottom: 0.9rem; color: var(--ink-soft); }
.budget-status.over { color: var(--warn); font-weight: 600; }
.nutrition-summary { font-size: 0.85rem; margin-bottom: 0.9rem; color: var(--ink-soft); }
.nutrition-summary:empty { display: none; }

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}
.day-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.day-card h3 { margin: 0; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); }
.day-card .recipe-name { font-weight: 600; font-size: 0.95rem; }
.day-card .meta { font-size: 0.78rem; color: var(--ink-soft); }
.day-card select { width: 100%; font-size: 0.82rem; padding: 0.3rem; }
.day-card .clear-btn { align-self: flex-start; font-size: 0.78rem; border: none; background: none; color: var(--warn); cursor: pointer; padding: 0; }

.tag-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.tag-filters button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
}
.tag-filters button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

#recipe-search { padding: 0.45rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; min-width: 220px; }

.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.85rem; }
.recipe-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem; display: flex; flex-direction: column; gap: 0.4rem; }
.recipe-card h3 { margin: 0; font-size: 1rem; }
.recipe-card .tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.recipe-card .tag { font-size: 0.68rem; background: var(--accent-soft); color: var(--accent); padding: 0.15rem 0.5rem; border-radius: 999px; }
.recipe-card .meta { font-size: 0.8rem; color: var(--ink-soft); }
.recipe-card .conflict { font-size: 0.75rem; color: var(--warn); }
.recipe-card .pantry-match { font-size: 0.75rem; color: var(--agent); }
.recipe-card .expiring { font-size: 0.75rem; color: var(--warn); }
.recipe-card .add-row { display: flex; gap: 0.4rem; margin-top: auto; }
.recipe-card select, .recipe-card button { font-size: 0.8rem; padding: 0.3rem 0.5rem; }
.recipe-card button { background: var(--accent); color: #fff; border: none; border-radius: 6px; cursor: pointer; }

.inline-form { display: flex; gap: 0.4rem; }
.inline-form input { padding: 0.4rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; }
.inline-form button, .ghost-btn { padding: 0.4rem 0.8rem; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
.ghost-btn { background: transparent; color: var(--accent); }

.pantry-list, .shopping-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.pantry-list li, .shopping-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}
.pantry-list li .name, .shopping-list li .name { flex: 1; }
.pantry-list li input[type="date"] { font-size: 0.78rem; padding: 0.2rem 0.4rem; border: 1px solid var(--line); border-radius: 6px; }
.pantry-list li .expiry-badge { font-size: 0.75rem; color: var(--ink-soft); white-space: nowrap; }
.pantry-list li .expiry-badge.soon { color: var(--warn); font-weight: 600; }
.shopping-list li.checked .name { text-decoration: line-through; color: var(--ink-soft); }
.shopping-list li .qty { color: var(--ink-soft); font-size: 0.85rem; }
.remove-btn { border: none; background: none; color: var(--warn); cursor: pointer; font-size: 0.85rem; }

.agent-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 800px) { .agent-columns { grid-template-columns: 1fr; } }

#undo-btn { margin-bottom: 0.75rem; }
#undo-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.activity-log { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; max-height: 480px; overflow-y: auto; }
.activity-log li { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.7rem; font-size: 0.85rem; }
.activity-log .actor { font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.1rem 0.4rem; border-radius: 4px; margin-right: 0.4rem; }
.activity-log .actor.human { background: var(--accent-soft); color: var(--accent); }
.activity-log .actor.agent { background: var(--agent-soft); color: var(--agent); }
.activity-log .actor.system { background: #eee; color: #666; }
.activity-log .ts { color: var(--ink-soft); font-size: 0.75rem; float: right; }

.tool-form { display: flex; flex-direction: column; gap: 0.4rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem; }
.tool-form label { font-size: 0.78rem; color: var(--ink-soft); }
.tool-form select, .tool-form textarea, .tool-form button { font-family: inherit; font-size: 0.85rem; padding: 0.4rem 0.5rem; border: 1px solid var(--line); border-radius: 6px; }
.tool-form textarea { font-family: ui-monospace, monospace; }
.tool-form button { background: var(--agent); color: #fff; border: none; cursor: pointer; margin-top: 0.2rem; }

.tool-result {
  margin-top: 0.75rem;
  background: #111417;
  color: #d7e3d0;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 2rem;
}

.app-footer { text-align: center; color: var(--ink-soft); font-size: 0.8rem; padding: 2rem 1rem; }

.flash {
  animation: flash-bg 1.4s ease-out;
}
@keyframes flash-bg {
  from { background: var(--agent-soft); }
  to { background: var(--surface); }
}
