/* ── Reset & base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #fafaf8;
  color: #1a1a1a;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ── Nav ─────────────────────────────────────────────────── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid #e8e8e6;
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-brand { font-weight: 700; font-size: 1.15rem; letter-spacing: -0.02em; }
.nav-link {
  font-size: 0.9rem;
  font-weight: 500;
  background: #1a1a1a;
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  transition: opacity 0.15s;
}
.nav-link:hover { opacity: 0.8; }

/* ── Main container ──────────────────────────────────────── */
.main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Page header (list page) ─────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.75rem; font-weight: 700; }
.search-input {
  flex: 1;
  max-width: 360px;
  padding: 0.55rem 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: #999; }

/* ── Recipe grid ─────────────────────────────────────────── */
#recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}
.recipe-card {
  background: #fff;
  border: 1px solid #e8e8e6;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
  cursor: pointer;
}
.recipe-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.1); transform: translateY(-2px); }
.recipe-card-img-wrap { position: relative; }
.recipe-card-img { width: 100%; height: 180px; object-fit: cover; }
.card-rating-badge {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  font-size: 1.4rem;
  line-height: 1;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(4px);
  border-radius: 8px;
  padding: 0.2rem 0.3rem;
}
.recipe-card-img--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0efeb;
  font-size: 3rem;
}
.recipe-card-body { padding: 1rem; flex: 1; display: flex; flex-direction: column; gap: 0.4rem; }
.recipe-card-title { font-size: 1rem; font-weight: 600; line-height: 1.35; }
.recipe-card-desc { font-size: 0.85rem; color: #666; line-height: 1.4; flex: 1; }
.recipe-card-meta { display: flex; gap: 0.75rem; font-size: 0.8rem; color: #888; margin-top: auto; padding-top: 0.5rem; }

.empty-state { color: #888; font-size: 1rem; text-align: center; padding: 3rem 0; }
.empty-state a { text-decoration: underline; }

/* ── Recipe detail ───────────────────────────────────────── */
.recipe { max-width: 780px; }
.recipe-hero { width: 100%; height: 340px; object-fit: cover; border-radius: 12px; margin-bottom: 1.5rem; }
.recipe-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 0.5rem; }
.recipe-title { font-size: 2rem; font-weight: 700; line-height: 1.2; }

.recipe-menu { position: relative; flex-shrink: 0; }
.recipe-menu-btn {
  background: none;
  border: 1px solid #e8e8e6;
  border-radius: 8px;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.2rem;
  cursor: pointer;
  color: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.recipe-menu-btn:hover { background: #f5f4f0; }
.recipe-menu-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  background: #fff;
  border: 1px solid #e8e8e6;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
  min-width: 200px;
  overflow: hidden;
  z-index: 20;
}
.recipe-menu-item {
  display: block;
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  color: #333;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s;
}
.recipe-menu-item:hover { background: #f5f4f0; }
.recipe-menu-item--info { color: #aaa; font-size: 0.8rem; cursor: default; }
.recipe-menu-item--info:hover { background: none; }
.recipe-menu-item--danger { color: #b91c1c; }
.recipe-menu-item--danger:hover { background: #fee2e2; }
.recipe-menu-divider { height: 1px; background: #e8e8e6; margin: 0.25rem 0; }
.recipe-description { color: #555; line-height: 1.65; margin: 1rem 0; }

.recipe-meta {
  display: flex;
  gap: 1.5rem;
  padding: 1rem 0;
  border-top: 1px solid #eee;
  border-bottom: 1px solid #eee;
  margin: 1.25rem 0;
}
.meta-item { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.9rem; }
.meta-label { font-size: 0.75rem; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }

.recipe-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 3rem;
  align-items: start;
}
@media (max-width: 640px) {
  .recipe-body { grid-template-columns: 1fr; gap: 2rem; }
  .smiley-btn { font-size: 1.75rem; padding: 0.3rem 0.3rem; }
  .rater-smileys { gap: 0.2rem; }
  .rater-name { width: 4rem; font-size: 0.85rem; }
}

/* ── Ingredients ─────────────────────────────────────────── */
.ingredients-section h2, .instructions-section h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.section-header { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.section-header h2 { margin-bottom: 0; }
.servings-control { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: #666; }
.servings-control input {
  width: 56px;
  padding: 0.25rem 0.4rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
}
.ingredients-list { list-style: none; display: flex; flex-direction: column; gap: 0.55rem; }
.ingredient { display: grid; grid-template-columns: 2.5rem 3rem 1fr; gap: 0 0.35rem; font-size: 0.95rem; line-height: 1.4; align-items: baseline; }
.ingredient-qty { font-weight: 600; text-align: right; white-space: nowrap; }
.ingredient-unit { color: #888; font-size: 0.85rem; white-space: nowrap; }
.ingredient-name { color: #333; }

/* ── Instructions ────────────────────────────────────────── */
.instructions-list {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  counter-reset: step-counter;
}
.step {
  counter-increment: step-counter;
  position: relative;
  padding: 0.85rem 1rem 0.85rem 3.25rem;
  background: #fff;
  border: 1px solid #e8e8e6;
  border-radius: 10px;
  line-height: 1.65;
  font-size: 0.95rem;
  color: #333;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.step--active {
  background: #fffbeb;
  border-color: #f59e0b;
}
.step--active::before {
  background: #f59e0b;
}
.step::before {
  content: counter(step-counter);
  position: absolute;
  left: 0.8rem;
  top: 0.85rem;
  width: 1.6rem;
  height: 1.6rem;
  background: #1a1a1a;
  color: #fff;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.6rem;
}

/* ── Steps edit mode ─────────────────────────────────────── */
.steps-done-btn {
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.2rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.steps-done-btn:hover { opacity: 0.85; }

.step-delete-btn {
  display: none;
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.6rem;
  height: 1.6rem;
  background: #fee2e2;
  color: #b91c1c;
  border: none;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.step-delete-btn:hover { background: #fecaca; }
.instructions-list--editing .step-delete-btn { display: flex; }
.instructions-list--editing .step { padding-right: 2.75rem; }

/* ── Step ingredients ────────────────────────────────────── */
.step-text { margin: 0; }
.step-ingredients {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.65rem;
}
.step-ing {
  font-size: 0.78rem;
  background: #f5f4f0;
  border: 1px solid #e2e0d8;
  color: #555;
  padding: 0.15rem 0.55rem;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── Tags ────────────────────────────────────────────────── */
.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 2rem; }
.tag {
  font-size: 0.8rem;
  background: #f0efeb;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  color: #555;
}

/* ── Import page ─────────────────────────────────────────── */
.import-page { max-width: 560px; }
.import-page h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; }
.import-hint { color: #666; margin-bottom: 1.5rem; }
.import-form { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.url-input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.95rem;
}
.url-input:focus { outline: none; border-color: #999; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn--primary { background: #1a1a1a; color: #fff; }
.btn--danger { background: #fee2e2; color: #b91c1c; }

/* ── Alert ───────────────────────────────────────────────── */
.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert--error { background: #fee2e2; color: #b91c1c; }

/* ── Smiley rating ───────────────────────────────────────── */
.rating-widget {
  margin: 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: #fff;
  border: 1px solid #e8e8e6;
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.rating-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #888; margin-bottom: 0.15rem; }
.rater-row, .rating-avg-row { display: flex; align-items: center; gap: 0.5rem; }
.rater-name { width: 4.5rem; font-size: 0.9rem; color: #555; flex-shrink: 0; }
.avg-label { font-weight: 700; color: #1a1a1a; }
.rater-smileys { display: flex; gap: 0.1rem; }
.smiley-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.1rem 0.15rem;
  opacity: 0.2;
  transition: opacity 0.1s, transform 0.1s;
  border-radius: 4px;
}
.smiley-btn:hover { opacity: 1; transform: scale(1.25); }
.smiley-btn--selected { opacity: 1; }
.avg-smiley { font-size: 1.4rem; line-height: 1; }
.avg-value { font-size: 0.85rem; font-weight: 600; color: #666; }
.rating-avg-row { margin-top: 0.25rem; padding-top: 0.35rem; border-top: 1px solid #f0efeb; }


/* ── Ingredients flyout ──────────────────────────────────── */
.ing-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 50;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  transition: opacity 0.15s, transform 0.15s;
}
.ing-fab:hover { opacity: 0.85; transform: translateY(-2px); }

.ing-drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}
.ing-drawer--open { pointer-events: all; }

.ing-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0);
  transition: background 0.25s;
}
.ing-drawer--open .ing-drawer-backdrop { background: rgba(0,0,0,.4); }

.ing-drawer-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 16px 16px 0 0;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -4px 24px rgba(0,0,0,.12);
}
.ing-drawer--open .ing-drawer-panel { transform: translateY(0); }

.ing-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid #e8e8e6;
  flex-shrink: 0;
}
.ing-drawer-header h3 { font-size: 1rem; font-weight: 700; }
.ing-drawer-close {
  background: none;
  border: none;
  font-size: 1rem;
  color: #888;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}
.ing-drawer-list {
  overflow-y: auto;
  padding: 0.85rem 1.25rem 2rem;
  -webkit-overflow-scrolling: touch;
}

/* ── HTMX indicator ──────────────────────────────────────── */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator { opacity: 1; }
