/* Binder-Specific Styles - Modern, Clean Design */

/* === BINDER CONTAINER === */
.binder-container {
  max-width: 1400px;
  margin: 0 auto;
}

.binder-spread {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0;
  margin-bottom: 32px;
  perspective: 2000px;
  perspective-origin: 50% 40%;
  position: relative;
  min-height: 600px;
  overflow: visible;
}

/* Spine shadow between pages */
.binder-spread::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 24px;
  transform: translateX(-50%);
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.35) 0%,
    rgba(0, 0, 0, 0.12) 35%,
    rgba(255, 255, 255, 0.02) 65%,
    rgba(0, 0, 0, 0.2) 100%
  );
  pointer-events: none;
  z-index: 5;
  border-left: 1px solid rgba(0, 0, 0, 0.25);
  border-right: 1px solid rgba(0, 0, 0, 0.15);
}

/* === BINDER PAGES === */
.binder-page {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  flex: 1;
  max-width: 600px;
  transform-style: preserve-3d;
  position: relative;
  will-change: transform;
  z-index: 2;
}

/* Border-radius via explicit classes — not :first-child/:last-child, which
   break when preview pages are appended after the real pages in the DOM */
.binder-page--left {
  border-radius: 12px 0 0 12px;
  border-right: none;
}

.binder-page--right {
  border-radius: 0 12px 12px 0;
  border-left: none;
}

/* Next-spread pages pre-rendered behind current pages.
   Width/height/left/top are set by JS via getBoundingClientRect. */
.binder-page-preview {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  box-sizing: border-box;
  overflow: hidden;
}

/* Flip animations — pivot from spine edge, no translateX jank */
.binder-page.flip-left-out {
  animation: flipLeftOut 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  z-index: 20;
}

.binder-page.flip-left-in {
  animation: flipLeftIn 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.binder-page.flip-right-out {
  animation: flipRightOut 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  z-index: 20;
}

.binder-page.flip-right-in {
  animation: flipRightIn 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* ── Forward flip: right page turns left ─────────────────────────────────── */
/* Outgoing page pivots from its LEFT edge (the spine) */
@keyframes flipLeftOut {
  0% {
    transform: rotateY(0deg);
    transform-origin: left center;
    filter: brightness(1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  90% {
    transform: rotateY(-90deg);
    transform-origin: left center;
    filter: brightness(0.4);
    opacity: 0;
  }
  100% {
    transform: rotateY(-180deg);
    transform-origin: left center;
    opacity: 0;
  }
}

/* Incoming page pivots from its RIGHT edge (the spine) */
@keyframes flipLeftIn {
  0% {
    transform: rotateY(180deg);
    transform-origin: right center;
    filter: brightness(0.8);
    opacity: 0;
  }
  10% {
    opacity: 0;
  }
  20% {
    transform: rotateY(90deg);
    transform-origin: right center;
    filter: brightness(0.4);
    opacity: 1;
  }
  100% {
    transform: rotateY(0deg);
    transform-origin: right center;
    filter: brightness(1);
    opacity: 1;
  }
}

/* ── Backward flip: left page turns right ────────────────────────────────── */
/* Outgoing page pivots from its RIGHT edge (the spine) */
@keyframes flipRightOut {
  0% {
    transform: rotateY(0deg);
    transform-origin: right center;
    filter: brightness(1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  90% {
    transform: rotateY(90deg);
    transform-origin: right center;
    filter: brightness(0.4);
    opacity: 0;
  }
  100% {
    transform: rotateY(180deg);
    transform-origin: right center;
    opacity: 0;
  }
}

/* Incoming page pivots from its LEFT edge (the spine) */
@keyframes flipRightIn {
  0% {
    transform: rotateY(-180deg);
    transform-origin: left center;
    filter: brightness(0.8);
    opacity: 0;
  }
  10% {
    opacity: 0;
  }
  20% {
    transform: rotateY(-90deg);
    transform-origin: left center;
    filter: brightness(0.4);
    opacity: 1;
  }
  100% {
    transform: rotateY(0deg);
    transform-origin: left center;
    filter: brightness(1);
    opacity: 1;
  }
}

.binder-page-empty {
  background: var(--bg-secondary);
  border: 2px dashed var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  font-size: 0.875rem;
  min-height: 400px;
}

/* === PAGE GRID === */
.page-grid {
  display: grid;
  gap: 8px;
  width: 100%;
}

.grid-2x2 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.grid-3x3 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.grid-4x4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

/* === CARD SLOTS === */
.card-slot {
  aspect-ratio: 5/7;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  position: relative;
  cursor: pointer;
  transition: all var(--transition-fast);
  overflow: hidden;
}

.card-slot:hover {
  border-color: var(--accent-primary);
  box-shadow: 0 0 16px rgba(74, 142, 255, 0.12), var(--shadow-md);
  transform: translateY(-2px);
}

.card-slot.highlight {
  animation: cardPulse 0.6s ease-in-out 3;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

@keyframes cardPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.card-slot-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-tertiary);
  font-size: 1.5rem;
  transition: all var(--transition-fast);
}

.card-slot:hover .card-slot-empty {
  color: var(--accent-primary);
  transform: scale(1.2);
}

.card-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius-md) - 2px);
  /* No default animation — cards always visible.
     Animation is opt-in via .card-slot.card-added (user-initiated adds only). */
}

/* Fade-in only when a card is explicitly added by the user */
.card-slot.card-added img {
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

/* === CARD BADGES === */
.card-quantity-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 1;
}

.card-foil-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: linear-gradient(135deg, #f59f00 0%, #ffd43b 50%, #f59f00 100%);
  color: #0d0f14;
  padding: 3px 7px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  pointer-events: none;
  letter-spacing: 0.06em;
  z-index: 1;
}

.card-condition-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  color: #f5f5f5;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  pointer-events: none;
  letter-spacing: 0.05em;
  z-index: 1;
}

/* === BINDER CONTROLS === */
.binder-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.nav-btn {
  padding: 10px 20px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.nav-btn:hover:not(:disabled) {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-md);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-indicator {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--text-secondary);
  min-width: 160px;
  text-align: center;
}

.add-pages-btn {
  padding: 8px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.add-pages-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

/* === MOBILE RESPONSIVE === */
@media (max-width: 1200px) {
  .binder-page {
    max-width: 500px;
  }

  .page-grid {
    gap: 10px;
  }
}

@media (max-width: 968px) {
  .binder-spread {
    flex-direction: column;
    align-items: center;
  }

  .binder-page {
    width: 100%;
    max-width: 100%;
  }

  /* Hide empty left page on mobile */
  .binder-page-empty {
    display: none;
  }
}

@media (max-width: 600px) {
  .binder-page {
    padding: 16px;
  }

  .page-grid {
    gap: 8px;
  }

  .card-quantity-badge,
  .card-foil-badge,
  .card-condition-badge {
    font-size: 0.65rem;
    padding: 3px 6px;
  }
}

/* === PAGE CURL INTERACTION === */

/* Edge zones — invisible hit targets that show grab cursor */
.page-curl-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 60px;
  z-index: 10;
  cursor: grab;
}

.page-curl-edge:active {
  cursor: grabbing;
}

.page-curl-edge--right {
  right: 0;
  border-radius: 0 12px 12px 0;
}

.page-curl-edge--left {
  left: 0;
  border-radius: 12px 0 0 12px;
}

/* Canvas overlay that replaces the page during curl */
.page-curl-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 25;
  border-radius: 12px;
}

/* =========================================================
   BINDER LAYOUT — panel + binder side by side
   ========================================================= */

.binder-layout {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

/* Override centering/max-width when inside the two-column layout */
.binder-layout .binder-container {
  flex: 1;
  min-width: 0;
  margin: 0;
  max-width: none;
  padding: 0 20px 32px;
}

/* =========================================================
   CARD SEARCH PANEL
   ========================================================= */

.card-search-panel {
  width: 800px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 18px;
  box-sizing: border-box;
  align-self: flex-start;
  margin-left: 32px;
}

/* ── Search input ── */
.csp-search-wrap {
  position: relative;
}

.csp-search-wrap input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.csp-search-wrap input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.csp-autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: none;
}

.csp-autocomplete.active {
  display: block;
}

.csp-autocomplete-item {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: background var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.csp-autocomplete-item:hover {
  background: var(--bg-hover);
}

/* ── Empty / loading state ── */
.csp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 10px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 24px 8px;
  min-height: 460px;
}

.csp-empty-icon {
  opacity: 0.35;
  font-size: 1.5rem;
  display: flex;
}

.csp-empty p {
  font-size: 0.8rem;
  margin: 0;
  line-height: 1.5;
}

/* ── Card area (shown once a card is selected) ── */
.csp-card-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.csp-body {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.csp-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.csp-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.csp-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.csp-select {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  padding: 9px 12px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.csp-select:focus {
  border-color: var(--accent-primary);
}

/* ── Condition button group ── */
.csp-cond-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.csp-cond-btn {
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 700;
  font-family: inherit;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: 0.04em;
}

.csp-cond-btn:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.csp-cond-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
}

/* ── Foil + price row ── */
.csp-foil-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.csp-foil-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9375rem;
  color: var(--text-primary);
  user-select: none;
}

.csp-foil-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.csp-price {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent-primary);
}

/* ── Card preview ── */
.csp-preview-wrap {
  width: 300px;
  flex-shrink: 0;
}

.csp-preview-img {
  width: 100%;
  border-radius: 4.5% / 3.2%;
  display: block;
  cursor: grab;
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.csp-preview-img:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.csp-preview-img:active {
  cursor: grabbing;
}

/* ── Add button ── */
.csp-add-btn {
  width: 100%;
  justify-content: center;
}

/* ── Card being dragged within binder ── */
.card-slot.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

/* ── Drag-over indicator on binder slots ── */
.card-slot.drag-over {
  border-color: var(--accent-primary) !important;
  box-shadow: 0 0 0 2px var(--accent-light), inset 0 0 12px rgba(74, 142, 255, 0.1);
  background: var(--accent-light);
}

/* ── Narrow screens: stack panel above binder ── */
@media (max-width: 1600px) {
  .binder-layout {
    flex-direction: column;
  }

  .card-search-panel {
    width: 100%;
    max-height: none;
    position: static;
    margin: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 16px;
  }

  .binder-layout .binder-container {
    padding: 16px 0 32px;
  }
}

/* =========================================================
   CARD HOVER TOOLTIP
   ========================================================= */

.card-tooltip {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.8125rem;
  pointer-events: none;
  z-index: 500;
  box-shadow: var(--shadow-lg);
  max-width: 240px;
  min-width: 160px;
}

.card-tooltip-name  { font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.card-tooltip-set   { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 6px; }
.card-tooltip-row   { display: flex; justify-content: space-between; gap: 8px; }
.card-tooltip-cond  { font-size: 0.75rem; color: var(--text-tertiary); }
.card-tooltip-price { font-size: 0.875rem; font-weight: 700; color: var(--accent-primary); }

/* =========================================================
   COVER PAGE
   ========================================================= */

.cover-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  border: 1px solid var(--border-color) !important;
}

.cover-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 32px;
}

.cover-icon {
  width: 48px;
  height: 48px;
  color: var(--accent-primary);
  opacity: 0.6;
}

.cover-binder-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.cover-binder-meta {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* =========================================================
   BINDER NAME IN TOOLBAR
   ========================================================= */

.binder-name-display {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
