:root {
  --bg: #faf6f0;
  --bg-card: #ffffff;
  --text: #3a2e26;
  --text-muted: #8a7a6d;
  --accent: #c1602e;
  --accent-dark: #9c4a20;
  --border: #e8ddd0;
  --danger: #b3392c;
}

* { box-sizing: border-box; }

/* Guards against any component rule (e.g. `.recipe-card { display: flex }`)
   accidentally winning over the hidden attribute on same-specificity grounds —
   filtering relies on `.hidden = true` actually hiding the element. */
[hidden] { display: none !important; }

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

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-dark);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.site-nav a {
  margin-left: 1.5rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
}
.site-nav a:hover { color: var(--accent); }

.site-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}

@media (max-width: 600px) {
  .site-header { padding: 0.75rem 1rem; }
  .brand { font-size: 1.2rem; }
  .site-nav a { margin-left: 1rem; font-size: 0.9rem; }
  .site-main { padding: 1rem; }
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 { margin: 0; }
.page-sub { color: var(--text-muted); margin: 0; }

/* ---- List page ---- */

.list-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 720px) {
  .list-layout { grid-template-columns: 1fr; }
}

.filter-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  position: sticky;
  top: 1rem;
}
@media (max-width: 720px) {
  .filter-panel { position: static; }
}
.filter-panel h2 { margin-top: 0; font-size: 1rem; }
.filter-hint { color: var(--text-muted); font-size: 0.85rem; }

#ingredient-search {
  width: 100%;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.ingredient-checklist {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ingredient-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.filter-panel h2 {
  margin-top: 1.25rem;
}
.filter-panel h2:first-child {
  margin-top: 0;
}

.label-checklist {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.label-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.label-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.4rem 0;
}

.label-badge {
  display: inline-block;
  background: #f1e3d3;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 0.15rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

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

.recipe-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.recipe-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(60, 40, 20, 0.1);
}

.recipe-photo {
  aspect-ratio: 4 / 3;
  flex-shrink: 0;
  background: #f1e8dc;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.recipe-photo img { width: 100%; height: 100%; object-fit: cover; }

.photo-placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.recipe-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 0.85rem 1rem 1rem;
}
.recipe-info h3 { margin: 0 0 0.35rem; font-size: 1.05rem; }
.recipe-info p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.recipe-info .label-badges { margin-top: auto; padding-top: 0.6rem; }

.empty-state { color: var(--text-muted); grid-column: 1 / -1; }

/* ---- Detail page ---- */

.back-link { display: inline-block; margin-bottom: 1rem; text-decoration: none; }

.recipe-detail {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 2rem;
}
@media (max-width: 720px) {
  .recipe-detail { grid-template-columns: 1fr; }
}

.recipe-detail-photo {
  aspect-ratio: 4 / 3;
  background: #f1e8dc;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.recipe-detail-photo img { width: 100%; height: 100%; object-fit: cover; }

.recipe-detail-body h1 { margin-top: 0; }
.recipe-description { color: var(--text-muted); }

.portion-selector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 1.25rem 0;
}
.portion-label { font-weight: 600; }
.portion-buttons { display: flex; gap: 0.4rem; }
.portion-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  font-size: 0.95rem;
}
.portion-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.portion-custom {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.portion-custom input {
  width: 70px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.ingredient-list { padding-left: 1.1rem; }
.ingredient-list li { margin-bottom: 0.3rem; }
.step-list li { margin-bottom: 0.6rem; }

/* ---- Admin ---- */

.admin-header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; }

.button-link {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 600;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 0;
  font-size: 0.95rem;
  text-decoration: underline;
}
.link-button.danger { color: var(--danger); }

.inline-form { display: inline; }

.table-scroll {
  overflow-x: auto;
  border-radius: 12px;
}

.admin-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}
.admin-row-actions { display: flex; gap: 0.75rem; }

.admin-login-wrap { max-width: 320px; margin: 3rem auto; text-align: center; }
.admin-login-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
.admin-login-form input {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.admin-login-form button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.form-error { color: var(--danger); font-weight: 600; }

.recipe-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 640px;
}
.recipe-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.recipe-form input,
.recipe-form textarea {
  font-weight: normal;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
}
.narrow-field { max-width: 160px; }

.form-section-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}
.recipe-form .label-checklist {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.current-photo { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; }
.current-photo img { width: 100px; height: 75px; object-fit: cover; border-radius: 8px; }
.remove-photo-label { font-weight: normal; font-size: 0.85rem; display: flex; align-items: center; gap: 0.35rem; }

.ingredient-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 2fr auto;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.step-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: start;
}
.remove-row-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--danger);
  width: 36px;
  min-height: 40px;
}

@media (max-width: 600px) {
  .ingredient-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "name name"
      "qty unit"
      "note note"
      "remove remove";
  }
  .ingredient-row input[name="ingredient_name"] { grid-area: name; }
  .ingredient-row input[name="ingredient_qty"] { grid-area: qty; }
  .ingredient-row input[name="ingredient_unit"] { grid-area: unit; }
  .ingredient-row input[name="ingredient_note"] { grid-area: note; }
  .ingredient-row .remove-row-btn { grid-area: remove; width: 100%; }
}

.form-actions { margin-top: 0.5rem; }
.form-actions button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.4rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
}
