/*
 * Producto: toCook (007 TCK)
 * Paleta base: Huerta — verde mercado + crema + acento limón
 * Referencias usadas: apps de cámara/escáner (visor como héroe) + recetarios editoriales food
 * Técnicas aplicadas:
 *   1. Visor de cámara como anchor visual — la captura ES la interfaz (no un botón escondido)
 *   2. Chips de ingredientes con "tres tonos por estado" (tint + border + texto deep)
 *   3. Scan-line animada + esquinas de encuadre tipo escáner (decoración funcional, no ruido)
 *   4. clip-path en el shutter + mask radial en el visor (técnicas no-default)
 */

:root {
  /* Huerta */
  --verde:        #3f6f4a;   /* principal */
  --verde-2:      #7aa45c;   /* secundario */
  --verde-deep:   #2f4032;   /* texto fuerte */
  --crema:        #f6f1e7;   /* fondo */
  --crema-2:      #fdfbf6;   /* superficie */
  --limon:        #e8c34a;   /* acento */
  --limon-deep:   #8a6d12;

  /* tints "tres tonos por estado" */
  --verde-tint:   #e3eed8;
  --limon-tint:   #faf0c8;
  --rojo:         #c0533e;   /* solo para alertas/eliminar */
  --rojo-tint:    #f4ddd6;

  --texto:        #2f4032;
  --texto-soft:   #6f7a68;
  --linea:        #e3ddcf;

  --sombra-sm:    0 2px 8px -4px rgba(47,64,50,.25);
  --sombra:       0 8px 24px -12px rgba(47,64,50,.35);
  --sombra-lg:    0 20px 50px -24px rgba(47,64,50,.45);

  --r-sm: 10px; --r: 14px; --r-lg: 20px;
  --fuente: 'Inter', system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--fuente);
  background: var(--crema);
  color: var(--texto);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100dvh;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ---------- App shell mobile-first ---------- */
.app { max-width: 560px; margin: 0 auto; padding: 0 16px 96px; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 4px 14px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--verde); color: #fff;
  display: grid; place-items: center; font-size: 15px;
  box-shadow: var(--sombra-sm);
}
.brand .mark svg { width: 17px; height: 17px; }
.top .acc { display: flex; align-items: center; gap: 8px; }

.btn {
  font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 999px;
  background: var(--verde); color: #fff;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
  box-shadow: var(--sombra-sm);
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn.ghost { background: transparent; color: var(--verde); box-shadow: none; }
.btn.outline { background: var(--crema-2); color: var(--verde-deep); box-shadow: inset 0 0 0 1.5px var(--linea); }
.btn.lim { background: var(--limon); color: var(--limon-deep); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Pestañas Cámara / Despensa ---------- */
.tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--crema-2); border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--linea);
  margin: 4px 2px 16px;
}
.tab {
  flex: 1; font-weight: 700; font-size: 14px;
  padding: 9px 12px; border-radius: 999px; color: var(--texto-soft);
  transition: all .15s ease;
}
.tab.on { background: var(--verde); color: #fff; box-shadow: var(--sombra-sm); }
.vista[hidden] { display: none; }

/* ---------- Despensa ---------- */
.despensa-search { position: relative; }
#despensa-input {
  width: 100%; font-family: inherit; font-size: 15px;
  padding: 14px 16px; border-radius: var(--r);
  background: var(--crema-2); color: var(--texto);
  border: 1.5px solid var(--linea); outline: none;
  transition: border-color .12s ease;
}
#despensa-input:focus { border-color: var(--verde-2); }
.autocomplete {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 10;
  background: var(--crema-2); border-radius: var(--r);
  box-shadow: var(--sombra); border: 1px solid var(--linea);
  overflow: hidden; max-height: 280px; overflow-y: auto;
}
.autocomplete button {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  padding: 12px 16px; font-size: 15px; color: var(--texto); text-align: left;
  border-bottom: 1px solid var(--linea);
}
.autocomplete button:last-child { border-bottom: none; }
.autocomplete button:hover, .autocomplete button:focus { background: var(--verde-tint); }
.autocomplete .cat { font-size: 11px; color: var(--texto-soft); text-transform: capitalize; }
.despensa-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 2px 4px; min-height: 8px; }
.despensa-chips .chip { cursor: pointer; }
.despensa-chips .chip .x { font-weight: 800; opacity: .55; margin-left: 2px; }
.despensa-chips .chip:hover .x { opacity: 1; }

/* ---------- HÉROE: visor de cámara ---------- */
.viewer-wrap { margin-top: 6px; }
.viewer {
  position: relative;
  aspect-ratio: 4/5;
  border-radius: var(--r-lg);
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 40%, #cfe0bf 0%, #9bbd86 60%, #7aa45c 100%);
  display: grid; place-items: center;
  box-shadow: var(--sombra-lg);
  -webkit-mask-image: radial-gradient(140% 140% at 50% 50%, #000 70%, rgba(0,0,0,.92));
}
.viewer.has-photo { background: var(--verde-deep); }
.viewer .preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* esquinas de encuadre */
.frame i { position: absolute; width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.9); }
.frame i:nth-child(1){ top: 18px; left: 18px; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.frame i:nth-child(2){ top: 18px; right: 18px; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.frame i:nth-child(3){ bottom: 18px; left: 18px; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.frame i:nth-child(4){ bottom: 18px; right: 18px; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

/* scan-line animada (solo en idle) */
.scanline {
  position: absolute; left: 10%; right: 10%; height: 3px;
  background: var(--limon); border-radius: 3px;
  box-shadow: 0 0 16px 2px var(--limon);
  animation: scan 2.6s ease-in-out infinite;
}
@keyframes scan { 0%,100%{ top: 22%; opacity:.4 } 50%{ top: 78%; opacity:1 } }
.viewer.has-photo .scanline, .viewer.loading .scanline { display: none; }

.viewer .hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  color: #fff; font-weight: 600; font-size: 12.5px;
  padding: 6px 14px; border-radius: 999px;
  background: rgba(47,64,50,.55); backdrop-filter: blur(4px);
  white-space: nowrap;
}

/* shutter (botón de captura) — clip-path no default */
.shutter-bar { display: flex; justify-content: center; margin-top: -34px; position: relative; z-index: 3; }
.shutter {
  width: 72px; height: 72px; border-radius: 50%;
  background: #fff; box-shadow: var(--sombra);
  display: grid; place-items: center;
  transition: transform .12s ease;
}
.shutter:active { transform: scale(.92); }
.shutter::after {
  content: ''; width: 54px; height: 54px; border-radius: 50%;
  background: var(--verde);
  box-shadow: inset 0 0 0 4px #fff;
}
.shutter.busy::after { background: var(--limon); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100%{ transform: scale(1) } 50%{ transform: scale(.82) } }

.subhint { text-align: center; color: var(--texto-soft); font-size: 13px; margin-top: 12px; }
.subhint b { color: var(--verde); }

/* ---------- Chips de ingredientes ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 2px 4px; }
.chip {
  font-size: 13px; font-weight: 600;
  padding: 8px 13px; border-radius: 999px;
  background: var(--verde-tint); color: var(--verde);
  box-shadow: inset 0 0 0 1px rgba(63,111,74,.18);
  display: inline-flex; align-items: center; gap: 7px;
  animation: chipin .35s cubic-bezier(.2,.8,.3,1) backwards;
}
.chip.dudoso { background: var(--limon-tint); color: var(--limon-deep); box-shadow: inset 0 0 0 1px rgba(138,109,18,.22); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .6; }
@keyframes chipin { from { opacity: 0; transform: translateY(6px) scale(.96); } }

/* ---------- Cards de receta ---------- */
.section-h { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 2px 14px; }
.section-h h2 { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.section-h .count { font-size: 13px; color: var(--texto-soft); font-weight: 600; }

.cards { display: grid; gap: 14px; }
.card {
  background: var(--crema-2); border-radius: var(--r);
  padding: 15px 16px; box-shadow: var(--sombra-sm);
  border: 1px solid var(--linea);
  transition: transform .14s ease, box-shadow .14s ease;
  text-align: left; width: 100%;
}
.card:active { transform: translateY(1px); }
.card:hover { box-shadow: var(--sombra); }
.card .ct { font-size: 16px; font-weight: 700; color: var(--verde-deep); line-height: 1.3; }
.card .meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; align-items: center; }
.badge {
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 8px;
  background: var(--verde-tint); color: var(--verde);
}
.badge.tipo-postre { background: #f4e3ec; color: #9c3f6a; }
.badge.tipo-bebida { background: #e0eef0; color: #2f6f7a; }
.badge.tipo-snack  { background: var(--limon-tint); color: var(--limon-deep); }
.badge.t { background: transparent; color: var(--texto-soft); padding-left: 2px; }
.badge.combo { background: var(--verde); color: #fff; }
.fav-star { margin-left: auto; color: var(--limon); font-size: 18px; line-height: 1; }

/* ---------- Estados ---------- */
.skeleton { background: var(--crema-2); border-radius: var(--r); border: 1px solid var(--linea); padding: 15px 16px; }
.skeleton .l { height: 13px; border-radius: 6px; background: linear-gradient(90deg,#eee7d8,#f3eee2,#eee7d8); background-size: 200% 100%; animation: shine 1.3s linear infinite; }
.skeleton .l.t { width: 70%; height: 17px; margin-bottom: 11px; }
.skeleton .l.s { width: 40%; }
@keyframes shine { from{ background-position: 200% 0 } to{ background-position: -200% 0 } }

.empty { text-align: center; padding: 40px 20px; color: var(--texto-soft); }
.empty .ic { width: 64px; height: 64px; margin: 0 auto 14px; color: var(--verde-2); }
.empty p { font-size: 14px; max-width: 280px; margin: 0 auto; }

/* ---------- Filtros dietéticos ---------- */
.filtros-wrap { position: relative; margin-top: 6px; }
.filtros-wrap::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 36px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(246,241,231,0), var(--crema));
}
.filtros { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 2px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.filtros::-webkit-scrollbar { display: none; }
.filtro {
  flex: 0 0 auto; font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 999px;
  background: var(--crema-2); color: var(--texto-soft);
  box-shadow: inset 0 0 0 1.5px var(--linea);
  transition: all .12s ease;
}
.filtro.on { background: var(--verde); color: #fff; box-shadow: none; }

/* ---------- Modal (detalle + auth + planes) ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(47,64,50,.5);
  backdrop-filter: blur(3px);
  display: none; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--crema-2); width: 100%; max-width: 560px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  max-height: 92dvh; overflow-y: auto;
  padding: 8px 20px 32px;
  animation: up .28s cubic-bezier(.2,.8,.3,1);
}
@keyframes up { from { transform: translateY(100%); } }
.modal .grip { width: 42px; height: 5px; border-radius: 3px; background: var(--linea); margin: 8px auto 16px; }
.modal h3 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.modal .meta { margin: 14px 0 18px; }
.modal h4 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--verde); margin: 20px 0 10px; }
.modal ul, .modal ol { padding-left: 4px; list-style: none; }
.modal .ing li { padding: 9px 0; border-bottom: 1px solid var(--linea); font-size: 15px; display: flex; gap: 10px; }
.modal .ing li::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--verde-2); margin-top: 8px; flex: 0 0 auto; }
.modal .pasos li { counter-increment: paso; padding: 12px 0 12px 42px; position: relative; font-size: 15px; border-bottom: 1px solid var(--linea); }
.modal .pasos li::before {
  content: counter(paso); position: absolute; left: 0; top: 10px;
  width: 28px; height: 28px; border-radius: 9px;
  background: var(--verde-tint); color: var(--verde);
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.modal .pasos { counter-reset: paso; }
.modal .actions { display: flex; gap: 10px; margin-top: 24px; position: sticky; bottom: 0; background: var(--crema-2); padding: 12px 0 0; }

/* formularios auth */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--texto-soft); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; font-family: inherit; font-size: 15px;
  padding: 12px 14px; border-radius: var(--r-sm);
  background: #fff; color: var(--texto);
  border: 1.5px solid var(--linea); outline: none;
  transition: border-color .12s ease;
}
.field input:focus { border-color: var(--verde-2); }
.msg { font-size: 13px; padding: 10px 12px; border-radius: var(--r-sm); margin-bottom: 12px; }
.msg.err { background: var(--rojo-tint); color: var(--rojo); }
.msg.ok { background: var(--verde-tint); color: var(--verde); }
.switch-auth { text-align: center; font-size: 13px; color: var(--texto-soft); margin-top: 14px; }
.switch-auth button { color: var(--verde); font-weight: 700; }

/* planes */
.planes { display: grid; gap: 12px; margin-top: 8px; }
.plan {
  border: 1.5px solid var(--linea); border-radius: var(--r);
  padding: 16px; background: #fff; position: relative;
}
.plan.destacado { border-color: var(--verde); box-shadow: 0 0 0 3px var(--verde-tint); }
.plan .badge-pop { position: absolute; top: -10px; right: 14px; background: var(--limon); color: var(--limon-deep); font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 7px; }
.plan .pn { font-size: 17px; font-weight: 800; color: var(--verde-deep); }
.plan .pp { font-size: 24px; font-weight: 800; margin: 4px 0 12px; }
.plan .pp span { font-size: 14px; font-weight: 600; color: var(--texto-soft); }
.plan ul { list-style: none; font-size: 14px; }
.plan ul li { padding: 5px 0 5px 24px; position: relative; color: var(--texto); }
.plan ul li::before { content: '✓'; position: absolute; left: 0; color: var(--verde-2); font-weight: 800; }
.plan ul li.no { color: var(--texto-soft); }
.plan ul li.no::before { content: '–'; color: var(--linea); }

/* aviso de límite */
.limite-aviso { background: var(--limon-tint); color: var(--limon-deep); border-radius: var(--r); padding: 14px 16px; margin: 16px 2px; font-size: 14px; font-weight: 600; display: flex; gap: 10px; align-items: center; }

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