/* ==========================================================================
   Despensa — sistema visual
   Tokens deliberados: superficie fría de cocina, tinta casi negra, y un único
   acento verde reservado para "esto está fresco". El color solo aparece cuando
   significa algo: frescura, prisa o urgencia.
   ========================================================================== */

:root {
  --bg:        #F2F2F7;
  --bg-deep:   #E8E8ED;
  --card:      rgba(255, 255, 255, 0.72);
  --card-solid:#FFFFFF;
  --ink:       #1C1C1E;
  --ink-2:     #6E6E73;
  --ink-3:     #A1A1A6;
  --sep:       rgba(60, 60, 67, 0.13);
  --tint:      #248A3D;
  --fresh:     #34C759;
  --soon:      #FF9F0A;
  --urgent:    #FF3B30;
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --shadow-up: 0 -1px 40px rgba(0,0,0,.14);
  --r-card:    22px;
  --r-ctrl:    14px;
  --spring:    cubic-bezier(.32, .72, 0, 1);
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #000000;
    --bg-deep:   #0A0A0C;
    --card:      rgba(28, 28, 30, 0.76);
    --card-solid:#1C1C1E;
    --ink:       #F2F2F7;
    --ink-2:     #98989E;
    --ink-3:     #636366;
    --sep:       rgba(84, 84, 88, 0.5);
    --tint:      #30D158;
    --shadow:    0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
  }
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  font-size: 17px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select {
  font: inherit; color: inherit; border: 0; background: none; margin: 0;
}
button { cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--tint); outline-offset: 2px; border-radius: 6px; }

/* ---------- tipografía ---------- */

.t-large  { font-size: 34px; font-weight: 700; letter-spacing: -0.7px; line-height: 1.1; }
.t-title  { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.t-head   { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; }
.t-body   { font-size: 16px; }
.t-cap    { font-size: 13px; color: var(--ink-2); }
.t-mini   { font-size: 11px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase; color: var(--ink-3); }

/* ==========================================================================
   Arranque y skeletons — nunca hay ruedas girando
   ========================================================================== */

@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

.sk {
  background: linear-gradient(90deg, var(--bg-deep) 25%, rgba(255,255,255,.55) 37%, var(--bg-deep) 63%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 8px;
}
@media (prefers-color-scheme: dark) {
  .sk { background: linear-gradient(90deg, #1C1C1E 25%, #2C2C2E 37%, #1C1C1E 63%); background-size: 200% 100%; }
}
.sk-card { height: 210px; border-radius: var(--r-card); }
.sk-line  { height: 13px; border-radius: 7px; }
.sk-chip  { height: 30px; width: 96px; border-radius: 15px; }

.boot { padding: 60px 28px; }
.boot-bar { height: 38px; width: 200px; margin-bottom: 28px; }
.boot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.boot .sk-card, .boot .boot-bar {
  background: linear-gradient(90deg, var(--bg-deep) 25%, rgba(255,255,255,.55) 37%, var(--bg-deep) 63%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--r-card);
}

/* ==========================================================================
   Estructura
   ========================================================================== */

.shell { display: flex; height: 100%; }

.sidebar {
  width: 264px; flex: none; padding: 22px 14px calc(14px + var(--safe-b));
  display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--sep);
  background: var(--bg-deep);
  overflow-y: auto;
}
.sidebar h1 { margin: 6px 10px 18px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 11px; width: 100%;
  font-size: 16px; font-weight: 500; text-align: left;
  transition: background .18s ease, transform .18s var(--spring);
}
.nav-item:active { transform: scale(.97); }
.nav-item[aria-current="true"] { background: var(--card-solid); box-shadow: var(--shadow); font-weight: 600; }
.nav-icon { font-size: 19px; width: 24px; text-align: center; }
.nav-count { margin-left: auto; font-size: 14px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.nav-count.alarm { color: var(--urgent); }

.main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(120px + var(--safe-b)); }
.main-head { padding: 26px 28px 12px; }
.main-head .t-large { margin: 0 0 3px; }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 15px; padding: 12px 28px 28px;
}

/* móvil y tablet: la barra lateral pasa a ser una fila de chips arriba */
@media (max-width: 1024px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: auto; flex-direction: row; overflow-x: auto; gap: 8px;
    border-right: 0; border-bottom: 1px solid var(--sep); padding: 10px 14px;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar h1 { display: none; }
  .side-foot { margin-top: 0; padding-top: 0; }
  .nav-item { width: auto; white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card-solid); }
  .main-head { padding: 18px 18px 8px; }
  .grid { padding: 10px 18px 24px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
  .ring-wrap { width: 100px; height: 100px; }
  .card-name { font-size: 17px; }
  .chip { font-size: 13px; padding: 4px 12px; }
  .fab { padding: 18px 26px; font-size: 18px; }
}

/* iPad vertical: rejilla fija de 3 columnas y hojas centradas más anchas */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  .grid { grid-template-columns: repeat(3, 1fr); padding-left: 28px; padding-right: 28px; }
  .sheet {
    left: 50%; right: auto; bottom: 24px; transform: translateX(-50%);
    width: min(600px, 92vw); max-width: 600px; border-radius: 26px; max-height: 86vh;
  }
}

.side-foot { margin-top: auto; padding-top: 12px; }

/* ==========================================================================
   Tarjeta de producto — el anillo de frescura es la firma de la app
   ========================================================================== */

@keyframes pop-in { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 9px; padding: 18px 12px 15px; text-align: center;
  background: var(--card); backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-radius: var(--r-card); box-shadow: var(--shadow);
  animation: pop-in .34s var(--spring) both;
  transition: transform .22s var(--spring), box-shadow .22s ease;
}
.card:active { transform: scale(.955); }
.card.is-gone { opacity: .35; transform: scale(.9); pointer-events: none; }

.ring-wrap { position: relative; width: 82px; height: 82px; }
.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-linecap: round; }
.ring .track { stroke: var(--sep); }
.ring .arc { transition: stroke-dashoffset .7s var(--spring), stroke .3s ease; }

.thumb {
  position: absolute; inset: 7px; border-radius: 50%; overflow: hidden;
  background: var(--bg-deep); display: grid; place-items: center; font-size: 30px;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .45s ease; }
.thumb img.loaded { opacity: 1; }

.card-name {
  font-size: 15px; font-weight: 600; letter-spacing: -0.2px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-qty { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.chip {
  font-size: 11.5px; font-weight: 650; letter-spacing: -0.1px;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.chip.fresh  { color: var(--fresh);  background: rgba(52,199,89,.14); }
.chip.soon   { color: #B26A00;       background: rgba(255,159,10,.16); }
.chip.urgent { color: var(--urgent); background: rgba(255,59,48,.14); }
.chip.none   { color: var(--ink-3);  background: rgba(120,120,128,.12); }
.chip.buy    { color: #B26A00; background: rgba(255,159,10,.16); font-size: 11.5px; padding: 3px 9px; }
@media (prefers-color-scheme: dark) { .chip.soon { color: var(--soon); } }

/* ==========================================================================
   Botones y controles
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border-radius: var(--r-ctrl); font-size: 16px; font-weight: 600;
  background: var(--card-solid); box-shadow: var(--shadow);
  transition: transform .16s var(--spring), opacity .16s ease;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--tint); color: #fff; box-shadow: 0 4px 16px rgba(36,138,61,.34); }
.btn.plain   { background: none; box-shadow: none; color: var(--tint); }
.btn.danger  { color: var(--urgent); }
.btn.wide    { width: 100%; }

.fabs {
  position: fixed; right: 24px; bottom: calc(24px + var(--safe-b));
  display: flex; gap: 12px; z-index: 40;
}
.fab {
  display: flex; align-items: center; gap: 9px; padding: 15px 22px;
  border-radius: 999px; font-size: 16px; font-weight: 650;
  background: var(--card-solid); box-shadow: 0 6px 30px rgba(0,0,0,.18);
  transition: transform .18s var(--spring);
}
.fab:active { transform: scale(.94); }
.fab:disabled { opacity: .45; transform: none; }
.fab.primary { background: var(--tint); color: #fff; }

.search {
  width: 100%; padding: 11px 15px; border-radius: 11px; font-size: 16px;
  background: rgba(120,120,128,.12); color: var(--ink);
}
.search::placeholder { color: var(--ink-3); }

.field { width: 100%; padding: 13px 15px; border-radius: var(--r-ctrl); background: rgba(120,120,128,.12); font-size: 16px; }
textarea.field { resize: vertical; min-height: 108px; line-height: 1.45; font-size: 15px; }

.stepper { display: flex; align-items: center; gap: 4px; background: rgba(120,120,128,.12); border-radius: 12px; padding: 4px; }
.stepper button { width: 44px; height: 40px; border-radius: 9px; font-size: 22px; font-weight: 400; transition: background .15s ease; }
.stepper button:active { background: var(--card-solid); }
.stepper .val { min-width: 76px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }

.seg { display: flex; gap: 3px; background: rgba(120,120,128,.12); border-radius: 11px; padding: 3px; }
.seg button { flex: 1; padding: 8px 10px; border-radius: 9px; font-size: 14px; font-weight: 550; transition: background .2s var(--spring); }
.seg button[aria-pressed="true"] { background: var(--card-solid); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 650; }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 8px 13px; border-radius: 999px; font-size: 14px; font-weight: 550;
  background: rgba(120,120,128,.12); transition: transform .15s var(--spring);
}
.pill:active { transform: scale(.94); }
.pill[aria-pressed="true"] { background: var(--tint); color: #fff; }

/* ==========================================================================
   Hojas modales — suben con muelle, se arrastran para cerrar
   ========================================================================== */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 50; animation: fade-in .28s ease both; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--card-solid); border-radius: 26px 26px 0 0;
  box-shadow: var(--shadow-up);
  animation: sheet-up .42s var(--spring) both;
  padding-bottom: var(--safe-b);
}
@media (min-width: 861px) {
  .sheet {
    left: 50%; right: auto; bottom: 24px; transform: translateX(-50%);
    width: min(560px, 92vw); border-radius: 26px; max-height: 86vh;
  }
  @keyframes sheet-up { from { transform: translate(-50%, 40px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
}

.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--ink-3); opacity: .35; margin: 9px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 10px 20px 12px; border-bottom: 1px solid var(--sep); flex: none; }
.sheet-head .t-title { flex: 1; }
.sheet-body { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 14px 20px calc(18px + var(--safe-b)); border-top: 1px solid var(--sep); display: flex; gap: 10px; flex: none; }

.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }

/* ---------- listas dentro de hojas ---------- */

.list { border-radius: var(--r-ctrl); overflow: hidden; background: rgba(120,120,128,.08); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--sep); }
.list-row:last-child { border-bottom: 0; }
.list-row .em { font-size: 24px; flex: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .name { font-weight: 600; font-size: 15px; }

.check {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 2px solid var(--ink-3); display: grid; place-items: center;
  color: #fff; font-size: 14px; transition: background .2s var(--spring), border-color .2s ease;
}
.check[aria-pressed="true"] { background: var(--tint); border-color: var(--tint); }

/* ---------- recetas ---------- */

.recipe {
  padding: 16px; border-radius: 18px; background: rgba(120,120,128,.09);
  display: flex; gap: 14px; text-align: left; width: 100%;
  animation: pop-in .3s var(--spring) both;
  transition: transform .18s var(--spring);
}
.recipe:active { transform: scale(.975); }
.recipe .em { font-size: 30px; flex: none; }
.recipe .hook { font-size: 14px; color: var(--ink-2); margin-top: 3px; }
.recipe .meta { font-size: 12.5px; color: var(--ink-3); margin-top: 7px; display: flex; gap: 12px; }

.step { display: flex; gap: 13px; padding: 13px 0; border-bottom: 1px solid var(--sep); }
.step:last-child { border-bottom: 0; }
.step .n {
  width: 25px; height: 25px; border-radius: 50%; flex: none; background: var(--tint); color: #fff;
  font-size: 13px; font-weight: 700; display: grid; place-items: center;
}
.step .time { font-size: 12.5px; color: var(--tint); font-weight: 600; margin-top: 4px; }

/* ---------- avisos y vacíos ---------- */

.banner {
  margin: 4px 28px 0; padding: 15px 18px; border-radius: 18px;
  background: var(--card-solid); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
  animation: pop-in .4s var(--spring) both;
}
@media (max-width: 860px) { .banner { margin: 4px 18px 0; } }

.empty { padding: 64px 32px; text-align: center; color: var(--ink-2); }
.empty .em { font-size: 46px; display: block; margin-bottom: 14px; }
.empty .t-head { color: var(--ink); margin-bottom: 6px; }

.error { padding: 13px 15px; border-radius: 12px; background: rgba(255,59,48,.12); color: var(--urgent); font-size: 14.5px; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%);
  padding: 12px 20px; border-radius: 999px; z-index: 60;
  background: rgba(28,28,30,.92); color: #fff; font-size: 15px; font-weight: 550;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); animation: pop-in .3s var(--spring) both;
}

/* ---------- acceso ---------- */

.login { height: 100%; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(340px, 100%); text-align: center; }
.login-box .em { font-size: 54px; margin-bottom: 16px; display: block; }
.login-box .field { margin: 22px 0 12px; text-align: center; }

/* ---------- respeto por quien reduce el movimiento ---------- */

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