/**
 * 모바일 퍼널 공통 스타일
 * - 단계별 폼 진행 UI
 * - roommate-register.html에서 추출하여 공통화
 *
 * 사용법:
 * 1. HTML: form-section에 data-step 속성 추가
 * 2. JS: MobileFunnel.init() 호출
 */

/* =====================================================
   모바일 퍼널 모드 (768px 이하)
   ===================================================== */
@media (max-width: 768px) {
  /* 모바일에서 폼 컨테이너 - 전체 화면 모드 */
  .mobile-funnel-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: #f2f4f6 !important;
    z-index: 1000 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    display: block !important;
    -webkit-overflow-scrolling: touch; /* iOS 부드러운 스크롤 */
  }

  /* 기존 폼 헤더 숨김 */
  .mobile-funnel-mode .form-header {
    display: none !important;
  }

  /* 폼 자체 배경 투명 */
  .mobile-funnel-mode form {
    background: transparent !important;
  }

  /* =====================================================
     퍼널 헤더 (진행 바)
     ===================================================== */
  .mobile-funnel-header {
    position: sticky;
    top: 0;
    background: #fff;
    padding: 12px 20px 16px;
    border-bottom: 1px solid #e5e8eb;
    z-index: 100;
  }

  .mobile-funnel-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .mobile-funnel-close-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #4e5968;
    cursor: pointer;
    border-radius: 8px;
    margin-left: -8px;
    transition: background 0.2s;
  }

  .mobile-funnel-close-btn:hover {
    background: #f2f4f6;
  }

  .mobile-funnel-close-btn svg {
    width: 24px;
    height: 24px;
  }

  .mobile-funnel-title {
    font-size: 17px;
    font-weight: 600;
    color: #191f28;
    flex: 1;
    text-align: center;
    margin-right: 40px; /* 닫기 버튼 너비만큼 오프셋 */
  }

  /* 진행률 바 */
  .mobile-funnel-progress-container {
    height: 4px;
    background: #e5e8eb;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
  }

  .mobile-funnel-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3182f6, #4990f7);
    border-radius: 2px;
    transition: width 0.3s ease;
  }

  /* 스텝 인디케이터 */
  .mobile-funnel-step-indicator {
    display: flex;
    justify-content: center;
    font-size: 13px;
    color: #8b95a1;
  }

  .mobile-funnel-step-indicator .current {
    color: #3182f6;
    font-weight: 600;
  }

  /* =====================================================
     퍼널 컨텐츠
     ===================================================== */
  .mobile-funnel-content {
    padding: 0;
    min-height: calc(100vh - 180px);
    padding-bottom: 100px;
  }

  /* 폼 섹션을 스텝으로 변환 */
  .mobile-funnel-mode .form-section,
  .mobile-funnel-mode .form-group.full-width[data-step],
  .mobile-funnel-mode .form-group[data-step],
  .mobile-funnel-mode .toss-form-group[data-step] {
    display: none;
    padding: 24px 20px;
    margin: 16px;
    background: #fff;
    border-radius: 16px;
    border-bottom: none;
    animation: funnelFadeInUp 0.3s ease;
  }

  .mobile-funnel-mode .form-section.active-step,
  .mobile-funnel-mode .form-group.full-width.active-step,
  .mobile-funnel-mode .form-group.active-step,
  .mobile-funnel-mode .toss-form-group.active-step {
    display: block;
    /* 액션 바 높이(~80px) + safe-area + 여유 공간 */
    margin-bottom: calc(100px + env(safe-area-inset-bottom, 20px));
    padding-bottom: 16px;
  }

  @keyframes funnelFadeInUp {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* 스텝 제목 스타일 */
  .mobile-funnel-mode .section-title {
    margin-bottom: 24px;
  }

  .mobile-funnel-mode .section-title h4 {
    font-size: 20px;
    font-weight: 700;
    color: #191f28;
    margin-bottom: 8px;
  }

  .mobile-funnel-mode .section-title .section-hint {
    display: block;
    font-size: 14px;
    color: #8b95a1;
    margin-top: 4px;
    margin-left: 0;
  }

  /* =====================================================
     하단 액션 바
     ===================================================== */
  .mobile-funnel-action-bar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: #fff !important;
    padding: 16px 20px !important;
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    border-top: 1px solid #e5e8eb;
    display: flex !important;
    gap: 12px;
    z-index: 10000 !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  }

  .mobile-funnel-btn {
    flex: 1;
    padding: 16px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  .mobile-funnel-btn-prev {
    flex: 0 0 56px;
    background: #f2f4f6;
    border: none;
    color: #4e5968;
  }

  .mobile-funnel-btn-prev:hover {
    background: #e5e8eb;
  }

  .mobile-funnel-btn-prev:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .mobile-funnel-btn-prev svg {
    width: 20px;
    height: 20px;
  }

  .mobile-funnel-btn-next {
    background: #3182f6;
    border: none;
    color: #fff;
  }

  .mobile-funnel-btn-next:hover {
    background: #1b64da;
  }

  .mobile-funnel-btn-next:disabled {
    background: #e5e8eb;
    color: #b0b8c1;
    cursor: not-allowed;
  }

  .mobile-funnel-btn-next.submit-btn {
    background: #20c997;
  }

  .mobile-funnel-btn-next.submit-btn:hover {
    background: #12b886;
  }

  /* 데스크톱 전용 요소 숨김 */
  .mobile-funnel-mode .form-footer {
    display: none !important;
  }

  /* =====================================================
     입력 필드 스타일 조정
     ===================================================== */
  .mobile-funnel-mode .toss-input,
  .mobile-funnel-mode .toss-select,
  .mobile-funnel-mode .toss-textarea {
    font-size: 16px;
    padding: 16px;
  }

  .mobile-funnel-mode .form-row {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  /* 카테고리 버튼 그리드 */
  .mobile-funnel-mode .category-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .mobile-funnel-mode .category-btn {
    padding: 16px 12px;
    font-size: 14px;
  }

  /* 체크인 모드 버튼 */
  .mobile-funnel-mode .checkin-mode-selector {
    flex-direction: column;
    gap: 10px;
  }

  .mobile-funnel-mode .checkin-mode-btn {
    width: 100%;
  }

  /* =====================================================
     유효성 검사 에러 표시
     ===================================================== */
  .mobile-funnel-error {
    color: #f04452;
    font-size: 13px;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .mobile-funnel-error::before {
    content: '!';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: #f04452;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
  }

  /* =====================================================
     이미지 업로드 영역 조정
     ===================================================== */
  /* 부모 컨테이너 오버플로우 방지 */
  .mobile-funnel-mode .form-section,
  .mobile-funnel-mode .form-group.full-width[data-step],
  .mobile-funnel-mode .form-group[data-step],
  .mobile-funnel-mode .toss-form-group[data-step] {
    box-sizing: border-box;
    overflow: hidden;
    max-width: calc(100vw - 32px);
  }

  .mobile-funnel-mode .multi-image-upload-area {
    min-height: 160px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
  }

  .mobile-funnel-mode .upload-placeholder {
    padding: 20px;
    text-align: center;
  }

  .mobile-funnel-mode .upload-placeholder p {
    word-break: keep-all;
    font-size: 14px;
  }

  .mobile-funnel-mode .image-preview-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px;
  }

  /* 480px 이하 추가 제약 - 16px 여백 일관성 유지 */
  @media (max-width: 480px) {
    .mobile-funnel-mode .form-section,
    .mobile-funnel-mode .form-group.full-width[data-step],
    .mobile-funnel-mode .form-group[data-step],
    .mobile-funnel-mode .toss-form-group[data-step] {
      padding: 16px;
      margin: 16px;
      max-width: calc(100vw - 32px);
    }

    /* 활성 스텝 하단 여백 - 액션 바와 충돌 방지 */
    .mobile-funnel-mode .form-section.active-step,
    .mobile-funnel-mode .form-group.full-width.active-step,
    .mobile-funnel-mode .form-group.active-step,
    .mobile-funnel-mode .toss-form-group.active-step {
      margin-bottom: calc(110px + env(safe-area-inset-bottom, 20px));
    }

    .mobile-funnel-mode .multi-image-upload-area {
      min-height: 140px;
    }

    .mobile-funnel-mode .upload-placeholder {
      padding: 16px;
    }

    .mobile-funnel-mode .upload-placeholder p {
      font-size: 13px;
    }

    .mobile-funnel-mode .image-preview-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: 8px;
      padding: 8px;
    }
  }

  /* =====================================================
     에디터 영역 조정
     ===================================================== */
  .mobile-funnel-mode .tiptap-editor {
    min-height: 200px;
    font-size: 16px;
  }

  .mobile-funnel-mode .tiptap-toolbar {
    flex-wrap: wrap;
    padding: 8px;
  }

  .mobile-funnel-mode .tiptap-btn {
    width: 36px;
    height: 36px;
  }

  /* =====================================================
     위치 선택 버튼
     ===================================================== */
  .mobile-funnel-mode .location-input-group {
    flex-direction: column;
    gap: 10px;
  }

  .mobile-funnel-mode .location-select-btn {
    width: 100%;
    justify-content: center;
  }

  /* =====================================================
     가격 미리보기
     ===================================================== */
  .mobile-funnel-mode .price-preview {
    margin-top: 16px;
  }

  /* =====================================================
     스텝 완료 표시
     ===================================================== */
  .mobile-funnel-step-complete {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: #e8f9ed;
    border-radius: 8px;
    color: #30c85e;
    font-size: 14px;
    font-weight: 500;
    margin-top: 16px;
  }

  .mobile-funnel-step-complete svg {
    width: 20px;
    height: 20px;
  }
}

/* =====================================================
   데스크톱에서는 퍼널 헤더/액션바 숨김
   ===================================================== */
@media (min-width: 769px) {
  .mobile-funnel-header,
  .mobile-funnel-action-bar {
    display: none !important;
  }
}
