/* ============================================
   app.css
   반응형 레이아웃 - 모바일/태블릿/데스크톱 최적화
   ============================================ */

/* ===== 전체 앱 구조 ===== */
html, body {
  height: 100%;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ===== 헤더 (고정, 축소 불가) ===== */
.header {
  flex-shrink: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-md);
  background: var(--c-bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid;
  border-image: linear-gradient(to right, var(--c-primary), transparent) 1;
}

.header__logo {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}

.header__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.header__subtitle {
  font-size: var(--fs-xs);
  color: var(--c-text-sub);
}

/* ===== 국기 선택 버튼 ===== */
.flag-selector {
  display: flex;
  gap: 4px;
  background: var(--c-surface);
  padding: 3px;
  border-radius: var(--r-full);
  border: 1px solid var(--c-border);
}

.flag-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  padding: 4px 6px;
  border-radius: var(--r-full);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
}

.flag-btn:hover {
  opacity: 0.8;
}

.flag-btn--active {
  opacity: 1;
  background: var(--c-bg-card);
  box-shadow: var(--shadow-sm);
  transform: scale(1.1);
}

/* ===== 메인 레이아웃 (나머지 공간 전부 사용) ===== */
.main-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* 핵심: flex 자식의 overflow 허용 */
}

/* ===== 모바일 기본: 동적 분할 ===== */
.split-top {
  flex: 1.2 1 0%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.split-bottom {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 2px solid var(--c-primary);
  background: var(--c-bg-card);
  padding-bottom: var(--safe-area-bottom);
}

/* ===== 식재료 선택 영역 ===== */
.ingredient-section {
  padding: var(--sp-sm) var(--sp-md);
}

/* ===== 카테고리 필터 바 ===== */
.category-filter-bar {
  display: flex;
  gap: var(--sp-sm);
  overflow-x: auto;
  padding-bottom: var(--sp-sm);
  margin-bottom: var(--sp-sm);
  scrollbar-width: none;
}
.category-filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  background: var(--c-surface);
  color: var(--c-text-dim);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
}
.filter-chip--active {
  background: var(--c-text);
  color: var(--c-bg);
  box-shadow: var(--shadow-sm);
}
.filter-chip:active {
  transform: scale(0.96);
}

/* ===== 식재료 그리드 ===== */
.category-group {
  margin-bottom: var(--sp-md);
}

.category-header {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-xs);
  padding-left: var(--sp-sm);
  border-left: 4px solid var(--c-text-dim);
}

.category-chips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.chip--grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: var(--r-lg);
}

.chip--grid .chip__icon {
  font-size: 2rem;
  line-height: 1.2;
}

.chip--grid .chip__name {
  font-size: 0.7rem;
  font-weight: var(--fw-medium);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ===== 선택 바 (상단 패널 내부 sticky) ===== */
.selected-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-xs) var(--sp-md);
  background: var(--c-bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--c-border);
  animation: fadeSlideDown var(--t-fast) var(--ease-out);
}

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

.selected-bar__count {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--c-text-sub);
  white-space: nowrap;
}

.selected-bar__count span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--r-full);
  background: var(--c-primary);
  color: #fff;
  font-weight: var(--fw-bold);
  font-size: var(--fs-xs);
}

.selected-bar__chips {
  flex: 1;
  display: flex;
  gap: var(--sp-xs);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.selected-bar__chips::-webkit-scrollbar {
  display: none;
}

/* ===== 결과 영역 (하단 패널) ===== */
.result-section {
  display: flex;
  flex-direction: column;
  padding: 0 var(--sp-md);
}

.result-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-sm) 0;
  border-bottom: 1px solid var(--c-border);
}

.result-header__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--c-primary);
}

.result-list {
  display: flex;
  flex-direction: row;
  gap: 16px;
  padding: var(--sp-sm) var(--sp-md) var(--sp-md) var(--sp-md);
  flex: 1;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* 파이어폭스용 */
}

.result-list::-webkit-scrollbar {
  display: none; /* 크롬/사파리용 */
}

/* ===== 결과 카드 ===== */
.result-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  opacity: 0;
  animation: fadeSlideUp var(--t-normal) var(--ease-out) forwards;
  flex-shrink: 0;
  width: 100%;
  scroll-snap-align: center;
  justify-content: space-between; /* 요소 배치 균등 분산 */
}

.result-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-card__header h3 {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
}

.match-badge {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}

.match-badge--high { background: rgba(78,205,196,0.15); color: var(--c-accent); }
.match-badge--mid  { background: rgba(255,200,87,0.15); color: var(--c-secondary); }
.match-badge--low  { background: rgba(255,107,107,0.15); color: var(--c-danger); }

.result-card__ingredients {
  font-size: var(--fs-xs);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip--has {
  background: rgba(78,205,196,0.1);
  color: var(--c-accent);
  border: 1px solid var(--c-accent);
}

.chip--lack {
  background: rgba(255,107,107,0.1);
  color: var(--c-danger);
  border: 1px dashed var(--c-danger);
}

.result-card__sauce {
  font-size: var(--fs-xs);
  color: var(--c-text-sub);
  background: var(--c-surface);
  padding: var(--sp-xs);
  border-radius: var(--r-sm);
}

/* ===== 빈 상태 ===== */
.empty-state {
  text-align: center;
  padding: var(--sp-xl) 0;
  color: var(--c-text-sub);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.empty-state__icon {
  font-size: var(--fs-2xl);
  margin-bottom: var(--sp-sm);
  display: block;
}

/* ===== 커스텀 재료 입력 ===== */
.custom-ingredient-box {
  display: flex;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-sm);
  padding: var(--sp-xs);
  background: var(--c-surface);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
}

.custom-ingredient-box input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--c-text);
  font-family: var(--font);
  font-size: var(--fs-sm);
  padding: 0 var(--sp-sm);
  outline: none;
}

.custom-ingredient-box input::placeholder {
  color: var(--c-text-dim);
}

.suggestion-box {
  background: var(--c-bg-card);
  border: 1px solid var(--c-primary);
  border-radius: var(--r-md);
  padding: var(--sp-md);
  margin-bottom: var(--sp-sm);
  box-shadow: var(--shadow-glow);
  animation: fadeSlideDown var(--t-fast) var(--ease-out);
}

.suggestion-box p {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--c-primary);
  margin-bottom: var(--sp-sm);
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-xs);
  margin-bottom: var(--sp-md);
}

/* ===== 반응형: 태블릿 (≥ 768px) ===== */
@media (min-width: 768px) {
  .main-layout {
    flex-direction: row;
  }

  .split-top {
    flex: 1;
    border-right: 2px solid var(--c-primary);
  }

  .split-bottom {
    flex: 1;
    border-top: none;
    max-height: none;
  }

  .category-chips {
    grid-template-columns: repeat(7, 1fr);
  }

  .result-list {
    flex-direction: column;
    overflow-x: visible;
    overflow-y: auto;
    scroll-snap-type: none;
    padding: var(--sp-sm) 0;
    gap: 12px;
  }

  .result-card {
    width: 100%;
    max-width: none;
  }

  .result-card__header h3 {
    font-size: var(--fs-md);
  }
}

/* ===== 반응형: 데스크톱 (≥ 1024px) ===== */
@media (min-width: 1024px) {
  .split-top {
    flex: 5;
    max-width: 600px;
  }

  .split-bottom {
    flex: 7;
  }

  .category-chips {
    grid-template-columns: repeat(8, 1fr);
  }

  .chip--grid .chip__icon {
    font-size: 2.4rem;
  }

  .chip--grid .chip__name {
    font-size: 0.8rem;
  }
}
