:root {
  --cream: #fbf6ee;
  --paper: #ffffff;
  --ink: #2f2620;
  --muted: #7a6f61;
  --terracotta: #c1613f;
  --terracotta-dark: #a34f31;
  --sage: #7f9473;
  --border: #e8ddcb;
  --danger: #b5443a;
  /* Text color for content sitting on a --terracotta/--terracotta-dark/
     --sage fill. Defaults to white (works fine against every current
     cookbook's accent) but a cookbook with a light/bright accent - e.g.
     D1's green, ~1.8:1 contrast with white text vs ~12:1 with black -
     overrides this per-request in base.html rather than every fill
     staying hardcoded to white. */
  --on-accent: #fff;
  --radius: 14px;
  --max-width: 720px;
}

* { box-sizing: border-box; }

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

a { color: var(--terracotta-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 13px;
  background: var(--paper);
  border-bottom: 3px solid;
  border-bottom-color: var(--terracotta-dark);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.brand-logo { width: 84px; height: 84px; border-radius: 18px; display: block; }
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-title { font-weight: 700; font-size: 1.05rem; }
.brand-subtitle { font-weight: 400; font-size: 0.78rem; color: var(--muted); }
.site-header .add-link {
  background: var(--terracotta);
  color: var(--on-accent);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}
.site-header .add-link:hover { background: var(--terracotta-dark); text-decoration: none; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 24px 16px;
}
.footer-icon { width: 24px; height: 24px; border-radius: 6px; display: block; }
.site-footer .share-link {
  background: transparent;
  border: 1.5px solid var(--terracotta);
  color: var(--terracotta-dark);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}
.site-footer .share-link:hover { background: var(--terracotta); color: var(--on-accent); }
.site-footer .share-link.copied { background: var(--sage); border-color: var(--sage); color: var(--on-accent); }

.flash-wrap { max-width: var(--max-width); margin: 12px auto 0; padding: 0 16px; }
.flash {
  background: #fff3e0;
  border: 1px solid #f0cf9f;
  color: #6b4a1c;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 0.92rem;
}

h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.1rem; margin: 20px 0 8px; }
.muted { color: var(--muted); font-size: 0.9rem; }
.small { font-size: 0.8rem; }
.hint { color: var(--muted); font-weight: 400; font-size: 0.85rem; }

/* Search + filters: one wrapping row of controls instead of ~31 chips */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.filter-search {
  flex: 1 1 100%;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: var(--paper);
  color: var(--ink);
}
/* The controls sit on their own line and share it, wrapping only if they must. */
.filter-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.filter-select {
  flex: 0 0 auto;
  width: auto;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  max-width: 100%;
}
.filter-select:hover { border-color: var(--terracotta); }
/* Only an actually-applied filter goes navy. The class is set server-side so
   this holds without JavaScript. */
.filter-select.filter-on {
  background: var(--terracotta-dark);
  color: var(--on-accent);
  border-color: var(--terracotta-dark);
}

.filter-dropdown { position: relative; flex: 0 0 auto; }
.filter-dropdown > summary {
  list-style: none;
  white-space: nowrap;
  display: inline-block;
}
.filter-dropdown > summary::-webkit-details-marker { display: none; }
.filter-dropdown > summary::after { content: " ▾"; }
.filter-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.filter-menu-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.9rem;
  cursor: pointer;
}
.filter-apply {
  margin-top: 8px;
  width: 100%;
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  background: var(--terracotta);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.filter-go {
  padding: 9px 16px;
  border-radius: 999px;
  border: none;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.filter-clear {
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: underline;
  white-space: nowrap;
}

/* Recipe grid */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.recipe-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
.recipe-card:hover { text-decoration: none; border-color: var(--terracotta); }
/* margin-top: auto pushes the photo to the bottom of the card. .recipe-grid
   is display:grid, so cards in the same row already stretch to match the
   tallest one; .recipe-card is already a flex column - so a card with a
   short title/byline just gets empty space above its photo instead of the
   photo floating high, and every photo in a row lands on the same baseline
   regardless of how much text sits above it. */
.recipe-card-photo { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: var(--border); margin-top: auto; }
.recipe-card-body { padding: 10px 12px; }
.recipe-card-body h3 { margin: 4px 0; font-size: 1rem; }

.badge {
  display: inline-block;
  background: var(--sage);
  color: var(--on-accent);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
}
.badge-muted { background: var(--muted); }
.badge-cuisine {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  margin-left: 4px;
}

.empty-state { color: var(--muted); padding: 32px 0; text-align: center; }

/* Recipe detail */
.back-link { display: inline-block; margin-bottom: 12px; }
.recipe-detail-photo { width: 100%; border-radius: var(--radius); margin-bottom: 12px; aspect-ratio: 4/3; object-fit: cover; }
.story {
  background: var(--paper);
  border-left: 4px solid var(--terracotta);
  padding: 10px 16px;
  margin: 12px 0;
  border-radius: 0 10px 10px 0;
  font-style: italic;
}
.ingredient-list, .instruction-list { padding-left: 20px; }
.ingredient-list li, .instruction-list li { margin-bottom: 6px; }
.ingredient-header {
  list-style: none;
  margin-left: -20px;
  font-weight: 700;
  margin-top: 10px;
}
.ingredient-header:first-child { margin-top: 0; }
.print-btn {
  margin-top: 20px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--paper);
}
@media print { .site-header, .site-footer, .no-print, .back-link { display: none; } }

/* Forms */
form label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 12px;
}
form input[type=text], form input[type=password], form input[type=search],
form input[type=file], form select, form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
  font-family: inherit;
  background: var(--paper);
  color: var(--ink);
}
form textarea { resize: vertical; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row label { flex: 1 1 140px; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: -4px 0 16px; }
.checkbox-group .checkbox-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  margin-bottom: 0;
}
.checkbox-group .checkbox-option input[type=checkbox] { width: auto; margin: 0; }

.primary-btn, .secondary-btn, .danger-btn {
  padding: 12px 20px;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  display: inline-block;
}
.primary-btn { background: var(--terracotta); color: var(--on-accent); }
.primary-btn:hover { background: var(--terracotta-dark); text-decoration: none; }
.secondary-btn { background: var(--paper); color: var(--ink); border: 1px solid var(--border); }
.danger-btn { background: #fbeae7; color: var(--danger); border: 1px solid #f2c9c2; }

.is-loading { cursor: wait; opacity: 0.8; padding-left: 2.5em; position: relative; }
.is-loading::before {
  content: "";
  position: absolute;
  left: 1em;
  top: 50%;
  width: 1em;
  height: 1em;
  margin-top: -0.5em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
.small { padding: 6px 12px; font-size: 0.8rem; }

/* Submit page tabs */
.tab-row { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--paper);
  font-weight: 600;
  cursor: pointer;
}
.tab-btn.tab-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab-panel { display: none; }
.tab-panel.tab-panel-active { display: block; }

/* Confirmation */
.confirmation { text-align: center; padding: 40px 16px; }
.confirmation-icon { font-size: 3rem; margin-bottom: 8px; }
.confirmation-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

/* Admin */
.admin-nav { display: flex; gap: 16px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); font-size: 0.92rem; flex-wrap: wrap; }
.admin-nav-logout { margin-left: auto; color: var(--muted); }
.admin-login { max-width: 320px; margin: 40px auto; }
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-list-item {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--ink);
}
.admin-list-item:hover { border-color: var(--terracotta); text-decoration: none; }
.admin-review { display: flex; flex-direction: column; gap: 24px; }
.source-photo, .source-pdf { width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.source-pdf { height: 500px; }
.source-media-gallery {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 16px 0;
}
.source-media {
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.admin-toolbar h2 {
  margin: 0;
  flex: 1;
}
.check-formatting-form {
  margin: 0;
  flex-shrink: 0;
}
.admin-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.welcome-banner {
  background: var(--paper);
  border: 1px solid var(--border);
  border-left: 4px solid var(--terracotta);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
  color: var(--ink);
  line-height: 1.5;
}
.proofreading-notes {
  background: #fdf3e7;
  border: 1px solid var(--border);
  border-left: 4px solid var(--terracotta);
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 20px;
}
.proofreading-notes h3 { margin: 0 0 6px; font-size: 0.95rem; }
.proofreading-list { margin: 0; padding-left: 0; list-style: none; }
.proofreading-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 0;
}
.proofreading-item .issue-text {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.4;
}
.apply-fix-form {
  margin: 0;
  flex-shrink: 0;
}
.apply-fix-btn {
  padding: 4px 10px;
  background: var(--terracotta);
  color: var(--on-accent);
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.apply-fix-btn:hover {
  background: var(--terracotta-dark);
}
.apply-fix-btn:active {
  opacity: 0.8;
}

/* Fix preview screen */
.fix-preview-container { max-width: var(--max-width); margin: 0 auto; padding: 16px; }
.fix-preview-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.fix-issue {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.fix-issue h2 { margin: 0 0 8px; font-size: 1rem; }
.issue-text {
  background: #fdf3e7;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 500;
  display: block;
}
.fix-field-info {
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.field-badge {
  background: var(--terracotta-dark);
  color: var(--on-accent);
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.85rem;
}
.fix-original, .fix-proposed {
  margin-bottom: 20px;
}
.fix-original h3, .fix-proposed h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}
.code-block {
  background: #f5f5f5;
  border-left: 3px solid var(--terracotta);
  padding: 12px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}
.explanation {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
}
.fix-options {
  margin-bottom: 20px;
}
.fix-options h3 { margin: 0 0 8px; font-size: 0.95rem; }
.fix-options-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.option-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fafafa;
  cursor: pointer;
  transition: background 0.2s;
}
.option-card:hover {
  background: #f0f0f0;
}
.option-card input[type="radio"]:checked ~ label {
  color: var(--terracotta-dark);
  font-weight: 600;
}
.option-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.option-header label {
  flex: 1;
  margin: 0;
  cursor: pointer;
  font-size: 0.9rem;
}
.option-text {
  margin-top: 8px;
}
/* Honeypot: off-screen rather than display:none, which some bots skip. */
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.recipe-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 20px; }
.suggest-link {
  font-size: 0.9rem;
  color: var(--terracotta-dark);
  border-bottom: 1px dashed var(--terracotta);
}
.suggest-link:hover { text-decoration: none; border-bottom-style: solid; }
.soft-rule { border: none; border-top: 1px solid var(--border); margin: 24px 0 8px; }

.snippet-diff {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}
.snippet-old, .snippet-new {
  padding: 8px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.snippet-old { background: #fdeceb; color: #7d2b23; }
.snippet-new { background: #eaf5e8; color: #2f5427; }
.snippet-removed { font-style: italic; opacity: 0.85; }

.full-field-check { margin-top: 12px; }
.full-field-check summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 4px 0;
}
.field-compare { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.field-compare h4 { margin: 0 0 4px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
@media (min-width: 720px) {
  .field-compare { flex-direction: row; }
  .field-compare > div { flex: 1; min-width: 0; }
}

.error-message {
  background: #fee;
  border: 1px solid #fcc;
  border-radius: 6px;
  padding: 12px;
  color: var(--danger);
  margin-bottom: 16px;
}
.button-group {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.button-group form {
  margin: 0;
}
.fix-context {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 20px;
}
.fix-context h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}
.context-item {
  font-size: 0.85rem;
  margin-bottom: 4px;
}

/* Ratings & reviews */
.star-display { color: var(--terracotta-dark); letter-spacing: 1px; }
.recipe-meta { display: flex; gap: 16px; color: var(--muted); font-size: 0.9rem; margin: 6px 0 0; }
.rating-summary { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.95rem; margin: 4px 0 16px; }
.rating-summary-small { font-size: 0.85rem; margin: 4px 0 0; }

.reviews-section { margin-top: 40px; border-top: 1px solid var(--border); padding-top: 24px; }
.review-list { list-style: none; padding: 0; margin: 0 0 24px; display: flex; flex-direction: column; gap: 16px; }
.review { background: var(--paper); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.review p { margin: 6px 0 0; }
.review-admin-delete { display: inline; margin-top: 6px; }
.link-btn { background: none; border: none; padding: 0; color: var(--danger); font-size: 0.85rem; cursor: pointer; text-decoration: underline; }

.review-form { max-width: 480px; margin-top: 12px; }

/* Dish photo gallery: horizontal swipe strip, no JS needed */
.photo-gallery {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 8px;
  margin: 4px 0 20px;
}
.photo-gallery-item { flex: 0 0 auto; scroll-snap-align: start; width: 200px; }
.photo-gallery-item img {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}
.photo-gallery-caption { font-size: 0.85rem; color: var(--muted); margin: 6px 0 0; }

/* Admin photo moderation grid */
.admin-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.admin-photo-card { background: var(--paper); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.admin-photo-card img { width: 100%; height: 180px; object-fit: cover; display: block; }
.admin-photo-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.admin-photo-card-actions { display: flex; gap: 8px; margin-top: 4px; }
.admin-photo-card-actions form { display: inline; }

/* Pure-CSS 5-star picker: radios are in reverse (5..1) DOM order so the
   :checked/:hover general-sibling selector can highlight every star up to
   and including the one under the pointer once the row is visually flipped
   back to 1..5 with row-reverse. */
.star-input { display: inline-flex; flex-direction: row-reverse; font-size: 1.8rem; margin-bottom: 12px; }
.star-input input { position: absolute; opacity: 0; pointer-events: none; }
.star-input label { color: var(--border); cursor: pointer; padding: 0 2px; }
.star-input input:checked ~ label,
.star-input label:hover,
.star-input label:hover ~ label { color: var(--terracotta-dark); }

/* Wider screens: side-by-side admin review, more grid columns */
@media (min-width: 700px) {
  .admin-review { flex-direction: row; align-items: flex-start; }
  .admin-source, .admin-fields { flex: 1; min-width: 0; }
  .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
