/* ===== Base ===== */
:root {
  --bg: #fbf7f0;
  --bg-2: #ffffff;
  --bg-3: #f3ece1;
  --texto: #24201b;
  --suave: #6d6459;
  --linea: #e6dccd;
  --acento: #1f6f4a;
  --acento-2: #c2603a;
  --sombra: 0 1px 2px rgba(60,45,25,.06), 0 8px 24px rgba(60,45,25,.07);
  --radio: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
html[data-tema="dark"] {
  --bg: #12100e;
  --bg-2: #1b1815;
  --bg-3: #241f1a;
  --texto: #f0e9df;
  --suave: #a79c8e;
  --linea: #332c25;
  --acento: #56c08c;
  --acento-2: #e8875c;
  --sombra: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--texto);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--linea);
  padding: max(10px, env(safe-area-inset-top)) 0 0;
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 6px 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.brand {
  font-family: var(--serif);
  font-size: 1.35rem; font-weight: 600; margin: 0;
  letter-spacing: -.01em; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* En pantallas angostas el título achica un poco y, si aun así no entra,
   pasa a dos renglones en vez de cortarse con puntos suspensivos. */
@media (max-width: 430px) {
  .brand {
    font-size: 1.12rem; line-height: 1.1;
    white-space: normal; overflow-wrap: anywhere;
  }
  .topbar-inner { padding: 6px 12px 10px; gap: 8px; }
  .btn-primary { padding: 9px 13px; }
}
@media (max-width: 360px) {
  .brand { font-size: 1rem; }
  /* El "modo local" es un aviso de configuración; en 320 px el título vale más. */
  .badge { display: none; }
  .btn-primary { padding: 8px 11px; font-size: .85rem; }
}

.badge {
  font-size: .68rem; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-3); color: var(--suave); border: 1px solid var(--linea);
  white-space: nowrap;
}
.badge:empty { display: none; }

.btn-primary {
  background: var(--acento); color: #fff; border: 0;
  padding: 9px 15px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  transition: filter .15s, transform .1s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(.97); }
html[data-tema="dark"] .btn-primary { color: #0d1a13; }

.btn-ghost {
  background: transparent; border: 1px solid var(--linea);
  padding: 9px 15px; border-radius: 999px; font-size: .9rem; color: var(--texto);
}
.btn-ghost:hover { background: var(--bg-3); }
.btn-danger {
  background: transparent; border: 1px solid #d4544a; color: #d4544a;
  padding: 9px 15px; border-radius: 999px; font-size: .9rem;
}
.btn-danger:hover { background: #d4544a; color: #fff; }
.btn-icon {
  background: transparent; border: 1px solid var(--linea);
  width: 36px; height: 36px; border-radius: 50%; font-size: 1rem; line-height: 1;
  display: grid; place-items: center; color: var(--suave);
}
.btn-icon:hover { background: var(--bg-3); }

/* ===== Buscador ===== */
.searchrow { max-width: 1100px; margin: 0 auto; padding: 0 16px 10px; }
.search { position: relative; display: flex; align-items: center; }
.search-ico {
  position: absolute; left: 13px; color: var(--suave); font-size: 1.15rem; pointer-events: none;
}
.search input {
  width: 100%; padding: 11px 38px 11px 38px;
  background: var(--bg-2); border: 1px solid var(--linea);
  border-radius: 999px; outline: none;
}
.search input:focus { border-color: var(--acento); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 8px; background: none; border: 0;
  color: var(--suave); font-size: .95rem; padding: 6px;
}

/* ===== Chips de categoría ===== */
.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  max-width: 1100px; margin: 0 auto; padding: 0 16px 12px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--linea); background: var(--bg-2);
  padding: 7px 13px; border-radius: 999px; font-size: .85rem; color: var(--suave);
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip:hover { border-color: var(--suave); }
.chip[aria-pressed="true"] {
  background: var(--texto); color: var(--bg); border-color: var(--texto); font-weight: 600;
}
.chip .n { opacity: .6; font-size: .78em; }

/* ===== Grilla ===== */
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
}
@media (min-width: 620px) {
  .grid { gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
}
.card {
  background: var(--bg-2); border: 1px solid var(--linea);
  border-radius: var(--radio); overflow: hidden; box-shadow: var(--sombra);
  text-align: left; padding: 0; display: flex; flex-direction: column;
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 6px 14px rgba(60,45,25,.1), 0 18px 40px rgba(60,45,25,.1); }
.card-img {
  aspect-ratio: 16/10; background-size: cover; background-position: center;
  display: grid; place-items: center; font-size: 2.6rem; position: relative;
}
.card-fav {
  position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.35);
  border: 0; color: #fff; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1rem; backdrop-filter: blur(4px);
}
.card-fav.on { color: #ffd166; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-cat { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--c, var(--acento-2)); font-weight: 700; }
.card-tit { font-family: var(--serif); font-size: 1.05rem; line-height: 1.25; margin: 0; }
.card-desc { font-size: .82rem; color: var(--suave); line-height: 1.4; margin: 0; }
html[data-tema="dark"] .card-cat,
html[data-tema="dark"] .det-cat { color: color-mix(in srgb, var(--c, var(--acento-2)) 62%, white); }
.card-meta { margin-top: auto; padding-top: 6px; font-size: .75rem; color: var(--suave); display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== Estado vacío / carga ===== */
.estado { text-align: center; color: var(--suave); padding: 48px 16px; }
.estado:empty { display: none; }
.estado h3 { font-family: var(--serif); color: var(--texto); font-size: 1.25rem; margin: 0 0 6px; }
.estado p { margin: 0 0 16px; font-size: .92rem; }

/* ===== Overlays ===== */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20,15,10,.5); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0 } }
.sheet {
  position: relative; background: var(--bg); width: 100%; max-width: 720px;
  max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 22px 22px 0 0; box-shadow: 0 -8px 40px rgba(0,0,0,.3);
  animation: subir .25s cubic-bezier(.2,.8,.3,1);
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
@keyframes subir { from { transform: translateY(28px); opacity: .6 } }
@media (min-width: 700px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: 20px; max-height: 88vh; }
  @keyframes subir { from { transform: scale(.97); opacity: .5 } }
}
.sheet-close {
  position: absolute; top: 12px; right: 12px; z-index: 3;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: var(--bg-3); color: var(--texto); font-size: .9rem;
  display: grid; place-items: center;
}
html[data-tema="dark"] .sheet-close { background: rgba(0,0,0,.5); }
.sheet-title { font-family: var(--serif); font-size: 1.35rem; margin: 0 0 18px; }

/* ===== Detalle ===== */
.det-hero { aspect-ratio: 16/9; background-size: cover; background-position: center; display: grid; place-items: center; font-size: 4rem; }
.det-hero.sin-foto { aspect-ratio: auto; height: 104px; font-size: 2.6rem; }
.det-body { padding: 20px 22px 4px; }
.det-cat { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--c, var(--acento-2)); font-weight: 700; }
.det-tit { font-family: var(--serif); font-size: 1.7rem; line-height: 1.15; margin: 6px 0 8px; }
.det-desc { color: var(--suave); margin: 0 0 16px; line-height: 1.5; }
.det-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.stat {
  background: var(--bg-3); border: 1px solid var(--linea); border-radius: 12px;
  padding: 8px 12px; font-size: .82rem;
}
.stat b { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--suave); font-weight: 600; }
.det-h { font-family: var(--serif); font-size: 1.12rem; margin: 24px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--linea); }
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { padding: 3px 0; }
/* Toda la fila es tocable: en el celular, apuntarle al cuadradito es un fastidio. */
.lista label { display: flex; gap: 11px; align-items: flex-start; line-height: 1.5; cursor: pointer; padding: 7px 0; min-height: 34px; }
.lista input[type=checkbox] { margin-top: .18em; accent-color: var(--acento); width: 21px; height: 21px; flex: 0 0 auto; }
.lista input:checked + span { text-decoration: line-through; opacity: .45; }
.pasos { counter-reset: p; }
.pasos li { display: flex; gap: 12px; padding: 9px 0; line-height: 1.55; border-bottom: 1px dashed var(--linea); }
.pasos li:last-child { border-bottom: 0; }
.pasos li::before {
  counter-increment: p; content: counter(p);
  flex: 0 0 24px; height: 24px; border-radius: 50%;
  background: var(--acento); color: #fff; font-size: .78rem; font-weight: 700;
  display: grid; place-items: center; margin-top: 1px;
}
html[data-tema="dark"] .pasos li::before { color: #0d1a13; }
.notas { background: var(--bg-3); border-left: 3px solid var(--acento-2); padding: 12px 14px; border-radius: 0 12px 12px 0; line-height: 1.55; font-size: .92rem; }
.uso { background: var(--bg-3); border-left: 3px solid var(--acento); padding: 12px 14px; border-radius: 0 12px 12px 0; line-height: 1.55; font-size: .92rem; }
.precaucion {
  display: flex; gap: 11px; align-items: flex-start;
  background: #fdf0e7; border: 1px solid #f0c9ae; color: #7a3d16;
  padding: 13px 15px; border-radius: 12px; line-height: 1.55; font-size: .92rem;
}
html[data-tema="dark"] .precaucion { background: #2d1d12; border-color: #5c3a1f; color: #f2c9a4; }
.precaucion-ico {
  flex: 0 0 20px; height: 20px; border-radius: 50%; margin-top: 1px;
  background: #c2601f; color: #fff; font-weight: 800; font-size: .76rem;
  display: grid; place-items: center;
}
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 18px; }
.tag { background: var(--bg-3); border: 1px solid var(--linea); border-radius: 999px; padding: 4px 10px; font-size: .76rem; color: var(--suave); }
.det-pie { display: flex; gap: 10px; align-items: center; padding: 22px 22px 0; border-top: 1px solid var(--linea); margin-top: 24px; }
.det-autor { font-size: .78rem; color: var(--suave); flex: 1; }

/* ===== Formulario ===== */
#form { padding: 22px 22px 0; }
.campo { display: block; margin-bottom: 15px; }
.campo > span { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; }
.campo > span em { font-weight: 400; color: var(--suave); font-style: normal; }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 10px 12px; background: var(--bg-2);
  border: 1px solid var(--linea); border-radius: 12px; outline: none;
}
.campo textarea { resize: vertical; line-height: 1.5; font-family: var(--sans); }
.campo input:focus, .campo select:focus, .campo textarea:focus { border-color: var(--acento); }
.campo-fila { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .campo-fila { grid-template-columns: 1fr 1fr; } .campo-fila .campo:last-child { grid-column: 1 / -1; } }

.foto-box { display: flex; gap: 12px; align-items: center; }
.foto-prev {
  width: 84px; height: 84px; border-radius: 12px; flex: 0 0 auto;
  background: var(--bg-3) center/cover; border: 1px dashed var(--linea);
  display: grid; place-items: center; color: var(--suave); font-size: 1.5rem;
}
.foto-btns { display: flex; flex-direction: column; gap: 8px; }
.foto-btns .btn-ghost { text-align: center; }

.form-acciones {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 0 4px; margin-top: 8px;
  position: sticky; bottom: 0; background: var(--bg);
  border-top: 1px solid var(--linea);
}
.form-acciones .spacer { flex: 1; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 90;
  background: var(--texto); color: var(--bg);
  padding: 11px 18px; border-radius: 999px; font-size: .88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fade .2s;
  max-width: 90vw; text-align: center;
}
