/* CDS Sync — "Periodico" magazine archive + 3D flipbook viewer.
   Year tabs over a grid of covers; clicking a cover opens a page-flip viewer.
   Self-contained + defensive so it looks consistent in any theme / Elementor. */

.cds-per {
  --cds-blue: #02A3E0;
  --cds-blue-dark: #0285ba;
  --cds-ink: #1f2733;
  --cds-muted: #6b7480;
  --cds-card: #ffffff;
  --cds-line: #e6e9ef;
  --cds-soft: #f4f7fb;
  --cds-per-cols: 4;
  font-family: inherit;
  color: var(--cds-ink);
}
.cds-per *, .cds-per *::before, .cds-per *::after { box-sizing: border-box; }
.cds-per button { margin: 0; font-family: inherit; background: none; border: none; cursor: pointer; -webkit-appearance: none; appearance: none; color: inherit; }
/* Never let the theme/Elementor paint a fallback colour on button hover/focus —
   our own brand-coloured states below take over. */
.cds-per button:hover, .cds-per button:focus { background-color: transparent; }
.cds-per--empty { padding: 28px; text-align: center; color: var(--cds-muted); }

/* ---- Year tabs ---- */
.cds-per-tabs {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--cds-line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  margin: 0 0 26px;
}
.cds-per-tab {
  flex: 1 1 auto;
  color: var(--cds-muted);
  font-size: clamp(20px, 2.4vw, 30px);
  font-weight: 400;
  line-height: 1.1;
  padding: 14px 18px;
  transition: background .15s ease, color .15s ease;
}
/* Dividers between the year tabs. Higher specificity than the defensive
   `.cds-per button { border:none }` reset above, which would otherwise erase them. */
.cds-per .cds-per-tab { border-right: 1px solid var(--cds-line); }
.cds-per .cds-per-tab:last-child { border-right: 0; }
.cds-per-tab:hover { background: var(--cds-soft); color: var(--cds-ink); }
/* High specificity so the active tab keeps its brand fill through hover/focus
   (beats the defensive button:focus reset above). */
.cds-per .cds-per-tab.is-active,
.cds-per .cds-per-tab.is-active:hover,
.cds-per .cds-per-tab.is-active:focus {
  background: var(--cds-blue);
  color: #fff;
}
.cds-per-tab:focus-visible { outline: 2px solid var(--cds-blue); outline-offset: -2px; }

/* ---- Panels + grid ---- */
.cds-per-panel { display: none; }
.cds-per-panel.is-active { display: block; }
.cds-per-grid {
  display: grid;
  grid-template-columns: repeat(var(--cds-per-cols), minmax(0, 1fr));
  gap: 28px 24px;
}

/* ---- Year divider layout (alternative to tabs) ---- */
.cds-per-yeardiv {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 0 0 24px;
}
.cds-per-yeardiv:not(:first-child) { margin-top: 46px; }
.cds-per-yeardiv::before,
.cds-per-yeardiv::after {
  content: "";
  flex: 1 1 auto;
  height: 2px;
  border-radius: 2px;
  background: var(--cds-line);
}
.cds-per-yeardiv__label {
  flex: none;
  font-size: clamp(22px, 2.6vw, 32px);
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--cds-blue);
}

/* ---- Cover item ---- */
.cds-per-item { display: flex; flex-direction: column; align-items: center; }
.cds-per-cover {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--cds-line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--cds-soft);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 22px rgba(16, 24, 40, .08);
  transition: transform .2s ease, box-shadow .2s ease;
  aspect-ratio: 1 / 1.414;            /* A4 portrait */
}
.cds-per-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cds-per-cover__ph {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--cds-muted);
}
/* Restore the cover border (the button:border reset strips it) + brand hover. */
.cds-per .cds-per-cover { border: 1px solid var(--cds-line); }
.cds-per-cover:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 8px rgba(16, 24, 40, .08), 0 22px 40px rgba(2, 163, 224, .22);
}
.cds-per .cds-per-cover:hover { border-color: var(--cds-blue); }
.cds-per-cover:focus-visible { outline: 3px solid var(--cds-blue); outline-offset: 2px; }
/* Caption follows the brand colour on hover (not Elementor's link fallback). */
.cds-per-item:hover .cds-per-occ,
.cds-per-item:hover .cds-per-num { color: var(--cds-blue); }
/* hover "Sfoglia" chip */
.cds-per-cover__hint {
  position: absolute;
  left: 50%; bottom: 14px;
  transform: translate(-50%, 8px);
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--cds-blue);
  color: #fff;
  font-size: 14px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(2, 163, 224, .45);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.cds-per-cover:hover .cds-per-cover__hint,
.cds-per-cover:focus-visible .cds-per-cover__hint { opacity: 1; transform: translate(-50%, 0); }

.cds-per-cap { margin-top: 14px; text-align: center; }
.cds-per-occ {
  display: block;
  font-size: clamp(15px, 1.5vw, 18px);
  font-weight: 800;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--cds-ink);
}
.cds-per-num {
  display: block;
  margin-top: 3px;
  font-size: 13.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--cds-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ====================== Flipbook modal ====================== */
.cds-per-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cds-per-modal[hidden] { display: none; }
.cds-per-modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(10, 16, 26, .82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.cds-per-modal__inner {
  position: relative;
  z-index: 1;
  width: min(98vw, 1480px);
  height: min(96vh, 960px);
  display: flex;
  flex-direction: column;
  animation: cds-per-zoom .22s ease;
}
@keyframes cds-per-zoom { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

.cds-per-modal__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 4px 12px;
  color: #fff;
}
.cds-per-modal__title { font-size: 17px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cds-per-modal__tools { display: flex; align-items: center; gap: 6px; flex: none; }
.cds-per-modal__pages { font-size: 14px; color: rgba(255, 255, 255, .8); margin-right: 4px; font-variant-numeric: tabular-nums; }
.cds-per-modal__btn {
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.cds-per-modal__btn:hover { background: rgba(255, 255, 255, .24); }
.cds-per-modal__close:hover { background: #e8443b; }

.cds-per-modal__stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
/* The book lives in a flex child between the two arrows, so the arrows always
   sit OUTSIDE the pages and the book is centered in the remaining space. */
.cds-per-flipwrap {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cds-per-flip { margin: 0; }
.cds-per-flip .stf__parent { margin: 0 auto; }
.cds-per-flip img { width: 100%; height: 100%; display: block; object-fit: contain; }

/* side arrows (flex siblings, never overlap the book) — bold + brand-coloured */
.cds-per-modal__edge {
  flex: none;
  z-index: 3;
  width: 58px; height: 58px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--cds-blue);
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  transition: background .15s ease, transform .15s ease;
}
.cds-per-modal__edge:hover { background: var(--cds-blue-dark); transform: scale(1.08); }
.cds-per-modal__edge svg { width: 28px; height: 28px; }

/* loading + error */
.cds-per-loading, .cds-per-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #fff; text-align: center;
}
.cds-per-spinner {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  animation: cds-per-spin .8s linear infinite;
}
@keyframes cds-per-spin { to { transform: rotate(360deg); } }
.cds-per-loading__txt { font-size: 15px; opacity: .9; }
.cds-per-progress { width: 180px; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, .22); overflow: hidden; }
.cds-per-progress__bar { display: block; height: 100%; width: 0; background: #fff; transition: width .2s ease; }
.cds-per-error[hidden] { display: none; }
.cds-per-error__dl { color: #fff; font-weight: 700; text-decoration: underline; }

/* Shared by the modal stage and the inline embed stage. */
.cds-per-stage.is-ready .cds-per-loading { display: none; }

/* ====================== Inline flipbook embed ([cds_flipbook]) ====================== */
.cds-per--embed { --cds-per-embed-h: clamp(420px, 72vh, 860px); }
.cds-per-embed {
  margin: 0;
  border: 1px solid var(--cds-line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 18px 44px rgba(16, 24, 40, .12);
}
.cds-per-embed__head {
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--cds-line);
  background: linear-gradient(180deg, #fff, var(--cds-soft));
}
.cds-per-embed__title {
  font-size: clamp(16px, 1.6vw, 21px);
  font-weight: 800; letter-spacing: .3px; text-transform: uppercase;
  color: var(--cds-ink);
}
.cds-per-embed__meta {
  font-size: 13px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  color: var(--cds-blue);
}
.cds-per-embed__viewer {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  height: var(--cds-per-embed-h);
  padding: 16px;
  background: radial-gradient(130% 110% at 50% 0%, #2a3340 0%, #161c25 72%);
}
.cds-per-embed__stage {
  position: relative;
  flex: 1 1 auto; min-width: 0; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
/* Side arrows reuse the modal edge look, a touch smaller. */
.cds-per-embed__edge { width: 50px; height: 50px; }
.cds-per-embed__edge svg { width: 24px; height: 24px; }

.cds-per-embed__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--cds-line);
  background: #fff;
}
.cds-per-embed__pages { font-size: 13.5px; font-weight: 600; color: var(--cds-muted); font-variant-numeric: tabular-nums; }
.cds-per-embed__tools { display: flex; align-items: center; gap: 6px; }
.cds-per-embed__btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--cds-soft);
  color: var(--cds-ink);
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.cds-per-embed__btn:hover { background: var(--cds-blue); color: #fff; }
.cds-per-embed__btn svg { width: 20px; height: 20px; }

/* Fullscreen: the viewer fills the screen, the book re-fits via JS. */
.cds-per-embed__viewer:fullscreen,
.cds-per-embed__viewer:-webkit-full-screen { width: 100vw; height: 100vh; padding: 26px; }

/* ---- Responsive ---- */
@media (max-width: 700px) {
  .cds-per-grid { gap: 22px 16px; }
  .cds-per-tab { font-size: 18px; padding: 11px 10px; }
  .cds-per-modal__inner { width: 100vw; height: 100vh; }
  .cds-per-modal__bar { padding: 10px 10px 10px; }
  .cds-per-modal__title { font-size: 14px; }
  .cds-per-modal__edge { display: none; } /* swipe / toolbar arrows instead */
  .cds-per-modal__btn { width: 40px; height: 40px; }
  .cds-per--embed { --cds-per-embed-h: 66vh; }
  .cds-per-embed__viewer { padding: 8px; }
  .cds-per-embed__head { padding: 13px 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .cds-per-cover, .cds-per-cover__hint, .cds-per-modal__inner { transition: none; animation: none; }
  .cds-per-spinner { animation-duration: 1.5s; }
}
