/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #b85c38;
  --primary-light: #d4835f;
  --primary-bg: #fdf6f0;
  --accent: #5c8a4a;
  --text: #3e2723;
  --text-light: #795548;
  --text-muted: #a1887f;
  --bg: #faf6f1;
  --card-bg: #fff;
  --border: #e8ddd4;
  --shadow: 0 4px 16px rgba(62,39,35,0.06);
  --shadow-hover: 0 12px 32px rgba(62,39,35,0.12);
  --radius: 16px;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, sans-serif;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* === Header === */
.site-header {
  background: #3e2723;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(62,39,35,0.2);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}
.logo-img {
  height: 36px;
  max-height: 36px;
  width: auto;
  display: block;
}

nav { display: flex; align-items: center; }
nav a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  margin-left: 24px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.2s;
}
nav a:hover, nav a.active { color: #fff; }

/* === Hero === */
.hero {
  background: linear-gradient(135deg, #5d4037 0%, #b85c38 60%, #d4835f 100%);
  color: #fff;
  padding: 52px 24px;
  text-align: center;
}
.hero h1 { font-family: var(--font-display); font-size: 3rem; font-weight: 400; margin-bottom: 10px; letter-spacing: -0.3px; }
.hero p { font-size: 1.1rem; opacity: 0.9; font-weight: 300; }

/* === Container === */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* === Search & Filter Bar === */
.search-filter-bar {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.search-box { position: relative; margin-bottom: 16px; }
.search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--text-muted);
}
#search-input {
  width: 100%; padding: 12px 40px 12px 44px; font-size: 1rem;
  border: 2px solid var(--border); border-radius: 14px;
  font-family: var(--font-body); transition: border-color 0.2s, box-shadow 0.2s; background: var(--bg);
}
#search-input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(184,92,56,0.1); }

.clear-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 1.3rem; color: var(--text-muted);
  cursor: pointer; display: none; padding: 4px 8px; line-height: 1;
}
.clear-btn.visible { display: block; }

.filter-controls { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end; }
.filter-group { flex: 1; min-width: 180px; }
.filter-group label {
  display: block; font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-light); margin-bottom: 6px;
}
#category-filter {
  width: 100%; padding: 10px 12px; border: 2px solid var(--border);
  border-radius: 14px; font-size: 0.9rem; font-family: var(--font-body);
  background: var(--bg); cursor: pointer;
}
#category-filter:focus { outline: none; border-color: var(--primary); }

.search-mode-toggle { display: flex; border: 2px solid var(--border); border-radius: 8px; overflow: hidden; }
.mode-btn {
  flex: 1; padding: 10px 14px; border: none; background: var(--bg);
  font-size: 0.85rem; font-family: var(--font-body); font-weight: 500;
  color: var(--text-light); cursor: pointer; transition: all 0.2s; white-space: nowrap;
  border-radius: 20px;
}
.mode-btn.active { background: var(--primary); color: #fff; border-radius: 20px; }
.mode-btn:not(.active):hover { background: var(--primary-bg); }

/* === Results Info === */
.results-info {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; font-size: 0.9rem; color: var(--text-light);
}
.results-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.view-toggle { display: flex; gap: 4px; }
.view-btn {
  padding: 6px 8px; border: 1px solid var(--border); background: var(--card-bg);
  border-radius: 6px; cursor: pointer; color: var(--text-muted);
  transition: all 0.2s; display: flex; align-items: center;
}
.view-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Favorites filter button */
.fav-filter-btn {
  display: flex; align-items: center; gap: 4px; padding: 6px 12px;
  border: 1px solid var(--border); background: var(--card-bg);
  border-radius: 6px; cursor: pointer; font-size: 0.82rem;
  font-family: var(--font-body); color: var(--text-muted); transition: all 0.2s;
}
.fav-filter-btn svg { fill: none; stroke: var(--text-muted); }
.fav-filter-btn.active {
  background: #fff0f0; border-color: #e88; color: #c44;
}
.fav-filter-btn.active svg { fill: #e55; stroke: #e55; }

/* === Recipe Grid === */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.recipe-grid.list-view { grid-template-columns: 1fr; }

.recipe-card {
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.recipe-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary-bg);
}

.card-image {
  width: 100%; height: 180px; overflow: hidden;
  background: var(--border);
}
.card-image img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.3s;
}
.recipe-card:hover .card-image img { transform: scale(1.05); }

.card-image-placeholder {
  display: flex; align-items: center; justify-content: center;
}
.card-icon { opacity: 0.3; width: 64px; height: 64px; color: var(--text-muted); }
.card-icon svg { width: 100%; height: 100%; }

.card-body { padding: 16px; display: flex; flex-direction: column; flex: 1; }

.recipe-grid.list-view .recipe-card {
  flex-direction: row; overflow: visible;
}
.recipe-grid.list-view .recipe-card:hover { transform: none; }
.recipe-grid.list-view .card-image {
  width: 120px; height: 80px; flex-shrink: 0; border-radius: var(--radius) 0 0 var(--radius);
}
.recipe-grid.list-view .card-icon { width: 40px; height: 40px; }
.recipe-grid.list-view .card-body {
  flex-direction: row; align-items: center; gap: 16px; padding: 12px 16px;
}

.card-category {
  display: inline-block; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--primary); background: var(--primary-bg);
  padding: 4px 12px; border-radius: 20px; margin-bottom: 8px;
}
.recipe-grid.list-view .card-category {
  margin-bottom: 0; flex-shrink: 0; min-width: 140px; text-align: center;
}

.card-fav-icon {
  display: inline-flex; margin-left: 6px; vertical-align: middle;
}
.card-fav-icon svg { fill: #e55; stroke: #e55; }

.card-title {
  font-family: var(--font-display); font-size: 1.1rem; font-weight: 600;
  color: var(--text); margin-bottom: 8px; line-height: 1.3;
}
.recipe-grid.list-view .card-title { margin-bottom: 0; flex: 1; }

.card-meta { margin-top: auto; display: flex; gap: 12px; font-size: 0.8rem; color: var(--text-muted); }
.recipe-grid.list-view .card-meta { margin-top: 0; flex-shrink: 0; }
.card-meta span { display: flex; align-items: center; gap: 4px; }
.card-nutrition-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.75rem; color: var(--accent); font-weight: 500;
}

/* === No Results === */
.no-results {
  text-align: center; padding: 60px 20px; color: var(--text-muted); grid-column: 1 / -1;
}
.no-results h3 { font-family: var(--font-display); font-size: 1.5rem; color: var(--text-light); margin-bottom: 8px; }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 40px 16px; backdrop-filter: blur(4px);
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--card-bg); border-radius: 16px; max-width: 800px;
  width: 100%; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); animation: modalIn 0.25s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute; top: 16px; right: 16px; background: var(--bg);
  border: none; width: 36px; height: 36px; border-radius: 50%;
  font-size: 1.3rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  color: var(--text-light); transition: all 0.2s; z-index: 1;
}
.modal-close:hover { background: var(--accent); color: #fff; }

.modal-body { padding: 36px; }

.modal-header { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 2px solid var(--border); }
.modal-header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

.modal-category {
  display: inline-block; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--primary); background: var(--primary-bg);
  padding: 4px 10px; border-radius: 4px;
}

/* Favorite button in modal */
.fav-btn {
  background: none; border: none; cursor: pointer; padding: 4px;
  transition: all 0.2s; border-radius: 50%;
}
.fav-btn svg { fill: none; stroke: #b88; stroke-width: 2.5; transition: all 0.2s; }
.fav-btn:hover svg { stroke: #e55; transform: scale(1.15); }
.fav-btn.active svg { fill: #e55; stroke: #e55; }
.modal-header-actions .fav-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; background: var(--bg); border-radius: 50%;
  border: 1px solid #ddd;
}
.modal-header-actions .fav-btn:hover { background: #fee; border-color: #e55; }
.modal.editing .fav-btn { display: none; }

.modal-header h2 {
  font-family: var(--font-display); font-size: 1.8rem; font-weight: 700;
  color: var(--text); line-height: 1.3; margin-bottom: 8px;
}

.modal-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Modal image */
.modal-image-container {
  margin-bottom: 20px; border-radius: 12px; overflow: hidden;
  max-height: 400px; position: relative;
}
.modal-image-container img {
  width: 100%; height: auto; max-height: 400px; object-fit: cover; display: block;
}

/* Image edit overlay */
.image-edit-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; gap: 8px; justify-content: center;
  padding: 12px; background: linear-gradient(transparent, rgba(0,0,0,0.6));
}
.image-edit-overlay[hidden] { display: none; }
.image-edit-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 0.85rem; font-weight: 500; font-family: var(--font-body);
  background: rgba(255,255,255,0.9); color: #333;
  transition: background 0.2s;
}
.image-edit-btn:hover { background: #fff; }
.image-remove-btn { background: rgba(255,200,200,0.9); color: #a33; }
.image-remove-btn:hover { background: #fdd; }

/* Image add button (when no photo) */
.image-add-container {
  margin-bottom: 20px;
}
.image-add-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 32px; border: 2px dashed #ccc; border-radius: 12px;
  background: #fafafa; color: #888; cursor: pointer;
  font-size: 0.95rem; font-family: var(--font-body);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.image-add-btn:hover { border-color: var(--accent); color: var(--accent); background: #f5f9f2; }

.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-bottom: 28px; }

.modal-section h3 {
  font-family: var(--font-display); font-size: 1.15rem; font-weight: 600;
  color: var(--text); margin-bottom: 14px;
  display: flex; align-items: baseline; gap: 8px;
}
.modal-section h3 small {
  font-family: var(--font-body); font-size: 0.75rem; font-weight: 400; color: var(--text-muted);
}

/* Ingredient list */
.ingredient-list { list-style: none; }
.ingredient-list li {
  padding: 6px 0; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem;
}
.ingredient-list li:last-child { border-bottom: none; }
.ingredient-qty { font-weight: 600; color: var(--primary); white-space: nowrap; min-width: 70px; }
.ingredient-name { flex: 1; color: var(--text); }

/* Nutrition panel */
.nutrition-panel { background: var(--primary-bg); border-radius: 8px; padding: 16px; }
.nutrition-row {
  display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px dotted rgba(0,0,0,0.1); font-size: 0.9rem;
}
.nutrition-row:last-child { border-bottom: none; }
.nutrition-label { color: var(--text-light); }
.nutrition-value { font-weight: 600; color: var(--text); }
.nutrition-value.calories { color: var(--accent); font-size: 1.1rem; }
.nutrition-unavailable { color: var(--text-muted); font-size: 0.85rem; font-style: italic; padding: 12px 0; }

/* Steps list */
.steps-list { padding-left: 0; list-style: none; counter-reset: step; }
.steps-list li {
  padding: 10px 0 10px 44px; border-bottom: 1px solid var(--border);
  position: relative; font-size: 0.95rem; line-height: 1.6; counter-increment: step;
}
.steps-list li:last-child { border-bottom: none; }
.steps-list li::before {
  content: counter(step); position: absolute; left: 0; top: 10px;
  width: 30px; height: 30px; background: var(--primary); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 600;
}

/* Tips */
#modal-notes {
  background: #fffbe6; border-left: 3px solid #f5c518; padding: 12px 16px;
  border-radius: 0 8px 8px 0; font-size: 0.9rem; color: var(--text-light); line-height: 1.6;
}

/* === Footer === */
.site-footer {
  text-align: center; padding: 32px 24px; margin-top: 48px;
  background: #3e2723; color: rgba(255,255,255,0.7); font-size: 0.85rem;
}
.site-footer a { color: #d4835f; text-decoration: none; }

/* === Buttons === */
.export-btn {
  background: rgba(255,255,255,0.15); color: #fff;
  border: 1px solid rgba(255,255,255,0.3); padding: 6px 14px;
  border-radius: 6px; font-size: 0.8rem; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; margin-left: 16px; transition: all 0.2s;
}
.export-btn:hover { background: rgba(255,255,255,0.25); }

.edit-btn, .pdf-btn, .shopping-btn {
  display: inline-block; margin-top: 0; padding: 6px 14px;
  background: var(--primary); color: #fff; border: none; border-radius: 6px;
  font-size: 0.82rem; font-family: var(--font-body); font-weight: 500;
  cursor: pointer; transition: background 0.2s;
}
.edit-btn:hover, .pdf-btn:hover, .shopping-btn:hover, .share-btn:hover { background: var(--primary-light); }
.modal.editing .edit-btn, .modal.editing .pdf-btn, .modal.editing .shopping-btn, .modal.editing .share-wrapper { display: none; }

/* Share dropdown */
.share-wrapper { position: relative; display: inline-block; }
.share-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px; background: var(--primary); color: #fff; border: none;
  border-radius: 6px; font-size: 0.82rem; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; transition: background 0.2s;
}
.share-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 6px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-hover);
  padding: 6px; min-width: 180px; z-index: 10;
}
.share-option {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; border: none; background: none;
  font-family: var(--font-body); font-size: 0.85rem;
  color: var(--text); cursor: pointer; border-radius: 8px;
  transition: background 0.15s;
}
.share-option:hover { background: var(--bg); }

.delete-btn {
  display: inline-block; padding: 6px 14px;
  background: #fff; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; font-size: 0.82rem; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.delete-btn:hover { background: var(--accent); color: #fff; }
.modal.editing .delete-btn { display: none; }

.add-recipe-btn {
  padding: 6px 14px; background: var(--primary); color: #fff;
  border: none; border-radius: 6px; font-size: 0.82rem;
  font-family: var(--font-body); font-weight: 500;
  cursor: pointer; transition: background 0.2s;
}
.add-recipe-btn:hover { background: var(--primary-light); }

/* Confirm delete overlay */
.confirm-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 300;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px);
}
.confirm-dialog {
  background: var(--card-bg); border-radius: 12px; padding: 28px;
  max-width: 400px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}
.confirm-dialog h3 { font-family: var(--font-display); font-size: 1.2rem; margin-bottom: 8px; }
.confirm-dialog p { color: var(--text-light); font-size: 0.9rem; margin-bottom: 20px; }
.confirm-dialog .confirm-actions { display: flex; gap: 10px; justify-content: center; }
.btn-danger {
  background: var(--accent); color: #fff; padding: 10px 24px; border: none;
  border-radius: 8px; font-size: 0.9rem; font-family: var(--font-body);
  font-weight: 600; cursor: pointer;
}
.btn-danger:hover { background: #a33; }

/* === Edit mode === */
.edit-actions {
  display: flex; gap: 12px; margin-top: 24px; padding-top: 20px;
  border-top: 2px solid var(--border);
}
.edit-actions[hidden] { display: none; }
.btn {
  padding: 10px 24px; border: none; border-radius: 8px; font-size: 0.9rem;
  font-family: var(--font-body); font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-save { background: var(--primary); color: #fff; }
.btn-save:hover { background: var(--primary-light); }
.btn-cancel { background: var(--bg); color: var(--text-light); border: 1px solid var(--border); }
.btn-cancel:hover { background: var(--border); }

.edit-input {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-family: var(--font-body); font-size: 0.9rem; background: #fff;
}
.edit-input:focus { outline: none; border-color: var(--primary); }
.edit-title-input { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; padding: 8px 12px; }
.edit-category-select {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.75rem; font-family: var(--font-body); background: #fff;
}

.ingredient-edit-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.ingredient-edit-row:last-child { border-bottom: none; }
.ingredient-edit-row .edit-input.qty { width: 80px; flex-shrink: 0; }
.ingredient-edit-row .edit-input.name { flex: 1; }
.ingredient-edit-row .remove-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 1.2rem; padding: 2px 6px; flex-shrink: 0;
}
.ingredient-edit-row .remove-btn:hover { color: #a33; }

.add-row-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 1px dashed var(--border);
  color: var(--primary); padding: 6px 12px; border-radius: 6px;
  cursor: pointer; font-size: 0.8rem; margin-top: 8px; font-family: var(--font-body);
}
.add-row-btn:hover { border-color: var(--primary); background: var(--primary-bg); }

/* Editable step row */
.step-edit-row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--border);
  padding-left: 0 !important; counter-increment: none !important;
}
.step-edit-row::before { display: none !important; }
.steps-list > li:has(.add-row-btn) { padding-left: 0; counter-increment: none; }
.steps-list > li:has(.add-row-btn)::before { display: none; }
.step-edit-row:last-child { border-bottom: none; }
.step-edit-row .step-number {
  width: 26px; height: 26px; background: var(--primary); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 600; flex-shrink: 0; margin-top: 4px;
}
.step-edit-row textarea {
  flex: 1; min-height: 50px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-family: var(--font-body); font-size: 0.9rem; resize: vertical;
}
.step-edit-row textarea:focus { outline: none; border-color: var(--primary); }
.step-edit-row .step-actions { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.step-edit-row .step-actions button {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.9rem; padding: 2px 4px;
}
.step-edit-row .step-actions button:hover { color: var(--primary); }

.edit-notes-textarea {
  width: 100%; min-height: 60px; padding: 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-family: var(--font-body); font-size: 0.9rem; resize: vertical;
}
.edit-notes-textarea:focus { outline: none; border-color: var(--primary); }

/* === Nutrition detail popup === */
.nutrition-detail-modal { max-width: 900px; }
.nutrition-detail-subtitle {
  font-family: var(--font-display); font-size: 1.1rem;
  color: var(--text-light); margin-bottom: 16px;
}
.nutrition-detail-table-wrap { overflow-x: auto; margin-bottom: 16px; }
.nutrition-detail-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.nutrition-detail-table th {
  background: var(--primary); color: #fff; padding: 8px 10px;
  text-align: left; font-weight: 600; white-space: nowrap;
}
.nutrition-detail-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.nutrition-detail-table tbody tr:hover { background: var(--primary-bg); }
.nutrition-detail-table tfoot td {
  font-weight: 700; background: var(--bg); border-top: 2px solid var(--primary);
}

.nd-status-matched { color: var(--primary); font-weight: 500; }
.nd-status-unmatched { color: var(--accent); font-weight: 500; }
.nd-status-no-qty { color: #c8a000; font-weight: 500; }

.nd-grams-input {
  width: 60px; padding: 3px 6px; border: 1px solid #c8a000;
  border-radius: 4px; font-size: 0.8rem; text-align: right; background: #fff;
}

.nutrition-detail-actions { display: flex; gap: 12px; justify-content: flex-end; }
.nutrition-clickable { cursor: pointer; text-decoration: underline; text-decoration-style: dotted; }
.nutrition-clickable:hover { color: var(--primary); }

/* === Autocomplete for ingredient matching === */
.nd-autocomplete-wrap { position: relative; display: inline-block; min-width: 160px; }
.nd-autocomplete {
  width: 100%; padding: 4px 8px; border: 1px solid var(--accent);
  border-radius: 4px; font-size: 0.8rem; background: #fff;
}
.nd-autocomplete:focus { outline: none; border-color: var(--primary); }
.nd-autocomplete-dropdown {
  position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15); max-height: 250px;
  overflow-y: auto; z-index: 50;
}
.nd-autocomplete-dropdown[hidden] { display: none; }
.ac-category {
  padding: 6px 10px; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--primary); background: var(--primary-bg);
  position: sticky; top: 0;
}
.ac-item {
  padding: 6px 10px; font-size: 0.82rem; cursor: pointer;
  transition: background 0.1s;
}
.ac-item:hover { background: var(--primary-bg); }
.ac-item small { color: var(--text-muted); }
.ac-empty { padding: 12px 10px; font-size: 0.82rem; color: var(--text-muted); text-align: center; }

/* === Ingredient Database Editor === */
.ingredient-db-modal-inner { max-width: 1000px; }
.db-subtitle { color: var(--text-light); font-size: 0.9rem; margin-bottom: 16px; }
.db-toolbar {
  display: flex; gap: 12px; margin-bottom: 16px; align-items: center; flex-wrap: wrap;
}
.db-search-box { flex: 1; min-width: 200px; }
.db-search-box input {
  width: 100%; padding: 8px 12px; border: 2px solid var(--border);
  border-radius: 6px; font-size: 0.9rem; font-family: var(--font-body);
}
.db-search-box input:focus { outline: none; border-color: var(--primary); }
.db-toolbar select {
  padding: 8px 12px; border: 2px solid var(--border); border-radius: 6px;
  font-size: 0.85rem; font-family: var(--font-body); background: #fff;
}

.db-table-wrap { overflow-x: auto; max-height: 60vh; overflow-y: auto; }
.db-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.db-table th {
  background: var(--primary); color: #fff; padding: 8px 10px;
  text-align: left; font-weight: 600; position: sticky; top: 0; z-index: 1;
}
.db-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
.db-table tbody tr:hover { background: var(--primary-bg); }
.db-custom-row { background: #fffbe6; }
.db-custom-badge {
  display: inline-block; font-size: 0.65rem; background: #f5c518; color: #333;
  padding: 1px 5px; border-radius: 3px; font-weight: 600; margin-left: 4px;
}

.db-edit-btn, .db-delete-btn {
  padding: 3px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.75rem; cursor: pointer; background: #fff;
  font-family: var(--font-body); transition: all 0.2s; margin-right: 4px;
}
.db-edit-btn:hover { background: var(--primary-bg); border-color: var(--primary); }
.db-delete-btn { color: var(--accent); border-color: var(--accent); }
.db-delete-btn:hover { background: var(--accent); color: #fff; }

/* DB edit form */
.db-edit-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.db-edit-form label { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.db-edit-form input, .db-edit-form select {
  flex: 1; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.9rem; font-family: var(--font-body);
}
.db-edit-form input:focus, .db-edit-form select:focus { outline: none; border-color: var(--primary); }

/* === Scrollbar === */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* === Responsive === */
/* === Hamburger Button (hidden on desktop) === */
.hamburger-btn {
  display: none; background: none; border: none; cursor: pointer;
  padding: 6px; flex-direction: column; gap: 4px;
}
.hamburger-btn span {
  display: block; width: 22px; height: 2px; background: #fff;
  border-radius: 1px; transition: all 0.3s;
}

@media (max-width: 768px) {
  .hamburger-btn { display: flex; }
  .header-content { flex-wrap: wrap; padding: 0 16px; height: auto; min-height: 50px; }
  nav {
    display: none; order: 3; width: 100%;
    flex-direction: column; align-items: flex-start;
    padding: 8px 0 12px;
    border-top: 1px solid rgba(255,255,255,0.15);
  }
  nav.open { display: flex; }
  nav a { margin-left: 0; padding: 6px 0; font-size: 0.85rem; }
  .export-btn { margin-left: 0; margin-top: 6px; }
  .user-area { margin-left: auto; }
  .logo-img { height: 28px; max-height: 28px; }

  .hero h1 { font-size: 2rem; }
  .hero { padding: 32px 16px; }
  .container { padding: 16px; }
  .search-filter-bar { padding: 16px; }
  .filter-controls { flex-direction: column; gap: 12px; }
  .filter-group { min-width: 100%; }
  .modal-grid { grid-template-columns: 1fr; }
  .modal-body { padding: 24px; }
  .modal-header h2 { font-size: 1.4rem; }
  .recipe-grid { grid-template-columns: 1fr; }
  .recipe-grid.list-view .recipe-card { flex-direction: column; align-items: flex-start; }
  .recipe-grid.list-view .card-category { min-width: auto; }
  .recipe-grid.list-view .card-image { width: 100%; height: 160px; }
  .modal-overlay { padding: 20px 8px; }
  .nutrition-detail-modal { max-width: 100%; }
  .nutrition-detail-table { font-size: 0.75rem; }
  .nutrition-detail-table th, .nutrition-detail-table td { padding: 5px 6px; }
  .edit-actions { flex-direction: column; }
  .results-actions { flex-wrap: wrap; }
  .card-image { height: 160px; }
  .modal-header-actions { gap: 4px; }
  .modal-header-actions button { font-size: 0.75rem; padding: 5px 10px; }
}

mark { background: #fff3cd; padding: 0 2px; border-radius: 2px; }
.loading { text-align: center; padding: 60px; color: var(--text-muted); }

/* === Random Recipe Button === */
.random-recipe-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-size: 1.3rem; padding: 4px 10px; line-height: 1;
  transition: all 0.2s;
}
.random-recipe-btn:hover { background: var(--accent); border-color: var(--accent); }

/* === Cook Button in Modal === */
.cook-btn {
  padding: 6px 14px; border: none; border-radius: 6px; cursor: pointer;
  font-size: 0.85rem; font-weight: 500; font-family: var(--font-body);
  background: #e67e22; color: #fff; transition: background 0.2s;
}
.cook-btn:hover { background: #d35400; }
.modal.editing .cook-btn { display: none; }

/* === Portion Calculator === */
.portion-calculator {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; margin-bottom: 20px;
  background: #f8f5ef; border-radius: 10px; border: 1px solid #e8e0d0;
}
.portion-calculator label {
  font-weight: 600; font-size: 0.9rem; color: var(--text);
}
.portion-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 1.1rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; color: var(--primary);
}
.portion-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.portion-count {
  font-size: 1.3rem; font-weight: 700; min-width: 28px; text-align: center;
  color: var(--primary);
}
.portion-label { font-size: 0.8rem; color: var(--text-muted); }
.modal.editing .portion-calculator { display: flex; }

/* === Related Recipes === */
.related-recipes-section { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 20px; }
.related-recipes-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px; margin-top: 12px;
}
.related-card {
  background: var(--card-bg); border-radius: 10px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08); cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s; border: 1px solid transparent;
}
.related-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); border-color: var(--accent); }
.related-card-img { height: 100px; overflow: hidden; background: #f0ece4; }
.related-card-img img { width: 100%; height: 100%; object-fit: cover; }
.related-card-body { padding: 10px; }
.related-card-body .card-category { font-size: 0.6rem; padding: 2px 6px; }
.related-card-body h4 { font-size: 0.8rem; font-weight: 600; margin-top: 4px; line-height: 1.3; color: var(--text); }
.modal.editing .related-recipes-section { display: none; }

/* === Cooking Mode === */
.cook-mode-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: linear-gradient(135deg, #1a3a1a 0%, #2d5016 50%, #3a6b1e 100%);
  color: #fff; display: flex; flex-direction: column;
}
.cook-mode-overlay[hidden] { display: none; }
.cook-mode-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; background: rgba(0,0,0,0.2);
}
.cook-mode-recipe-name {
  font-family: var(--font-display); font-size: 1.1rem; font-weight: 600;
  opacity: 0.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cook-mode-close {
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.5rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.cook-mode-close:hover { background: rgba(255,255,255,0.3); }
.cook-mode-body {
  flex: 1; display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: 40px 32px; text-align: center; overflow-y: auto;
}
.cook-mode-step-label {
  font-size: 1rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; opacity: 0.7; margin-bottom: 20px;
}
.cook-mode-step-text {
  font-size: clamp(1.3rem, 4vw, 2.2rem); line-height: 1.6;
  max-width: 800px; font-weight: 300;
}
.cook-mode-step-text .cook-ingredients-list {
  text-align: left; list-style: none; padding: 0; margin: 0;
}
.cook-mode-step-text .cook-ingredients-list li {
  padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.15);
  font-size: clamp(1rem, 3vw, 1.5rem);
}
.cook-mode-step-text .cook-ingredients-list .cook-qty {
  display: inline-block; min-width: 80px; font-weight: 600; opacity: 0.9;
}
.cook-mode-nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 32px; background: rgba(0,0,0,0.2);
}
.cook-mode-nav-btn {
  padding: 14px 28px; border: 2px solid rgba(255,255,255,0.4);
  border-radius: 10px; background: rgba(255,255,255,0.1);
  color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: all 0.2s; font-family: var(--font-body);
}
.cook-mode-nav-btn:hover { background: rgba(255,255,255,0.25); border-color: rgba(255,255,255,0.7); }
.cook-mode-nav-btn:disabled { opacity: 0.3; cursor: default; }
.cook-mode-nav-btn:disabled:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.4); }
.cook-mode-progress { font-size: 1rem; opacity: 0.7; }

/* === User Area (Login/Logout) === */
.user-area {
  display: flex; align-items: center; margin-left: 16px;
}
.login-btn {
  background: rgba(255,255,255,0.15); color: #fff;
  border: 1px solid rgba(255,255,255,0.3); padding: 6px 16px;
  border-radius: 20px; font-size: 0.8rem; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.login-btn:hover { background: rgba(255,255,255,0.3); }
.user-badge {
  display: flex; align-items: center; gap: 10px;
  color: rgba(255,255,255,0.9); font-size: 0.85rem;
}
.user-badge[hidden] { display: none; }
.user-badge span { font-weight: 500; }
.logout-btn {
  background: none; border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.7); padding: 4px 10px; border-radius: 4px;
  font-size: 0.75rem; cursor: pointer; font-family: var(--font-body);
  transition: all 0.2s;
}
.logout-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* === Login Modal === */
.login-modal { max-width: 360px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form label {
  font-size: 0.85rem; font-weight: 500; color: var(--text-light);
}
.login-form input[type="text"],
.login-form input[type="password"] {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 0.95rem; font-family: var(--font-body);
  transition: border-color 0.2s;
}
.login-form input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45,80,22,0.1);
}
.login-error {
  color: var(--accent); font-size: 0.85rem; margin: 0;
}
.login-form .btn-save { margin-top: 4px; }

/* === Admin Button === */
.admin-btn {
  background: rgba(255,255,255,0.15); color: #fff;
  border: 1px solid rgba(255,255,255,0.3); padding: 4px 10px;
  border-radius: 4px; font-size: 0.75rem; cursor: pointer;
  font-family: var(--font-body); transition: all 0.2s;
}
.admin-btn:hover { background: rgba(255,255,255,0.3); }

/* === Admin Modal === */
.admin-modal-inner { max-width: 700px; }
.admin-actions { display: flex; gap: 6px; justify-content: flex-end; }
.admin-actions .btn, .admin-actions .delete-btn { font-size: 0.78rem; padding: 4px 10px; }
.admin-edit-btn { font-size: 0.78rem !important; padding: 4px 10px !important; }

.admin-user-form {
  margin-top: 20px; padding: 20px; background: var(--primary-bg);
  border-radius: 10px; border: 1px solid var(--border);
}
.admin-user-form h3 {
  font-family: var(--font-display); font-size: 1.1rem;
  margin-bottom: 14px; color: var(--text);
}
.admin-form-grid {
  display: grid; grid-template-columns: auto 1fr;
  gap: 8px 14px; align-items: center; font-size: 0.9rem;
}
.admin-form-grid label { font-weight: 500; color: var(--text-light); }
.admin-form-grid small {
  grid-column: 2; color: var(--text-muted); font-size: 0.8rem; margin-top: -4px;
}
.admin-form-actions {
  display: flex; gap: 10px; margin-top: 14px;
}

@media (max-width: 700px) {
  .user-area { margin-left: 8px; }
  .user-badge span { display: none; }
  .admin-form-grid { grid-template-columns: 1fr; }
}

/* === Homepage Cards === */
.home-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 32px;
  padding: 40px 0;
}

.home-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
  color: var(--text);
  display: block;
}

a.home-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.home-card-soon {
  opacity: 0.6;
  cursor: default;
}

.home-card-icon {
  color: var(--primary);
  margin-bottom: 20px;
}

.home-card h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin-bottom: 12px;
  color: var(--primary);
}

.home-card p {
  color: var(--text-light);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* === Back to Top Button === */
.back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: background 0.2s, transform 0.2s, opacity 0.3s;
  z-index: 90;
  opacity: 1;
}

.back-to-top[hidden] {
  opacity: 0;
  pointer-events: none;
  display: flex;
}

.back-to-top:hover {
  background: var(--primary-light);
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .back-to-top {
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
  }
}

/* === Portion Edit Input === */
.portion-edit-input {
  width: 60px;
  text-align: center;
  padding: 4px 8px;
  font-size: 1.1rem;
  border-radius: 6px;
}

/* === Ingredient DB Recipe Count === */
.db-recipe-count {
  text-align: center;
}

.db-recipe-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary-bg);
  transition: background 0.2s;
}

.db-recipe-link:hover {
  background: var(--primary);
  color: #fff;
}

/* === Weekplanner === */
.weekplanner-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; background: var(--accent); color: #fff;
  border: none; border-radius: 6px; font-size: 0.82rem;
  font-family: var(--font-body); font-weight: 500;
  cursor: pointer; transition: background 0.2s;
}
.weekplanner-btn svg { flex-shrink: 0; }
.weekplanner-btn:hover { background: #4a7a3a; }

.weekplanner-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  z-index: 200; background: rgba(0,0,0,0.3);
}
.weekplanner-overlay[hidden] { display: none; }

.weekplanner-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 420px; max-width: 100%;
  background: var(--bg); box-shadow: -4px 0 24px rgba(0,0,0,0.15);
  display: flex; flex-direction: column;
  animation: slideInRight 0.25s ease;
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.weekplanner-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.weekplanner-header h2 {
  font-family: var(--font-display); font-size: 1.4rem; margin: 0; color: var(--text);
}
.weekplanner-close {
  background: none; border: none; font-size: 1.8rem;
  color: var(--text-muted); cursor: pointer; line-height: 1;
}
.weekplanner-close:hover { color: var(--text); }

.weekplanner-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

.weekplanner-day {
  margin-bottom: 10px; background: var(--card-bg);
  border-radius: 12px; border: 1px solid var(--border); overflow: hidden;
}
.weekplanner-day-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--primary-bg);
  font-weight: 600; font-size: 0.9rem; color: var(--text);
}
.weekplanner-day-count { font-size: 0.75rem; color: var(--text-muted); font-weight: 400; }

.weekplanner-day-meals { padding: 0 16px; }
.weekplanner-meal {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.weekplanner-meal:last-child { border-bottom: none; }
.weekplanner-meal-name { flex: 1; color: var(--text); }
.weekplanner-meal-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1.2rem; padding: 2px 6px; line-height: 1;
}
.weekplanner-meal-remove:hover { color: #e55; }

.weekplanner-add-btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 8px; border: none; background: none;
  color: var(--primary); font-size: 0.8rem; font-weight: 500;
  cursor: pointer; font-family: var(--font-body); border-top: 1px solid var(--border);
}
.weekplanner-add-btn:hover { background: var(--primary-bg); }

.weekplanner-picker { padding: 8px 16px 12px; }
.weekplanner-picker input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-family: var(--font-body); font-size: 0.85rem;
  box-sizing: border-box;
}
.weekplanner-picker input:focus { outline: none; border-color: var(--primary); }
.weekplanner-picker-results { max-height: 160px; overflow-y: auto; margin-top: 4px; }
.weekplanner-picker-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; border: none; background: none;
  font-family: var(--font-body); font-size: 0.85rem;
  cursor: pointer; border-radius: 6px; color: var(--text);
}
.weekplanner-picker-item:hover { background: var(--primary-bg); }
.weekplanner-picker-category { font-size: 0.7rem; color: var(--text-muted); margin-left: 6px; }

.weekplanner-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.weekplanner-footer .btn { font-size: 0.85rem; text-align: center; }

@media (max-width: 768px) {
  .weekplanner-panel { width: 100%; }
}
