/* ==============================================
   NewsMade CMS - Common CSS (basic theme)
   ============================================== */
:root {
    --primary:   #1c6fcb;
    --primary-h: #1558a8;
    --accent:    #e33;
    --text:      #222;
    --text-sub:  #555;
    --text-muted:#888;
    --text-h2:#ffffff;
    --border:    #e0e0e0;
    --bg:        #f4f4f4;
    --bg-card:   #fff;
    --header-h:  56px;
    /* fixed 헤더 실제 높이(px) — JS가 갱신, 초기값은 한 줄 높이 */
    --header-offset: var(--header-h);
    --max-w:     1100px;
    --radius:    0;
    /* PC 사이드바 position:sticky 시 top 값 (fixed 헤더 아래) */
    --sidebar-sticky-top: calc(env(safe-area-inset-top, 0px) + var(--header-offset) + 8px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    scroll-behavior: smooth;
    max-width: 100%;
    /* root에 overflow-x: clip/hidden 금지 → position:sticky(사이드바) 조상이 되면 뷰포트 스티키가 깨짐 */
    overflow-x: visible;
    /* 고정 헤더 아래 앵커 이동 시 가리지 않도록 */
    scroll-padding-top: calc(env(safe-area-inset-top, 0px) + var(--header-offset) + 4px);
}
body {
    max-width: 100%;
    overflow-x: visible;
    overflow-y: auto;
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }

/* ── Container ── */
.container {
    max-width: var(--max-w);
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
    overflow: visible;
}

/* ── Header ── */
/* 뷰포트 고정: 긴 페이지 어디서든 스크롤 방향으로 숨김/표시 (sticky는 스크롤 맥락과 엮여 어색해질 수 있음) */
.site-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    transition: transform 0.32s ease, box-shadow 0.32s ease;
    will-change: transform;
}
.site-header.is-scroll-hidden {
    transform: translateY(-100%);
    pointer-events: none;
    box-shadow: none;
}
.header-inner {
    display: flex;
    align-items: center;
    height: var(--header-h);
    gap: 0;
}
.site-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.18rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
    flex-shrink: 0;
    padding-left: 10px;
    padding-right: 16px;
}
.logo-icon { width: 26px; height: 26px; object-fit: contain; }

/* ── Navigation ── */
.main-nav {
    display: flex;
    align-items: stretch;
    flex: 1;
    height: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}
.main-nav::-webkit-scrollbar { display: none; }
.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    font-size: .87rem;
    color: var(--text-sub);
    white-space: nowrap;
    transition: color .15s;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;   /* 헤더 하단 border-bottom(2px)과 겹치도록 */
    height: calc(var(--header-h) + 2px);
}
.nav-link:hover { color: var(--primary); }
.nav-link.active { color: var(--primary); font-weight: 600; border-bottom-color: var(--primary); }

.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
    padding-left: 8px;
}
.search-toggle, .nav-toggle {
    background: none; border: none; cursor: pointer;
    font-size: 1.05rem; padding: 7px 8px; color: var(--text-sub);
    line-height: 1;
}
.nav-toggle {
    font-size: 1.5rem;
    padding: 6px 10px;
    min-width: 44px;
    min-height: 44px;
    display: none;
    align-items: center;
    justify-content: center;
}
.search-toggle:hover, .nav-toggle:hover { color: var(--primary); }

/* ── Search Bar ── */
.search-bar {
    padding: 8px 0;
    border-top: 1px solid var(--border);
    background: #fff;
}
.search-form { display: flex; gap: 6px; }
.search-input {
    flex: 1;
    padding: 7px 12px;
    border: 1px solid var(--border);
    font-size: .9rem;
    outline: none;
    background: #fff;
    color: var(--text);
}
.search-input:focus { border-color: var(--primary); }
.search-btn {
    padding: 7px 18px;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: .9rem;
    transition: background .15s;
}
.search-btn:hover { background: var(--primary-h); }

/* ── Mobile Nav ── */
.mobile-nav-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 200;
}
.mobile-nav-overlay.show { display: block; }
.mobile-nav {
    position: fixed;
    top: 0; right: -280px; bottom: 0;
    width: 280px;
    background: #fff;
    z-index: 201;
    transition: right .25s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-left: 1px solid var(--border);
}
.mobile-nav.open { right: 0; }
.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 2px solid var(--primary);
    background: var(--primary);
    color: #fff;
    flex-shrink: 0;
}
.mobile-nav-header strong { font-size: .95rem; }
.mobile-nav-header button {
    background: none; border: none;
    font-size: 1.2rem; cursor: pointer; color: #fff;
    line-height: 1; padding: 4px;
}
.mobile-nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: .93rem;
    transition: background .1s;
}
.mobile-nav-link:hover { background: #f5f5f5; color: var(--primary); }
.mobile-nav-count {
    font-size: .76rem;
    color: var(--text-muted);
    background: #f0f0f0;
    padding: 1px 7px;
    min-width: 28px;
    text-align: center;
}

/* ── Main ── (fixed 헤더 높이만큼 상단 여백 — --header-offset 는 bottom.php에서 동기화) */
.site-main {
    padding: calc(var(--header-offset) + 20px) 0 32px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
}

/* ── Ad ──
   반응형 단위는「직계 부모의 가용 폭」을 본다 → .ad-container로 폭을 명확히 제한
   ins 폭은 .ad-container 등 안에만 둠(전역 ins에 width:100% 주면 앵커·자동광고가 문서폭으로 커져 가로 스크롤 유발)
   Google이 넣는 margin-left:-16px·width:390px 인라인은 모바일에서 !important로 덮음 */
/* overflow-x만 hidden/clip 주면 overflow-y가 auto로 바뀌어(스펙) 세로로 광고가 잘려 보일 수 있음 → visible */
.ad-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: visible;
    position: relative;
    flex-shrink: 1;
}
.ad-wrap {
    margin: 12px 0;
    text-align: center;
    min-height: 30px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
    box-sizing: border-box;
}
/* 사이트에서 출력하는 슬롯·본문·위젯만(앵커/오버레이용 ins 제외) */
.ad-container ins.adsbygoogle,
.ad-wrap ins.adsbygoogle,
.post-ad ins.adsbygoogle,
.widget-ad ins.adsbygoogle {
    display: block !important;
    position: relative;
    z-index: 1;
    cursor: pointer;
    pointer-events: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
    box-sizing: border-box !important;
}
/* Google 주입 래퍼·iframe — 부모 폭에 맞춤 */
.ad-container ins.adsbygoogle > div,
.ad-wrap ins.adsbygoogle > div,
.ad-container ins.adsbygoogle div[id^="aswift_"],
.ad-wrap ins.adsbygoogle div[id^="aswift_"] {
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}
.ad-container ins.adsbygoogle iframe,
.ad-wrap ins.adsbygoogle iframe {
    max-width: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}
@media (max-width: 768px) {
    .ad-container,
    .ad-wrap,
    .post-ad.post-ad--slot {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
    /* margin 0 오버라이드 금지: 좌우 auto 중앙 정렬이 깨져 광고가 왼쪽으로 치우침 */
    .ad-container ins.adsbygoogle,
    .ad-wrap ins.adsbygoogle,
    .post-ad ins.adsbygoogle,
    .widget-ad ins.adsbygoogle {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
    .ad-container ins.adsbygoogle div[id^="aswift_"],
    .ad-wrap ins.adsbygoogle div[id^="aswift_"],
    .post-ad ins.adsbygoogle div[id^="aswift_"],
    .widget-ad ins.adsbygoogle div[id^="aswift_"] {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        /* height:auto !important 금지 — 인라인 높이(반응형·정사각 등)를 덮어 ~150px처럼 잘림 */
    }
    .ad-container ins.adsbygoogle iframe,
    .ad-wrap ins.adsbygoogle iframe,
    .post-ad ins.adsbygoogle iframe,
    .widget-ad ins.adsbygoogle iframe {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
}

/* ── Pagination (메인·카테고리·태그 공통) ── */
.site-pagination {
    width: 100%;
    display: block;
}
.pagination {
    display: flex; gap: 2px;
    justify-content: center;
    margin: 24px 0;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; padding: 0 6px;
    border: 1px solid var(--border);
    font-size: .85rem;
    color: var(--text-sub);
    transition: all .12s;
    background: #fff;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination a.active, .pagination span.current {
    background: var(--primary); color: #fff; border-color: var(--primary);
}

/* ── Category Badge ── */
.cat-badge {
    display: inline-block;
    padding: 1px 7px;
    background: var(--primary);
    color: #fff;
    font-size: .73rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ── Tag ── */
.tag {
    display: inline-block;
    padding: 2px 9px;
    background: #fff;
    border: 1px solid var(--border);
    font-size: .78rem;
    color: var(--text-sub);
    margin: 2px;
    transition: all .12s;
}
.tag:hover { border-color: var(--primary); color: var(--primary); }

/* ── Utilities ── */
.text-muted  { color: var(--text-h2); }
.text-sub    { color: var(--text-sub); }
.text-primary { color: var(--primary); }
.text-small  { font-size: .82rem; }
.text-center { text-align: center; }

/* ── Footer ── */
.site-footer {
    background: #1a1a2e;
    color: #aaa;
    padding: 28px 0 16px;
    margin-top: 36px;
    text-align: center;
}
.footer-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.footer-brand strong { color: #fff; font-size: 1rem; display: block; }
.footer-info {
    font-size: .82rem;
    line-height: 1.9;
    color: #999;
}
.footer-bottom {
    border-top: 1px solid #2e2e44;
    padding-top: 12px;
    font-size: .78rem;
    color: #666;
}

/* ── 맨 위로 (고정 버튼) ── */
.back-to-top {
    position: fixed;
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: max(18px, env(safe-area-inset-bottom, 0px));
    z-index: 998;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid #d8dde4;
    background: #fff;
    color: var(--primary);
    box-shadow: 0 2px 14px rgba(0, 0, 0, .12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    line-height: 1;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity .22s ease, visibility .22s, transform .22s ease, background .15s, border-color .15s;
}
.back-to-top.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.back-to-top:hover {
    background: #f0f6ff;
    border-color: var(--primary);
}
.back-to-top:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .main-nav { display: none; }
    .nav-toggle { display: inline-flex; }
    :root { --header-h: 55px; }
    /* 헤더(상단 메뉴)와 본문 사이 여백 제거 — fixed 헤더 높이는 유지 */
    .site-main { padding: calc(var(--header-offset) + 0px) 0 24px; }
    .site-main > .container > .ad-wrap:first-child {
        margin-top: 0;
    }
    /* 모바일 본문 기본 글자 (15% 확대) */
    body { font-size: calc(15px * 1.15); }
    /* 가로 스크롤: html에 overflow-x 주면 sticky 깨짐 → .ad-container·본문 .post-body 등에서만 클립 */
}
