/* Photobook Index */
.photobook-index-container {
  min-height: calc(100vh - 64px); /* Adjust based on navbar */
  background-color: var(--paper-warm);
  background-image: 
    url("data:image/svg+xml,%3Csvg width='4' height='4' viewBox='0 0 4 4' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 3h1v1H1V3zm2-2h1v1H3V1z' fill='%23000000' fill-opacity='0.03'/%3E%3C/svg%3E"),
    radial-gradient(circle at center, transparent 0%, rgba(0,0,0,0.05) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
  font-family: var(--font-serif);
}

.index-header {
  margin-top: var(--space-xl);
  margin-bottom: var(--space-xxl);
  text-align: center;
  z-index: 10;
}

.index-title {
  font-size: var(--text-display);
  color: var(--ink-dark);
  margin-bottom: var(--space-xs);
  letter-spacing: 0.02em;
  font-weight: 400;
}

.index-subtitle {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--ink-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.photobook-index-gap { height: var(--dashboard-content-top-gap); flex-shrink: 0; }

.photobook-library-actions { display: none; }

/* Carousel Stage */
.book-carousel-stage {
  width: 100%;
  max-width: 1000px;
  height: 500px; /* Adjust based on book size */
  perspective: 1500px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  margin-bottom: var(--space-xl);
}

.carousel-book {
  position: absolute;
  width: 280px; /* Base width */
  aspect-ratio: 3/4;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.5s ease, z-index 0s;
  cursor: var(--cursor-pointer);
  
  /* Book Visuals */
  background-color: #5A3E2B; /* Fallback */
  border-radius: 2px 5px 5px 2px;
  box-shadow: 
    -10px 10px 20px rgba(0,0,0,0.3),
    -2px 0 5px rgba(0,0,0,0.2) inset; /* Spine shadow */
}

/* Texture & Finish */
.carousel-book::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(to right, rgba(255,255,255,0.1) 0%, transparent 4%, transparent 96%, rgba(0,0,0,0.2) 100%),
    url("data:image/svg+xml,%3Csvg width='4' height='4' viewBox='0 0 4 4' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 3h1v1H1V3zm2-2h1v1H3V1z' fill='%23000000' fill-opacity='0.1'/%3E%3C/svg%3E");
  border-radius: inherit;
  pointer-events: none;
  mix-blend-mode: multiply;
}

/* Spine Highlight */
.carousel-book::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  background: linear-gradient(to right, rgba(255,255,255,0.2) 0%, rgba(0,0,0,0.1) 100%);
  border-right: 1px solid rgba(0,0,0,0.1);
  border-radius: 2px 0 0 2px;
  pointer-events: none;
}

.book-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 30px;
  text-align: center;
  transform: translateZ(1px); /* Ensure content is above bg */
  color: rgba(255,255,255,0.9);
}

.book-title {
  font-family: var(--font-serif);
  font-size: 28px;
  line-height: 1.2;
  margin-bottom: 12px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  background: rgba(0,0,0,0.2);
  padding: 15px 20px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
}

.book-meta {
  font-family: var(--font-sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.8;
  margin-top: auto;
}

/* Carousel Navigation Areas (Optional visual cues) */
.carousel-nav-area {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20%;
  z-index: 20;
  cursor: var(--cursor-pointer);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
  font-size: 40px;
  color: var(--ink-muted);
  border: 0;
}
.carousel-nav-area:hover,
.carousel-nav-area:focus-visible { opacity: 0.65; }
.nav-prev { left: 0; background: linear-gradient(to right, rgba(0,0,0,0.05), transparent); }
.nav-next { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.05), transparent); }

.stack-view-trigger {
  margin-top: 30px;
  /* Removed low opacity to improve visibility */
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-photobook-nav {
  background: white;
  border: 1px solid rgba(0,0,0,0.1);
  color: var(--ink-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 20px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-photobook-nav:hover {
  background: white;
  color: var(--ink-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

/* Empty State */
.empty-shelf {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400px;
  text-align: center;
  color: var(--ink-muted);
}

.empty-text {
  font-size: var(--text-lg);
  margin-bottom: var(--space-lg);
  max-width: 400px;
  line-height: 1.6;
}

/* Photobook Creation Workspace */
.creation-workspace {
  display: grid;
  grid-template-columns: 350px 1fr;
  height: calc(100vh - 80px); /* Adjust for header */
  overflow: hidden;
  background: var(--ui-bg);
}

.photo-source-panel {
  background: #fff;
  border-right: 1px solid var(--border-color, #e5e7eb);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.source-header {
  padding: var(--dashboard-content-top-gap) 20px 20px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: #fff;
  z-index: 10;
}

.source-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink-dark);
}

.source-subtitle {
  font-size: 12px;
  color: var(--ink-soft);
}

.source-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.memory-group {
  margin-bottom: 30px;
}

.memory-date {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-soft);
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  background: rgba(255,255,255,0.9);
  padding: 5px 0;
  backdrop-filter: blur(5px);
  z-index: 5;
}

.memory-photos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.source-photo-item {
  aspect-ratio: 1;
  position: relative;
  cursor: grab;
  transition: transform 0.2s;
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
}

.source-photo-item:hover,
.source-photo-item:focus-visible { transform: scale(1.05); z-index: 2; }

.source-photo-item:focus-visible {
  outline: 3px solid var(--ui-accent);
  outline-offset: 2px;
}

.sequence-page-controls {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 0.4rem;
}

.sequence-page-controls button {
  min-width: 44px;
  min-height: 44px;
}

.source-photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.1);
}

.encrypted-thumb-container, .encrypted-seq-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  background-color: var(--ui-bg-muted, #f3f4f6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-placeholder, .seq-placeholder {
  font-size: 20px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-image, .seq-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Right Column: Sequence */
.book-sequence-panel {
  background: var(--paper-warm, #EFE7DA);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: inset 10px 0 20px rgba(0,0,0,0.05);
  min-width: 0; /* Crucial for scrolling inside grid */
  overflow: hidden;
}

.sequence-header {
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-md);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.sequence-stats {
  font-family: var(--font-serif);
  color: var(--ink-soft);
  font-size: 14px;
}

.sequence-content {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 40px;
  display: flex;
  align-items: center;
  gap: 40px;
  white-space: nowrap;
}

.sequence-page {
  position: relative;
  width: 240px;
  height: 320px;
  background: var(--paper-aged, #F6F1E8);
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

.sequence-page:hover {
  transform: translateY(-5px);
  transition: transform 0.2s;
}

.seq-photo-frame {
  width: 100%;
  height: 70%;
  background: #fff;
  padding: 8px;
  box-shadow: 1px 1px 4px rgba(0,0,0,0.1);
  margin-bottom: 15px;
  margin-top: 20px;
}

.seq-photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: sepia(0.2);
}

.seq-page-num {
  margin-top: auto;
  font-size: 10px;
  color: var(--ink-soft);
  font-family: var(--font-serif);
}

.sequence-placeholder {
  width: 240px;
  height: 320px;
  border: 2px dashed rgba(0,0,0,0.1);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0,0,0,0.3);
  font-size: 14px;
  flex-shrink: 0;
}

/* Delete Button on Cover */
.book-cover-link {
    display: block; 
    width: 100%; 
    height: 100%; 
    color: inherit; 
    text-decoration: none;
}

.delete-book-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 28px;
    height: 28px;
    background: white;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 50%;
    color: var(--danger, #cc0000); /* Red */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: var(--cursor-pointer);
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 20;
    padding: 0;
}

.delete-book-btn:hover {
    background: var(--danger, #cc0000);
    color: white;
    transform: scale(1.1);
}

.book-cover-wrapper:hover .delete-book-btn {
    opacity: 1;
}

/* Ensure wrapper maintains positioning context */
.book-cover-wrapper {
    position: relative;
    display: block; /* It was potentially a link before, enforce block if div */
    perspective: 1000px; /* Enable 3D for children */
}

.delete-page-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  background: white;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 50%;
  color: var(--danger, #cc0000);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  cursor: var(--cursor-pointer);
  font-family: var(--font-sans);
  font-weight: bold;
  font-size: 16px;
  line-height: 1;
  text-decoration: none;
}

.delete-page-btn:hover {
  background: var(--danger, #cc0000);
  color: white;
  transform: scale(1.1);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.draggable-page:hover .delete-page-btn {
  opacity: 1;
}

/* ─── Curation: Audio Upload ─── */
.sequence-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}

.audio-upload-section {
  display: flex;
  align-items: center;
  margin-right: var(--space-md);
  padding-right: var(--space-md);
  border-right: 1px solid rgba(0,0,0,0.08);
}

.audio-upload-section__form {
  display: flex;
  align-items: center;
}

.audio-upload-section__input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.audio-upload-section__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ink-soft);
  cursor: var(--cursor-pointer);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 14px;
  background: rgba(255,255,255,0.6);
  transition: all 0.2s ease;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.audio-upload-section__trigger:hover {
  color: var(--ink-dark);
  border-color: var(--ink-soft);
  background: rgba(255,255,255,0.9);
  box-shadow: var(--shadow-sm);
}

.audio-upload-section__trigger svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.audio-upload-section__trigger:hover svg {
  opacity: 1;
}

.audio-upload-section__status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--ink-soft);
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 14px;
  padding: var(--space-xs) var(--space-sm);
}

.audio-upload-section__icon {
  font-size: var(--text-sm);
  color: var(--action-primary);
  line-height: 1;
}

.audio-upload-section__filename {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-dark);
  font-weight: 500;
}

.audio-upload-section__remove {
  background: none;
  border: none;
  color: var(--ink-light);
  cursor: var(--cursor-pointer);
  font-size: 13px;
  line-height: 1;
  padding: 2px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.audio-upload-section__remove:hover {
  color: var(--danger);
  background: rgba(158,74,63,0.08);
}

/* ─── Viewer: Floating Audio Player ─── */
.photobook-audio-player {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 20px;
  padding: var(--space-xs) var(--space-sm);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.photobook-container:hover .photobook-audio-player,
.photobook-audio-player:focus-within {
  opacity: 1;
}

.photobook-audio-player__btn {
  background: none;
  border: none;
  cursor: var(--cursor-pointer);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xs);
  border-radius: 50%;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.photobook-audio-player__btn:hover {
  color: var(--leather-brown);
  background-color: rgba(0,0,0,0.05);
}

.photobook-audio-player__btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.photobook-audio-player__label {
  font-family: var(--font-sans);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-light);
  user-select: none;
}

.sequence-pages { display: flex; gap: 40px; }

/* Keep the source and arranged pages usable without a wide canvas. */
@media (max-width: 900px) {
  .creation-workspace {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    overflow: visible;
  }

  .photo-source-panel {
    max-height: 40dvh;
    min-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--sepia-line);
  }

  .source-header { padding: var(--dashboard-content-top-gap) var(--space-md) var(--space-sm); }
  .source-content { padding: var(--space-md); }
  .sequence-header { padding: var(--space-md); }
  .sequence-actions { gap: var(--space-sm); }
  .sequence-actions .btn { min-height: 44px; }
  .audio-upload-section { margin-right: 0; padding-right: 0; border-right: 0; }
  .audio-upload-section__trigger { min-height: 44px; }
  .audio-upload-section__filename { max-width: 140px; overflow-wrap: anywhere; }
  .sequence-content { min-height: 400px; padding: var(--space-md); gap: var(--space-md); }
  .sequence-pages { gap: var(--space-md); }
}

@media (max-width: 768px) {
  .carousel-nav-area {
    display: none;
  }

  .photobook-library-actions {
    display: flex;
    justify-content: center;
    padding: 0 var(--space-md);
    width: 100%;
  }

  .btn-photobook-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    background: var(--paper-base);
    color: var(--ink-dark);
  }
}
