:root {
  --bg: #fff8f0;
  --card: #ffffff;
  --accent: #ff8c42;
  --accent-dark: #e56f1f;
  --text: #2b2320;
  --muted: #8a7a70;
  --border: #f0e0d0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  background: var(--accent);
  color: white;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}

header h1 {
  margin: 0 0 12px;
  font-size: 1.3rem;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.controls input, .controls select, .controls button {
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
}

#search { flex: 1 1 160px; }

.primary-btn {
  background: white;
  color: var(--accent-dark);
  font-weight: 600;
  cursor: pointer;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  position: relative;
}

.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.card .meta { color: var(--muted); font-size: 0.85rem; }

.fav-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 12px;
  overflow-y: auto;
  z-index: 20;
}

.modal {
  background: white;
  border-radius: 14px;
  padding: 20px;
  max-width: 560px;
  width: 100%;
}

.modal h2 { margin-top: 0; }
.modal .section { margin-top: 14px; white-space: pre-wrap; }
.modal .section h4 { margin: 0 0 6px; color: var(--accent-dark); }

.smart-add {
  background: var(--bg);
  border: 1px dashed var(--accent);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
}

.smart-add label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.smart-add textarea {
  width: 100%;
  min-height: 100px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.9rem;
}

.smart-add .modal-actions { margin-top: 8px; }
#smartStatus { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
}

.modal-actions .danger-btn {
  border-color: #d9534f;
  color: #d9534f;
  margin-right: auto;
}

form.recipe-form label {
  display: block;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

form.recipe-form input, form.recipe-form select, form.recipe-form textarea {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  font-family: inherit;
}

form.recipe-form textarea { min-height: 80px; }

.chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  z-index: 15;
}

.chat-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: min(340px, calc(100vw - 40px));
  max-height: 60vh;
  background: white;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  display: none;
  flex-direction: column;
  z-index: 15;
  overflow: hidden;
}

.chat-panel.open { display: flex; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-size: 0.9rem;
}

.chat-messages .msg { margin-bottom: 10px; white-space: pre-wrap; }
.chat-messages .msg.user { color: var(--accent-dark); font-weight: 600; }

.chat-input {
  display: flex;
  border-top: 1px solid var(--border);
}

.chat-input input {
  flex: 1;
  border: none;
  padding: 10px;
  font-size: 0.9rem;
}

.chat-input button {
  border: none;
  background: var(--accent);
  color: white;
  padding: 0 16px;
  cursor: pointer;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 40px;
}
