/**
 * index.css — 글로벌 스타일 & 레이아웃 시스템
 * Gemini 3.5 Flash 담당: 프리미엄 디자인 시스템 구축 및 모바일 레이아웃 최적화
 */

/* ─────────────────────────────────────────────
   디자인 토큰 (CSS Custom Properties)
   ───────────────────────────────────────────── */
:root {
  /* 브랜드 컬러 (Premium Indigo) */
  --primary-color: #6C63FF;
  --primary-light: #ECEBFF;
  --primary-dark: #5146E5;
  --primary-rgb: 108, 99, 255;

  /* 수입 & 지출 시맨틱 컬러 */
  --success-color: #00D2A0;
  --success-light: #E6FAF6;
  --success-dark: #00B086;
  --danger-color: #FF4F70;
  --danger-light: #FFEBEF;
  --danger-dark: #E03556;

  /* 중립 컬러 (Neutral Colors) */
  --bg-color: #F8F9FD;
  --card-bg: #FFFFFF;
  --text-primary: #1F2937;
  --text-secondary: #4B5563;
  --text-muted: #9CA3AF;
  --border-color: #EBF0F6;
  --border-focus: #C4C1FF;

  /* 그림자 (Shadows) */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 8px 24px rgba(108, 99, 255, 0.05);
  --shadow-lg: 0 16px 36px rgba(108, 99, 255, 0.1);
  --shadow-active: 0 4px 12px rgba(108, 99, 255, 0.15);

  /* 보더 래디우스 (Radius) */
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;

  /* 인터랙션 */
  --transition-bounce: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --transition-smooth: all 0.25s ease;
}

/* ─────────────────────────────────────────────
   글로벌 리셋 & 기본 스타일
   ───────────────────────────────────────────── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: #F0F2F6;
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* ─────────────────────────────────────────────
   모바일 최적화 컨테이너 (#app)
   ───────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 100%; /* 모바일 및 iPad 풀스크린 대응 */
  min-width: 320px;
  height: 100%;
  background-color: var(--bg-color);
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   PWA 레이아웃 구성
   ───────────────────────────────────────────── */
.layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
}

/* ─────────────────────────────────────────────
   플로팅 추가 버튼 (FAB)
   ───────────────────────────────────────────── */
.fab {
  position: absolute;
  bottom: calc(72px + env(safe-area-inset-bottom) + 16px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), #8F88FF);
  color: white;
  font-size: 28px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(108, 99, 255, 0.35);
  transition: var(--transition-bounce);
  z-index: 90;
  line-height: 1;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 28px rgba(108, 99, 255, 0.45);
}

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(120px + env(safe-area-inset-bottom)) 20px;
  /* 스크롤 끝에서 WKWebView 전체로 바운스 전파 차단 */
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y; /* 내부 스크롤 허용 */
}

/* 스크롤바 세련되게 스타일링 */
.main-content::-webkit-scrollbar {
  width: 5px;
}
.main-content::-webkit-scrollbar-track {
  background: transparent;
}
.main-content::-webkit-scrollbar-thumb {
  background: rgba(108, 99, 255, 0.15);
  border-radius: 10px;
}

/* ─────────────────────────────────────────────
   하단 네비게이션 탭 바 (Tab Bar)
   ───────────────────────────────────────────── */
.tab-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(64px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.02);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-muted);
  transition: var(--transition-smooth);
  position: relative;
}

.tab-icon {
  font-size: 20px;
  margin-bottom: 4px;
  transition: var(--transition-bounce);
}

.tab-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: -0.2px;
  transition: var(--transition-smooth);
}

/* 액티브 탭 상태 */
.tab-item--active {
  color: var(--primary-color);
}

.tab-item--active .tab-icon {
  transform: translateY(-2px) scale(1.15);
}

.tab-item--active .tab-label {
  color: var(--primary-color);
  font-weight: 700;
}

/* ─────────────────────────────────────────────
   스플래시 스크린 (Splash Screen)
   ───────────────────────────────────────────── */
.splash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #8F88FF, var(--primary-color));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  color: white;
}

.splash__icon {
  font-size: 72px;
  margin-bottom: 16px;
  animation: bounce 2s infinite ease-in-out;
}

.splash__title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 32px;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.splash__spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top: 3px solid #ffffff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ─────────────────────────────────────────────
   애니메이션 키프레임 (Animations)
   ───────────────────────────────────────────── */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-15px) scale(1.05); }
}

@keyframes toastSlideIn {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

@keyframes popIn {
  from { transform: scale(0.9) translate(-50%, -50%); opacity: 0; }
  to { transform: scale(1) translate(-50%, -50%); opacity: 1; }
}

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

/* ─────────────────────────────────────────────
   태블릿/iPad 반응형 대응 (Responsive UI)
   ───────────────────────────────────────────── */
@media (min-width: 768px) {
  .main-content {
    padding-left: 10%;
    padding-right: 10%;
  }
  .tab-bar {
    padding-left: 10%;
    padding-right: 10%;
  }
  .fab {
    right: 10%;
  }
}

@media (min-width: 1024px) {
  .main-content {
    padding-left: 15%;
    padding-right: 15%;
  }
  .tab-bar {
    padding-left: 15%;
    padding-right: 15%;
  }
  .fab {
    right: 15%;
  }
}

/* AdMob Banner Padding (When ads are active) */
body.has-ad-banner {
  padding-bottom: env(safe-area-inset-bottom);
}
body.has-ad-banner .tab-bar {
  bottom: 50px; /* AdMob Banner height */
}
body.has-ad-banner .fab {
  bottom: calc(130px + env(safe-area-inset-bottom)); /* tab(60)+ad(50)+gap(20) */
}
body.has-ad-banner .main-content {
  padding-bottom: calc(200px + env(safe-area-inset-bottom)) !important;
}
