/*
Theme Name: InsightHub
Theme URI: https://insighthub.kr
Description: 애드센스 수익 최적화 테마. Elementor 페이지 빌더 완전 호환. 광고 배치, 반응형, 다크모드 지원.
Version: 1.0.0
Author: InsightHub
Author URI: https://insighthub.kr
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: insighthub
Requires at least: 6.0
Tested up to: 6.5
Requires PHP: 7.4
Tags: blog, news, adsense, elementor, responsive, dark-mode
*/

/* ============================================
   Elementor 필수: 빈 body 여백 제거
============================================ */
body.elementor-page {
    margin: 0 !important;
    padding: 0 !important;
}

/* Elementor Full Width 레이아웃 지원 */
.elementor-section-full_width {
    width: 100%;
}

/* ============================================
   CSS 변수 (커스터마이저로 제어)
============================================ */
:root {
    --color-accent:        #1D9E75;
    --color-accent-dark:   #0F6E56;
    --color-accent-light:  #E1F5EE;
    --color-accent-border: #9FE1CB;

    --color-bg:            #F5F5F3;
    --color-surface:       #FFFFFF;
    --color-surface-2:     #F1EFE8;
    --color-border:        rgba(0,0,0,0.1);
    --color-border-strong: rgba(0,0,0,0.2);

    --color-text-1: #1a1a1a;
    --color-text-2: #555552;
    --color-text-3: #888884;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --font-sans: -apple-system, BlinkMacSystemFont, 'Noto Sans KR', 'Apple SD Gothic Neo', sans-serif;

    --max-width:      1100px;
    --content-width:  760px;
    --sidebar-width:  300px;
    --header-height:  60px;
}

/* 다크모드 */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg:            #111111;
        --color-surface:       #1c1c1c;
        --color-surface-2:     #242424;
        --color-border:        rgba(255,255,255,0.1);
        --color-border-strong: rgba(255,255,255,0.18);
        --color-text-1:        #e8e8e8;
        --color-text-2:        #aaaaaa;
        --color-text-3:        #666666;
    }
}

body.dark-mode {
    --color-bg:            #111111;
    --color-surface:       #1c1c1c;
    --color-surface-2:     #242424;
    --color-border:        rgba(255,255,255,0.1);
    --color-border-strong: rgba(255,255,255,0.18);
    --color-text-1:        #e8e8e8;
    --color-text-2:        #aaaaaa;
    --color-text-3:        #666666;
}

/* ============================================
   리셋 & 기본
============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text-1);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--color-accent); }

/* ============================================
   레이아웃
============================================ */
.site-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* Elementor Canvas 템플릿 사용 시 헤더/푸터 숨김 */
.elementor-template-canvas .site-header,
.elementor-template-canvas .site-footer {
    display: none;
}

/* ============================================
   헤더
============================================ */
.site-header {
    background: var(--color-surface);
    border-bottom: 0.5px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--header-height);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.site-title-link {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text-1);
    letter-spacing: -0.5px;
}

.site-title-link .accent { color: var(--color-accent); }

/* Elementor 헤더 빌더 사용 시 기본 헤더 숨김 처리 */
body.elementor-header-active .site-header {
    display: none;
}

/* 내비게이션 */
.primary-nav ul {
    list-style: none;
    display: flex;
    gap: 24px;
}

.primary-nav a {
    font-size: 14px;
    color: var(--color-text-2);
}

.primary-nav a:hover { color: var(--color-accent); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dark-toggle {
    background: none;
    border: 0.5px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    padding: 5px 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--color-text-2);
    line-height: 1;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--color-text-2);
}

/* ============================================
   광고 슬롯
============================================ */
.ad-slot {
    text-align: center;
    overflow: hidden;
    line-height: 0; /* 광고 이미지 하단 여백 제거 */
}

.ad-slot ins.adsbygoogle { display: block; }

/* 리더보드 728×90 */
.ad-leaderboard {
    background: var(--color-surface);
    padding: 8px 0;
    border-bottom: 0.5px solid var(--color-border);
}

.ad-leaderboard .ad-slot { max-width: 728px; margin: 0 auto; min-height: 90px; }

/* 인피드 */
.ad-infeed { margin: 24px 0; min-height: 100px; }

/* 본문 중간 */
.ad-in-content {
    margin: 32px auto;
    max-width: 336px;
    min-height: 280px;
}

/* 사이드바 300×250 */
.ad-sidebar-rect { min-height: 250px; width: 300px; margin: 0 auto; }

/* 사이드바 300×600 */
.ad-sidebar-half { min-height: 600px; width: 300px; margin: 0 auto; }

/* 모바일 앵커 */
.ad-anchor-mobile {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--color-surface);
    border-top: 0.5px solid var(--color-border);
    padding: 4px 0 env(safe-area-inset-bottom);
    text-align: center;
    min-height: 50px;
}

.ad-anchor-close {
    position: absolute;
    top: 2px;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--color-text-3);
    line-height: 1;
    padding: 4px;
}

/* ============================================
   Elementor 위젯 보완 스타일
============================================ */

/* Elementor 포스트 카드 커스터마이징 */
.elementor-post__card {
    border-radius: var(--radius-lg) !important;
    border: 0.5px solid var(--color-border) !important;
    overflow: hidden;
    transition: border-color 0.15s;
}

.elementor-post__card:hover {
    border-color: var(--color-border-strong) !important;
}

/* Elementor Posts 위젯 카테고리 뱃지 */
.elementor-post__badge {
    background: var(--color-accent-light) !important;
    color: var(--color-accent-dark) !important;
    font-weight: 600 !important;
    border-radius: 20px !important;
    font-size: 11px !important;
}

/* Elementor 버튼 */
.elementor-button {
    border-radius: var(--radius-md) !important;
    font-family: var(--font-sans) !important;
}

.elementor-button.elementor-button-primary,
.elementor-button[class*="accent"] {
    background-color: var(--color-accent) !important;
    border-color: var(--color-accent) !important;
}

.elementor-button.elementor-button-primary:hover {
    background-color: var(--color-accent-dark) !important;
}

/* Elementor 제목 위젯 */
.elementor-widget-heading .elementor-heading-title {
    font-family: var(--font-sans);
    color: var(--color-text-1);
}

/* Elementor 텍스트 에디터 */
.elementor-widget-text-editor p {
    color: var(--color-text-2);
    line-height: 1.8;
}

/* Elementor 구분선 */
.elementor-divider-separator {
    border-color: var(--color-border) !important;
}

/* Elementor 이미지 박스 */
.elementor-image-box-wrapper {
    background: var(--color-surface);
    border: 0.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: border-color 0.15s;
}

.elementor-image-box-wrapper:hover {
    border-color: var(--color-border-strong);
}

/* Elementor 아이콘 박스 */
.elementor-icon-box-wrapper {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
}

/* ============================================
   포스트 카드 (PHP 템플릿 기반)
============================================ */
.post-card {
    background: var(--color-surface);
    border: 0.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.15s;
    height: 100%;
}

.post-card:hover { border-color: var(--color-border-strong); }

.post-card .card-thumbnail {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    background: var(--color-surface-2);
}

.post-card .card-body { padding: 14px 16px 18px; }

.post-card .card-category {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-accent-dark);
    background: var(--color-accent-light);
    padding: 3px 10px;
    border-radius: 20px;
    margin-bottom: 8px;
}

.post-card .card-title {
    font-size: 15px;
    font-weight: 500;
    line-height: 1.45;
    margin-bottom: 8px;
    color: var(--color-text-1);
}

.post-card .card-excerpt {
    font-size: 13px;
    color: var(--color-text-2);
    line-height: 1.6;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.post-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--color-text-3);
    flex-wrap: wrap;
}

.post-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

/* ============================================
   단일 포스트
============================================ */
.main-layout {
    display: grid;
    grid-template-columns: 1fr var(--sidebar-width);
    gap: 28px;
    padding: 24px 0 48px;
}

.entry-title {
    font-size: 28px;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.5px;
    margin-bottom: 12px;
}

.entry-summary {
    font-size: 15px;
    color: var(--color-text-2);
    line-height: 1.7;
    padding: 14px 16px;
    background: var(--color-accent-light);
    border-left: 3px solid var(--color-accent);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    margin-bottom: 24px;
}

.entry-content {
    font-size: 16px;
    line-height: 1.9;
    color: var(--color-text-1);
}

.entry-content h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 36px 0 14px;
    padding-bottom: 8px;
    border-bottom: 0.5px solid var(--color-border);
}

.entry-content h3 {
    font-size: 17px;
    font-weight: 500;
    margin: 24px 0 10px;
}

.entry-content p { margin-bottom: 18px; }

.entry-content blockquote {
    border-left: 3px solid var(--color-accent);
    margin: 24px 0;
    padding: 12px 20px;
    background: var(--color-surface-2);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--color-text-2);
}

/* TOC */
.toc-box {
    background: var(--color-surface-2);
    border: 0.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    margin: 28px 0;
}

.toc-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.toc-list { list-style: none; counter-reset: toc; }
.toc-list li {
    counter-increment: toc;
    font-size: 13px;
    padding: 5px 0;
    border-bottom: 0.5px solid var(--color-border);
    color: var(--color-text-2);
}
.toc-list li:last-child { border-bottom: none; }
.toc-list li::before {
    content: counter(toc, decimal-leading-zero) "  ";
    color: var(--color-text-3);
    font-size: 11px;
    margin-right: 6px;
}
.toc-list a { color: inherit; }
.toc-list a:hover { color: var(--color-accent); }

/* 공유 바 */
.share-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 16px 0;
    border-top: 0.5px solid var(--color-border);
    border-bottom: 0.5px solid var(--color-border);
    margin: 24px 0;
    flex-wrap: wrap;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 20px;
    border: 0.5px solid var(--color-border-strong);
    background: var(--color-surface);
    font-size: 13px;
    color: var(--color-text-2);
    cursor: pointer;
}

.share-btn:hover { background: var(--color-surface-2); }

/* 관련 글 */
.related-posts { margin-top: 40px; padding-top: 24px; border-top: 0.5px solid var(--color-border); }
.related-posts-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.related-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* ============================================
   사이드바
============================================ */
.site-sidebar { display: flex; flex-direction: column; gap: 20px; }

.widget {
    background: var(--color-surface);
    border: 0.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
}

.widget-title {
    font-size: 14px;
    font-weight: 600;
    padding-bottom: 10px;
    margin-bottom: 12px;
    border-bottom: 0.5px solid var(--color-border);
}

.popular-posts-list { list-style: none; }
.popular-posts-list li {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 0.5px solid var(--color-border);
    align-items: flex-start;
}
.popular-posts-list li:last-child { border-bottom: none; }
.popular-rank { font-size: 18px; font-weight: 700; color: var(--color-border-strong); min-width: 26px; line-height: 1.2; }
.popular-title { font-size: 13px; line-height: 1.45; }
.popular-views { font-size: 11px; color: var(--color-text-3); margin-top: 2px; display: block; }

.sidebar-sticky-ad { position: sticky; top: calc(var(--header-height) + 16px); }

/* ============================================
   푸터
============================================ */
.site-footer {
    background: var(--color-surface);
    border-top: 0.5px solid var(--color-border);
    padding: 28px 0;
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.footer-nav ul { list-style: none; display: flex; gap: 20px; flex-wrap: wrap; }
.footer-nav a { font-size: 13px; color: var(--color-text-3); }
.footer-nav a:hover { color: var(--color-accent); }
.footer-copy { font-size: 12px; color: var(--color-text-3); }

/* ============================================
   반응형
============================================ */
@media (max-width: 1024px) {
    .main-layout { grid-template-columns: 1fr; }
    .site-sidebar { display: none; }
}

@media (max-width: 768px) {
    .primary-nav { display: none; }
    .primary-nav.is-open {
        display: block;
        position: absolute;
        top: var(--header-height);
        left: 0; right: 0;
        background: var(--color-surface);
        border-bottom: 0.5px solid var(--color-border);
        padding: 16px 20px;
        z-index: 999;
    }
    .primary-nav.is-open ul { flex-direction: column; gap: 12px; }
    .mobile-menu-toggle { display: flex; }
    .ad-anchor-mobile { display: block; }
    .ad-leaderboard { display: none; }
    body { padding-bottom: 58px; }
    .post-grid { grid-template-columns: 1fr; }
    .related-grid { grid-template-columns: 1fr 1fr; }
    .entry-title { font-size: 22px; }
    .footer-inner { flex-direction: column; text-align: center; }
    .footer-nav ul { justify-content: center; }
}

@media (max-width: 480px) {
    .site-container { padding: 0 14px; }
    .related-grid { grid-template-columns: 1fr; }
    .entry-title { font-size: 20px; }
}
