/* ===== Variables + temas ===== */
:root {
  --radius: 18px;
  --radius-sm: 12px;
  --gap: 14px;
  --header-h: 56px;
  --tabbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Tema Saffron (cálido/apetitoso) — default */
.theme-saffron {
  --bg:        #14100d;
  --bg-2:      #1b1510;
  --surface:   #221a13;
  --surface-2: #2c2219;
  --text:      #f7efe6;
  --text-dim:  #b39d88;
  --border:    rgba(255,255,255,0.08);
  --accent:    #ff8c42;
  --accent-2:  #ffb347;
  --accent-ink:#1a1006;
  --glow:      0 0 24px rgba(255,140,66,0.35);
  --protein:   #ff8c42;
  --calories:  #ffd166;
  --carbs:     #7cc6fe;
  --fat:       #f78fb3;
}

/* Tema Matcha (verde fresco) — alternativo */
.theme-matcha {
  --bg:        #0e1411;
  --bg-2:      #121b16;
  --surface:   #16201a;
  --surface-2: #1e2b23;
  --text:      #eef6f0;
  --text-dim:  #8fae9c;
  --border:    rgba(255,255,255,0.08);
  --accent:    #6fe39b;
  --accent-2:  #a8f0c2;
  --accent-ink:#06160d;
  --glow:      0 0 24px rgba(111,227,155,0.30);
  --protein:   #6fe39b;
  --calories:  #ffd166;
  --carbs:     #7cc6fe;
  --fat:       #f78fb3;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: calc(var(--header-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ===== Header ===== */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--bg) 60%, transparent);
  backdrop-filter: blur(8px);
}
.brand { font-size: 17px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; }
.brand span { color: var(--accent); }
.admin-btn {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  margin-top: calc(env(safe-area-inset-top) / 2);
  background: none; border: none; font-size: 20px; opacity: 0.7;
}
.admin-btn.on { opacity: 1; filter: drop-shadow(var(--glow)); }

/* ===== Vistas ===== */
.view { padding: var(--gap); display: flex; flex-direction: column; gap: var(--gap); }

/* ===== Buscador ===== */
.search-bar {
  position: relative; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.search-bar input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 16px; font-family: var(--font);
}
.search-bar input::placeholder { color: var(--text-dim); }
.search-bar .clear { color: var(--text-dim); font-size: 18px; background: none; border: none; padding: 0 4px; }

/* Chips de categoría */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: var(--glow); }

/* ===== Tarjeta de receta ===== */
.cards { display: flex; flex-direction: column; gap: var(--gap); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  animation: fadeUp 0.4s ease both;
}
.card-photo {
  position: relative; aspect-ratio: 16/10; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 56px; overflow: hidden;
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.card-fav {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
  border: none; font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.card-cat {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  padding: 5px 10px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,0.5); color: var(--text); backdrop-filter: blur(4px);
}
.card-body { padding: 14px; }
.card-title { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.card-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; line-height: 1.4; }

/* Fila de macros */
.macros { display: flex; gap: 8px; }
.macro {
  flex: 1; text-align: center; background: var(--bg-2);
  border-radius: var(--radius-sm); padding: 8px 4px;
}
.macro .val { font-size: 17px; font-weight: 800; line-height: 1; }
.macro .lbl { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }
.macro.protein  .val { color: var(--protein); }
.macro.calories .val { color: var(--calories); }
.macro.carbs    .val { color: var(--carbs); }
.macro.fat      .val { color: var(--fat); }

.card-meta { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--text-dim); }

/* ===== Detalle (overlay) ===== */
.detail {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg); overflow-y: auto;
  transform: translateY(100%); transition: transform 0.32s cubic-bezier(0.22,1,0.36,1);
  -webkit-overflow-scrolling: touch;
}
.detail.open { transform: translateY(0); }
.detail-inner { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }

.detail-photo {
  position: relative; aspect-ratio: 4/3; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 80px;
}
.detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.detail-back {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 12px; z-index: 2;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(6px); color: var(--text); font-size: 20px;
}
.detail-fav {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 2;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(6px); font-size: 20px;
}
.detail-content { padding: var(--gap); display: flex; flex-direction: column; gap: 20px; }
.detail-title { font-size: 26px; font-weight: 800; line-height: 1.1; }
.detail-desc { color: var(--text-dim); line-height: 1.5; }
.detail-meta { display: flex; gap: 16px; font-size: 13px; color: var(--text-dim); }

.macros-big { display: flex; gap: 10px; }
.macros-big .macro { padding: 14px 4px; animation: pop 0.35s ease both; }
.macros-big .macro .val { font-size: 22px; }

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); margin-bottom: 10px; }

.ingredients { display: flex; flex-direction: column; gap: 2px; }
.ingredient {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 15px;
}
.ingredient .amt { color: var(--text-dim); font-weight: 600; flex: 0 0 auto; }

.steps { display: flex; flex-direction: column; gap: 14px; counter-reset: step; }
.step { display: flex; gap: 12px; }
.step::before {
  counter-increment: step; content: counter(step);
  flex: 0 0 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px;
}
.step p { line-height: 1.5; padding-top: 3px; }

/* ===== Filtros ===== */
.filter-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.filter-group label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 8px; font-weight: 600; }
.filter-group input, .filter-group select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; color: var(--text); font-size: 16px; font-family: var(--font);
}
.btn {
  width: 100%; padding: 15px; border: none; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 800;
  box-shadow: var(--glow);
}
.btn-ghost { background: var(--surface); color: var(--text); box-shadow: none; border: 1px solid var(--border); }

/* ===== Estados ===== */
.empty { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty .icon { font-size: 48px; margin-bottom: 12px; }
.skeleton { background: var(--surface); border-radius: var(--radius); height: 280px; animation: pulse 1.4s ease-in-out infinite; }

/* ===== Tabbar ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
}
.tab {
  flex: 1; background: none; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 20px;
}
.tab span { font-size: 10px; font-weight: 600; }
.tab.active { color: var(--accent); }

/* ===== Toast (fondo OPACO) ===== */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 80;
  background: var(--surface-2); color: var(--text);
  padding: 12px 20px; border-radius: 999px; border: 1px solid var(--border);
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.show { animation: toastPop 2.2s ease forwards; }

/* ===== Animaciones ===== */
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { 0% { opacity: 0; transform: scale(0.9); } 60% { transform: scale(1.04); } 100% { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 0.8; } }
@keyframes toastPop {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px); }
  10%,85% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(20px); }
}

/* ===== Admin / formularios ===== */
#modal.open { transform: translateY(0); }
.modal-head {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 14px 14px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 18px; font-weight: 800; flex: 1; }
.modal-head .x { background: none; border: none; color: var(--text); font-size: 24px; }
.form { padding: var(--gap); display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; color: var(--text); font-size: 16px; font-family: var(--font);
}
.field textarea { resize: vertical; min-height: 70px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; animation: fadeUp 0.3s ease both;
}
.list-item .thumb {
  width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 22px; flex: 0 0 auto; overflow: hidden;
}
.list-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .info .t { font-weight: 700; font-size: 15px; }
.list-item .info .s { font-size: 12px; color: var(--text-dim); }

/* Filas repetibles (ingredientes / pasos) */
.repeat-row { display: flex; gap: 8px; align-items: flex-start; }
.repeat-row .grow { flex: 1; }
.repeat-row .del { background: var(--surface-2); border: 1px solid var(--border); color: var(--fat); border-radius: 10px; padding: 0 12px; font-size: 18px; align-self: stretch; }
.add-row { background: var(--surface); border: 1px dashed var(--border); color: var(--accent); border-radius: var(--radius-sm); padding: 11px; font-weight: 700; width: 100%; }

/* FAB nuevo */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 55; width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 28px; box-shadow: var(--glow);
}

.parse-box { display: flex; gap: 8px; }
.parse-box button { flex: 0 0 auto; background: var(--surface-2); border: 1px solid var(--border); color: var(--accent); border-radius: var(--radius-sm); padding: 0 16px; font-weight: 700; }
.hint { font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.pill-link { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--accent); background: var(--bg-2); padding: 3px 8px; border-radius: 999px; }

/* ===== Modo cocina ===== */
.cook {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: none; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.cook.open { display: flex; }
.cook.flash { animation: cookFlash 0.6s ease 3; }
@keyframes cookFlash { 0%,100% { background: var(--bg); } 50% { background: var(--accent); } }

.cook-top { display: flex; align-items: center; gap: 12px; padding: 14px; }
.cook-count { flex: 1; text-align: center; font-weight: 800; font-size: 15px; color: var(--accent); letter-spacing: 1px; }
.cook-x { background: var(--surface); border: 1px solid var(--border); color: var(--text); width: 42px; height: 42px; border-radius: 50%; font-size: 18px; }

.cook-body { flex: 1; overflow-y: auto; padding: 10px 20px; display: flex; flex-direction: column; justify-content: center; }
.cook-step { font-size: 26px; line-height: 1.45; font-weight: 600; }
.cook-quick { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.cook-tbtn { background: var(--accent); color: var(--accent-ink); border: none; border-radius: 999px; padding: 12px 18px; font-weight: 800; font-size: 15px; box-shadow: var(--glow); }

.cook-timers { padding: 0 14px; display: flex; flex-direction: column; gap: 8px; }
.cook-timer { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.cook-timer .lbl { color: var(--text-dim); font-size: 13px; }
.cook-timer .cd { flex: 1; text-align: right; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent-2); }
.cook-timer.done { border-color: var(--accent); box-shadow: var(--glow); }
.cook-timer.done .cd { color: var(--accent); animation: pop 0.5s ease infinite alternate; }
.cook-timer .del { background: none; border: none; color: var(--text-dim); font-size: 18px; }

.cook-manual { display: flex; gap: 8px; padding: 12px 14px; }
.cook-manual input { width: 80px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; color: var(--text); font-size: 16px; }
.cook-manual button { flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); font-weight: 700; }

.cook-nav { display: flex; gap: 10px; padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); }
.cook-prev, .cook-next { flex: 1; padding: 18px; border: none; border-radius: var(--radius); font-size: 17px; font-weight: 800; }
.cook-prev { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.cook-next { background: var(--accent); color: var(--accent-ink); box-shadow: var(--glow); }
.cook-prev:disabled, .cook-next:disabled { opacity: 0.35; box-shadow: none; }

.cook-ing-ov { position: absolute; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; z-index: 5; }
.cook-ing-card { background: var(--surface); width: 100%; border-radius: var(--radius) var(--radius) 0 0; padding: 20px; max-height: 75%; overflow-y: auto; animation: fadeUp 0.25s ease; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

.cook-btn { /* botón "Cocinar" en el detalle */
  width: 100%; padding: 16px; border: none; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-size: 17px; font-weight: 800; box-shadow: var(--glow);
}
.detail-source { font-size: 13px; }
.detail-source a { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
