/* ========== VARIABLES ========== */
:root {
  --bg: #f8f8f8;
  --fg: #111;
  --muted: #6b6b6b;
  --accent: #ff0054;
  --accent-light: rgba(255, 0, 84, 0.1);
  --surface: #ffffff;
  --border: rgba(17, 17, 17, 0.1);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --header-height: 56px;
  --unit-price: 3.90;
  font-family: 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ========== RESET & BASE ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
}

body {
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  touch-action: none;
  overscroll-behavior: none;
}

/* ========== APP HEADER ========== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(248, 248, 248, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 1000;
}

.app-header__brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--fg);
}

.app-header__location {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: right;
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== SNAP CONTAINER ========== */
.snap-container {
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for iOS */
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none; /* Prevent overscroll bounce */
}

/* When scroll is enabled (default state now) */
.snap-container.scroll-enabled {
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}

/* Hide scrollbar */
.snap-container::-webkit-scrollbar {
  display: none;
}
.snap-container {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* ========== SNAP SECTIONS ========== */
.snap-section {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--header-height);
  box-sizing: border-box;
}

.section-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  width: 100%;
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  max-height: calc(100vh - var(--header-height));
  max-height: calc(100dvh - var(--header-height));
  overflow: hidden;
  box-sizing: border-box;
}

/* ========== SECTION 1: FORMATS ========== */
.section-formats {
  background: var(--bg);
}

.section-header {
  text-align: center;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.section-title {
  font-size: clamp(1.25rem, 5vw, 1.75rem);
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 0.15rem;
}

.section-location {
  font-size: 0.8rem;
  color: var(--muted);
}

.formats-subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 0.5rem;
  color: var(--fg);
  flex-shrink: 0;
}

/* ========== CAROUSEL ========== */
.carousel-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  max-height: 100%;
  gap: 0.5rem;
  padding: 0;
  overflow: hidden;
  width: 100%;
}

.carousel {
  width: 100%;
  max-width: 280px;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.carousel-track {
  display: flex;
  transition: transform 0.3s ease-out;
  will-change: transform;
}

.carousel-slide {
  flex: 0 0 100%;
  width: 100%;
  min-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

.carousel-slide.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-light);
}

.carousel-slide .layout-preview {
  width: 120px;
  height: 180px;
  aspect-ratio: 10 / 15;
  flex-shrink: 0;
}

.carousel-slide .layout-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
  flex-shrink: 0;
}

/* Carousel dots */
.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.25rem 0;
  flex-shrink: 0;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.carousel-dot.is-active {
  background: var(--accent);
  transform: scale(1.2);
}

.carousel-dot:hover {
  background: var(--accent);
  opacity: 0.7;
}

/* Select button */
.btn-select-layout {
  max-width: 280px;
  flex-shrink: 0;
}

/* Swipe hint animation */
@keyframes swipeHint {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-10px); }
}

.carousel-track.hint {
  animation: swipeHint 1s ease-in-out 2;
}

/* Legacy grid styles (kept for compatibility) */
.layouts-grid {
  display: none;
}

.layout-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
}

/* Layout Previews - Base */
.layout-preview {
  background: #f0f0f0;
  border-radius: 4px;
  display: flex;
  gap: 2px;
  padding: 2px;
  overflow: hidden;
  box-sizing: border-box;
}

.lp-zone {
  background: linear-gradient(135deg, #ddd 0%, #ccc 100%);
  border-radius: 2px;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.lp-zone-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.lp-zone-group--row {
  flex-direction: row;
}

/* Layout 1: Solo - 1 grande photo paysage */
.layout-preview--solo {
  flex-direction: column;
}

/* Layout 2: Duo - 2 bandes verticales côte à côte */
.layout-preview--duo {
  flex-direction: row;
}

/* Layout 3: Triptyque - 3 bandes verticales côte à côte */
.layout-preview--triptyque {
  flex-direction: row;
}

/* Layout 4: 4-Pack - Grille 2x2 (4 photos identiques) */
.layout-preview--4pack {
  flex-direction: row;
  flex-wrap: wrap;
  align-content: stretch;
}
.layout-preview--4pack .lp-zone {
  width: calc(50% - 1px);
  height: calc(50% - 1px);
  flex: none;
}

/* Layout 5: 6-Pack - Grille 2x3 (6 photos identiques) */
.layout-preview--6pack {
  flex-direction: row;
  flex-wrap: wrap;
  align-content: stretch;
}
.layout-preview--6pack .lp-zone {
  width: calc(33.333% - 1.5px);
  height: calc(50% - 1px);
  flex: none;
}

/* Layout 6: Collage Gauche - 2 photos à gauche + 1 grande à droite */
.layout-preview--collage-left {
  flex-direction: row;
}
.layout-preview--collage-left > .lp-zone-group {
  flex: 1;
}
.layout-preview--collage-left > .lp-zone--large {
  flex: 1;
}

/* Layout 7: H-Layout - 3 colonnes avec milieu divisé */
.layout-preview--h-layout {
  flex-direction: row;
}
.layout-preview--h-layout > .lp-zone {
  flex: 1;
}
.layout-preview--h-layout > .lp-zone-group {
  flex: 1;
}

/* ========== SECTION 2: EDITOR ========== */
.section-editor {
  background: var(--bg);
}

.section-editor .section-content {
  gap: 0.25rem;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.btn-back,
.btn-flip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--fg);
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-back:active,
.btn-flip:active {
  background: var(--accent-light);
  border-color: var(--accent);
}

.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
  padding: 0.25rem;
}

.canvas-workspace {
  width: auto;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  aspect-ratio: 10 / 15;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 3px;
  padding: 3px;
  overflow: hidden;
  transition: transform 0.3s ease;
  box-sizing: border-box;
}

.canvas-workspace.flipped {
  aspect-ratio: 15 / 10;
}

/* Editor zones */
.editor-zone {
  flex: 1;
  background: #f5f5f5;
  border: 2px dashed var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}


.editor-zone:active {
  border-color: var(--accent);
}

.editor-zone.has-image {
  border-style: solid;
  border-color: transparent;
}

.editor-zone.has-image.active-delete {
  border: 2px solid var(--accent);
}

.editor-zone__placeholder {
  color: var(--muted);
  font-size: 2rem;
  pointer-events: none;
}

.editor-zone__image {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  touch-action: none;
  cursor: move;
}

.editor-zone__delete {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background: rgba(255, 0, 84, 0.9);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(255, 0, 84, 0.4);
}

.editor-zone.active-delete .editor-zone__delete {
  display: flex;
}

.zone-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.zone-group--row {
  flex-direction: row;
}

.editor-footer {
  text-align: center;
  padding: 0.5rem 0;
  padding-bottom: env(safe-area-inset-bottom, 0.5rem);
  flex-shrink: 0;
}

.editor-hint {
  font-size: 0.65rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

/* ========== SECTION 3: PREVIEW ========== */
.section-preview {
  background: var(--bg);
}

.section-preview .section-content {
  gap: 0.25rem;
}

.preview-header {
  flex-shrink: 0;
}

.print-preview {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.print-paper {
  width: auto;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  aspect-ratio: 10 / 15;
  background: white;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 3px;
  box-sizing: border-box;
}

.print-paper.flipped {
  aspect-ratio: 15 / 10;
}

.print-logo {
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  color: var(--fg);
  padding: 4px 0;
}

.print-canvas {
  flex: 1;
  display: flex;
  gap: 2px;
  overflow: hidden;
  min-height: 0;
}

.print-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.55rem;
  color: var(--muted);
  padding: 4px 0 0;
}

.print-zone {
  flex: 1;
  background: #f0f0f0;
  border-radius: 2px;
  overflow: hidden;
}

.print-zone__image {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.print-zone-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.print-zone-group--row {
  flex-direction: row;
}

/* Checkout Panel */
.checkout-panel {
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  padding: 0.5rem;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0.5rem));
  margin: 0 -0.5rem -0.5rem;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
}

.qty-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.qty-label,
.total-label {
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--muted);
}

.qty-btn {
  width: 32px;
  height: 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.qty-btn:active {
  background: var(--accent-light);
  border-color: var(--accent);
}

.qty-value {
  font-size: 1rem;
  font-weight: 700;
  min-width: 1.5rem;
  text-align: center;
}

.total-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.total-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

/* ========== SECTION 4: THANKS ========== */
.section-thanks {
  background: linear-gradient(180deg, #f8f8f8 0%, #fff 100%);
}

.section-thanks[data-locked="true"] {
  pointer-events: none;
}

.thanks-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.75rem;
  padding: 1rem;
}

.thanks-icon {
  color: #22c55e;
  animation: scaleIn 0.5s ease;
}

.thanks-icon svg {
  width: clamp(50px, 15vw, 70px);
  height: clamp(50px, 15vw, 70px);
}

.thanks-title {
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  font-weight: 600;
  color: var(--fg);
}

.thanks-location {
  font-size: clamp(1.25rem, 5vw, 1.6rem);
  font-weight: 700;
  color: var(--accent);
}

.thanks-message {
  font-size: clamp(0.85rem, 3vw, 1rem);
  color: var(--muted);
  max-width: 280px;
}

.thanks-print-icon {
  color: var(--muted);
  margin-top: 0.5rem;
  animation: bounce 2s infinite;
}

.thanks-print-icon svg {
  width: clamp(40px, 12vw, 55px);
  height: clamp(40px, 12vw, 55px);
}

@keyframes scaleIn {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ========== BUTTONS ========== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}

.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-primary:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.btn-validate {
  max-width: 200px;
  margin: 0 auto;
}

.btn-pay {
  background: #635bff;
}

.btn-pay:active {
  background: #4f46e5;
}

/* ========== RESPONSIVE ========== */

/* Very small phones (height) */
@media (max-height: 550px) {
  .section-content {
    padding: 0.35rem;
  }

  .section-header {
    margin-bottom: 0.15rem;
  }

  .section-title {
    font-size: 1rem;
  }

  .formats-subtitle {
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
  }

  .carousel-container {
    gap: 0.25rem;
  }

  .carousel-slide {
    padding: 0.4rem;
    gap: 0.3rem;
  }

  .carousel-slide .layout-label {
    font-size: 0.75rem;
  }

  .carousel-dots {
    padding: 0.15rem 0;
    gap: 0.3rem;
  }

  .carousel-dot {
    width: 6px;
    height: 6px;
  }

  .btn-primary {
    padding: 0.45rem 0.8rem;
    font-size: 0.8rem;
  }

  .btn-back,
  .btn-flip {
    padding: 0.25rem 0.4rem;
    font-size: 0.7rem;
  }

  .editor-hint {
    font-size: 0.6rem;
    margin-bottom: 0.15rem;
  }

  .checkout-panel {
    padding: 0.35rem;
    gap: 0.25rem;
  }

  .qty-btn {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }

  .qty-value {
    font-size: 0.9rem;
  }

  .qty-label,
  .total-label {
    font-size: 0.7rem;
  }

  .total-value {
    font-size: 0.95rem;
  }

  .thanks-content {
    gap: 0.4rem;
    padding: 0.5rem;
  }
}

/* Small phones */
@media (max-height: 667px) and (min-height: 551px) {
  .section-header {
    margin-bottom: 0.25rem;
  }

  .section-title {
    font-size: 1.1rem;
  }

  .formats-subtitle {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
  }

  .carousel {
    max-width: 240px;
  }

  .carousel-slide {
    padding: 0.5rem;
    gap: 0.4rem;
  }

  .carousel-slide .layout-preview {
    width: 100px;
    height: 150px;
  }

  .carousel-slide .layout-label {
    font-size: 0.85rem;
  }

  .btn-primary {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }

  .thanks-content {
    gap: 0.5rem;
  }
}

/* Medium screens */
@media (min-width: 480px) {
  .carousel {
    max-width: 300px;
  }

  .carousel-slide .layout-preview {
    width: 140px;
    height: 210px;
  }
}

/* Tablets and desktop */
@media (min-width: 768px) {
  :root {
    --header-height: 60px;
  }

  .section-content {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
  }

  .carousel {
    max-width: 350px;
  }

  .carousel-slide {
    padding: 1rem;
  }

  .carousel-slide .layout-preview {
    width: 160px;
    height: 240px;
  }

  .carousel-slide .layout-label {
    font-size: 1rem;
  }
}

/* Large screens */
@media (min-width: 1024px) and (min-height: 700px) {
  .section-content {
    padding: 1.5rem;
  }

  .section-title {
    font-size: 1.75rem;
  }

  .layouts-grid {
    max-width: 700px;
  }

  .layout-preview {
    max-height: 140px;
  }
}

/* ========== UTILITY ========== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
