/* ========================================
   CatSEye Native App UI
   PWA/Standalone 모드에서만 적용되는 네이티브 앱 스타일
   ======================================== */

/* ========================================
   1. 하단 탭 네비게이션 (Bottom Tab Bar)
   ======================================== */

/* 앱 모드에서 스크롤 제어 */
html.app-mode,
body.app-mode {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-x: none;
}

.app-tab-bar {
  display: none; /* 기본적으로 숨김 */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + env(safe-area-inset-bottom));
  min-height: 56px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.1);
  z-index: 1000;
  box-sizing: border-box;
  padding-bottom: env(safe-area-inset-bottom); /* iOS Safe Area */
}

/* 앱 모드에서만 표시 */
body.app-mode .app-tab-bar {
  display: flex;
}

/* 앱 모드에서는 기존 상단 네비게이션 숨김 */
body.app-mode .navbar {
  display: none !important;
}

.app-tab-bar-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  height: 56px;
}

.app-tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  text-decoration: none;
  color: #AEAEB2; /* 비활성 */
  transition: color 0.2s ease;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.app-tab-item.active {
  color: #007AFF; /* 파란색 */
}

.app-tab-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 4px;
}

/* SVG 아이콘 스타일 */
.app-tab-item svg.app-tab-icon {
  stroke: currentColor;
  fill: none;
}

.app-tab-item.active svg.app-tab-icon {
  stroke-width: 2.5;
}

.app-tab-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: -0.2px;
}

/* 알림 뱃지 */
.app-tab-item .badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  width: 8px;
  height: 8px;
  background: #FF3B30;
  border-radius: 50%;
  border: 2px solid #fff;
}

.app-tab-item .badge.has-count {
  width: auto;
  height: 16px;
  min-width: 16px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  top: 4px;
}

/* ========================================
   2. 앱 스타일 헤더 (App Header)
   ======================================== */

.app-header {
  display: none; /* 기본 숨김 */
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  min-height: 52px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  z-index: 999;
  padding-top: env(safe-area-inset-top); /* iOS Safe Area */
}

body.app-mode .app-header {
  display: block;
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 16px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* 왼쪽 영역 (뒤로가기 or 로고) */
.app-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 60px;
}

.app-back-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: none;
  border: none;
  color: #1D1D1F;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
  padding: 6px;
}

.app-back-btn svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
}

.app-back-btn:active {
  background: rgba(0, 0, 0, 0.05);
}

.app-logo {
  font-size: 20px;
  font-weight: 700;
  color: #1D1D1F;
  letter-spacing: -0.5px;
}

.app-logo span {
  color: #007AFF; /* 파란색 - 웹과 동일 */
}

/* 중앙 타이틀 */
.app-header-center {
  flex: 1;
  text-align: center;
}

.app-page-title {
  font-size: 17px;
  font-weight: 600;
  color: #1D1D1F;
  letter-spacing: -0.3px;
  margin: 0;
}

/* 우측 아이콘들 */
.app-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 60px;
  justify-content: flex-end;
}

.app-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: none;
  border: none;
  color: #1D1D1F;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  padding: 6px;
}

.app-icon-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

.app-icon-btn:active {
  background: rgba(0, 0, 0, 0.05);
}

.app-icon-btn .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: #FF3B30;
  border-radius: 50%;
  border: 2px solid #fff;
}

/* ========================================
   3. FAB 버튼 (Floating Action Button)
   ======================================== */

.app-fab {
  display: none !important; /* 기본 숨김 */
  position: fixed;
  right: 20px;
  bottom: calc(56px + 20px + env(safe-area-inset-bottom)); /* 탭바 위 */
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF6B35 0%, #E55A25 100%);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
  border: none;
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
  cursor: pointer;
  z-index: 998;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  -webkit-tap-highlight-color: transparent;
}

body.app-mode .app-fab {
  display: flex !important;
}

.app-fab:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.4);
}

/* 관리자만 표시 - 기본 숨김 */
.app-fab.admin-only {
  display: none !important;
}

body.app-mode.is-admin .app-fab.admin-only {
  display: flex !important;
}

/* ========================================
   4. 카드형 리스트 (당근 스타일)
   ======================================== */

/* 공고 카드 - 앱 모드 */
body.app-mode .app-post-card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.05);
  margin-bottom: 12px;
  transition: transform 0.2s, box-shadow 0.2s;
}

body.app-mode .app-post-card:active {
  transform: scale(0.98);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.app-post-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.app-post-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.app-post-badge.urgent {
  background: #FFE8E0;
  color: #FF6B35;
}

.app-post-badge.normal {
  background: #F0F0F0;
  color: #666;
}

.app-post-time {
  font-size: 12px;
  color: #AEAEB2;
}

.app-post-title {
  font-size: 16px;
  font-weight: 600;
  color: #1D1D1F;
  margin-bottom: 8px;
  line-height: 1.4;
}

.app-post-meta {
  font-size: 14px;
  color: #86868B;
  margin-bottom: 8px;
  line-height: 1.5;
}

.app-post-fee {
  font-size: 13px;
  color: #4A4A4A;
  margin-bottom: 12px;
}

.app-post-divider {
  height: 1px;
  background: #F0F0F0;
  margin: 12px 0;
}

.app-post-actions {
  display: flex;
  gap: 8px;
}

.app-post-btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.app-post-btn.primary {
  background: #FF6B35;
  color: #fff;
}

.app-post-btn.primary:active {
  background: #E55A25;
}

.app-post-btn.secondary {
  background: #F0F0F0;
  color: #4A4A4A;
}

.app-post-btn.secondary:active {
  background: #E0E0E0;
}

/* 엔터테이너 카드 - 앱 모드 */
body.app-mode .app-entertainer-card {
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.05);
  margin-bottom: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}

body.app-mode .app-entertainer-card:active {
  transform: scale(0.98);
}

.app-entertainer-photo {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  background: linear-gradient(145deg, #E5E5EA 0%, #D1D1D6 100%);
}

.app-entertainer-body {
  padding: 16px;
}

.app-entertainer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.app-entertainer-name {
  font-size: 18px;
  font-weight: 700;
  color: #1D1D1F;
}

.app-level-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #FFE8E0;
  color: #FF6B35;
  font-size: 11px;
  font-weight: 600;
}

.app-entertainer-type {
  font-size: 14px;
  color: #86868B;
  margin-bottom: 4px;
}

.app-entertainer-meta {
  font-size: 13px;
  color: #AEAEB2;
  margin-bottom: 12px;
}

.app-profile-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.app-progress-bar {
  flex: 1;
  height: 4px;
  background: #F0F0F0;
  border-radius: 2px;
  overflow: hidden;
}

.app-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #FF6B35 0%, #FFB020 100%);
  border-radius: 2px;
  transition: width 0.3s;
}

.app-progress-text {
  font-size: 11px;
  color: #86868B;
  font-weight: 500;
  white-space: nowrap;
}

.app-entertainer-footer {
  padding-top: 12px;
  border-top: 1px solid #F0F0F0;
  text-align: right;
}

.app-view-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  color: #FF6B35;
  text-decoration: none;
}

/* ========================================
   5. 컨텐츠 영역 패딩 조정 (앱 모드)
   ======================================== */

body.app-mode {
  padding-top: 0;
}

body.app-mode .container,
body.app-mode main,
body.app-mode .main-content {
  padding-bottom: calc(56px + 20px + env(safe-area-inset-bottom)); /* 탭바 높이 + 여백 */
}

/* 앱 모드 페이지 전환 시 스크롤 위치 초기화 방지 */
body.app-mode {
  scroll-behavior: auto;
}

/* ========================================
   6. 애니메이션
   ======================================== */

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ========================================
   7. 다크모드 대응
   ======================================== */

@media (prefers-color-scheme: dark) {
  body.app-mode {
    background: #000;
    color: #F5F5F7;
  }

  body.app-mode .app-header,
  body.app-mode .app-tab-bar {
    background: rgba(28, 28, 30, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
  }

  body.app-mode .app-page-title,
  body.app-mode .app-logo {
    color: #F5F5F7;
  }

  body.app-mode .app-icon-btn {
    color: #F5F5F7;
  }

  body.app-mode .app-post-card,
  body.app-mode .app-entertainer-card {
    background: #1C1C1E;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }

  body.app-mode .app-post-title,
  body.app-mode .app-entertainer-name {
    color: #F5F5F7;
  }

  body.app-mode .app-post-meta,
  body.app-mode .app-entertainer-type {
    color: #98989D;
  }

  body.app-mode .app-post-btn.secondary {
    background: #2C2C2E;
    color: #F5F5F7;
  }

  body.app-mode .app-progress-bar {
    background: #3A3A3C;
  }
}

/* ========================================
   8. 모바일 최적화
   ======================================== */

@media (max-width: 768px) {
  /* 탭바 아이콘 크기 조정 */
  .app-tab-icon {
    font-size: 22px;
  }

  .app-tab-label {
    font-size: 9px;
  }

  /* FAB 버튼 위치 조정 */
  .app-fab {
    right: 16px;
    bottom: calc(56px + 16px + env(safe-area-inset-bottom));
  }
}

/* ========================================
   9. iPhone SE (375px) 대응
   ======================================== */

@media (max-width: 375px) {
  .app-header-inner,
  .app-tab-bar-inner {
    padding: 0 12px;
  }

  .app-entertainer-body {
    padding: 14px;
  }

  .app-post-card {
    padding: 14px;
  }

  .app-fab {
    width: 52px;
    height: 52px;
    font-size: 24px;
  }

  .app-page-title {
    font-size: 16px;
  }
}

/* ========================================
   10. 데스크탑에서는 앱 모드 비활성화
   ======================================== */

@media (min-width: 1024px) {
  body.app-mode .app-tab-bar {
    display: none !important;
  }

  body.app-mode .app-header {
    display: none !important;
  }

  body.app-mode .navbar {
    display: flex !important;
  }

  body.app-mode .app-fab {
    display: none !important;
  }

  body.app-mode .container,
  body.app-mode main,
  body.app-mode .main-content {
    padding-bottom: 40px;
  }
}

/* ========================================
   11. 기존 페이지 스타일 오버라이드 (앱 모드)
   ======================================== */

/* index.html - 엔터테이너 목록 */
body.app-mode .entertainer-gallery {
  padding: 16px;
  gap: 16px;
}

/* posts.html - 공고 목록 */
body.app-mode .post-list {
  padding: 16px;
}

/* 검색/필터 영역 */
body.app-mode .search-filter-area {
  padding: 12px 16px;
  background: #fff;
  position: sticky;
  top: 52px;
  z-index: 100;
  border-bottom: 1px solid #f0f0f0;
}

/* 앱 모드 전용 검색 바 */
body.app-mode .app-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #F0F0F0;
  border-radius: 10px;
  padding: 10px 14px;
}

body.app-mode .app-search-bar input {
  flex: 1;
  border: none;
  background: none;
  font-size: 15px;
  outline: none;
}

body.app-mode .app-search-bar input::placeholder {
  color: #AEAEB2;
}

/* 필터 칩 */
body.app-mode .filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

body.app-mode .filter-chips::-webkit-scrollbar {
  display: none;
}

body.app-mode .filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  background: #F0F0F0;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: #4A4A4A;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

body.app-mode .filter-chip.active {
  background: #FF6B35;
  color: #fff;
}

body.app-mode .filter-chip:active {
  transform: scale(0.95);
}

/* ========================================
   12. 페이지 전환 효과
   ======================================== */

body.app-mode.page-transitioning {
  overflow: hidden;
}

body.app-mode .page-content {
  animation: fadeIn 0.2s ease;
}

/* ========================================
   13. 스플래시 스크린 (선택사항)
   ======================================== */

.app-splash {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #FF6B35 0%, #E55A25 100%);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

body.app-mode.show-splash .app-splash {
  display: flex;
}

.app-splash-logo {
  font-size: 36px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 16px;
}

.app-splash-tagline {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

/* ========================================
   14. Pull to Refresh 영역 (선택사항)
   ======================================== */

body.app-mode .ptr-element {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #AEAEB2;
  font-size: 14px;
  transform: translateY(-100%);
  transition: transform 0.3s;
}

body.app-mode.ptr-active .ptr-element {
  transform: translateY(0);
}
