/**
 * Global Modal System CSS
 * 전역 모달 시스템을 위한 독립적인 스타일시트
 * 모든 모달이 일관된 디자인과 동작을 갖도록 보장합니다.
 * 
 * @version 1.0.0
 * @author Daily Moment Team
 */

/* ==========================================================================
   전역 모달 컨테이너
   ========================================================================== */

/**
 * 전역 모달 컨테이너 - 모든 모달의 최상위 컨테이너
 * JavaScript에서 pointer-events를 동적으로 관리합니다.
 */
#globalModalContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* 기본적으로 비활성화, JavaScript에서 모달 열릴 때 auto로 변경 */
  z-index: 9999;
  contain: layout style paint;
}

/* ==========================================================================
   모달 오버레이 및 기본 컨테이너
   ========================================================================== */

/**
 * 모달 오버레이 - 배경 레이어
 * 모달 내용을 중앙에 배치하고 배경을 어둡게 처리합니다.
 */
.modal-overlay {
  position: fixed;
  inset: 0; /* top: 0; left: 0; right: 0; bottom: 0; 의 단축형 */
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: auto;
  backdrop-filter: blur(2px); /* 부드러운 배경 효과 */
}

/**
 * 기본 모달 컨테이너
 * 전체적인 모달 모양과 동작을 정의합니다.
 */
.modal-container {
  background: #ffffff;
  color: #111827;
  border-radius: 12px;
  box-shadow: 
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 90vw;
  max-height: 90vh;
  width: 100%;
  overflow: hidden;
  pointer-events: auto;
  animation: modalFadeIn 0.2s ease-out;
  will-change: transform, opacity; /* 애니메이션 최적화 */
}

/* ==========================================================================
   모달 애니메이션
   ========================================================================== */

/**
 * 모달 열기 애니메이션
 * 부드럽게 나타나며 약간의 스케일과 이동 효과
 */
@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/**
 * 모달 닫기 애니메이션 (필요시 사용)
 */
@keyframes modalFadeOut {
  from {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
}

/* ==========================================================================
   모달 헤더
   ========================================================================== */

/**
 * 모달 헤더 - 제목과 닫기 버튼이 위치하는 영역
 */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #e5e7eb;
  min-height: 60px; /* 일관된 높이 보장 */
  background: #ffffff;
  color: #111827;
}

/**
 * 모달 제목
 */
.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
  line-height: 1.4;
  flex: 1;
  margin-right: 16px;
}

/**
 * 모달 닫기 버튼
 */
.modal-close-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: #6b7280;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-close-btn:hover {
  background: #f3f4f6;
  color: #374151;
  transform: scale(1.1);
}

.modal-close-btn:focus {
  outline: 2px solid #0ea5e9;
  outline-offset: 2px;
}

/* ==========================================================================
   모달 바디
   ========================================================================== */

/**
 * 모달 바디 - 주요 컨텐츠가 들어가는 영역
 */
.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(90vh - 140px); /* 헤더와 푸터 공간 확보 */
  -webkit-overflow-scrolling: touch; /* iOS 스크롤 개선 */
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
  background: #ffffff;
  color: #111827;
}

/* 웹킷 기반 브라우저용 스크롤바 스타일 */
.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ==========================================================================
   모달 푸터
   ========================================================================== */

/**
 * 모달 푸터 - 액션 버튼들이 위치하는 영역
 */
.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 20px 24px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  min-height: 70px;
  align-items: center;
}

/* ==========================================================================
   모달 버튼 스타일
   ========================================================================== */

/**
 * 모달 내 기본 버튼 스타일
 */
.modal-btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  min-width: 80px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  user-select: none;
}

.modal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/**
 * 기본 버튼 (Primary)
 */
.modal-btn-primary {
  background: #0ea5e9;
  color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.modal-btn-primary:hover:not(:disabled) {
  background: #0284c7;
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/**
 * 보조 버튼 (Secondary)
 */
.modal-btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-btn-secondary:hover:not(:disabled) {
  background: #e5e7eb;
  border-color: #d1d5db;
  transform: translateY(-1px);
}

.modal-btn-secondary:active:not(:disabled) {
  transform: translateY(0);
  background: #d1d5db;
}

/* ==========================================================================
   프로필 설정 모달 전용 스타일
   ========================================================================== */

/**
 * 프로필 설정 모달의 특정 디멘션과 레이아웃
 */
.profile-settings-modal {
  width: 500px;
  max-width: 90vw;
}

.profile-form-group {
  margin-bottom: 20px;
}

.profile-form-label {
  display: block;
  font-weight: 500;
  color: #374151;
  margin-bottom: 8px;
}

.profile-form-input,
.profile-form-select {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.2s;
  background: #ffffff !important;
  color: #111827 !important;
}

.profile-form-input:focus,
.profile-form-select:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.profile-region-group {
  display: flex;
  gap: 12px;
}

.profile-region-group .profile-form-select {
  flex: 1;
}

/**
 * 소속 입력 영역 (자동완성 기능 포함)
 */
.profile-affiliation-input {
  position: relative;
}

/**
 * 자동완성 제안 목록
 */
.profile-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  z-index: 10;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  margin-top: 4px;
}

.profile-suggestions.active {
  display: block;
}

.suggestion-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  transition: background 0.2s;
}

.suggestion-item:hover {
  background: #f9fafb;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.org-name {
  font-weight: 500;
  color: #1f2937;
}

.org-type {
  font-size: 12px;
  color: #6b7280;
  margin-left: 8px;
}

.org-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.verified-badge {
  color: #059669;
  font-size: 12px;
}

.user-input-badge {
  color: #7c3aed;
  font-size: 12px;
}

.member-count {
  font-size: 11px;
  color: #6b7280;
}

.selected-affiliation {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #f0f9ff;
  border: 1px solid #0ea5e9;
  border-radius: 8px;
  color: #0369a1;
}

.selected-affiliation.active {
  display: flex;
}

.remove-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-btn:hover {
  color: #ef4444;
}

.profile-note {
  font-size: 12px;
  color: #6b7280;
  margin-top: 8px;
}

/* ==========================================================================
   반응형 디자인
   ========================================================================== */

/**
 * 모바일 기기용 레이아웃 조정
 */
@media (max-width: 640px) {
  .modal-overlay {
    /* 모바일에서 하단 네비게이션 바에 가려지지 않도록 padding 추가 */
    padding-bottom: 80px;
    /* 모달 위치 조정 - 상단 메뉴에 가려지지 않도록 */
    padding-top: 80px;
    /* 모바일에서 z-index를 더 높게 설정 */
    z-index: 10000;
  }
  
  .modal-container {
    margin: 16px auto;
    width: calc(100% - 32px);
    /* 모바일에서 최대 높이 조정 - 상하단 여백 확보 */
    max-height: calc(100vh - 160px);
    /* 스크롤 가능하도록 설정 */
    overflow-y: auto;
    /* 상단에 너무 가깝지 않도록 최소 margin 설정 */
    margin-top: 20px;
    /* 모달 컨테이너 자체도 높은 z-index */
    position: relative;
    z-index: 10001;
  }
  
  .modal-header {
    /* 모바일에서 헤더가 다른 요소에 가려지지 않도록 */
    position: relative;
    z-index: 10002;
    /* 헤더 배경색을 명확하게 설정 */
    background: #ffffff;
    /* 헤더에 약간의 그림자 추가로 구분 강화 */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  .modal-close-btn {
    /* 닫기 버튼의 클릭 영역을 더 크게 설정 */
    min-width: 44px;
    min-height: 44px;
    /* 모바일에서 더 높은 z-index */
    position: relative;
    z-index: 10003;
    /* 터치하기 쉽도록 패딩 추가 */
    padding: 8px;
  }
  
  .modal-body {
    /* 모바일에서 모달 바디 높이 제한 */
    max-height: calc(100vh - 300px);
    overflow-y: auto;
  }
  
  .profile-settings-modal {
    width: 100%;
  }
  
  .profile-region-group {
    flex-direction: column;
  }
  
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 16px;
  }
  
  .modal-footer {
    flex-direction: column-reverse;
    /* 모바일에서 footer가 화면 하단에 고정되지 않도록 */
    position: relative;
    /* 하단 여백 추가로 네비게이션 바에 가려지지 않도록 */
    margin-bottom: 20px;
    /* 배경색을 명시적으로 흰색으로 설정 (검은 배경 문제 해결) */
    background: #ffffff !important;
    border-top: 1px solid #e5e7eb;
  }
  
  .modal-btn {
    width: 100%;
  }
}

/* ==========================================================================
   다크모드 지원 (미래 확장용)
   ========================================================================== */

/* ==========================================================================
   라이트 모드 강제 적용 (우선순위 높음)
   ========================================================================== */

/**
 * 라이트 모드 강제 스타일 - 다크 모드 오버라이드 방지
 * 더 높은 우선순위로 라이트 모드 스타일 적용
 */
.modal-overlay {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  background: rgba(0, 0, 0, 0.5) !important;
  z-index: 1000 !important;
}

.modal-container,
.modal-header,
.modal-body {
  background: #ffffff !important;
  color: #111827 !important;
}

.profile-form-input,
.profile-form-select {
  background: #ffffff !important;
  color: #111827 !important;
  border-color: #e5e7eb !important;
}

.profile-form-label {
  color: #374151 !important;
}

/* ==========================================================================
   다크 모드 지원 (비활성화됨 - 라이트 모드 테스트용)
   ========================================================================== */

/**
 * 시스템 다크모드 선호도에 따른 스타일
 * 미래 수동 다크모드 설정 기능이 추가될 때 활용
 * 현재는 라이트 모드 테스트를 위해 비활성화
 */
@media (prefers-color-scheme: dark) and (max-width: 0) {
  .modal-container {
    background: #1f2937;
    color: #f9fafb;
  }
  
  .modal-header {
    border-bottom-color: #374151;
  }
  
  .modal-footer {
    background: #111827;
    border-top-color: #374151;
  }
  
  .profile-form-input,
  .profile-form-select {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
  }
  
  .profile-form-input:focus,
  .profile-form-select:focus {
    border-color: #0ea5e9;
  }
  
  .profile-suggestions {
    background: #374151;
    border-color: #4b5563;
  }
  
  .suggestion-item {
    border-bottom-color: #4b5563;
  }
  
  .suggestion-item:hover {
    background: #4b5563;
  }
}