/* ===== MODAL COMPONENTS ===== */
.modal {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
  z-index: 1000;
}

.modal.open {
  visibility: visible;
  opacity: 1;
}

.modal-content {
  position: relative;
  width: 94vw;
  height: 94vh;
  background-color: var(--bg-primary);
  border-radius: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: none;
}

/* ===== MODAL CONTROLS ===== */
.modal-close
{
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal-close {
  top: 1.5rem;
  right: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
}

.modal-close:hover  {
  background-color: var(--bg-primary);
  box-shadow: var(--shadow-lg);
}

.modal-close:hover {
  transform: scale(1.1);
}

/* Positionnement pour la modal principale */
.modal-close.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

.modal-close.close-btn:hover {
  background-color: rgba(255, 255, 255, 1);
  box-shadow: var(--shadow-md);
}



.btn-prev,
.btn-next {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: all var(--transition-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  box-shadow: var(--shadow-md);
  z-index: 20;
}

.btn-prev,
.btn-next {
  top: 50%;
  transform: translateY(-50%);
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-md);
  transition: right 0.3s ease, transform 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease, border-radius var(--transition-normal);
  z-index: 500;
}

.btn-prev {
  left: 1.5rem;
}

.btn-next {
  right: 1.5rem;
}

.btn-prev.hidden,
.btn-next.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.btn-prev:hover,
.btn-next:hover {
  background-color: var(--bg-primary);
  box-shadow: var(--shadow-lg);
}

.btn-prev:hover,
.btn-next:hover {
  transform: translateY(-50%) scale(1.05);
}

.btn-next.shifted {
  right: calc(320px + 1.5rem) !important;
}

.btn-next {
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity var(--transition-normal), visibility var(--transition-normal), transform var(--transition-normal), background-color var(--transition-normal), box-shadow var(--transition-normal), border-radius var(--transition-normal);
}

/* ===== MODAL TOOLBAR ===== */
.modal-toolbar {
  flex: 0 0 auto;
  background-color: var(--bg-primary);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem calc(0.75rem + constant(safe-area-inset-bottom));
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  box-shadow: none;
  border-top: 1px solid var(--border-light);
  z-index: 30;
}

.dark-mode .modal-toolbar {
  background-color: var(--bg-primary);
}

.modal-toolbar > .toolbar-btn,
.modal-toolbar > #page-indicator {
  flex-shrink: 0;
}

.toolbar-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ===== EMBED VIEWER ADJUSTMENTS ===== */
.embed-body #flipbook-modal .modal-content {
  box-sizing: border-box;
  padding-bottom: calc(5.5rem + constant(safe-area-inset-bottom));
  padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
}

.embed-body #flipbook-modal .flipbook-area {
  min-height: 0;
}

.embed-body #flipbook-modal .modal-toolbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
}

/* ===== TOOLBAR BUTTONS ===== */
.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--primary);
  color: var(--text-light);
  border: none;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0;
  cursor: pointer;
  transition: all var(--transition-normal);
  box-shadow: none;
  position: relative;
}

.toolbar-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: none;
}

.toolbar-btn::after {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-0.5rem);
  padding: 0.75rem;
  background-color: var(--tooltip-bg);
  color: var(--tooltip-color);
  border-radius: 0;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  box-shadow: none;
  z-index: 100;
}

.toolbar-btn:hover::after,
.toolbar-btn:focus::after {
  opacity: 1;
  transform: translateX(-50%) translateY(-0.75rem);
}

.toolbar-btn.secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  box-shadow: none;
}

.toolbar-btn.secondary:hover {
  background-color: var(--border-light);
  box-shadow: none;
}

.toolbar-btn .icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* ===== ZOOM CONTROLS ===== */
.zoom-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-tertiary);
  padding: 0.375rem 0.75rem;
  border-radius: 0;
  box-shadow: none;
  flex-grow: 0;
  flex-shrink: 1;
}

.zoom-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0;
  transition: background-color var(--transition-fast);
  position: relative;
}

.zoom-btn:hover {
  background-color: var(--border-light);
}

.zoom-btn::after {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-0.5rem);
  margin-bottom: 0.25rem;
  padding: 0.5rem 0.75rem;
  background-color: var(--tooltip-bg);
  color: var(--tooltip-color);
  border-radius: 0;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  box-shadow: none;
  z-index: 100;
}

.zoom-btn:hover::after,
.zoom-btn:focus::after {
  opacity: 1;
  transform: translateX(-50%) translateY(-0.75rem);
}

/* ===== ZOOM RANGE SLIDER ===== */
#zoom-range {
  appearance: none;
  -webkit-appearance: none;
  width: 120px;
  height: 6px;
  border-radius: var(--radius-full);
  background: linear-gradient(to right, var(--primary) 0%, var(--primary) 50%, var(--border-medium) 50%, var(--border-medium) 100%);
  cursor: pointer;
  transition: background var(--transition-normal);
  margin: 0;
  flex-grow: 1;
  min-width: 80px;
}

#zoom-range::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: var(--bg-primary);
  border: 3px solid var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-normal);
  margin-top: -6px;
}

#zoom-range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: var(--bg-primary);
  border: 3px solid var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-normal);
}

#zoom-range::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

#zoom-range::-moz-range-thumb:hover {
  transform: scale(1.1);
}

#zoom-range:focus {
  outline: none;
}

/* ===== ZOOM LABEL ===== */
#zoom-label {
  min-width: 4ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ===== PAGE INDICATOR ===== */
#page-indicator {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background-color: var(--bg-tertiary);
  padding: 0.75rem;
  /*! box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); */
  min-width: 100px;
  text-align: center;
  margin: 0 auto;
  order: 0;
}

/* ===== MOBILE ZOOM STRIP ===== */
.mobile-zoom-strip {
  display: none;
}

/* ===== FOCUS STYLES FOR MODAL ELEMENTS ===== */
.toolbar-btn:focus-visible,
.zoom-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.toolbar-btn:focus:not(:focus-visible),
.zoom-btn:focus:not(:focus-visible) {
  outline: none;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 940px) {
  .modal-content {
    width: 98vw;
    height: 98vh;
  }
}

@media (max-width: 768px) {
  .modal-toolbar .page-counter,
  .modal-toolbar .zoom-control,
  .modal-toolbar #zoom-range-desktop,
  .modal-toolbar #zoom-label-desktop,
  .modal-toolbar #zoom-reset-desktop {
    display: none !important;
  }

  .toolbar-hide-mobile,
  .modal-toolbar .toolbar-btn.toolbar-hide-mobile {
    display: none !important;
  }

  #page-indicator {
    position: absolute !important;
    top: 0.85rem !important;
    left: 1rem !important;
    transform: translateY(0) !important;
    z-index: 1011 !important;
    padding: 0.35rem 0.8rem !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    background-color: rgba(var(--bg-primary-rgb), 0.85) !important;
    backdrop-filter: blur(4px) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-sm) !important;
    color: var(--text-secondary) !important;
    min-width: auto !important;
    text-align: left !important;
    order: initial !important;
    flex-grow: 0 !important;
    margin: 0 !important;
    display: inline-block !important;
  }

  .dark-mode #page-indicator {
    background-color: rgba(var(--bg-primary-rgb), 0.85) !important;
    color: var(--text-secondary) !important;
  }

  .mobile-zoom-strip {
    display: flex !important;
    position: fixed !important;
    bottom: calc(var(--mobile-toolbar-height) + constant(safe-area-inset-bottom)) !important;
    bottom: calc(var(--mobile-toolbar-height) + env(safe-area-inset-bottom)) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--mobile-zoom-strip-height) !important;
    background-color: var(--bg-primary) !important;
    border-top: 1px solid var(--border-light) !important;
    box-shadow: var(--shadow-xs) !important;
    z-index: 1009 !important;
    padding: 0 0.5rem !important;
    padding-left: calc(0.5rem + env(safe-area-inset-left)) !important;
    padding-right: calc(0.5rem + env(safe-area-inset-right)) !important;
    align-items: center !important;
    gap: 0.5rem !important;
  }

  .dark-mode .mobile-zoom-strip {
    background-color: var(--bg-primary) !important;
    border-top: 1px solid var(--border-light) !important;
  }

  .mobile-zoom-strip .zoom-btn {
    flex-shrink: 0 !important;
    width: 2.2rem !important;
    height: 2.2rem !important;
    padding: 0 !important;
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background-color var(--transition-fast) !important;
  }

  .mobile-zoom-strip .zoom-btn:hover {
    background-color: var(--border-light) !important;
  }

  .mobile-zoom-strip .zoom-btn .icon {
    width: 1.1rem !important;
    height: 1.1rem !important;
  }

  .mobile-zoom-strip #zoom-range-mobile {
    flex-grow: 1 !important;
    width: auto !important;
    height: 16px !important;
    margin: 0 !important;
  }

  .mobile-zoom-strip #zoom-range-mobile::-webkit-slider-thumb {
    width: 28px !important;
    height: 28px !important;
    margin-top: -6px !important;
    border-width: 2px !important;
  }

  .mobile-zoom-strip #zoom-range-mobile::-moz-range-thumb {
    width: 28px !important;
    height: 28px !important;
    border-width: 2px !important;
  }

  .mobile-zoom-strip #zoom-label-mobile {
    flex-shrink: 0 !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    padding: 0.25rem 0.5rem !important;
    background-color: var(--bg-tertiary) !important;
    border-radius: var(--radius-sm) !important;
    min-width: 3.5ch !important;
    color: var(--text-primary) !important;
    text-align: center !important;
  }

  .modal-toolbar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: calc(var(--mobile-toolbar-height) + constant(safe-area-inset-bottom)) !important;
    height: calc(var(--mobile-toolbar-height) + env(safe-area-inset-bottom)) !important;
    padding: 0 0.25rem !important;
    padding-bottom: constant(safe-area-inset-bottom) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    display: flex !important;
    justify-content: space-around !important;
    align-items: stretch !important;
    background-color: var(--bg-primary) !important;
    border-top: 1px solid var(--border-light) !important;
    box-shadow: var(--shadow-sm) !important;
    z-index: 1010 !important;
    gap: 0.25rem !important;
    flex-wrap: nowrap !important;
    border-bottom: none !important;
  }

  .toolbar-group {
    display: flex !important;
    align-items: stretch !important;
    flex-grow: 1 !important;
    flex-basis: 0 !important;
    justify-content: center !important;
  }

  .modal-toolbar .toolbar-btn {
    flex: 1 1 auto !important;
    min-width: 48px !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0.3rem 0.2rem !important;
    border-radius: var(--radius-sm) !important;
    cursor: pointer !important;
    order: initial !important;
    margin: 0 !important;
    background-color: var(--bg-tertiary) !important;
    box-shadow: none !important;
    color: var(--text-primary) !important;
    transition: background-color var(--transition-fast), color var(--transition-fast) !important;
  }

  .modal-toolbar .toolbar-btn.toc-hidden {
    display: none !important;
  }

  .modal-toolbar .toolbar-btn:hover,
  .modal-toolbar .toolbar-btn:focus-visible {
    background-color: var(--border-light) !important;
    color: var(--primary) !important;
  }

  .modal-toolbar .toolbar-btn.active {
    color: var(--primary) !important;
    background-color: var(--border-light) !important;
  }

  .toolbar-btn .icon {
    width: 1.6rem !important;
    height: 1.6rem !important;
  }

  .toolbar-btn-label {
    font-size: 0.65rem !important;
    line-height: 1.2 !important;
    margin-top: 3px !important;
    display: block !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 100% !important;
    color: inherit !important;
  }

  .modal-toolbar .toolbar-btn::after {
    display: none !important;
  }

  .modal-close {
    top: 0.75rem !important;
    right: 0.75rem !important;
    z-index: 1012 !important;
  }

  .btn-next.shifted {
    right: 1.5rem !important;
  }
}

@media (max-width: 600px) {
  .mobile-zoom-strip {
    padding: 0 0.4rem;
    padding-left: calc(0.4rem + env(safe-area-inset-left));
    padding-right: calc(0.4rem + env(safe-area-inset-right));
    gap: 0.4rem;
  }

  .mobile-zoom-strip .zoom-btn {
    width: 2rem;
    height: 2rem;
  }

  .mobile-zoom-strip .zoom-btn .icon {
    width: 1rem;
    height: 1rem;
  }

  .mobile-zoom-strip #zoom-range,
  .mobile-zoom-strip #zoom-range-mobile {
    height: 14px;
  }

  .mobile-zoom-strip #zoom-range::-webkit-slider-thumb,
  .mobile-zoom-strip #zoom-range-mobile::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    margin-top: -5px;
  }

  .mobile-zoom-strip #zoom-range::-moz-range-thumb,
  .mobile-zoom-strip #zoom-range-mobile::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  .mobile-zoom-strip #zoom-label,
  .mobile-zoom-strip #zoom-label-mobile {
    font-size: 0.75rem;
    padding: 0.2rem 0.3rem;
  }

  .modal-toolbar {
    padding: 0 0.1rem;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    gap: 0.1rem;
  }

  .toolbar-btn .icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  .toolbar-btn-label {
    display: none;
  }

  .modal-toolbar .toolbar-btn {
    justify-content: center;
    min-width: 44px;
  }

  #page-indicator {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    top: 0.7rem;
    left: 0.7rem;
  }

  .modal-close {
    top: 0.6rem;
    right: 0.6rem;
  }

  .modal-content {
    border-radius: var(--radius-md);
  }
}

@media (max-width: 480px) {
  .mobile-zoom-strip {
    gap: 0.3rem;
  }

  .mobile-zoom-strip .zoom-btn {
    width: 1.9rem;
    height: 1.9rem;
  }

  .mobile-zoom-strip .zoom-btn .icon {
    width: 0.9rem;
    height: 0.9rem;
  }

  .mobile-zoom-strip #zoom-range,
  .mobile-zoom-strip #zoom-range-mobile {
    height: 12px;
  }

  .mobile-zoom-strip #zoom-range::-webkit-slider-thumb,
  .mobile-zoom-strip #zoom-range-mobile::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -5px;
  }

  .mobile-zoom-strip #zoom-range::-moz-range-thumb,
  .mobile-zoom-strip #zoom-range-mobile::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  .mobile-zoom-strip #zoom-label,
  .mobile-zoom-strip #zoom-label-mobile {
    display: none;
  }

  .toolbar-btn .icon {
    width: 1.4rem;
    height: 1.4rem;
  }

  .modal-toolbar .toolbar-btn {
    min-width: 40px;
  }

  #page-indicator {
    top: 0.6rem;
    left: 0.6rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
  }
}

@media (max-width: 400px) {
  .toolbar-btn .icon {
    width: 1.3rem;
    height: 1.3rem;
  }

  .mobile-zoom-strip .zoom-btn .icon {
    width: 0.8rem;
    height: 0.8rem;
  }

  .mobile-zoom-strip #zoom-range,
  .mobile-zoom-strip #zoom-range-mobile {
    min-width: 30px;
  }
}

/* ===== EMBED ERROR STATE ===== */
.embed-status-message {
    backdrop-filter: blur(16px);
    border-radius: 0;
    border: none;
    box-shadow: 0 18px 32px -24px rgba(15, 23, 42, 0.24);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    max-width: min(420px, 90vw);
    padding: 2.5rem 2.75rem;
    text-align: center;

}

.dark-mode .embed-status-message {
    border: none;
    box-shadow: 0 26px 40px -28px rgba(8, 47, 73, 0.42);
    color: var(--dark-text-primary, #e2e8f0);

}

.embed-status-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.embed-status-text,
.embed-status-subtext {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.6;
}

.dark-mode .embed-status-text,
.dark-mode .embed-status-subtext {
  color: var(--dark-text-secondary, #94a3b8);
}

.embed-status-subtext {
  font-size: 0.95rem;
}

.embed-status-icon {
  width: 64px;
  height: 64px;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(14, 165, 233, 0.1) 100%);
  color: rgba(79, 70, 229, 0.85);
  border: none;
  box-shadow: none;
}

.embed-status-message--error .embed-status-icon {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(14, 165, 233, 0.16) 100%);
  color: rgba(37, 99, 235, 0.85);
}

.embed-status-message--expired .embed-status-icon {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(217, 70, 239, 0.18) 100%);
  color: rgba(217, 70, 239, 0.85);
}

.dark-mode .embed-status-icon {
  color: rgba(165, 180, 252, 0.78);
  box-shadow: none;
}

.dark-mode .embed-status-message--expired .embed-status-icon {
  color: rgba(244, 114, 182, 0.78);
}

.embed-status-icon svg {
  width: 38px;
  height: 38px;
  stroke: currentColor;
  opacity: 0.92;
}

.embed-error-state .modal-toolbar,
.embed-error-state .btn-prev,
.embed-error-state .btn-next,
.embed-error-state .mobile-zoom-strip {
  opacity: 0.45;
  pointer-events: none;
}

.embed-error-state .modal-toolbar .toolbar-btn,
.embed-error-state .toolbar-actions button,
.embed-error-state .zoom-control button,
.embed-error-state .mobile-zoom-strip button {
  cursor: not-allowed;
}

.embed-error-state .zoom-control input,
.embed-error-state .mobile-zoom-strip input {
  pointer-events: none;
  cursor: not-allowed;
}

.embed-controls-disabled .toolbar-btn,
.embed-controls-disabled .toolbar-actions button,
.embed-controls-disabled .zoom-control input,
.embed-controls-disabled .zoom-control button,
.embed-controls-disabled .mobile-zoom-strip button,
.embed-controls-disabled .mobile-zoom-strip input {
  opacity: 0.45;
}

/* ===== HOVER EFFECTS ===== */
.toolbar-btn:hover {
  transform: translateY(-1px) !important;
}

/* ===== TRANSITIONS ===== */
.toolbar-btn,
.zoom-btn {
  transition:
    color var(--transition-normal),
    background-color var(--transition-normal),
    box-shadow var(--transition-normal),
    transform var(--transition-normal);
}

#zoom-label-desktop {
  width: 40px;
}
