/**
 * atJeju — 데스크탑·태블릿 (브라우저)
 * RN WebView(html.in-webview)는 모바일 shell 유지
 */

/* ── 태블릿 768px+ ── */
@media (min-width: 768px) {
  html:not(.in-webview) {
    --app-viewport-v-pad: var(--space-4);
    height: 100%;
    overflow: hidden;
  }

  html:not(.in-webview) body {
    padding: var(--app-viewport-v-pad) var(--space-4);
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    box-sizing: border-box;
  }

  html:not(.in-webview) .app-shell {
    max-width: var(--app-max-width-tablet);
    min-height: calc(100dvh - 2 * var(--app-viewport-v-pad));
    max-height: calc(100dvh - 2 * var(--app-viewport-v-pad));
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  html:not(.in-webview) .app-tabbar {
    max-width: var(--app-max-width-tablet);
  }

  html:not(.in-webview) .page {
    padding: var(--space-5) var(--space-6);
  }

  html:not(.in-webview) .home-page.page {
    padding-left: calc(var(--space-6) + var(--safe-left));
    padding-right: calc(var(--space-6) + var(--safe-right));
  }

  /* 태블릿 — shell 고정 높이 안에서 main 스크롤 */
  html:not(.in-webview) .app-main {
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
  }

  html:not(.in-webview) .app-header__inner {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }

  html:not(.in-webview) .search-bar {
    max-width: 420px;
    margin-left: auto;
  }

  html:not(.in-webview) .card-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }

  html:not(.in-webview) .card-list .card {
    flex-direction: column;
    height: 100%;
  }

  html:not(.in-webview) .card-list .card__media {
    width: 100%;
    min-width: 0;
    aspect-ratio: 16 / 10;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }

  html:not(.in-webview) .home-page .card-scroll {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    margin: 0;
    padding: 0;
    scroll-snap-type: none;
  }

  html:not(.in-webview) .home-page .card-scroll .card {
    flex: none;
    max-width: none;
    width: auto;
  }

  html:not(.in-webview) .home-page .home-recent-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }

  html:not(.in-webview) .detail-actions {
    max-width: var(--app-max-width-tablet);
  }

  /* 광고 — 리스트 grid 안에서 전체 너비 */
  html:not(.in-webview) .card-list .ad-slot {
    grid-column: 1 / -1;
    width: 100%;
  }

  html:not(.in-webview) .home-ad-slot,
  html:not(.in-webview) .detail-ad-slot {
    display: block;
    width: 100%;
  }
}

/* ── 데스크탑 1024px+ : 사이드 네비 + 넓은 콘텐츠 ── */
@media (min-width: 1024px) {
  html:not(.in-webview) {
    --app-viewport-v-pad: var(--space-6);
  }

  html:not(.in-webview) body {
    padding: var(--app-viewport-v-pad) var(--space-4);
    background: linear-gradient(180deg, #e8eef2 0%, var(--color-bg) 120px);
  }

  html:not(.in-webview) .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      'header header'
      'nav main';
    max-width: var(--app-max-width-desktop);
    width: 100%;
    min-height: calc(100dvh - 2 * var(--app-viewport-v-pad));
    max-height: calc(100dvh - 2 * var(--app-viewport-v-pad));
    box-shadow: var(--shadow-md);
  }

  html:not(.in-webview) .app-header {
    grid-area: header;
    position: sticky;
    top: 0;
  }

  html:not(.in-webview) .app-main {
    grid-area: main;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    /* 사이드바 레이아웃 — 모바일 탭바용 하단 여백 제거 */
    padding-bottom: var(--space-6);
  }

  html:not(.in-webview) .app-tabbar {
    grid-area: nav;
    position: sticky;
    top: 0;
    bottom: auto;
    left: auto;
    transform: none;
    width: var(--sidebar-w);
    max-width: none;
    height: 100%;
    min-height: 0;
    align-self: stretch;
    border-top: none;
    border-right: 1px solid var(--color-border);
    box-shadow: none;
    padding-bottom: 0;
  }

  html:not(.in-webview) .app-tabbar__inner {
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: var(--space-1);
    min-height: 0;
    height: 100%;
    padding: var(--space-4) var(--space-2);
  }

  html:not(.in-webview) .app-tabbar__link {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    text-align: left;
  }

  html:not(.in-webview) .app-tabbar__link:hover {
    background: var(--color-bg);
  }

  html:not(.in-webview) .app-tabbar__link.is-active {
    background: var(--color-primary-light);
  }

  html:not(.in-webview) .app-tabbar__icon {
    width: 1.5rem;
    text-align: center;
  }

  html:not(.in-webview) .search-bar {
    max-width: 520px;
  }

  html:not(.in-webview) .page {
    max-width: var(--desktop-content-max);
    margin: 0 auto;
    padding: var(--space-6) var(--space-8);
  }

  html:not(.in-webview) .home-page.page {
    padding-left: calc(var(--space-8) + var(--safe-left));
    padding-right: calc(var(--space-8) + var(--safe-right));
  }

  html:not(.in-webview) .app-main--map .page,
  html:not(.in-webview) .app-main--map .map-page {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  html:not(.in-webview) .card-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  html:not(.in-webview) .home-page .card-scroll,
  html:not(.in-webview) .home-page .home-recent-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* 상세 — 정보 | 지도 2단 */
  html:not(.in-webview) .detail-page #detail-root {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    gap: var(--space-6);
    align-items: start;
  }

  html:not(.in-webview) .detail-page .detail-hero {
    grid-column: 1 / -1;
    margin-left: 0;
    margin-right: 0;
    aspect-ratio: 21 / 9;
    max-height: 360px;
  }

  html:not(.in-webview) .detail-page .detail-head,
  html:not(.in-webview) .detail-page .detail-title,
  html:not(.in-webview) .detail-page .detail-chips,
  html:not(.in-webview) .detail-page .detail-info,
  html:not(.in-webview) .detail-page .detail-body,
  html:not(.in-webview) .detail-page .detail-visit-block {
    grid-column: 1;
  }

  html:not(.in-webview) .detail-page .detail-map-block {
    grid-column: 2;
    grid-row: 2 / span 6;
    position: sticky;
    top: var(--space-4);
    margin-top: 0;
  }

  html:not(.in-webview) .detail-page .detail-map-block__canvas {
    height: min(420px, calc(100vh - var(--header-h) - 120px));
  }

  html:not(.in-webview) .detail-page .detail-view-count {
    grid-column: 1;
  }

  html:not(.in-webview) .detail-page #detail-ad-slot,
  html:not(.in-webview) .detail-page .ad-slot--detail_footer {
    grid-column: 1 / -1;
    width: 100%;
    margin-top: var(--space-4);
    margin-bottom: var(--space-4);
  }

  html:not(.in-webview) .detail-actions {
    position: sticky;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100%;
    max-width: none;
    margin: var(--space-4) 0 0;
    padding: var(--space-3) 0;
    background: linear-gradient(to top, var(--color-surface) 80%, transparent);
    border-radius: 0;
  }

  html:not(.in-webview) .app-main--detail {
    padding-bottom: var(--space-4);
  }

  /* 지도 — 옆 패널 */
  html:not(.in-webview) .map-page {
    flex-direction: row;
    align-items: stretch;
    min-height: calc(100dvh - var(--header-h) - 2 * var(--app-viewport-v-pad));
  }

  html:not(.in-webview) .map-canvas-wrap {
    flex: 1;
    min-width: 0;
    min-height: 480px;
  }

  html:not(.in-webview) .map-sheet {
    flex-shrink: 0;
    width: min(360px, 32vw);
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--color-border);
    box-shadow: none;
    display: flex;
    flex-direction: column;
  }

  html:not(.in-webview) .map-sheet__handle {
    flex-shrink: 0;
    cursor: default;
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border);
  }

  html:not(.in-webview) .map-sheet__body {
    flex: 1;
    min-height: 0;
    padding-top: 0;
  }

  html:not(.in-webview) #map-recommend-block {
    display: none !important;
  }

  html:not(.in-webview) .map-nearby-list {
    gap: 0;
  }

  html:not(.in-webview) .map-sheet--collapsed {
    max-height: none;
  }

  html:not(.in-webview) .map-sheet--collapsed .map-sheet__body {
    display: flex;
  }

  html:not(.in-webview) .map-sheet__grab {
    display: none;
  }

  html:not(.in-webview) .search-page .search-history__list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  html:not(.in-webview) .home-ad-slot .ad-slot--home_feed {
    max-width: none;
  }
}

/* ── 와이드 1280px+ ── */
@media (min-width: 1280px) {
  html:not(.in-webview) .card-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  html:not(.in-webview) .home-page .card-scroll,
  html:not(.in-webview) .home-page .home-recent-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
