/*
 * recipe.css — recipe page specific styles
 * Depends on: tokens.css, base.css, layout.css, components.css
 */

/* ============================================================
   LOADING / ERROR STATES
   ============================================================ */
.recipe-loading {
  min-height: 60vh;
}

.recipe-error {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: justify-content;
}

.recipe-error[hidden] { display: none; }

/* ============================================================
   RECIPE HERO
   ============================================================ */
.recipe-hero {
  position: relative;
  background: var(--color-surface-offset);
}

.recipe-hero__img-wrap {
  position: relative;
  width: 100%;
  height: clamp(260px, 40vw, 520px);
  max-height: 0;
  overflow: hidden;
  visibility: hidden;
  transition: max-height 0.3s ease, visibility 0s linear 0.3s;
}

.recipe-hero__img-wrap.has-image {
  max-height: clamp(260px, 40vw, 520px);
  visibility: visible;
  overflow: visible;
  transition: max-height 0.3s ease, visibility 0s linear 0s;
}

.recipe-hero__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--color-primary-highlight) 0%, var(--color-surface-offset) 100%);
  color: var(--color-primary);
}

.recipe-hero__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.recipe-hero__img.is-hidden {
  display: none !important;
}

.recipe-hero__scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0, 32, 40, 0.75) 0%,
    rgba(0, 32, 40, 0.20) 50%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 1;
}

.recipe-hero__content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding-bottom: var(--space-8);
  z-index: 2;
}

.recipe-hero__title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
  line-height: 1.15;
}

/* ============================================================
   META BAR
   ============================================================ */
.recipe-meta-bar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  padding-block: var(--space-4);
}

.recipe-meta-bar__inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-5);
}

.recipe-meta-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.recipe-meta-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--color-primary);
}

.recipe-meta-item strong {
  color: var(--color-text);
  font-weight: 600;
}

.diet-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

/* ============================================================
   GALLERY SECTION
   ============================================================ */
.recipe-gallery-section {
  padding-block: var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.recipe-gallery-section[hidden] { display: none; }

.recipe-gallery-section .section-heading {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

/* ── Grid ────────────────────────────────────────────────── */
.gallery-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 1fr;
  gap: var(--space-2);
}

@media (min-width: 640px) {
  .gallery-strip {
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-2);
  }
}

@media (min-width: 1024px) {
  .gallery-strip {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* ── Thumbnail ──────────────────────────────────────────── */
.gallery-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  opacity: 0;
  transform: translateY(6px);
}

.gallery-thumb--enter {
  animation: galleryEnter 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes galleryEnter {
  to { opacity: 1; transform: translateY(0); }
}

.gallery-thumb--featured {
  grid-column: auto;
  grid-row: auto;
}

.gallery-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.gallery-thumb:hover img,
.gallery-thumb:focus-visible img {
  transform: scale(1.08);
}

.gallery-thumb:focus-visible {
  outline: 3px solid var(--color-primary-btn);
  outline-offset: 2px;
}

.gallery-thumb__overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 32, 40, 0);
  color: #fff;
  opacity: 0;
  transition:
    opacity 0.2s ease,
    background 0.2s ease;
}

.gallery-thumb:hover .gallery-thumb__overlay,
.gallery-thumb:focus-visible .gallery-thumb__overlay {
  opacity: 1;
  background: rgba(0, 32, 40, 0.38);
}

.gallery-thumb__overlay svg {
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
  width: 16px;
  height: 16px;
}

.gallery-thumb__count {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: var(--radius-full);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.gallery-thumb--error {
  background: var(--color-surface-offset);
  cursor: default;
  pointer-events: none;
}

.gallery-thumb--error::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='1.5'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpolyline points='21 15 16 10 5 21'/%3E%3C/svg%3E") center/24px no-repeat;
}

/* ============================================================
   RECIPE BODY LAYOUT
   ============================================================ */
.recipe-body {
  padding-block: var(--space-5) var(--space-10);
}

@media (min-width: 640px) {
  .recipe-body {
    padding-block: var(--space-8) var(--space-16);
  }
}

.recipe-layout {
  display: grid;
  gap: var(--space-10);
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .recipe-layout {
    grid-template-columns: minmax(260px, 320px) 1fr;
    gap: var(--space-12);
    align-items: start;
  }
}

/* ============================================================
   INGREDIENT PANEL — DESKTOP
   ============================================================ */
.recipe-ingredients-panel {
  position: sticky;
  top: calc(60px + var(--space-6));
  max-height: calc(100dvh - 60px - var(--space-12));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 767px) {
  .recipe-ingredients-panel {
    display: none;
  }
}

.recipe-ingredients-panel__inner {
  padding: var(--space-5) var(--space-5) var(--space-6);
}

.ingredients-header {
  margin-bottom: var(--space-3);
}

.ingredients-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

/* ============================================================
   INGREDIENTS CONTROLS (unit toggle + scaler side-by-side)
   ============================================================ */
.ingredients-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-block: var(--space-3);
  border-top: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
  margin-bottom: var(--space-4);
  flex-wrap: nowrap;
}

/* In the drawer the serving scaler loses its own top/bottom borders
   since the controls wrapper provides them */
.ingredients-controls .serving-scaler {
  border-top: none;
  border-bottom: none;
  padding-block: 0;
  margin-bottom: 0;
  flex: 1;
  justify-content: flex-end;
}

.ingredients-controls .unit-toggle {
  flex-shrink: 0;
}

/* ============================================================
   UNIT TOGGLE
   ============================================================ */
.unit-toggle {
  display: inline-flex;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--color-border);
}

.unit-btn {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  min-height: 28px;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
}

.unit-btn.is-active {
  background: var(--color-primary-btn);
  color: var(--color-text-inverse);
}

[data-theme="dark"] .unit-btn.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .unit-btn.is-active {
    background: var(--color-primary);
    color: var(--color-text-inverse);
  }
}

.unit-btn:not(.is-active):hover {
  color: var(--color-text);
}

/* ============================================================
   SERVING SCALER
   ============================================================ */
.serving-scaler {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
  margin-bottom: var(--space-4);
}

.serving-scaler__label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
}

.serving-scaler__controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.serving-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast);
}

.serving-btn:hover {
  background: var(--color-primary-highlight);
  border-color: var(--color-primary);
  color: var(--color-primary-btn);
}

.serving-btn:active {
  transform: scale(0.94);
}

.serving-count {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  min-width: 2ch;
  text-align: center;
}

/* ============================================================
   INGREDIENTS LIST
   ============================================================ */
.ingredients-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.ingredient-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
  cursor: pointer;
  user-select: none;
}

.ingredient-item:hover {
  background: var(--color-surface-offset);
}

.ingredient-item.is-checked {
  opacity: 0.45;
}

.ingredient-item.is-checked .ingredient-text {
  text-decoration: line-through;
}

.ingredient-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: var(--radius-xs);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  margin-top: 2px;
  display: grid;
  place-items: center;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.ingredient-checkbox:checked {
  background: var(--color-primary-btn);
  border-color: var(--color-primary-btn);
}

.ingredient-checkbox:checked::after {
  content: '';
  display: block;
  width: 9px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}

.ingredient-text {
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-text);
}

.ingredient-qty {
  font-weight: 600;
  color: var(--color-text);
}

/* ============================================================
   COPY INGREDIENTS BUTTON
   ============================================================ */
.ingredients-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition:
    background var(--transition-interactive),
    color var(--transition-interactive),
    border-color var(--transition-interactive);
}

.ingredients-copy-btn:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.ingredients-copy-btn--copied {
  color: var(--color-success) !important;
  border-color: var(--color-success) !important;
  background: var(--color-success-highlight) !important;
}

/* ============================================================
   STEPS
   ============================================================ */
.recipe-section-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

@media (min-width: 640px) {
  .recipe-section-title {
    margin-bottom: var(--space-4);
  }
}

.steps-section {
  margin-bottom: var(--space-5);
}

@media (min-width: 640px) {
  .steps-section {
    margin-bottom: var(--space-8);
  }
}

.steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.step-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition:
    background var(--transition-interactive),
    border-color var(--transition-interactive),
    box-shadow var(--transition-interactive);
}

.step-item:hover {
  background: var(--color-surface-2);
  border-color: var(--color-divider);
}

.step-item.is-active {
  background: var(--color-surface-2);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.step-number {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-primary-highlight);
  color: var(--color-primary-btn);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-xs);
  display: grid;
  place-items: center;
  margin-top: 3px;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.step-item.is-active .step-number {
  background: var(--color-primary-btn);
  color: var(--color-text-inverse);
}

[data-theme="dark"] .step-number {
  background: var(--color-surface-offset-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .step-number {
    background: var(--color-surface-offset-2);
    color: var(--color-text);
    border: 1px solid var(--color-border);
  }
}

[data-theme="dark"] .step-item.is-active .step-number {
  background: var(--color-primary);
  color: var(--color-bg);
  border-color: transparent;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .step-item.is-active .step-number {
    background: var(--color-primary);
    color: var(--color-bg);
    border-color: transparent;
  }
}

.step-body {
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--color-text);
  padding-block: 1px;
}

.step-body strong { font-weight: 700; }

/* ============================================================
   PROSE SECTIONS (About, Notes, Nutrition)
   ============================================================ */
.recipe-prose {
  margin-bottom: var(--space-6);
}

@media (min-width: 640px) {
  .recipe-prose {
    margin-bottom: var(--space-10);
  }
}

/* Hide the About heading — content renders without a section label */
#recipe-about .recipe-section-title {
  display: none;
}

/* ============================================================
   SHARE BAR
   ============================================================ */
.share-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-divider);
  margin-top: var(--space-8);
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  cursor: pointer;
  min-height: 40px;
  transition:
    background var(--transition-interactive),
    color var(--transition-interactive);
}

.share-btn:hover {
  background: var(--color-primary-highlight);
  color: var(--color-primary-btn);
  border-color: var(--color-primary);
}

.share-btn--copied {
  color: var(--color-success) !important;
  border-color: var(--color-success) !important;
  background: var(--color-success-highlight) !important;
}

/* ============================================================
   MOBILE BOTTOM DRAWER
   ============================================================ */
.ingredients-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-drawer);
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  box-shadow: 0 -8px 32px oklch(0 0 0 / 0.15);
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
}

.ingredients-drawer.is-open {
  transform: translateY(0);
}

@media (min-width: 768px) {
  .ingredients-drawer {
    display: none !important;
  }
}

.ingredients-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}

.ingredients-drawer__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.ingredients-drawer__close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
}

.ingredients-drawer__close:hover {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.ingredients-drawer__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-4) var(--space-5) var(--space-8);
  flex: 1;
}

/* ============================================================
   INGREDIENTS FAB (mobile only)
   ============================================================ */
.ingredients-fab {
  display: none;
}

@media (max-width: 767px) {
  .ingredients-fab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    z-index: var(--z-fab, calc(var(--z-drawer) - 1));
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-full);
    background: var(--color-primary-btn);
    color: var(--color-text-inverse);
    font-size: var(--text-sm);
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    border: none;
    cursor: pointer;
    transition:
      background var(--transition-interactive),
      box-shadow var(--transition-interactive),
      transform var(--transition-interactive);
  }

  .ingredients-fab:hover {
    background: var(--color-primary-hover);
    box-shadow: var(--shadow-lg);
  }

  .ingredients-fab:active {
    transform: scale(0.96);
  }
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-lightbox);
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox[hidden] { display: none; }

.lightbox__img-wrap {
  max-width: min(92vw, 1200px);
  max-height: 88dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__img {
  max-width: 100%;
  max-height: 88dvh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  display: block;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.lightbox__close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: grid;
  place-items: center;
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.lightbox__close:hover {
  background: rgba(255,255,255,0.22);
}

.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: grid;
  place-items: center;
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.lightbox__nav:hover {
  background: rgba(255,255,255,0.22);
}

.lightbox__nav--prev { left: var(--space-4); }
.lightbox__nav--next { right: var(--space-4); }

.lightbox__nav[hidden] { display: none; }

.lightbox__counter {
  position: absolute;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.4);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .site-header,
  .recipe-gallery-section,
  .share-bar,
  .ingredients-drawer,
  .ingredients-fab,
  .ingredients-copy-btn,
  .lightbox,
  .site-footer,
  .unit-toggle,
  .serving-scaler,
  .no-print,
  #recipe-about,
  #recipe-nutrition {
    display: none !important;
  }

  .recipe-body {
    padding-block: var(--space-4);
  }

  .recipe-layout {
    grid-template-columns: 300px 1fr;
    gap: var(--space-8);
  }

  .recipe-ingredients-panel {
    display: block !important;
    position: static;
    max-height: none;
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .recipe-hero__img-wrap {
    max-height: 220px;
    visibility: visible;
  }

  .step-item {
    border: 1px solid #ddd;
    break-inside: avoid;
  }

  a[href]::after {
    content: none;
  }
}
