* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  line-height: 1.5;
}
[hidden] { display: none !important; }

/* ---------- Encabezado ---------- */
header {
  background: #1e293b;
  padding: 0.8rem 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid #334155;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}
.brandbar { display: flex; align-items: center; gap: 0.8rem; }
.logo { height: 52px; width: auto; background: #fff; border-radius: 6px; padding: 2px; }
.brandbar p { font-size: 0.8rem; opacity: 0.75; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
header button, #flipToolbar button, #flipToolbar select {
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
}
#updateBtn, .primary { background: #0ea5e9; }
.secondary { background: #334155; }
#updateBtn:disabled { opacity: 0.6; cursor: wait; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.seg { display: inline-flex; background: #0f172a; border-radius: 9px; padding: 3px; }
.seg button { background: transparent; color: #94a3b8; padding: 0.45rem 0.8rem; }
.seg button.active { background: #334155; color: #fff; }
#status { flex-basis: 100%; font-size: 0.8rem; color: #94a3b8; min-height: 1em; text-align: center; }
#status:empty { display: none; }

@media (max-width: 640px) {
  header { justify-content: center; text-align: center; }
  .brandbar { flex-direction: column; gap: 0.2rem; }
  .logo { height: 44px; }
  .actions { justify-content: center; }
  header button { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
}

#appUpdate {
  display: block; width: 100%; border: none; cursor: pointer;
  background: #308647; color: #fff; font: inherit; font-size: 0.9rem; padding: 0.6rem 1rem;
}

/* ---------- Buscador ---------- */
#searchBar { background: #1e293b; padding: 0.7rem 0.7rem 0; }
.search-box {
  display: flex; align-items: center; gap: 0.5rem;
  max-width: 640px; margin: 0 auto;
  background: #0f172a; border: 1px solid #334155; border-radius: 10px; padding: 0 0.4rem 0 0.8rem;
}
.search-box:focus-within { border-color: #0ea5e9; }
#searchInput {
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  color: #e2e8f0; font: inherit; font-size: 16px; padding: 0.65rem 0;
}
#searchInput::-webkit-search-cancel-button { display: none; }
#searchClear { background: #334155; color: #fff; border: none; border-radius: 6px; padding: 0.3rem 0.6rem; cursor: pointer; }
#searchActions {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.8rem 1rem 0; max-width: 100%;
}
#searchCount { font-size: 0.9rem; color: #94a3b8; }
#searchActions button {
  border: none; padding: 0.55rem 1rem; border-radius: 8px; font-size: 0.9rem; cursor: pointer; color: #fff;
}

/* ---------- Categorías ---------- */
nav#categories {
  display: flex;
  overflow-x: auto;
  gap: 0.5rem;
  padding: 0.7rem;
  background: #1e293b;
  border-bottom: 1px solid #334155;
}
nav#categories button {
  flex-shrink: 0;
  background: #334155;
  color: #e2e8f0;
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
}
nav#categories button.active { background: #0ea5e9; color: white; }

/* ---------- Cuadrícula ---------- */
main#products {
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.product {
  background: #1e293b;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #334155;
  display: flex;
  flex-direction: column;
}
.product img { width: 100%; height: 140px; object-fit: contain; background: #fff; }
.product-info { padding: 0.7rem; display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.p-brand { font-size: 0.7rem; letter-spacing: 0.06em; color: #94a3b8; font-weight: 600; }
.product-info h3 { font-size: 0.88rem; line-height: 1.25; }
.p-meta { font-size: 0.75rem; color: #94a3b8; }
.product-info .price { color: #38bdf8; font-weight: bold; }
.p-actions { display: flex; gap: 0.4rem; margin-top: auto; padding-top: 0.5rem; }
.p-actions button {
  flex: 1; background: #334155; color: #fff; border: none; padding: 0.4rem 0.5rem;
  border-radius: 6px; font-size: 0.78rem; cursor: pointer;
}
.p-actions button[data-act="pdf"] { background: #0ea5e9; }
.p-actions button[data-act="share"] { flex: 0 0 auto; }

/* ---------- Flipbook ---------- */
#flipView { padding: 1rem 12px 0.5rem; display: flex; flex-direction: column; align-items: center; }
#flipStage { margin: 0 auto; max-width: 100%; }
.flip-book { margin: 0 auto; }
.page { background: #fff; overflow: hidden; }
.page-hard { background: #143346; }

#flipToolbar {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: 0.5rem; margin-top: 0.9rem; max-width: 100%;
}
#flipToolbar button { padding: 0.5rem 0.85rem; }
#prevBtn, #nextBtn { background: #334155; min-width: 44px; }
#pageInfo { font-size: 0.85rem; color: #94a3b8; min-width: 64px; text-align: center; }
#flipToolbar select { background: #334155; max-width: 220px; padding-right: 0.6rem; }

/* Ficha (misma geometría que el PDF; unidades relativas a la página) */
.ficha {
  position: relative; width: 100%; height: 100%;
  background: #fff; color: #143346;
  container-type: size;
  font-family: Helvetica, Arial, sans-serif;
  line-height: 1;
}
.f-head { position: absolute; left: 0; top: 0; width: 100%; background: #143346; }
.f-text { position: absolute; white-space: nowrap; }
.f-bold { font-weight: 700; color: #fff; }
.f-title { white-space: normal; line-height: 1.05; }
.f-desc { white-space: normal; line-height: 1.2; color: #143346; }
.f-foot { color: #143346; }
.f-pre { white-space: pre; }
.f-logo { position: absolute; background: #fff; padding: 0.35%; display: flex; align-items: center; justify-content: center; }
.f-logo img { max-width: 100%; max-height: 100%; }
.f-card { position: absolute; border: 1px solid #dce5e9; background: #fff; }
.f-img { position: absolute; display: flex; align-items: center; justify-content: center; }
.f-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.f-noimg { font-size: 2cqw; color: #94a3b8; }
.f-label {
  position: absolute; left: 4%; right: 4%; text-align: center;
  font-weight: 700; color: #143346; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.f-rule { position: absolute; background: #308647; }
.ficha.blank { display: flex; align-items: center; justify-content: center; }
.ficha.blank img { width: 30%; opacity: 0.12; }

/* Portadas */
.cover {
  width: 100%; height: 100%; background: #143346; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4cqh; text-align: center; padding: 8%;
  container-type: size; font-family: Helvetica, Arial, sans-serif;
}
.cover-logo { background: #fff; padding: 3cqw; border-radius: 2cqw; width: 70%; }
.cover-logo img { width: 100%; display: block; }
.cover-cat { font-size: 7cqw; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
.cover-sub { font-size: 3.4cqw; opacity: 0.85; }
.cover-web { font-size: 3cqw; color: #7dd3a0; border-top: 0.5cqw solid #308647; padding-top: 2cqh; }

/* ---------- Varios ---------- */
footer { text-align: center; padding: 1.2rem; font-size: 0.75rem; opacity: 0.6; }
.empty { grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; opacity: 0.7; }
