/* ── Reset & base ─────────────────────────────────────────────────────────── */

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

:root {
  --bg: #f5f0eb;
  --surface: #ffffff;
  --surface-alt: #faf8f5;
  --header-bg: #1c1917;
  --primary: #c0392b;
  --primary-hover: #a93226;
  --primary-light: #fdecea;
  --accent: #d97706;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-light: #a8a29e;
  --border: #e7e2da;
  --tag-bg: #ede9e4;
  --tag-text: #57534e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.08);
  --radius: 10px;
  --radius-sm: 6px;
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 180ms ease;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }

/* ── Header ──────────────────────────────────────────────────────────────── */

.site-header {
  background: var(--header-bg);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  flex: 1;
}

.site-title a { color: inherit; }

.header-nav { display: flex; gap: 8px; align-items: center; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
}

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

.btn-secondary {
  background: var(--tag-bg);
  color: var(--text);
}
.btn-secondary:hover { background: var(--border); }

.btn-outline {
  background: transparent;
  color: rgba(255,255,255,.85);
  border: 1px solid rgba(255,255,255,.25);
}
.btn-outline:hover { background: rgba(255,255,255,.1); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
}
.btn-ghost:hover { background: var(--tag-bg); color: var(--text); }

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

.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-sm { padding: 5px 11px; font-size: 0.8125rem; }

/* ── Page wrapper ─────────────────────────────────────────────────────────── */

.page { max-width: 1400px; margin: 0 auto; padding: 0 24px 60px; }

/* ── Search & filter bar ─────────────────────────────────────────────────── */

.search-bar {
  display: flex;
  gap: 12px;
  padding: 24px 0 16px;
  align-items: center;
}

.search-input {
  flex: 1;
  max-width: 480px;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2378716c' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.099zm-5.242 1.156a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E") no-repeat 14px center;
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(192,57,43,.12);
}

.recipe-count {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}

/* ── Tag filter strip ─────────────────────────────────────────────────────── */

.tag-strip-wrapper {
  position: relative;
  margin-top: 24px;
}

.tag-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--tag-text);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  user-select: none;
}
.tag-pill:hover { background: var(--tag-bg); border-color: var(--text-light); }
.tag-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.tag-pill .count {
  font-size: 0.75rem;
  opacity: .7;
  font-weight: 400;
}

.active-tags-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.active-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 500;
}

.active-tag-chip button {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
}
.active-tag-chip button:hover { color: #fff; }

/* ── Recipe grid ──────────────────────────────────────────────────────────── */

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

.recipe-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  cursor: pointer;
}
.recipe-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.card-image {
  width: 100%;
  height: 190px;
  object-fit: cover;
  background: var(--bg);
}

.card-image-placeholder {
  width: 100%;
  height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 4rem;
  font-weight: 700;
  color: rgba(255,255,255,.8);
  text-transform: uppercase;
  flex-shrink: 0;
}

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

.card-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-author {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.card-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
  grid-column: 1 / -1;
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h2 { font-family: var(--font-serif); margin-bottom: 8px; color: var(--text); }

/* ── Recipe detail page ───────────────────────────────────────────────────── */

.recipe-detail { max-width: 860px; margin: 0 auto; padding: 32px 24px 80px; }

.recipe-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 24px;
  transition: color var(--transition);
}
.recipe-back:hover { color: var(--primary); }

.recipe-hero-img {
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}

.recipe-title {
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 8px;
}

.recipe-author {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.recipe-author strong { color: var(--text); }

.recipe-meta {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.meta-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 600; }
.meta-value { font-size: 0.9375rem; font-weight: 600; color: var(--text); }

.recipe-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 48px;
  align-items: start;
  margin-bottom: 32px;
}

@media (max-width: 640px) {
  .recipe-body { grid-template-columns: 1fr; gap: 32px; }
}

.section-heading {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  display: inline-block;
}

.ingredients-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ingredients-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
  line-height: 1.45;
  cursor: pointer;
  transition: opacity var(--transition);
}
.ingredients-list li:last-child { border-bottom: none; }
.ingredients-list li.checked { opacity: .45; text-decoration: line-through; }

.ingredient-checkbox {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 3px;
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ingredients-list li.checked .ingredient-checkbox {
  background: var(--primary);
  border-color: var(--primary);
}
.ingredient-checkbox::after {
  content: '';
  width: 8px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
  display: none;
}
.ingredients-list li.checked .ingredient-checkbox::after { display: block; }

.method-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.method-step {
  display: flex;
  gap: 16px;
  font-size: 0.9375rem;
  line-height: 1.65;
}

.step-number {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
  width: 28px;
  margin-top: 1px;
}

.recipe-notes {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 0.9375rem;
  line-height: 1.65;
  margin-bottom: 24px;
  color: var(--text-muted);
}
.recipe-notes strong { color: var(--text); }

.recipe-tags-section { margin-bottom: 24px; }

.recipe-tags-section .tag { padding: 4px 12px; font-size: 0.8125rem; }

.recipe-source {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.recipe-source a { color: var(--primary); text-decoration: underline; }

/* ── Password overlay ─────────────────────────────────────────────────────── */

.password-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.password-box {
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  width: 340px;
}

.password-box h2 {
  margin-bottom: 1rem;
}

.password-box input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* ── Admin page ───────────────────────────────────────────────────────────── */

.admin-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: start;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-alt);
}

.panel-title { font-size: 0.9375rem; font-weight: 600; }

.panel-body { padding: 20px; }

/* Recipe list in admin */
.admin-recipe-list { display: flex; flex-direction: column; gap: 0; }

.admin-recipe-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  font-size: 0.875rem;
}
.admin-recipe-item:last-child { border-bottom: none; }
.admin-recipe-item:hover { background: var(--surface-alt); }
.admin-recipe-item.active { background: var(--primary-light); }

.admin-recipe-item-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  overflow: hidden;
}

.admin-recipe-item-name { flex: 1; font-weight: 500; line-height: 1.3; }
.admin-recipe-item-author { font-size: 0.8rem; color: var(--text-muted); }

/* Admin search */
.admin-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.admin-search input {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--bg);
  outline: none;
}
.admin-search input:focus { border-color: var(--primary); }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(192,57,43,.1);
}
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px) { .form-row { grid-template-columns: 1fr; } }

.tags-input-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 42px;
  cursor: text;
  background: var(--surface);
  transition: border-color var(--transition);
}
.tags-input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(192,57,43,.1); }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.8125rem;
}
.tag-chip-remove {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  font-size: 1rem;
  line-height: 1;
  padding: 0 0 0 2px;
  cursor: pointer;
}
.tag-chip-remove:hover { color: #fff; }

.auto-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 999px;
  font-size: 0.8125rem;
}
.auto-tag-chip .tag-chip-remove {
  color: var(--text-muted);
  opacity: .7;
}
.auto-tag-chip .tag-chip-remove:hover { opacity: 1; color: var(--danger); }

.tags-input {
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 0.875rem;
  background: none;
  flex: 1;
  min-width: 100px;
}

.list-textarea {
  font-size: 0.875rem;
  line-height: 1.7;
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-zone input { display: none; }
.upload-zone-icon { font-size: 2.5rem; margin-bottom: 12px; }
.upload-zone p { font-size: 0.9375rem; color: var(--text-muted); margin-bottom: 6px; }
.upload-zone small { font-size: 0.8125rem; color: var(--text-light); }

/* Import preview */
.import-preview {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 16px;
}
.import-preview h4 { font-size: 0.9375rem; margin-bottom: 8px; color: var(--text-muted); }

/* Status / alerts */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.alert { display: none; }
.alert.visible { display: flex; }

/* Loading spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0,0,0,.12);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Image management */
.image-preview-wrap {
  position: relative;
  display: inline-block;
  margin-top: 8px;
}
.image-preview {
  max-width: 200px;
  max-height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.image-remove-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Action bar in detail/edit */
.action-bar {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  justify-content: flex-end;
}

/* Placeholder colors */
.placeholder-a { background: #c0392b; }
.placeholder-b { background: #16a085; }
.placeholder-c { background: #8e44ad; }
.placeholder-d { background: #d35400; }
.placeholder-e { background: #27ae60; }
.placeholder-f { background: #2980b9; }

/* Utility */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* Responsive */
@media (max-width: 600px) {
  .page { padding: 0 16px 40px; }
  .recipe-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .card-image, .card-image-placeholder { height: 140px; }
}
@media (max-width: 400px) {
  .recipe-grid { grid-template-columns: 1fr; }
}
