/**
 * SLECS 웹뷰(모바일 앱) 전용 CSS
 * 사람인 앱 스타일의 네이티브 UX
 */

/* CSS 변수 기본값 */
:root {
  --webview-header-height: 48px;
  --webview-tabbar-height: 56px;
  --webview-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --tabbar-bg: #ffffff;
  --tabbar-text: #666666;
  --tabbar-active: var(--primary-color, #007bff);
}

/* 웹뷰 기본 스타일 */
html.webview-mode {
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}

.webview-body {
  margin: 0;
  padding: 0;
  min-height: calc(var(--vh, 1vh) * 100);
  background: #f5f5f5;
  padding-top: var(--safe-area-inset-top);
  padding-bottom: calc(var(--webview-tabbar-height) + var(--safe-area-inset-bottom));
}

.webview-body.keyboard-open {
  padding-bottom: 0;
}

/* 미니멀 헤더 */
.webview-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--webview-header-height);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  padding-top: var(--safe-area-inset-top);
  z-index: 1000;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.webview-header__back {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #333;
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.webview-header__back:active {
  opacity: 0.6;
}

.webview-header__title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}

.webview-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.webview-header__action {
  position: relative;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #333;
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.webview-header__action:active {
  opacity: 0.6;
}

.webview-header__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #ff4444;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.webview-header--full {
  height: auto;
  min-height: var(--webview-header-height);
  padding: 0;
  flex-direction: column;
}

/* 메인 콘텐츠 영역 */
.webview-main {
  min-height: calc(var(--vh, 1vh) * 100);
  padding-top: calc(var(--webview-header-height) + var(--safe-area-inset-top));
  padding-bottom: calc(var(--webview-tabbar-height) + var(--safe-area-inset-bottom) + 16px);
  transition: padding-bottom var(--webview-transition);
}

.webview-main.tabbar-hidden {
  padding-bottom: var(--safe-area-inset-bottom);
}

/* 하단 탭바 네비게이션 */
.webview-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--webview-tabbar-height); /* safe-area는 padding으로만 처리 */
  background: var(--tabbar-bg);
  display: flex;
  align-items: center; /* 아이템 중앙 정렬 */
  justify-content: space-around;
  padding: 0; /* 불필요한 padding 제거 */
  padding-bottom: env(safe-area-inset-bottom, 0px); /* Android 호환성을 위해 env() 직접 사용 */
  z-index: 1000;
  box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.08);
  transform: translateY(0);
  transition: transform var(--webview-transition);
  box-sizing: content-box; /* padding을 height에 추가 */
}

.webview-tabbar.hidden {
  transform: translateY(100%);
}

.webview-tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--tabbar-text);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease;
}

.webview-tabbar__item:active {
  opacity: 0.7;
}

.webview-tabbar__item.active {
  color: var(--tabbar-active);
}

.webview-tabbar__item.active .webview-tabbar__icon i {
  transform: scale(1.1);
}

.webview-tabbar__icon {
  position: relative;
  font-size: 20px;
  line-height: 1;
  margin-bottom: 4px;
}

.webview-tabbar__icon i {
  transition: transform 0.15s ease;
}

.webview-tabbar__badge {
  position: absolute;
  top: -6px;
  right: -10px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #ff4444;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.webview-tabbar__badge--dot {
  min-width: 8px;
  width: 8px;
  height: 8px;
  padding: 0;
  top: -2px;
  right: -4px;
}

.webview-tabbar__label {
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
}

/* 풀다운 새로고침 (Pull to Refresh) */
.ptr-indicator {
  position: fixed;
  top: var(--safe-area-inset-top);
  left: 50%;
  transform: translateX(-50%) translateY(-50px);
  width: 36px;
  height: 36px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: transform 0.2s ease;
}

.ptr-indicator i {
  font-size: 16px;
  color: var(--primary-color, #007bff);
  transition: transform 0.1s ease;
}

.ptr-indicator.ready i {
  color: #4caf50;
}

.ptr-indicator.refreshing {
  transform: translateX(-50%) translateY(20px) !important;
}

.ptr-indicator.refreshing i {
  animation: ptr-spin 0.8s linear infinite;
}

@keyframes ptr-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 키보드 열림 상태 */
.keyboard-open .webview-tabbar {
  display: none !important;
}

.keyboard-open .webview-main {
  padding-bottom: 0 !important;
}

/* 유틸리티 클래스 */
.webview-only {
  display: none !important;
}

.webview-body .webview-only {
  display: block !important;
}

.webview-body .webview-hide {
  display: none !important;
}

/* 웹뷰 모드에서 숨길 요소들 (PC용 푸터, 헤더 등) */
.webview-body .site-footer,
.webview-body .footer-wrapper,
.webview-body .footer-section,
.webview-body [data-widget-area="FOOTER"],
.webview-body .widget-footer,
.webview-body .slecs-footer {
  display: none !important;
}

/* 웹뷰 모드에서 PC용 헤더 숨김 (미니멀 헤더 사용) */
.webview-body.hide-header .site-header,
.webview-body.hide-header .header-wrapper,
.webview-body.hide-header [data-widget-area="HEADER"] {
  display: none !important;
}

/* 웹뷰 모드에서 메인 콘텐츠 하단 패딩 조정 */
.webview-body .main-content,
.webview-body .content-wrapper,
.webview-body .page-content {
  padding-bottom: calc(var(--webview-tabbar-height) + var(--safe-area-inset-bottom) + 16px) !important;
}

/* 웹뷰 콘텐츠 영역 상단 간격 제거 */
.webview-body .tn-main-content,
.webview-body .main-content,
.webview-body .page-content {
  padding-top: 0 !important;
  margin-top: 0 !important;
}

/* 히어로 슬라이더 상단 간격 제거 */
.webview-body .tn-hero-slider,
.webview-body .hero-slider {
  margin-top: 0 !important;
}

/* 프로필 섹션 상단 간격 조정 */
.webview-body .tn-profile-section {
  margin-top: 0;
  padding-top: 16px;
}

/* 페이지 헤더 다음 프로필 섹션 간격 */
.webview-body .tn-page-header + .tn-profile-section {
  margin-top: 0;
}

/* 반응형 (태블릿에서는 탭바 숨김) */
@media (min-width: 768px) {
  .webview-tabbar {
    display: none;
  }

  .webview-main {
    padding-bottom: 16px;
  }

  .webview-body {
    padding-bottom: 0;
  }
}
