/* ══════════════════════════════════════════════════════
   TWD DISTRIBUTOR SOLUTIONS — Brand Stylesheet v2
   Navy  #1C2B4B  |  Gold  #BE8E4B  |  Text #333333
   Font: Poppins (Google Fonts)
   ══════════════════════════════════════════════════════ */

:root {
  --twd-navy:     #1C2B4B;
  --twd-gold:     #BE8E4B;
  --text-color:   #333333;
  --gold-soft:    rgba(190, 142, 75, 0.12);
  --stripe-navy:  22%;
  --stripe-total: 32%;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
  background: #181f2e;
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}


/* ══════════════════════════════════════════════════════
   App bar
   ══════════════════════════════════════════════════════ */
#app-bar {
  background: var(--twd-navy);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  flex: 0 0 auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  z-index: 10;
}

#brand-name {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}
#brand-logo {
  height: 40px;
  width: auto;
  display: block;
}

#controls {
  display: flex;
  flex: 1;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

#search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}

#search {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 5px;
  font-size: 0.84rem;
  font-family: inherit;
  background: rgba(255,255,255,0.08);
  color: #fff;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#search::placeholder { color: rgba(255,255,255,0.36); }
#search:focus { border-color: var(--twd-gold); background: rgba(255,255,255,0.13); }

/* ── Search suggestions dropdown (jump-to-product) ── */
#search-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  overflow: hidden;
  max-height: 280px;
  overflow-y: auto;
  z-index: 50;
}

.search-suggestion {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--twd-navy);
  background: #fff;
  border: none;
  border-bottom: 1px solid #f0f2f7;
  cursor: pointer;
  transition: background 0.12s;
}
.search-suggestion:last-child { border-bottom: none; }
.search-suggestion:hover,
.search-suggestion.is-active {
  background: var(--gold-soft);
}

.search-suggestion-empty {
  padding: 10px 14px;
  font-size: 0.78rem;
  color: #8a8f9c;
}

/* Brief highlight pulse on the product row a search jump lands on */
@keyframes twd-search-pulse {
  0%   { background-color: var(--gold-soft); }
  100% { background-color: transparent; }
}
.product-row.search-highlight {
  animation: twd-search-pulse 1.8s ease-out;
  border-radius: 6px;
}

#results-count {
  font-size: 0.74rem;
  color: rgba(255,255,255,0.48);
  white-space: nowrap;
}

#app-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

#admin-link {
  font-size: 0.74rem;
  font-weight: 600;
  color: rgba(255,255,255,0.52);
  text-decoration: none;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 5px;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: color 0.18s, border-color 0.18s;
}
#admin-link:hover { color: var(--twd-gold); border-color: rgba(190,142,75,0.4); }

#btn-download-pdf {
  font-size: 0.74rem;
  font-weight: 600;
  font-family: inherit;
  color: rgba(255,255,255,0.52);
  background: transparent;
  cursor: pointer;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 5px;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: color 0.18s, border-color 0.18s;
}
#btn-download-pdf:hover { color: var(--twd-gold); border-color: rgba(190,142,75,0.4); }


/* ══════════════════════════════════════════════════════
   Book stage — dark studio backdrop
   ══════════════════════════════════════════════════════ */
#book-scene {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  background: radial-gradient(ellipse 80% 65% at 50% 46%, #22304a 0%, #181f2e 100%);
  position: relative;
  min-height: 220px;
  min-width: 0;
  /* Lets the user pan around once #book-frame is scaled up past 100% zoom. */
  overflow: auto;
}

/* Sized in JS to the exact computed book dimensions — see #book-frame
   comment in index.html. autoSize then has nothing extra to stretch into.
   The zoom controls scale this same element via a CSS transform, which
   keeps St.PageFlip's own layout math untouched. */
#book-frame {
  position: relative;
  transition: transform 0.18s ease;
  flex: 0 0 auto;
}
#book       { position: relative; z-index: 1; }

/* Outer book shadow */
.stf__parent {
  box-shadow:
    0 24px 64px rgba(0,0,0,0.55),
    0  6px 20px rgba(0,0,0,0.35);
}

/*
  Spine / center-fold shadow — CSS crease visible at rest;
  StPageFlip canvas shadows animate during the flip.
  Only meaningful in two-page spread mode (#book-frame.is-spread, set in
  script.js from pageSize().spread) — in single-page/mobile mode there's
  only one page filling the frame, so this would otherwise draw a stray
  vertical line straight through the middle of it.
*/
.stf__wrapper { position: relative; }
#book-frame.is-spread .stf__wrapper::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 10px;
  transform: translateX(-50%);
  background: linear-gradient(
    to right,
    transparent            0%,
    rgba(0,0,0,0.10)      25%,
    rgba(0,0,0,0.28)      50%,
    rgba(0,0,0,0.10)      75%,
    transparent           100%
  );
  pointer-events: none;
  z-index: 999;
}

.stf__item--left  { box-shadow: inset -10px 0 24px rgba(0,0,0,0.14); }
.stf__item--right { box-shadow: inset  10px 0 24px rgba(0,0,0,0.14); }


/* ══════════════════════════════════════════════════════
   Navigation
   ══════════════════════════════════════════════════════ */
#book-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 24px;
  padding: 12px 20px;
  background: #111722;
  border-top: 1px solid rgba(255,255,255,0.05);
}
#book-nav[hidden] { display: none; }

.nav-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Visual separator between the page-flip controls and the zoom controls */
.nav-group--zoom {
  padding-left: 18px;
  border-left: 1px solid rgba(255,255,255,0.1);
}
@media (max-width: 480px) {
  .nav-group--zoom { padding-left: 0; border-left: none; }
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 18px;
  border: 1px solid rgba(190,142,75,0.42);
  border-radius: 5px;
  background: transparent;
  color: var(--twd-gold);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
}
.nav-btn svg { width: 15px; height: 15px; flex: 0 0 auto; }

/* Compact square buttons for zoom in/out/reset */
.nav-btn--icon {
  padding: 0;
  width: 32px;
  height: 32px;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

#zoom-level {
  min-width: 42px;
  text-align: center;
  font-size: 0.76rem;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.04em;
  font-family: inherit;
}
.nav-btn:hover:not(:disabled) { background: rgba(190,142,75,0.1); border-color: var(--twd-gold); }
.nav-btn:disabled { opacity: 0.26; cursor: default; }

#page-info {
  min-width: 80px;
  text-align: center;
  font-size: 0.76rem;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.04em;
  font-family: inherit;
}


/* ══════════════════════════════════════════════════════
   Empty state
   ══════════════════════════════════════════════════════ */
#empty {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 20px;
  background: radial-gradient(ellipse 80% 65% at 50% 46%, #22304a 0%, #181f2e 100%);
  color: rgba(255,255,255,0.32);
  min-height: 300px;
}
#empty:not([hidden]) { display: flex; }
#empty p { font-size: 0.88rem; }


/* ══════════════════════════════════════════════════════
   Page base (shared by all flipbook page types)
   container-type enables cqw units inside pages.
   ══════════════════════════════════════════════════════ */
.page {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  background: #fff;
  user-select: none;
  container-type: inline-size;
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
}
.page-inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}


/* ══════════════════════════════════════════════════════
   .portada  —  Cover page
   Left border: Navy (outer) + Gold (inner) CSS stripes
   TWD logo pinned to bottom-right
   ══════════════════════════════════════════════════════ */
.page.portada {
  background:
    linear-gradient(
      to right,
      var(--twd-navy)  0%,
      var(--twd-navy)  var(--stripe-navy),
      var(--twd-gold)  var(--stripe-navy),
      var(--twd-gold)  var(--stripe-total),
      #fff             var(--stripe-total)
    );
}
/* Padding/margins in cqw (not fixed px) so they shrink proportionally with
   the page on mobile — otherwise they eat a bigger relative share of a
   shorter page and squeeze the logo down against the bottom edge instead
   of leaving it the same breathing room desktop has. */
.page.portada .page-inner {
  padding: 9.47cqw 7.37cqw 7.37cqw calc(var(--stripe-total) + 6.32cqw);
  justify-content: space-between;
}
.page.portada .portada-intro {
  font-size: 2.36cqw;
  font-weight: 400;
  color: var(--text-color);
  line-height: 1.6;
  margin-top: 3.68cqw;
}
.page.portada .portada-bottom {
  display: flex;
  justify-content: flex-end;
}
.page.portada .twd-logo img {
  height: 9.47cqw;
  width: auto;
  display: block;
}
.page.portada .twd-logo .logo-sub {
  font-size: 2.11cqw;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(28,43,75,0.4);
  margin-top: 1.05cqw;
}


/* ══════════════════════════════════════════════════════
   .cierre  —  Back cover page
   Right border: Navy (outer) + Gold (inner) CSS stripes
   ══════════════════════════════════════════════════════ */
.page.cierre {
  background:
    linear-gradient(
      to left,
      var(--twd-navy)  0%,
      var(--twd-navy)  var(--stripe-navy),
      var(--twd-gold)  var(--stripe-navy),
      var(--twd-gold)  var(--stripe-total),
      #fff             var(--stripe-total)
    );
}
.page.cierre .page-inner {
  padding: 10.53cqw calc(var(--stripe-total) + 7.37cqw) 9.47cqw 8.42cqw;
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
  gap: 3.16cqw;
}
.page.cierre .twd-logo {
  margin-top: auto;
}
.page.cierre .twd-logo img {
  height: 9.47cqw;
  width: auto;
  display: block;
}
.page.cierre .cierre-text {
  font-size: 2.36cqw;
  color: var(--text-color);
  line-height: 1.6;
  font-weight: 400;
}
.page.cierre .cierre-text strong { font-weight: 800; color: var(--twd-navy); }
.page.cierre .cierre-copy {
  font-size: 1.52cqw;
  color: #9aa3b8;
  margin-top: 1.58cqw;
  line-height: 1.4;
}


/* ══════════════════════════════════════════════════════
   .page-productos  (ref: page-13.jpg — new design)

   Layout:
     ┌── pg-header (64px, absolute top) ─────────────┐
     │  [════Navy════✕]  [✕═Gold═✕]   TWD Logo       │
     └────────────────────────────────────────────────┘
     pg-body (fills remaining space, padded)
       products-list (2-3 rows, however many fit fully)
         product-row (flex: image 40% | text 60%)
     ┌── pg-footer (40px, absolute bottom) ───────────┐
     │  [════Gold════✕]  [✕══════Navy══════]          │
     └────────────────────────────────────────────────┘

   Diagonal shapes use clip-path on full-size overlays
   (both at inset:0) so all % values share the same
   coordinate system → guarantees parallel cuts.
   ══════════════════════════════════════════════════════ */
.page.page-productos { background: #fff; }

/* ── Header ── */
.pg-header {
  position: absolute;
  top: 3.68cqw; left: 0; right: 0;
  height: 3.42cqw;
  overflow: hidden;
  background: #fff;
}

/* Both shape layers fill the entire header box */
.pg-header-navy,
.pg-header-gold {
  position: absolute;
  inset: 0;
}

/*
  Navy parallelogram — left section, roughly half the width.
  At top: 0% → 50%.  At bottom: 0% → 46%.
  Right-edge slope: 4 pp per full header height.
*/
.pg-header-navy {
  background: var(--twd-navy);
  clip-path: polygon(0 0, 50% 0, 46% 100%, 0 100%);
}

/*
  Gold parallelogram — second section, narrower than navy,
  set apart from the logo by a white gap. Same 4-pp slope.
  Top: 51% → 71%.  Bottom: 47% → 67%.
*/
.pg-header-gold {
  background: var(--twd-gold);
  clip-path: polygon(51% 0, 71% 0, 67% 100%, 47% 100%);
}

/*
  Logo — top-right corner, independent of the thin header band
  so it can be larger than the stripe without being clipped.
*/
.pg-header-logo {
  position: absolute;
  top: 2.11cqw; right: 3.68cqw;
  display: flex;
  align-items: center;
  z-index: 2;
}
.pg-header-logo img {
  max-height: 6.84cqw;
  width: auto;
  display: block;
}

/* ── Body ── */
.pg-body {
  position: absolute;
  top: 7.11cqw;
  bottom: 7.11cqw;
  left: 0; right: 0;
  overflow: hidden;
  padding: 2.63cqw 4.74cqw;
  display: flex;
  flex-direction: column;
}

/* 2-3 products per page (however many fit fully) — rows size to their
   own content and extra space is distributed evenly, like the source PDF. */
.products-list {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0;
  justify-content: space-evenly;
  min-height: 0;
}

/* ── Product row — height follows its own content, never stretched ── */
.product-row {
  display: flex;
  align-items: center;
  gap: 5.05cqw;
  flex: 0 0 auto;
  padding: 1.58cqw 0;
  border-bottom: 1px solid #f0f2f7;
}
.product-row:last-child { border-bottom: none; }

/* Left column — fixed-size thumbnail, independent of row height.
   Pure cqw (no floor) so it shrinks proportionally with the page on
   narrow screens instead of staying pinned at a fixed px size — that's
   what keeps the same 2-3-products-per-page composition at every size
   instead of mobile collapsing to 1-per-page. */
.product-img-col {
  flex: 0 0 38%;
  height: 24cqw;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-img-col img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  /*
    mix-blend-mode: multiply removes white product-image backgrounds
    when displayed on the white page background, mimicking
    transparency without requiring transparent PNGs.
  */
  mix-blend-mode: multiply;
  display: block;
}

/* Fallback emoji shown when no image loads */
.product-img-col .img-fallback {
  font-size: 6.74cqw;
  opacity: 0.35;
  line-height: 1;
}

/* Right column — 60% — text */
.product-text-col {
  flex: 1;
  min-width: 0;
}

/* Brand rule: Navy · Bold · Uppercase
   Pure cqw, calibrated so the result at the desktop page width (380px)
   matches the previous fixed size exactly — desktop looks unchanged,
   while mobile now scales down with the page instead of holding steady
   at a floor size (which used to make text take up relatively more
   room on narrow pages and collapse pagination to 1 product/page). */
.product-name {
  text-transform: uppercase;
  font-weight: 800;
  font-size: 2.61cqw;
  color: var(--twd-navy);
  line-height: 1.2;
  letter-spacing: 0.03em;
}

/* Description + price (price is embedded at end of text) */
.product-desc {
  margin-top: 2.11cqw;
  font-weight: 400;
  font-size: 2.32cqw;
  color: var(--text-color);
  line-height: 1.6;
}

/* ── Footer ── */
.pg-footer {
  position: absolute;
  bottom: 3.68cqw; left: 0; right: 0;
  height: 3.42cqw;
  overflow: hidden;
  background: #fff;
}

.pg-footer-gold,
.pg-footer-navy {
  position: absolute;
  inset: 0;
}

/*
  Footer mirrors the header with the opposite slant
  (bottom-right to top-left) and swapped colors.
  No logo here, so navy fills the remainder to the edge.
  Gold — Top: 0% → 46%.  Bottom: 0% → 50%.
  Navy — Top: 47% → 100%. Bottom: 51% → 100%.
*/
.pg-footer-gold {
  background: var(--twd-gold);
  clip-path: polygon(0 0, 46% 0, 50% 100%, 0 100%);
}
.pg-footer-navy {
  background: var(--twd-navy);
  clip-path: polygon(47% 0, 100% 0, 100% 100%, 51% 100%);
}


/* ══════════════════════════════════════════════════════
   Skeleton loader
   ══════════════════════════════════════════════════════ */
#skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 5;
  background: radial-gradient(ellipse 80% 65% at 50% 46%, #22304a 0%, #181f2e 100%);
  pointer-events: none;
}
#skeleton[hidden] { display: none; }

.sk-book {
  position: relative;
  display: flex;
  width: min(720px, calc(100vw - 40px));
  height: clamp(300px, 50vh, 480px);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 22px 58px rgba(0,0,0,0.5), 0 5px 18px rgba(0,0,0,0.32);
}

@keyframes sk-shimmer {
  0%   { background-position: -720px 0; }
  100% { background-position:  720px 0; }
}
.sk-page {
  flex: 1;
  background-color: #252e42;
  background-image: linear-gradient(90deg, #252e42 0px, #303d58 40%, #252e42 80%);
  background-size: 720px 100%;
  animation: sk-shimmer 1.5s infinite linear;
  padding: 18px 16px;
  position: relative;
  overflow: hidden;
}
.sk-page--left { border-right: 1px solid rgba(0,0,0,0.3); }
.sk-page--left::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 12px; height: 100%;
  background: rgba(255,255,255,0.05);
}
.sk-header-bar {
  height: 20px;
  background: rgba(255,255,255,0.07);
  border-radius: 3px;
  margin-bottom: 14px;
}
.sk-line {
  height: 9px;
  background: rgba(255,255,255,0.08);
  border-radius: 5px;
  margin-bottom: 8px;
}
.sk-line--short  { width: 36%; }
.sk-line--medium { width: 58%; }
.sk-line--long   { width: 80%; }
.sk-product-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  height: clamp(80px, 25%, 112px);
  margin-bottom: 8px;
}
.sk-product-img {
  flex: 0 0 clamp(50px, 14%, 68px);
  height: 100%;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
}
.sk-product-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  padding-top: 4px;
}
.sk-spine {
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 8px;
  transform: translateX(-50%);
  background: linear-gradient(to right, transparent, rgba(0,0,0,0.28) 50%, transparent);
  z-index: 1;
}
.sk-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.28);
  animation: sk-pulse 1.6s ease-in-out infinite;
  font-family: inherit;
}
@keyframes sk-pulse {
  0%, 100% { opacity: 0.3; }
  50%       { opacity: 1; }
}


/* ══════════════════════════════════════════════════════
   Responsive
   The flipbook's own pixel size is computed in script.js
   (pageSize()), which measures the real #app-bar/#book-nav
   height at runtime and shrinks the book so it always fits
   the viewport — no scrolling needed to reach Prev/Next.
   These rules only handle chrome (bar/nav/touch targets);
   they intentionally avoid forcing tall min-heights that
   would fight that calculation.
   ══════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  #app-bar       { padding: 8px 12px; gap: 8px; }
  #brand-logo    { height: 30px; }
  #controls      { gap: 6px; }
  #app-bar-actions { gap: 6px; }
  #book-scene    { padding: 14px 10px; min-height: 180px; }
  #book-nav      { gap: 8px 14px; padding: 8px 14px; }
  .nav-btn       { padding: 8px 16px; font-size: 0.78rem; min-height: 40px; }
  .nav-btn--icon { padding: 0; width: 40px; min-height: 40px; }
  #admin-link,
  #btn-download-pdf { padding: 8px 10px; min-height: 36px; display: inline-flex; align-items: center; }
}

/* Short viewports (landscape phones) — trim chrome further so the book
   stays as large as possible without ever pushing nav off-screen. */
@media (max-height: 480px) {
  #app-bar    { padding: 6px 12px; }
  #book-scene { padding: 8px 10px; min-height: 140px; }
  #book-nav   { padding: 6px 14px; }
  .nav-btn    { min-height: 34px; padding: 6px 14px; }
  .nav-btn--icon { width: 34px; padding: 0; }
}


/* ══════════════════════════════════════════════════════
   PDF export (print)
   #print-pages holds plain, untransformed clones of every
   page — built by buildPrintPages() in script.js — kept
   hidden on screen and revealed only when printing, since
   the flipbook's 3D transforms don't render in print.
   Page size (380×538px ≈ 100.6×142.4mm) matches the
   on-screen flipbook exactly, so the PDF looks identical.
   ══════════════════════════════════════════════════════ */
#print-pages { display: none; }

@media print {
  @page {
    size: 100.6mm 142.4mm;
    margin: 0;
  }
  #app-bar, #book-scene, #book-nav, #empty, #skeleton { display: none !important; }
  body { background: #fff; }
  #print-pages { display: block; }
  /*
    Browsers skip CSS backgrounds (gradients/colors) when printing
    unless explicitly told to keep them — without this, the navy/gold
    stripes (all built with `background`) render as blank white.
  */
  #print-pages, #print-pages * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  #print-pages .page {
    width: 380px;
    height: 538px;
    box-shadow: none;
    page-break-after: always;
  }
  #print-pages .page:last-child { page-break-after: auto; }
}
