/* ============================================
   MOBILE WIZARD — DesignCV
   CV en haut, formulaire étapes en bas
   Navbar 52px, boutons desktop cachés
   ============================================ */

/* ---- Navbar 52px mobile ---- */
@media (max-width: 700px) {
  .navbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 52px !important;
    z-index: 100 !important;
    padding: 0 12px !important;
  }
  .brand {
    font-size: 1.15rem !important;
  }
  .nav-actions .btn-ghost,
  .nav-actions #btn-history,
  .nav-actions #btn-optimize {
    display: none !important;
  }
  #btn-download {
    font-size: 0.75rem !important;
    padding: 6px 10px !important;
  }
}

/* ---- Layout mobile : CV en haut, wizard en bas ---- */
@media (max-width: 700px) {
  .app-grid {
    display: flex !important;
    flex-direction: column !important;
    position: fixed !important;
    top: 52px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
  }

  /* CV preview : en haut, compact mais LISIBLE */
  .preview-panel {
    position: relative !important;
    top: 0 !important;
    max-height: none !important;
    min-height: 0 !important;
    order: -1;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    margin-bottom: 4px;
  }

  .preview-toolbar {
    display: none !important;
  }

  .preview-area {
    padding: 10px 8px 4px 8px !important;
    height: 235px !important;
    min-height: 235px !important;
    max-height: 235px !important;
    overflow: hidden !important;
    background: #e2e8f0;
    justify-content: center !important;
    align-items: flex-start !important;
    display: flex !important;
    cursor: pointer !important;
    position: relative !important;
  }

  /* Tap hint on preview */
  .preview-area::after {
    content: '\D83D\DD0D  Appuyez pour agrandir';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #64748b;
    background: rgba(255,255,255,0.85);
    padding: 3px 10px;
    border-radius: 12px;
    pointer-events: none;
    white-space: nowrap;
    font-weight: 500;
  }

  .cv-sheet {
    transform: scale(0.45) !important;
    transform-origin: top center !important;
    margin: 0 auto !important;
    pointer-events: none;
    width: 210mm !important;
    background: white !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
    border-radius: 4px !important;
    flex-shrink: 0;
  }

  /* Form panel : en bas */
  .form-panel {
    position: relative !important;
    top: 0 !important;
    max-height: none !important;
    border-right: none !important;
    border-bottom: none !important;
    padding: 0 !important;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
  }

  .form-header {
    display: none !important;
  }

  /* Toutes les sections cachées par défaut */
  .form-panel > .form-section {
    display: none !important;
    padding: 1rem 1rem 0.5rem !important;
    border-top: none !important;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }

  .form-panel > .form-section.mobile-active {
    display: flex !important;
    flex-direction: column !important;
  }

  /* ---- Step Indicator ---- */
  #mobile-step-bar {
    display: flex !important;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 4px;
    flex-shrink: 0;
  }

  .mobile-step-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 2px 4px;
    cursor: pointer;
    border: none;
    background: none;
    position: relative;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-step-tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: transparent;
    transition: background 0.2s ease;
  }

  .mobile-step-tab.active::after {
    background: var(--primary);
  }

  .mobile-step-tab .step-icon {
    font-size: 14px;
    margin-bottom: 1px;
    opacity: 0.45;
    transition: opacity 0.2s ease;
  }

  .mobile-step-tab.active .step-icon,
  .mobile-step-tab.completed .step-icon {
    opacity: 1;
  }

  .mobile-step-tab .step-label {
    font-size: 9px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    transition: color 0.2s ease;
  }

  .mobile-step-tab.active .step-label {
    color: var(--primary);
  }

  .mobile-step-tab.completed .step-label {
    color: var(--text-secondary);
  }

  /* ---- Navigation buttons ---- */
  #mobile-step-nav {
    display: flex;
    gap: 8px;
    padding: 6px 1rem;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  #mobile-step-nav .btn {
    flex: 1;
    padding: 10px !important;
    font-size: 0.9rem !important;
    min-height: 44px;
    border-radius: 10px !important;
  }

  #mobile-step-nav .btn-prev {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1.5px solid var(--border) !important;
  }

  #mobile-step-nav .btn-next {
    background: var(--primary);
    color: white;
  }

  #mobile-step-nav .btn-next:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* ---- Section tweaks ---- */
  .form-panel .form-section .section-title {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
  }

  .form-panel .form-section .form-group {
    margin-bottom: 0.5rem;
  }

  .form-panel .form-section .form-row,
  .form-panel .form-section .skill-row {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
  }

  /* Nom + Prénom gardent 2 colonnes sur mobile */
  .form-panel .form-section .form-row.name-row {
    grid-template-columns: 1fr 1fr !important;
  }

  .form-panel .form-section .photo-upload {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .form-panel .form-section .form-textarea {
    min-height: 100px;
  }

  /* ---- Design step controls ---- */
  #mobile-design-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 4px;
  }

  #mobile-design-controls .mobile-control-row {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  #mobile-design-controls .mobile-control-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 55px;
  }

  #mobile-design-controls .mobile-theme-switcher {
    display: flex;
    background: var(--bg);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid var(--border);
    flex: 1;
  }

  #mobile-design-controls .mobile-theme-btn {
    flex: 1;
    padding: 7px 4px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile-design-controls .mobile-theme-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  }

  #mobile-design-controls .mobile-color-picker {
    display: flex;
    gap: 8px;
    flex: 1;
    justify-content: center;
  }

  #mobile-design-controls .mobile-color-dot {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile-design-controls .mobile-color-dot:active {
    transform: scale(0.9);
  }

  #mobile-design-controls .mobile-color-dot.active {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
  }

  .form-panel .form-section .entry-card {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
  }

  .form-panel .form-section .btn-outline {
    width: 100%;
    padding: 10px !important;
    min-height: 44px;
  }

  .toast {
    bottom: 80px !important;
    left: 16px !important;
    right: 16px !important;
    text-align: center;
    border-radius: 10px !important;
  }

  /* ---- Fullscreen CV Preview Overlay ---- */
  #cv-preview-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  #cv-preview-overlay.open {
    display: flex;
    flex-direction: column;
    opacity: 1;
  }

  #cv-preview-overlay .overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  #cv-preview-overlay .overlay-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
  }

  #cv-preview-overlay .overlay-actions {
    display: flex;
    gap: 8px;
  }

  #cv-preview-overlay .overlay-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
  }

  #cv-preview-overlay .overlay-btn-close {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
  }

  #cv-preview-overlay .overlay-btn-download {
    background: var(--primary);
    color: white;
  }

  #cv-preview-overlay .overlay-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #e2e8f0;
    display: flex;
    justify-content: center;
    padding: 16px 8px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  #cv-preview-overlay .overlay-body .cv-sheet {
    transform: none !important;
    margin: 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    background: white !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12) !important;
    border-radius: 4px !important;
    pointer-events: auto;
  }
}

@media (max-width: 700px) and (orientation: landscape) {
  .preview-area {
    height: 160px !important;
    min-height: 160px !important;
    max-height: 160px !important;
  }
  .cv-sheet {
    transform: scale(0.35) !important;
  }
  .mobile-step-tab { padding: 4px 2px 3px; }
  .mobile-step-tab .step-icon { font-size: 14px; }
  .mobile-step-tab .step-label { font-size: 8px; }
}

@media (max-width: 379px) {
  .preview-area {
    height: 180px !important;
    min-height: 180px !important;
    max-height: 180px !important;
  }
  .cv-sheet {
    transform: scale(0.38) !important;
  }
  .mobile-step-tab .step-label { font-size: 7.5px; }
}

/* ============================================
   DESKTOP : cacher les éléments mobile-only
   Le thème/couleur sont dans la toolbar desktop.
   ============================================ */
@media (min-width: 701px) {
  #mobile-step-bar,
  #mobile-step-nav,
  #step-design {
    display: none !important;
  }
  #cv-preview-overlay {
    display: none !important;
  }
}