/* ==========================================================================
   magazine.css — 매거진 전용 (목록 · 카테고리 · 글 상세)
   - 5단계: home.php · archive.php(category.php) · single.php에서만 연결
   1. 목록 공통 틀 (M02 ~ M04)
   2. 카테고리 탭 (M02)
   3. 추천 글 (M03, 고정 글)
   4. 카드 목록 · 페이지 번호 (M04)
   5. 글 머리 · 대표 이미지 (D01 · D02)
   6. 본문 + 목차 (D03 · D06)
   7. 상담 박스 · 태그 · 링크 복사 (D04 · D05)
   8. 관련 글 (D08)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. 목록 공통 틀: 따뜻한 회색 배경 위에 탭 → 추천 글 → 카드 → 페이지 번호
   - 위 여백은 상단 띠 바로 아래라 섹션 기본값보다 좁게
   -------------------------------------------------------------------------- */
.magazine-body {
    padding-top: 40px;
}

.magazine-body .cb-inner {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

@media (min-width: 768px) {
    .magazine-body {
        padding-top: 56px;
    }

    .magazine-body .cb-inner {
        gap: 40px;
    }
}

@media (min-width: 1024px) {
    .magazine-body {
        padding-top: 72px;
    }

    .magazine-body .cb-inner {
        gap: 48px;
    }
}

/* --------------------------------------------------------------------------
   2. 카테고리 탭 (카테고리가 2개 이상일 때만 출력)
   - 모바일: 넘치면 가로 스크롤 / 다 들어가면 가운데 정렬
     (ul을 내용 너비로 만들고 margin auto → 예전 text-align: center + inline-block과 비슷한 효과)
   -------------------------------------------------------------------------- */
.magazine-tabs {
    margin-inline: calc(var(--inner-pad) * -1); /* 스크롤 영역을 화면 끝까지 */
    overflow-x: auto;
    scrollbar-width: none;
}

.magazine-tabs::-webkit-scrollbar {
    display: none;
}

.magazine-tabs .tab-list {
    display: flex;
    gap: 8px;
    width: max-content;
    margin-inline: auto;
    padding: 2px var(--inner-pad); /* 위아래 2px: 초점 테두리가 잘리지 않게 */
}

.magazine-tabs a {
    display: flex;
    align-items: center;
    min-height: var(--tap-min);
    padding: 0 20px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-white);
    color: var(--text-body);
    font-size: var(--fs-small);
    font-weight: 600;
    white-space: nowrap;
    transition:
        border-color var(--duration) var(--ease),
        color var(--duration) var(--ease);
}

.magazine-tabs a:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.magazine-tabs a[aria-current="page"] {
    border-color: var(--color-primary-dark);
    background: var(--color-primary-dark);
    color: var(--text-on-dark);
}

@media (min-width: 1024px) {
    .magazine-tabs a {
        padding: 0 24px;
        font-size: var(--fs-body);
    }
}

/* --------------------------------------------------------------------------
   3. 추천 글 (고정 글 1개, 첫 페이지에서만)
   - 모바일 · 태블릿 세로: 사진 16:9 → 글
   - 768px 이상: 사진 | 글 가로 (PC 사진 55%)
   -------------------------------------------------------------------------- */
.magazine-featured a {
    display: grid;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--bg-white);
}

.magazine-featured .thumb {
    width: 100%;
    height: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: #dce5ec;
}

/* 대표 이미지가 없는 고정 글 (작업용 회색 자리) */
.magazine-featured .thumb.is-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #4a5966;
    font-size: 0.875rem;
}

.magazine-featured .body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 24px 22px 28px;
}

.magazine-featured .label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.875rem;
    font-weight: 600;
}

.magazine-featured .badge {
    padding: 2px 10px;
    border-radius: 4px;
    background: var(--bg-primary-light);
    color: var(--color-primary);
}

.magazine-featured .cat {
    color: var(--color-primary);
}

.magazine-featured .title {
    font-size: 1.375rem; /* 22px */
    line-height: 1.4;
    transition: color var(--duration) var(--ease);
}

.magazine-featured a:hover .title {
    color: var(--color-primary);
}

/* 요약은 3줄까지 */
.magazine-featured .excerpt {
    display: -webkit-box;
    overflow: hidden;
    color: var(--text-sub);
    line-height: 1.7;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
}

.magazine-featured .date {
    margin-top: 4px;
    color: var(--text-sub);
    font-size: 0.875rem;
}

@media (min-width: 768px) {
    .magazine-featured a {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: center;
    }

    /* 사진 크기가 칸 높이를 늘리지 않게: 높이는 글 쪽에 맞추고(stretch) 사진은 잘라서 채움 */
    .magazine-featured .thumb {
        align-self: stretch;
        height: auto;
        min-height: 280px;
        aspect-ratio: auto;
        contain: size;
        contain-intrinsic-size: none; /* 워드프레스가 lazy 이미지에 넣는 기본 크기(3000 × 1500px) 무시 */
    }

    .magazine-featured .body {
        padding: 32px;
    }
}

@media (min-width: 1024px) {
    .magazine-featured a {
        grid-template-columns: 55fr 45fr;
    }

    .magazine-featured .thumb {
        min-height: 380px;
    }

    .magazine-featured .body {
        gap: 14px;
        padding: 48px 52px;
    }

    .magazine-featured .title {
        font-size: 1.75rem; /* 28px */
    }

    .magazine-featured .excerpt {
        font-size: var(--fs-body-lg);
    }
}

/* --------------------------------------------------------------------------
   4. 카드 목록 (모바일 1열 → 768px 2열 → PC 3열, 한 페이지 9개)
   -------------------------------------------------------------------------- */
.magazine-posts .post-list {
    display: grid;
    gap: 16px;
}

/* 글이 없을 때 */
.magazine-posts .no-posts {
    padding: 64px 20px;
    border-radius: var(--radius);
    background: var(--bg-white);
    color: var(--text-sub);
    text-align: center;
}

@media (min-width: 768px) {
    .magazine-posts .post-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 20px;
    }
}

@media (min-width: 1024px) {
    .magazine-posts .post-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        row-gap: 28px;
    }
}

/* 페이지 번호
   - 워드프레스 the_posts_pagination() 출력 구조 그대로 꾸밈
     (nav.pagination > h2.screen-reader-text + .nav-links > .page-numbers)
   - 글이 9개 이하면 워드프레스가 아예 출력하지 않음 */
.pagination {
    margin-top: 40px;
}

.pagination .nav-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.pagination .page-numbers {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap-min);
    height: var(--tap-min);
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-btn);
    background: var(--bg-white);
    color: var(--text-body);
    font-size: var(--fs-small);
    font-weight: 600;
    transition:
        border-color var(--duration) var(--ease),
        color var(--duration) var(--ease);
}

.pagination a.page-numbers:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.pagination .page-numbers.current {
    border-color: var(--color-primary-dark);
    background: var(--color-primary-dark);
    color: var(--text-on-dark);
}

/* … (건너뜀 표시) */
.pagination .page-numbers.dots {
    border-color: transparent;
    background: none;
}

/* 이전 화살표는 오른쪽 화살표를 뒤집어서 사용 */
.pagination .prev .icon {
    transform: scaleX(-1);
}

@media (min-width: 1024px) {
    .pagination {
        margin-top: 56px;
    }
}

/* --------------------------------------------------------------------------
   5. 글 머리 · 대표 이미지
   - 기본: 글 머리 · 대표 이미지 · 본문 · 글 아래 모두 같은 폭 800px
   - 1280px~ 목차 있는 글(.has-toc): 대표 이미지 960px = [목차 210 | 30 | 본문 720]
   -------------------------------------------------------------------------- */
.post-single {
    --post-w: 800px;
}

.post-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: calc(var(--post-w) + var(--inner-pad) * 2);
    padding-top: 40px;
    text-align: center;
}

/* 현재 위치 (흰 배경용) */
.post-head .crumbs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    color: var(--text-sub);
    font-size: var(--fs-xs);
}

.post-head .crumbs li {
    display: flex;
    align-items: center;
}

.post-head .crumbs li + li::before {
    content: "›";
    content: "›" / "";
    margin: 0 8px;
}

.post-head .crumbs a {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 32px;
}

.post-head .crumbs a:hover {
    color: var(--color-primary);
}

.post-head .title {
    font-size: 1.625rem; /* 26px */
    line-height: 1.4;
    letter-spacing: -0.03em;
}

.post-head .meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 4px 12px;
    color: var(--text-sub);
    font-size: 0.875rem;
}

.post-head .meta .cat {
    color: var(--color-primary);
    font-weight: 600;
}

.post-head .meta .cat:hover {
    text-decoration: underline;
}

/* 카테고리 · 날짜 사이 세로선 */
.post-head .meta .date::before {
    content: "";
    display: inline-block;
    width: 1px;
    height: 12px;
    margin-right: 12px;
    background: var(--line);
    vertical-align: -1px;
}

/* 대표 이미지 (없는 글은 figure 자체를 출력하지 않음) */
.post-thumb {
    max-width: calc(var(--post-w) + var(--inner-pad) * 2);
    margin-top: 28px;
}

.post-thumb img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: var(--radius);
}

@media (min-width: 768px) {
    .post-head {
        gap: 16px;
        padding-top: 56px;
    }

    .post-head .crumbs {
        font-size: 0.875rem;
    }

    .post-head .title {
        font-size: 2rem; /* 32px */
    }

    .post-head .meta {
        font-size: var(--fs-small);
    }

    .post-thumb {
        margin-top: 40px;
    }
}

@media (min-width: 1024px) {
    .post-head {
        padding-top: 72px;
    }

    .post-head .title {
        font-size: 2.375rem; /* 38px */
    }

    .post-thumb {
        margin-top: 48px;
    }
}

/* --------------------------------------------------------------------------
   6. 본문 + 목차
   - ~1279px: 목차는 본문 위 접히는 상자 (버튼으로 열기)
   - 1280px~: [목차 210px | 간격 30px | 본문 720px] = 대표 이미지 폭 960px에 맞춤,
     (오른쪽은 빠른 상담 버튼이 있어 목차는 왼쪽, HTML 순서와도 같음)
     목차는 스크롤 따라옴 (1024px에서는 목차 칸이 좁아 1280px부터 — 회사소개 A02처럼 예외 구간)
   - 목차는 post.js가 본문 h2 · h3로 만듦, h2가 3개 미만이면 hidden 그대로
     → 목차를 만들면 article.post-single에 .has-toc를 붙임 (없으면 1280px~도 모두 800px)
     → 5단계: 화면 덜컹임을 막으려고 PHP에서 h2 개수를 세어 .has-toc를 미리 출력
   -------------------------------------------------------------------------- */
.post-layout {
    max-width: calc(var(--post-w) + var(--inner-pad) * 2);
    margin-top: 40px;
}

/* 목차 */
.post-toc {
    margin-bottom: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-warm);
}

.post-toc .toc-title {
    display: none; /* PC에서만 보이는 제목 (모바일은 버튼이 제목 역할) */
}

.post-toc .toc-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 52px;
    padding: 0 20px;
    color: var(--text-title);
    font-weight: 700;
    text-align: left;
}

.post-toc .toc-toggle .icon {
    color: var(--color-primary);
    transform: rotate(90deg);
    transition: transform var(--duration) var(--ease);
}

.post-toc.is-open .toc-toggle .icon {
    transform: rotate(-90deg);
}

.post-toc .toc-list {
    display: none;
    padding: 0 20px 18px;
    counter-reset: toc;
}

.post-toc.is-open .toc-list {
    display: block;
}

.post-toc .toc-list li {
    counter-increment: toc;
}

.post-toc .toc-list a {
    display: flex;
    gap: 8px;
    padding: 6px 0;
    color: var(--text-body);
    font-size: var(--fs-small);
    line-height: 1.5;
}

.post-toc .toc-list a::before {
    content: counter(toc) ".";
    flex: none;
    min-width: 1.2em;
    color: var(--color-primary);
    font-weight: 700;
}

/* h3 (한 단계 들여쓰기, 번호 없음) */
.post-toc .toc-list ol {
    margin: 0 0 4px;
    padding-left: 1.6em;
    list-style: none;
}

.post-toc .toc-list ol li {
    counter-increment: none;
}

.post-toc .toc-list ol a {
    color: var(--text-sub);
    font-size: 0.875rem;
}

.post-toc .toc-list ol a::before {
    content: "–";
    content: "–" / "";
    color: var(--text-sub);
    font-weight: 400;
}

.post-toc .toc-list a:hover {
    color: var(--color-primary);
}

/* 지금 읽는 위치 */
.post-toc .toc-list a.is-active {
    color: var(--color-primary);
    font-weight: 700;
}

@media (min-width: 1280px) {
    .post-layout {
        margin-top: 56px;
    }

    .has-toc .post-thumb,
    .has-toc .post-foot {
        max-width: calc(960px + var(--inner-pad) * 2);
    }

    .has-toc .post-layout {
        display: grid;
        grid-template-columns: 210px minmax(0, 720px);
        column-gap: 30px;
        max-width: calc(960px + var(--inner-pad) * 2); /* 대표 이미지와 같은 폭 */
    }

    .post-content {
        grid-row: 1;
        grid-column: 2;
    }

    .post-toc {
        position: sticky;
        top: calc(var(--header-h) + 32px);
        grid-row: 1;
        grid-column: 1;
        align-self: start;
        max-height: calc(100vh - var(--header-h) - 64px);
        margin: 0;
        padding: 22px 20px 20px 0; /* 글자 시작 = 사진 왼쪽 끝 */
        overflow-y: auto;
        border: 0;
        border-right: 2px solid var(--line); /* 본문과 나누는 선 */
        border-radius: 0;
        background: none;
    }

    .post-toc .toc-title {
        display: block;
        margin-bottom: 8px;
        color: var(--text-title);
        font-weight: 700;
    }

    .post-toc .toc-toggle {
        display: none;
    }

    .post-toc .toc-list {
        display: block;
        padding: 0;
    }

    .post-toc .toc-list a {
        padding: 5px 0;
        font-size: 0.875rem;
    }

    .post-toc .toc-list ol a {
        font-size: var(--fs-xs);
    }
}

/* 본문 글자 모양은 components.css의 .cb-prose (post.html: class="post-content cb-prose") */

/* --------------------------------------------------------------------------
   7. 글 아래: 상담 박스 → 태그 · 링크 복사
   -------------------------------------------------------------------------- */
.post-foot {
    display: flex;
    flex-direction: column;
    gap: 28px;
    max-width: calc(var(--post-w) + var(--inner-pad) * 2);
    margin-top: 56px;
    padding-bottom: var(--section-space);
}

/* 상담 박스 (글 상세는 CTA 띠 대신) */
.post-consult {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 28px 22px;
    border-radius: var(--radius);
    background: var(--color-primary-dark);
}

.post-consult .title {
    color: var(--text-on-dark);
    font-size: 1.25rem; /* 20px */
    line-height: 1.4;
}

.post-consult .desc {
    margin-top: 8px;
    color: var(--text-on-dark-sub);
    font-size: var(--fs-small);
}

.post-consult .buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 태그 · 링크 복사 한 줄 */
.post-share {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.post-share .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.post-share .tags a {
    display: flex;
    align-items: center;
    min-height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--bg-cool);
    color: var(--text-body);
    font-size: 0.875rem;
    transition:
        background-color var(--duration) var(--ease),
        color var(--duration) var(--ease);
}

.post-share .tags a:hover {
    background: var(--bg-primary-light);
    color: var(--color-primary);
}

/* 태그가 없는 글: 링크 복사만 오른쪽에 */
.post-share .copy-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap-min);
    margin-left: auto;
    padding: 0 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius-btn);
    background: var(--bg-white);
    color: var(--text-title);
    font-size: var(--fs-small);
    font-weight: 600;
    transition:
        border-color var(--duration) var(--ease),
        color var(--duration) var(--ease);
}

.post-share .copy-link:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.post-share .copy-link .icon {
    color: var(--color-primary);
}

.post-share .copy-link.is-copied {
    border-color: var(--color-primary);
    background: var(--bg-primary-light);
    color: var(--color-primary);
}

@media (min-width: 768px) {
    .post-consult {
        gap: 24px;
        padding: 36px 40px;
    }

    .post-consult .title {
        font-size: 1.5rem; /* 24px */
    }

    .post-consult .desc {
        font-size: var(--fs-body);
    }

    .post-consult .buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

@media (min-width: 1024px) {
    .post-foot {
        gap: 32px;
        margin-top: 72px;
    }
}

/* --------------------------------------------------------------------------
   8. 관련 글 3개 (같은 카테고리, 부족하면 최신 글)
   -------------------------------------------------------------------------- */
.post-related .post-list {
    display: grid;
    gap: 16px;
}

@media (min-width: 768px) {
    .post-related .post-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .post-related .post-list {
        gap: 20px;
    }
}
