:root {
  --primary: #2d6a4f;
  --primary-dark: #1b4332;
  --primary-light: #40916c;
  --bg: #f0f7f4;
  --card-bg: #ffffff;
  --text: #1b2a24;
  --text-light: #5a7a6e;
  --danger: #e63946;
  --warning: #f4a261;
  --gold: #ffd166;
  --shadow: 0 4px 12px rgba(27, 67, 50, 0.12);
  --shadow-hover: 0 8px 24px rgba(27, 67, 50, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: all 0.25s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 40px;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 20px 16px;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.app-logo {
  font-size: 1.5rem;
  font-weight: 700;
}

.diabetes-badge {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Container */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* Stats Bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Search */
.search-section {
  margin-bottom: 16px;
}

.search-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: 2px solid #d8e8e0;
  border-radius: var(--radius-sm);
  outline: none;
  transition: var(--transition);
  background: var(--card-bg);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.filter-select {
  padding: 10px 14px;
  border: 2px solid #d8e8e0;
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  font-size: 0.95rem;
  outline: none;
  cursor: pointer;
}

.fav-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--text);
}

.fav-filter input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.btn-secondary {
  background: #e8efeb;
  color: var(--text);
  border: none;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: #d6e2db;
}

.add-btn {
  width: 100%;
  margin-bottom: 20px;
  padding: 15px;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
}

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

/* Recipe Card */
.recipe-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.recipe-title {
  font-size: 1.1rem;
  line-height: 1.3;
  flex: 1;
  color: var(--primary-dark);
}

.fav-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #ccc;
  transition: var(--transition);
  line-height: 1;
  padding: 0;
}

.fav-btn.favorited {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 209, 102, 0.5);
}

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

.meal-badge {
  align-self: flex-start;
  background: var(--primary-light);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
}

.method-badge {
  align-self: flex-start;
  background: #e8b4b8;
  color: #7a2e36;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
}

.recipe-ingredients-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ingredient-line {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.3;
}

.ingredient-more {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}

.temp-badge {
  background: #f4e1c1;
  color: #8a5a2b;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 8px;
  font-weight: 600;
}

.recipe-desc {
  color: var(--text-light);
  font-size: 0.9rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.nutrition-item {
  background: var(--bg);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--text);
}

.tags-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  background: #fff3d6;
  color: #8a6d1f;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 8px;
  font-weight: 600;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  border-top: 1px solid #eceff0;
  padding-top: 12px;
}

.source-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.source-link:hover {
  text-decoration: underline;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.view-btn {
  background: none;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
  color: var(--primary);
}

.view-btn:hover {
  background: var(--primary);
  color: #fff;
}

.edit-btn {
  background: none;
  border: 1px solid #d8e8e0;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
}

.edit-btn:hover {
  background: var(--bg);
}

.delete-btn {
  background: none;
  border: 1px solid #f5d5d8;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
}

.delete-btn:hover {
  background: #fdedee;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--card-bg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 28px 24px;
  position: relative;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-light);
}

.modal h2 {
  margin-bottom: 24px;
  color: var(--primary-dark);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #d8e8e0;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  background: var(--card-bg);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Dynamic list (ingredients / steps) */
.dynamic-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.list-item-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.list-item-input {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid #d8e8e0;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  background: var(--card-bg);
}

.list-item-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

.list-item-remove {
  width: 40px;
  height: 40px;
  border: 1px solid #f5d5d8;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--danger);
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.list-item-remove:hover {
  background: #fdedee;
}

.btn-add-item {
  width: 100%;
  background: none;
  border: 2px dashed var(--primary-light);
  color: var(--primary);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-add-item:hover {
  background: var(--bg);
  border-color: var(--primary);
}

/* Stage row (temperature / time / action) */
.stage-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.stage-input {
  padding: 10px 12px;
  border: 2px solid #d8e8e0;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  background: var(--card-bg);
}

.stage-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

.stage-input.temp {
  width: 110px;
}

.stage-input.time {
  width: 110px;
}

.stage-input.action {
  flex: 1;
  min-width: 160px;
}

.temp-more {
  background: #e8efeb;
  color: var(--primary-dark);
}

/* Detail view: stages */
.stage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stage-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid #d8e8e0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.95rem;
}

.stage-num {
  font-weight: 700;
  color: var(--primary);
  min-width: 24px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.form-actions button {
  flex: 1;
}

/* Nutrition collapsible section (form) */
.nutrition-section {
  margin-bottom: 16px;
  border: 1px solid #d8e8e0;
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--bg);
}

.nutrition-section summary {
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--primary-dark);
  padding: 4px 0;
}

.nutrition-section .form-row {
  margin-top: 12px;
}

/* Detail Modal */
.detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.detail-badges span {
  background: var(--primary-light);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 14px;
}

.detail-temp {
  margin: 8px 0;
  font-size: 0.9rem;
  color: #8a5a2b;
  background: #f4e1c1;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
}

.detail-source {
  margin: 8px 0;
}

.detail-source a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.detail-source a:hover {
  text-decoration: underline;
}

.detail-section {
  margin: 16px 0;
  border-top: 1px solid #eceff0;
  padding-top: 14px;
}

.detail-section h3 {
  font-size: 1rem;
  color: var(--primary-dark);
  margin-bottom: 10px;
}

.ingredient-list {
  list-style: none;
  padding: 0;
}

.ingredient-list li {
  padding: 6px 0;
  border-bottom: 1px dashed #eceff0;
  font-size: 0.95rem;
}

.step-list {
  padding-left: 20px;
}

.step-list li {
  padding: 5px 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

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

.detail-nutrition span {
  background: var(--bg);
  border: 1px solid #d8e8e0;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-dark);
  color: #fff;
  padding: 14px 24px;
  border-radius: 30px;
  box-shadow: var(--shadow-hover);
  font-weight: 500;
  z-index: 2000;
  animation: toastIn 0.3s ease;
  white-space: nowrap;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast.error {
  background: var(--danger);
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #d8e8e0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.empty-state h2 {
  margin-bottom: 8px;
  color: var(--text);
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Responsive */
@media (min-width: 640px) {
  .modal {
    border-radius: var(--radius);
    margin-bottom: 8vh;
  }
}

@media (max-width: 480px) {
  .stats-bar {
    gap: 8px;
  }

  .stat-card {
    padding: 12px 8px;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .nutrition-item {
    font-size: 0.7rem;
    padding: 3px 8px;
  }
}