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

:root {
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-400: #4ade80;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-800: #166534;
  --amber-400: #fbbf24;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Typography ===== */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }

/* ===== Buttons ===== */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.6em 1.2em;
  transition: background 0.2s, transform 0.1s;
}
button:active { transform: scale(0.97); }

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

.btn-icon {
  background: none;
  font-size: 1.4rem;
  padding: 0.3em;
  line-height: 1;
}

.btn-edit, .btn-delete, .btn-fav {
  padding: 0.5em 1em;
  border-radius: 8px;
  font-size: 0.9rem;
  touch-action: manipulation;
}
.btn-edit { background: var(--green-100); color: var(--green-800); }
.btn-delete { background: #fecaca; color: var(--red-600); min-width: 44px; min-height: 44px; padding: 0.5em 0.75em; }
.btn-fav { background: var(--gray-100); color: var(--gray-700); }
.btn-fav.liked { background: #fee2e2; color: var(--red-500); }

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

/* ===== Auth Overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--green-700);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s;
}
.overlay.active { display: flex; }
.overlay:not(.active) { display: none; }

.auth-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  width: min(400px, 90vw);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  text-align: center;
}
.auth-card h1 { margin-bottom: 1.5rem; color: var(--green-800); }

#auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--gray-200);
}
.auth-tab {
  flex: 1;
  padding: 0.6em;
  border-radius: 0;
  background: var(--gray-50);
  color: var(--gray-500);
  font-weight: 500;
}
.auth-tab.active {
  background: var(--green-600);
  color: #fff;
}

.auth-form {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}
.auth-form.active { display: flex; }
.auth-form input {
  padding: 0.75em;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}
.auth-form input:focus { outline: 2px solid var(--green-400); outline-offset: -2px; }
.auth-form button { padding: 0.8em; font-size: 1rem; }

.error-msg {
  color: var(--red-500);
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* ===== Header ===== */
header {
  background: var(--green-600);
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
header h1 { font-size: 1.3rem; white-space: nowrap; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.header-actions .btn-icon { color: #fff; font-size: 1.3rem; background: none; padding: 0.3em; line-height: 1; }
.header-actions .btn-primary { background: #fff; color: var(--green-700); font-weight: 600; }

.menu-wrapper { position: relative; }
.menu-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.5rem;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  min-width: 160px;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  z-index: 200;
}
.menu-dropdown a,
.menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5em 0.75em;
  border: none;
  border-radius: 8px;
  background: none;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--gray-700);
  cursor: pointer;
  text-decoration: none;
}
.menu-dropdown a:hover,
.menu-dropdown button:hover { background: var(--gray-100); }
.menu-theme-row {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem 0.75rem;
  justify-content: center;
}
.theme-btn {
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%; border: 2px solid transparent;
  background: none; font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.theme-btn.active { border-color: var(--green-500); background: var(--green-50); }

/* ===== Category Nav ===== */
#category-nav {
  display: flex;
  overflow-x: auto;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #fff;
  position: sticky;
  top: 52px; /* approx header height */
  z-index: 99;
  -webkit-overflow-scrolling: touch;
}
#category-nav::-webkit-scrollbar { display: none; }

.cat-tab {
  background: var(--gray-100);
  color: var(--gray-700);
  padding: 0.5em 1em;
  border-radius: 20px;
  white-space: nowrap;
  font-size: 0.9rem;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.cat-tab.active {
  background: var(--green-600);
  color: #fff;
}

/* ===== Recipe Grid ===== */
#recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1rem;
}
.empty-msg {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--gray-500);
  padding: 2rem;
}

/* ===== Recipe Card ===== */

/* Category color bars */
.recipe-card.reggeli { border-top: 4px solid #16a34a; }
.recipe-card.ebed { border-top: 4px solid #f59e0b; }
.recipe-card.vacsora { border-top: 4px solid #2563eb; }
.recipe-card.nasi { border-top: 4px solid #8b5cf6; }

.cat-tab[data-cat="reggeli"] { background: #dcfce7; color: #166534; }
.cat-tab[data-cat="reggeli"].active { background: #16a34a; color: #fff; }
.cat-tab[data-cat="ebed"] { background: #fef3c7; color: #92400e; }
.cat-tab[data-cat="ebed"].active { background: #f59e0b; color: #fff; }
.cat-tab[data-cat="vacsora"] { background: #dbeafe; color: #1e40af; }
.cat-tab[data-cat="vacsora"].active { background: #2563eb; color: #fff; }
.cat-tab[data-cat="nasi"] { background: #f3e8ff; color: #6b21a8; }
.cat-tab[data-cat="nasi"].active { background: #8b5cf6; color: #fff; }
.cat-tab[data-cat="__trash__"] { background: #f3f4f6; color: #6b7280; }
.cat-tab[data-cat="__trash__"].active { background: #6b7280; color: #fff; }

.recipe-card {
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}
.recipe-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.recipe-card:active { transform: scale(0.98); }

.recipe-card > img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  display: block;
  background: var(--gray-200);
  flex-shrink: 0;
}
.recipe-card .card-body {
  padding: 0.5rem 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.recipe-card .card-top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.recipe-card .card-name {
  font-weight: 600;
  font-size: 0.95rem;
}
.recipe-card .card-meta {
  font-size: 0.8rem;
  color: var(--gray-500);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.recipe-card .card-public-badge {
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-left: 0.35rem;
}
.recipe-card .card-author {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  padding: 0.15em 0.3em;
  border-radius: 12px;
  transition: background 0.15s;
}
.recipe-card .card-author:hover { background: var(--gray-100); }
.modal-author-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-200);
  vertical-align: middle;
  margin-right: 0.35rem;
}

.card-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-200);
  flex-shrink: 0;
}

/* Owner profile */
.owner-header {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}
.owner-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-200);
  flex-shrink: 0;
}
.owner-recipes {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.owner-recipe-card {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.owner-recipe-card:hover { background: var(--gray-50); }
.owner-recipe-card img {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--gray-200);
  flex-shrink: 0;
}
.owner-recipe-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.owner-recipe-info strong { font-size: 0.9rem; }
.owner-recipe-info span { font-size: 0.8rem; color: var(--gray-500); }

.nav-spacer { flex: 1; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--gray-700);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.toggle-label input[type="checkbox"] {
  accent-color: var(--green-600);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--gray-700);
  cursor: pointer;
  padding: 0.5em 0;
}
.checkbox-label input[type="checkbox"] {
  accent-color: var(--green-600);
  width: 1.1em;
  height: 1.1em;
}

/* ===== Modal ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
}
.modal.active { display: flex; align-items: flex-start; justify-content: center; padding-top: 2rem; }

.modal-content {
  background: #fff;
  border-radius: var(--radius);
  width: min(600px, 100%);
  padding: 1.5rem;
  position: relative;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  color: var(--gray-500);
  z-index: 5;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  background: var(--gray-50);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--gray-200); }

.modal-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 1rem;
  background: var(--gray-200);
}

.modal-meta {
  font-size: 0.9rem;
  color: var(--gray-500);
  margin-bottom: 0.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.modal-actions .btn-delete {
  margin-left: auto;
  flex-shrink: 0;
}

/* Free text blocks */
.free-text {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--gray-700);
  margin: 0.25rem 0 1rem;
  padding-left: 0.25rem;
}

/* ===== Form ===== */
#recipe-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
#recipe-form label {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--gray-700);
  margin-top: 0.3rem;
}
#recipe-form input[type="text"],
#recipe-form textarea,
#recipe-form select {
  padding: 0.65em;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}
#recipe-form textarea { resize: vertical; }
#recipe-form input:focus,
#recipe-form textarea:focus,
#recipe-form select:focus { outline: 2px solid var(--green-400); outline-offset: -2px; }
#recipe-form input[type="file"] { font-size: 0.9rem; }

.preview-img {
  width: 100%;
  max-height: 150px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--gray-200);
}

/* ===== Ingredient List ===== */
.ingredient-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  min-height: 2rem;
}
.ingredient-item {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.6em 0.6em;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 0.95rem;
  transition: background 0.15s, opacity 0.15s;
  min-height: 2.5em;
}
.ingredient-item.dragging {
  opacity: 0.4;
}
.ingredient-item.drag-over {
  border-color: var(--green-400);
  border-style: dashed;
  background: var(--green-50);
}
.ingredient-item .drag-handle {
  color: var(--green-600);
  font-weight: 700;
  font-size: 1.1rem;
  min-width: 2em;
  text-align: center;
  line-height: 1.4;
  cursor: grab;
  user-select: none;
  touch-action: none;
  background: var(--gray-200);
  border-radius: 4px;
  padding: 0.15em 0.3em;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ingredient-item .drag-handle:active { cursor: grabbing; }
.ingredient-item .ingredient-text {
  flex: 1;
  word-break: break-word;
}
.ingredient-item .ingredient-edit {
  background: none; border: none;
  font-size: 0.85rem; cursor: pointer;
  padding: 0.15em 0.3em; line-height: 1; border-radius: 4px;
  opacity: 0.5;
  flex-shrink: 0;
}
.ingredient-item .ingredient-edit:hover { opacity: 1; background: var(--gray-100); }
.ingredient-item .ingredient-edit.saving { opacity: 1; background: var(--green-100); color: var(--green-700); }
.ingredient-item .ingredient-remove {
  background: none;
  border: none;
  color: var(--red-500);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.2em;
  line-height: 1;
  border-radius: 4px;
}
.ingredient-item .ingredient-remove:hover {
  background: #fecaca;
}
.ingredient-input-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.ingredient-input-top,
.ingredient-input-bottom {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.ingredient-input-row input {
  padding: 0.65em;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}
.ingredient-input-row input:focus {
  outline: 2px solid var(--green-400);
  outline-offset: -2px;
}
.ingredient-input-row select {
  padding: 0.65em;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
}
.ingredient-input-row select:focus {
  outline: 2px solid var(--green-400);
  outline-offset: -2px;
}
.ingredient-input-row button {
  background: var(--green-100);
  color: var(--green-800);
  padding: 0.5em 1em;
  border-radius: 8px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.ingredient-input-row button:hover {
  background: var(--green-400);
  color: #fff;
}
.ing-qty { width: 80px; flex: none !important; }
.ing-unit { width: 80px; flex: none; }
.ing-name { flex: 1; }

/* Inline edit fields for ingredients */
.ingredient-edit-fields {
  display: flex;
  gap: 0.35rem;
  flex: 1;
  align-items: center;
}
.ingredient-edit-fields .ing-qty,
.ingredient-edit-fields .ing-unit,
.ingredient-edit-fields .ing-name {
  padding: 0.25em 0.35em;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
}
.ingredient-edit-fields .ing-qty { width: 55px; flex: none; }
.ingredient-edit-fields .ing-unit { width: 58px; flex: none; }
.ingredient-edit-fields .ing-name { flex: 1; }

/* Trash actions */
.trash-actions { display: flex; gap: 0.35rem; margin-top: 0.35rem; }
.btn-danger { background: #fecaca; color: var(--red-600); }

/* Ingredient table (read-only in modal) */
.ingredient-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.25rem 0 1rem;
  font-size: 0.95rem;
}
.ingredient-table td {
  padding: 0.35em 0.5em;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: top;
}
.ingredient-table tr:nth-child(even) td {
  background: var(--gray-50);
}
.ing-qty-cell {
  width: 1%;
  white-space: nowrap;
  text-align: right;
  font-weight: 600;
  color: var(--gray-700);
  padding-right: 0.3em !important;
}
.ing-name-cell {
  color: var(--gray-700);
}

/* Step list (read-only in modal) */
#modal-steps.ingredient-detail-list {
  list-style: decimal;
}
.ingredient-detail-list {
  list-style: disc;
  padding-left: 1.5em;
  margin: 0.25rem 0 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--gray-700);
}

/* ===== Responsive ===== */

/* Tablet and up */
@media (min-width: 768px) {
  header h1 { font-size: 1.5rem; }
  #category-nav { justify-content: center; }
  #recipe-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    padding: 1.5rem;
    gap: 1.5rem;
  }
  .recipe-card > img { height: 120px; }
  .modal.active { padding-top: 3rem; }
}

/* Desktop */
@media (min-width: 1024px) {
  #recipe-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    max-width: 1200px;
    margin: 0 auto;
  }
  .modal-content { padding: 2rem; }
}

/* ===== Search Bar ===== */
.search-bar {
  background: #fff;
  padding: 1rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.search-row {
  display: flex;
  gap: 0.5rem;
}
.search-row input {
  flex: 1;
  padding: 0.65em;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}
.search-row input:focus { outline: 2px solid var(--green-400); outline-offset: -2px; }
.search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
.search-filter { flex: 1; min-width: 150px; }
.search-filter label { font-size: 0.8rem; color: var(--gray-500); display: block; margin-bottom: 0.25rem; }
.range-inputs { display: flex; gap: 0.35rem; align-items: center; }
.range-inputs input {
  width: 70px;
  padding: 0.4em;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
.range-inputs input:focus { outline: 2px solid var(--green-400); outline-offset: -2px; }
.search-filter select {
  width: 100%;
  padding: 0.4em;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
#search-btn { align-self: flex-start; }

.btn-sm { padding: 0.4em 0.8em; font-size: 0.85rem; border-radius: 8px; border: none; cursor: pointer; font-family: inherit; }
.btn-outline { background: none; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }

/* ===== Calorie Calculator ===== */
.calorie-calc {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: var(--gray-50);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin: 0.5rem 0 1rem;
  font-size: 0.9rem;
}
.calorie-servings { display: flex; align-items: center; gap: 0.35rem; }
.calorie-servings button { width: 28px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; font-size: 1rem; }

/* ===== Tags ===== */
.tag-badge {
  display: inline-block;
  background: var(--green-100);
  color: var(--green-800);
  font-size: 0.75rem;
  padding: 0.15em 0.5em;
  border-radius: 10px;
  margin-right: 0.25rem;
}
.card-tags { margin-bottom: 0.25rem; min-height: 0; }
.card-tags-details { margin-bottom: 0.25rem; font-size: 0.75rem; }
.card-tags-details summary { cursor: pointer; color: var(--gray-400); }
.card-tags-details .card-tags { margin-top: 0.3rem; }
.tag-list { min-height: 0; margin-bottom: 0.5rem; }
.tag-select { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.tag-check { font-size: 0.85rem; padding: 0.25em 0; margin: 0; }
.tag-manage-list { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.tag-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--gray-100);
  padding: 0.25em 0.5em;
  border-radius: 8px;
  font-size: 0.85rem;
}
.tag-item button { font-size: 0.75rem; padding: 0.1em 0.3em; background: none; border: none; cursor: pointer; color: var(--red-500); }
.tag-item button:hover { background: #fecaca; border-radius: 4px; }

/* Crop controls */
.crop-container { width: 100%; margin-top: 0.5rem; }
.crop-wrapper {
  position: relative;
  width: 100%;
  touch-action: none;
  overflow: hidden;
  border-radius: 8px;
  border: 2px solid var(--gray-300);
}
.crop-wrapper img {
  width: 100%;
  display: block;
}
.crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.crop-square {
  position: absolute;
  aspect-ratio: 1;
  touch-action: none;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  cursor: grab;
  border: 2px solid #fff;
  border-radius: 4px;
}
.crop-square:active { cursor: grabbing; }
.crop-hint { font-size: 0.75rem; color: var(--gray-500); text-align: center; margin-top: 0.3rem; }

/* ===== Themes ===== */
/* Beige theme */
body.theme-beige {
  --green-50: #fefce8;
  --green-100: #fef9c3;
  --green-400: #f59e0b;
  --green-500: #d97706;
  --green-600: #b45309;
  --green-700: #92400e;
  --green-800: #78350f;
  background: #fefce8;
}
body.theme-beige header { background: var(--green-600); }
body.theme-beige .cat-tab { background: #fffffb; color: var(--gray-700); }
body.theme-beige .cat-tab.active { background: var(--green-600); color: #fff; }
body.theme-beige .btn-primary { background: var(--green-600); color: #fff; }
body.theme-beige .btn-primary:hover { background: var(--green-700); }
body.theme-beige #auth-overlay { background: var(--green-700); }
body.theme-beige #auth-tabs .auth-tab.active { background: var(--green-600); }
body.theme-beige .overlay { background: var(--green-700); }
body.theme-beige #category-nav { background: transparent; }
body.theme-beige .recipe-card { background: #fffffb; }
body.theme-beige .modal-content { background: #fffffb; }
body.theme-beige .auth-card { background: #fffffb; }
body.theme-beige .search-bar { background: #fffffb; }
body.theme-beige .ingredient-item { background: #fffffb; }

/* Dark theme */
body.theme-dark {
  --green-50: #1e2e1e;
  --green-100: #243324;
  --green-400: #4ade80;
  --green-500: #22c55e;
  --green-600: #166534;
  --green-700: #14532d;
  --green-800: #bef264;
  --gray-50: #262636;
  --gray-100: #2e2e40;
  --gray-200: #353550;
  --gray-300: #454560;
  --gray-500: #a8a8c0;
  --gray-700: #d0d0e0;
  --gray-800: #e8e8f0;
  --gray-900: #f4f4f8;
  --red-500: #f87171;
  --red-600: #ef4444;
  --amber-400: #fbbf24;
  background: #1e1e32;
  color: #e8e8f0;
}
body.theme-dark header { background: #1e3a24; }
body.theme-dark .cat-tab { background: #2e2e44; color: #a8a8c0; }
body.theme-dark .cat-tab.active { background: var(--green-600); color: #fff; }
body.theme-dark #category-nav { background: transparent; }
body.theme-dark .recipe-card { background: #2a2a44; }
body.theme-dark .modal-content { background: #2a2a44; color: #d0d0e0; }
body.theme-dark .search-bar { background: #2a2a44; }
body.theme-dark input, body.theme-dark textarea, body.theme-dark select { background: #323250; color: #d0d0e0; border-color: #454560; }
body.theme-dark .auth-card { background: #2a2a44; }
body.theme-dark .auth-form input { background: #323250; color: #d0d0e0; border-color: #454560; }
body.theme-dark .btn-outline { border-color: #374151; color: #9ca3af; }
body.theme-dark .btn-outline:hover { background: #1e2e3e; }
body.theme-dark .ingredient-item { background: #1a1a2e; border-color: #374151; }
body.theme-dark .admin-section { background: #12121e; }
body.theme-dark .admin-table th { border-color: #374151; }
body.theme-dark .preview-img { border-color: #374151; }
body.theme-dark .calorie-calc { background: #1a1a2e; }
body.theme-dark .card-author:hover { background: #1e2e3e; }
body.theme-dark .tag-badge { background: #1a3a1a; color: #4ade80; }
body.theme-dark #auth-overlay { background: #0f1a0f; }
body.theme-dark .checkbox-label { color: #d1d5db; }

/* Photo upload button */
.photo-upload {
  width: 100px; height: 100px;
  border: 2px dashed var(--gray-300);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  overflow: hidden;
  margin-bottom: 0.75rem;
  background: var(--gray-100);
  transition: border-color 0.2s;
}
.photo-upload:hover { border-color: var(--green-500); }
.photo-preview {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  color: var(--gray-400);
  font-size: 0.8rem;
  line-height: 1.4;
}
.photo-preview img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-upload.has-image {
  border-style: solid;
  border-color: var(--green-500);
}
body.theme-dark .toggle-label { color: #d1d5db; }.cuisine-badge { font-size: 0.7rem; background: var(--green-100); color: var(--green-700); padding: 0.1em 0.4em; border-radius: 8px; }
.card-allergens { display: block; font-size: 0.7rem; color: var(--gray-500); margin-bottom: 0.2rem; }

/* DEV mode — blue header */
body[data-mode=dev] header { background: #2563eb !important; }
body[data-mode=dev] .btn-primary { background: #2563eb; }
body[data-mode=dev] input:focus, body[data-mode=dev] select:focus { outline-color: #2563eb; }
body[data-mode=dev] .cat-tab.active { border-bottom-color: #2563eb; color: #2563eb; }
