/* ============ Reset & base ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #e85d3d;
  --primary-dark: #c94828;
  --primary-soft: #fdeee9;
  --accent: #0ea5a3;
  --bg: #faf6f1;
  --bg2: #f4eee6;
  --card: #ffffff;
  --text: #2c2418;
  --muted: #9b8f80;
  --border: #eae2d5;
  --fav: #e63950;
  --gold: #eda820;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(60,42,20,.05), 0 6px 20px -6px rgba(60,42,20,.12);
  --shadow-lg: 0 12px 40px -8px rgba(60,42,20,.25);
  --topbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; overscroll-behavior-y: none; }

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; display: block; }
small { font-weight: 500; color: var(--muted); }

.container { max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* Nav de escritorio (oculto en móvil) */
.desktop-nav { display: none; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.btn-add.ghost {
  background: transparent;
  color: var(--primary-dark);
  border: 1.5px solid var(--primary);
}

/* ============ Vistas (transiciones) ============ */
#app { position: relative; height: 100dvh; overflow: hidden; }

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  visibility: hidden;
  transform: translateX(40px);
  opacity: 0;
  transition: transform .25s cubic-bezier(.2,.8,.3,1), opacity .2s ease, visibility 0s .25s;
  pointer-events: none;
  background: var(--bg);
}
.view.active {
  visibility: visible;
  transform: translateX(0);
  opacity: 1;
  transition: transform .25s cubic-bezier(.2,.8,.3,1), opacity .2s ease;
  pointer-events: auto;
  z-index: 2;
}
.view.slide-back { transform: translateX(-40px); }

/* ============ Topbar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: var(--safe-top);
  background: rgba(250,246,241,.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(60,42,20,.06);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: var(--topbar-h);
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}
.detail-bar {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: var(--topbar-h);
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--primary), #f0855f);
  border-radius: 14px;
  box-shadow: 0 4px 12px -2px rgba(232,93,61,.45);
}
.logo-text { line-height: 1.15; }
.logo-text b {
  display: block;
  font-family: "Fraunces", serif;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -.01em;
}
.logo-text small { font-size: .72rem; color: var(--muted); font-weight: 600; }

.btn-add {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-weight: 700;
  font-size: .88rem;
  transition: transform .12s, background .15s;
}
.btn-add:active { transform: scale(.95); }
.btn-add:hover { background: #000; }

.btn-circle {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  font-size: 1.25rem;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform .12s;
  flex-shrink: 0;
}
.btn-circle:active { transform: scale(.9); }
.btn-circle.ghost { visibility: hidden; }

.detail-title {
  flex: 1;
  text-align: center;
  font-family: "Fraunces", serif;
  font-weight: 800;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ Hero banner ============ */
.hero-banner {
  margin: 18px 0 16px;
  padding: 22px 22px 20px;
  border-radius: 22px;
  background: linear-gradient(120deg, #e85d3d 0%, #e8823d 55%, #f0a44f 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px -8px rgba(232,93,61,.5);
}
.hero-banner::after {
  content: "";
  position: absolute;
  right: -30px; top: -40px;
  width: 160px; height: 160px;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
}
.hero-text h2 {
  font-family: "Fraunces", serif;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -.01em;
}
.hero-text p { margin-top: 6px; font-size: .85rem; opacity: .92; font-weight: 500; }
.hero-emoji {
  font-size: 3rem;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.15));
  position: relative;
  z-index: 1;
}

/* ============ Búsqueda ============ */
.search-wrap {
  position: relative;
  margin-bottom: 14px;
}
.search-icon {
  position: absolute;
  left: 16px; top: 50%;
  transform: translateY(-50%);
  font-size: .95rem;
  opacity: .55;
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 14px 44px 14px 44px;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  font: inherit;
  font-size: .95rem;
  outline: none;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
#search:focus { border-color: var(--primary); }
.clear-x {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  border-radius: 50%;
  color: var(--muted);
  font-size: .9rem;
  background: var(--bg2);
}

/* ============ Categorías (scroll horizontal) ============ */
.cats {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.cats::-webkit-scrollbar { display: none; }
.cat-chip {
  flex-shrink: 0;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 68px;
  padding: 10px 4px 8px;
  border-radius: 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  transition: all .15s;
}
.cat-chip i { font-style: normal; font-size: 1.35rem; line-height: 1; }
.cat-chip span { font-size: .68rem; font-weight: 700; color: var(--muted); }
.cat-chip.active {
  background: var(--text);
  border-color: var(--text);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.cat-chip.active span { color: #fff; }

/* ============ Chips ============ */
.chips {
  display: flex;
  gap: 8px;
  padding-bottom: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--card);
  border: 1.5px solid var(--border);
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
  transition: all .15s;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.fav-on { background: var(--fav); border-color: var(--fav); color: #fff; }
.chip-filter { border-style: dashed; }

/* ============ Panel filtros ============ */
.filters-panel {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.filter-row label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: .76rem;
  font-weight: 700;
  color: var(--muted);
}
.filter-row select {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font: inherit;
  font-size: .9rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.filter-row select:focus { border-color: var(--primary); }
.filter-actions { display: flex; gap: 10px; margin-top: 14px; }
.filter-actions .btn { flex: 1; }

/* ============ Botones ============ */
.btn {
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .92rem;
  transition: transform .12s, opacity .15s;
}
.btn:active { transform: scale(.96); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), #ef7d51);
  color: #fff;
  box-shadow: 0 6px 16px -4px rgba(232,93,61,.5);
}
.btn.primary.big { padding: 15px 26px; font-size: 1rem; }
.btn.secondary { background: var(--bg2); color: var(--text); }
.btn.danger { background: #fdecec; color: var(--fav); }

/* ============ Grid recetas ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 14px;
  padding-bottom: 20px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  position: relative;
  animation: card-in .3s ease backwards;
}
.card:nth-child(2) { animation-delay: .04s; }
.card:nth-child(3) { animation-delay: .08s; }
.card:nth-child(4) { animation-delay: .12s; }
.card:nth-child(5) { animation-delay: .16s; }
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card:active { transform: scale(.97); }

.card-img {
  aspect-ratio: 5/4;
  position: relative;
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  overflow: hidden;
}
.card-img img {
  width: 100%; height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}
.card-body { padding: 12px 14px 14px; }
.card-title {
  font-weight: 700;
  font-size: .92rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  font-size: .75rem;
  color: var(--muted);
  font-weight: 600;
  flex-wrap: wrap;
  align-items: center;
}
.badge-tmx {
  color: var(--accent);
  font-weight: 800;
  font-size: .68rem;
  letter-spacing: .04em;
}
.card .fav {
  position: absolute;
  top: 10px; right: 10px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(255,255,255,.92);
  color: #cdc4b4;
  font-size: 1.05rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  backdrop-filter: blur(4px);
  transition: transform .15s, color .15s;
}
.card .fav:active { transform: scale(1.2); }
.card .fav.on { color: var(--fav); }
.rating { color: var(--gold); letter-spacing: .05em; }

/* Tarjeta "añadir" */
.card.add-card {
  display: grid;
  place-items: center;
  min-height: 200px;
  border: 2px dashed var(--border);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-weight: 700;
  gap: 6px;
}
.card.add-card span { font-size: 2rem; }
.card.add-card:hover { border-color: var(--primary); color: var(--primary); }

/* ============ Empty ============ */
.empty { text-align: center; padding: 50px 20px 30px; color: var(--muted); }
.empty-emoji { font-size: 3.4rem; margin-bottom: 10px; }
.empty h3 { font-family: "Fraunces", serif; font-size: 1.3rem; color: var(--text); margin-bottom: 4px; }
.empty p { font-size: .9rem; margin-bottom: 18px; }

.foot {
  text-align: center;
  padding: 10px 0 30px;
  font-size: .78rem;
  color: var(--muted);
  font-weight: 600;
}

/* ============ Detalle ============ */
.detail { padding-top: 18px; padding-bottom: 110px; }
.hero {
  aspect-ratio: 16/10;
  border-radius: 22px;
  background: linear-gradient(135deg, #ffe3d3, #ffd0ba);
  display: grid;
  place-items: center;
  font-size: 4rem;
  overflow: hidden;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.hero img { width: 100%; height: 100%; object-fit: cover; }

.d-title {
  font-family: "Fraunces", serif;
  font-size: 1.75rem;
  font-weight: 900;
  letter-spacing: -.02em;
  line-height: 1.2;
  margin-bottom: 12px;
}
.d-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
  font-size: .8rem;
}
.d-meta .pill {
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--card);
  border: 1.5px solid var(--border);
  font-weight: 700;
  color: var(--muted);
}
.pill.tmx { color: var(--accent); border-color: var(--accent); background: #e8f7f7; }
.pill.rating { color: var(--gold); }

.d-section { margin-bottom: 26px; }
.d-section h2 {
  font-family: "Fraunces", serif;
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 12px;
}
.ing-list { list-style: none; }
.ing-list li {
  padding: 10px 0 10px 30px;
  position: relative;
  border-bottom: 1px dashed var(--border);
  font-size: .95rem;
}
.ing-list li::before {
  content: "•";
  position: absolute;
  left: 10px;
  color: var(--primary);
  font-weight: 900;
  font-size: 1.2rem;
  line-height: 1.3;
}
.step-list { list-style: none; counter-reset: step; }
.step-list li {
  counter-increment: step;
  position: relative;
  padding: 12px 0 12px 46px;
  border-bottom: 1px dashed var(--border);
  font-size: .95rem;
}
.step-list li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 10px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: .85rem;
  display: grid;
  place-items: center;
}
.d-actions { display: flex; gap: 10px; }
.d-actions .btn { flex: 1; }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + var(--safe-bottom));
  height: 56px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform .15s;
}
.fab::after { content: "Cocinar"; font-size: .9rem; }
.fab:active { transform: scale(.93); }

/* ============ Modal cocina ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(30,20,10,.55);
  backdrop-filter: blur(3px);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal-box {
  background: var(--card);
  border-radius: 24px;
  padding: 22px;
  width: 100%;
  max-width: 480px;
  max-height: 82dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: pop-in .25s cubic-bezier(.2,.8,.3,1.2);
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(.92) translateY(12px); }
}
.cook-box h3 {
  font-family: "Fraunces", serif;
  font-size: 1.3rem;
  margin-bottom: 16px;
}
.cook-step {
  padding: 16px;
  border-radius: 14px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  margin-bottom: 10px;
  font-size: 1rem;
  line-height: 1.55;
}
.cook-step b {
  display: block;
  color: var(--primary-dark);
  margin-bottom: 5px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
#cook-close { width: 100%; margin-top: 8px; }

/* ============ Formulario ============ */
.form-page { padding-bottom: 60px; }
.form-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  margin-top: 4px;
}
.form-section { display: flex; flex-direction: column; gap: 13px; }
.form-section h3 {
  font-family: "Fraunces", serif;
  font-size: 1.05rem;
  font-weight: 800;
}
.form-section h3 small { font-size: .75rem; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
}
.field input, .field select, .field textarea {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 13px;
  font: inherit;
  font-size: .95rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 100%;
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.field-row { display: grid; gap: 10px; }
.field-row.two { grid-template-columns: 1fr 1fr; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.form-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
#img-preview-wrap { margin-top: -4px; }
#img-preview {
  border-radius: 14px;
  max-height: 200px;
  object-fit: cover;
  width: 100%;
  border: 1.5px solid var(--border);
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 13px 24px;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 600;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s cubic-bezier(.2,.8,.3,1.2);
  max-width: 90vw;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============ Desktop: web normal ============ */
@media (min-width: 900px) {
  .container { max-width: 1080px; }

  /* Nav de categorías en la barra superior */
  .desktop-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    justify-content: center;
  }
  .nav-link {
    padding: 8px 13px;
    border-radius: 999px;
    font-size: .86rem;
    font-weight: 600;
    color: var(--muted);
    transition: all .15s;
  }
  .nav-link:hover { color: var(--text); background: var(--bg2); }
  .nav-link.active { background: var(--text); color: #fff; }

  /* Ocultar elementos de app en PC */
  .cats { display: none; }
  .hero-banner { display: none; }
  #btn-install { display: none; }
  .btn-add { font-size: .84rem; padding: 10px 16px; }
  .fab { display: none; }

  /* Grid más ancho con hover */
  .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
  .card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
  }
  .card .fav { opacity: 0; transition: opacity .15s; }
  .card:hover .fav { opacity: 1; }
  .card .fav.on { opacity: 1; }

  /* Detalle a dos columnas */
  .detail { padding-top: 28px; padding-bottom: 40px; }
  .detail-cols { display: none; }
  #detail-content {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 36px;
    align-items: start;
  }
  .hero { aspect-ratio: 4/5; position: sticky; top: 88px; margin-bottom: 0; }
  .d-title { font-size: 2.2rem; }
  .d-main { min-width: 0; }
  .d-actions { max-width: 420px; }

  /* Formulario más contenido */
  .form-page .form-card { max-width: 720px; margin: 20px auto 0; }
}

/* En móvil, envolver contenido principal del detalle */
@media (max-width: 899px) {
  .d-main { display: contents; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
