/* 
 * Posts Archive and Single Post Styles
 * Styles for archive.php and single.php templates
 */

/* ===========================
   Archive Page Styles
   =========================== */

.posts-archive {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 2rem;
}

.archive-header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
}

.archive-header-content {
    max-width: 800px;
    margin: 0 auto;
}

.archive-title {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-weight: 700;
}

.archive-description {
    font-size: 1.1rem;
    color: #666;
    line-height: 1.6;
}

/* Posts Grid */
.posts-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 2rem;
    margin-bottom: 3rem;
}

@media (min-width: 600px) {
    .posts-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 900px) {
    .posts-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Post Card Link Wrapper */
.post-card-link-wrapper {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* Post Card */
.post-card {
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.post-card-link-wrapper:hover .post-card {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.post-card-image {
    height: 200px;
    background-color: #f0f0f0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    overflow: hidden;
}

.post-card-image-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    z-index: 1;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.post-card-image-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.loader-dot {
    width: 6px;
    height: 6px;
    background-color: var(--accent-color);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}

.loader-dot:nth-child(1) {
    animation-delay: 0s;
}

.loader-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loader-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    40% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

.post-card-content {
    padding: 1.5rem;
}

.post-card-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: #999;
}

.post-card-meta time {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.post-category {
    padding: 0.25rem 0.75rem;
    background-color: var(--accent-color);
    color: #fff;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.post-card-title {
    margin: 0 0 1rem;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
}

.post-card-title a {
    text-decoration: none;
    color: var(--text-color);
    transition: color 0.3s ease;
}

.post-card-title a:hover {
    color: var(--accent-color);
}

.post-card-excerpt {
    color: #666;
    line-height: 1.6;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.post-card-read-more {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: gap 0.3s ease;
}

.post-card-read-more:hover {
    gap: 0.75rem;
}

.post-card-read-more svg {
    transition: transform 0.3s ease;
}

.post-card-read-more:hover svg {
    transform: translateX(4px);
}

/* No Posts Message */
.no-posts {
    text-align: center;
    padding: 4rem 2rem;
    color: #999;
    font-size: 1.1rem;
}

/* ===========================
   Single Post Styles
   =========================== */

.site-main.single-post {
	max-width: 1200px;
}

.post-content {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 3rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .post-content {
        padding: 2rem 1.5rem;
    }
}

.post-header {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #eee;
}

.post-category-badge {
    display: inline-block;
    padding: 0.5rem 1rem;
    background-color: var(--accent-color);
    color: #fff;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1rem;
}

.post-title {
    font-size: 2.5rem;
    line-height: 1.3;
    color: var(--primary-color);
    margin: 0 0 1rem;
    font-weight: 700;
}

@media (max-width: 768px) {
    .post-content {
        padding: 2rem 1.5rem;
    }
    
    .post-title {
        font-size: 1.75rem;
    }
    
    .post-content-wrapper h2 {
        font-size: 1.5rem;
    }
    
    .post-content-wrapper h3 {
        font-size: 1.25rem;
    }
    
    .post-content-wrapper h4 {
        font-size: 1.1rem;
    }
    
    .post-content-wrapper h5 {
        font-size: 1rem;
    }
    
    .post-content-wrapper h6 {
        font-size: 0.95rem;
    }
}

.post-meta {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    color: #999;
    font-size: 0.9rem;
}

.post-meta time,
.post-meta .post-author {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.post-meta svg {
    color: var(--accent-color);
}

.post-featured-image {
    margin-bottom: 2rem;
    border-radius: 8px;
    overflow: hidden;
}

.post-featured-image img {
    width: 100%;
    height: auto;
    display: block;
}

.post-content-wrapper {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-color);
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.post-content-main {
    flex: 1;
    min-width: 0; /* 防止 flex item 溢出 */
}

/* ===========================
   Table of Contents (TOC)
   =========================== */

.toc-container {
    flex-shrink: 0;
    width: 280px;
    order: 2; /* TOC 顯示在右側 */
    padding: 1.5rem;
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
}

.post-content-wrapper h2 {
    font-size: 1.8rem;
    color: var(--primary-color);
    margin: 2rem 0 1rem;
    font-weight: 600;
}

.post-content-wrapper h3 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin: 1.5rem 0 1rem;
    font-weight: 600;
}

.post-content-wrapper h4 {
    font-size: 1.3rem;
    color: var(--primary-color);
    margin: 1.5rem 0 1rem;
    font-weight: 600;
}

.post-content-wrapper p {
    margin-bottom: 1.5rem;
	word-break: break-word;
}

.post-content-wrapper ul,
.post-content-wrapper ol {
    margin-bottom: 1.5rem;
    padding-left: 2rem;
}

.post-content-wrapper li {
    margin-bottom: 0.5rem;
	word-break: break-word;
}

.post-content-wrapper a {
    color: var(--accent-color);
    text-decoration: underline;
    transition: color 0.3s ease;
}

.post-content-wrapper a:hover {
    color: #d81b60;
}

.post-content-wrapper img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5rem 0;
}

.post-content-wrapper blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1.5rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: #666;
}

.post-content-wrapper code {
    background-color: #f5f5f5;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.post-content-wrapper pre {
    background-color: #f5f5f5;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5rem 0;
}

.post-content-wrapper pre code {
    background: none;
    padding: 0;
}

/* Tables - Responsive */
.post-content-wrapper table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}

.post-content-wrapper table thead {
    background-color: var(--primary-color);
    color: #fff;
}

.post-content-wrapper table th,
.post-content-wrapper table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border: 1px solid #ddd;
    word-break: break-word;
}

.post-content-wrapper table th {
    font-weight: 600;
}

.post-content-wrapper table tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

.post-content-wrapper table tbody tr:hover {
    background-color: #f0f0f0;
}

@media (max-width: 768px) {
    /* 隱藏表格的 thead */
    .post-content-wrapper table thead {
        display: none;
    }
    
    /* 將表格改為區塊顯示 */
    .post-content-wrapper table,
    .post-content-wrapper table tbody,
    .post-content-wrapper table tr {
        display: block;
        width: 100%;
    }
    
    /* 每一行變成一個卡片 */
    .post-content-wrapper table tr {
        margin-bottom: 1rem;
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 1rem;
        background: #fff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }
    
    /* 每個儲存格變成一個項目 */
    .post-content-wrapper table td {
        display: block;
        text-align: left;
        border: none;
        padding: 0.5rem 0;
        white-space: normal;
        word-break: break-word;
    }
    
    /* 在每個儲存格前顯示欄位名稱 */
    .post-content-wrapper table td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--primary-color);
        display: block;
        margin-bottom: 0.25rem;
        font-size: 0.85rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    /* 移除最後一個儲存格的下邊距 */
    .post-content-wrapper table td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    /* 移除 hover 效果 */
    .post-content-wrapper table tbody tr:hover {
        background-color: #fff;
    }
}



/* Page Links */
.page-links {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid #eee;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.page-links a,
.page-links > span {
    display: inline-block;
    padding: 0.5rem 1rem;
    background-color: #f5f5f5;
    border-radius: 4px;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.3s ease;
}

.page-links a:hover {
    background-color: var(--accent-color);
    color: #fff;
}

/* Post Tags */
.post-tags {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid #eee;
}

.post-tags svg {
    color: var(--accent-color);
    flex-shrink: 0;
}

.post-tags .tag {
    display: inline-block;
    padding: 0.4rem 1rem;
    background-color: #f5f5f5;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.post-tags .tag:hover {
    background-color: var(--accent-color);
    color: #fff;
}

/* Post Navigation */
.post-navigation {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .post-navigation {
        grid-template-columns: 1fr;
    }
}

.post-navigation a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.post-navigation a:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.post-navigation svg {
    color: var(--accent-color);
    flex-shrink: 0;
}

.nav-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-label {
    font-size: 0.85rem;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

.nav-next {
    justify-content: flex-end;
    text-align: right;
}

/* Pagination for Archive */
.posts-archive .pagination {
    position: static;
    background: transparent;
    backdrop-filter: none;
    padding: 2rem 0;
    box-shadow: none;
    border-top: none;
}


.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--accent-color);
}

.post-content-wrapper p.toc-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
}

.wp-block-separator {
	border-width: 1px;
	border-color: #efefef;
}

.toc-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--accent-color);
    transition: transform 0.3s ease;
}

.toc-toggle:hover {
    color: #d81b60;
}

.toc-toggle svg {
    display: block;
}

.toc-list {
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom scrollbar for TOC */
.toc-list::-webkit-scrollbar {
    width: 4px;
}

.toc-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 2px;
}

.toc-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.toc-list::-webkit-scrollbar-thumb:hover {
    background: #d81b60;
}

.post-content-wrapper ul.toc-items {
    list-style: none;
    padding: 0;
    margin: 0;
}

.post-content-wrapper ul.toc-nested {
    padding-left: .8rem;
    margin-top: 0.5rem;
}

.post-content-wrapper li.toc-item {
    margin-bottom: 0.5rem;
	margin-right: 0.5rem;
}

.toc-link {
    display: block;
    padding: 0.4rem 0.6rem;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
}

.toc-link:hover {
    background-color: rgba(233, 30, 99, 0.1);
    color: var(--accent-color);
}

.post-content-wrapper li a.toc-link.active {
    background-color: var(--accent-color);
    color: #fff;
    font-weight: 500;
}

.post-content-wrapper li a.toc-link.active:hover {
    background-color: #d81b60;
}

/* Different levels styling */
.toc-level-2 .toc-link {
    font-weight: 500;
	color: var(--primary-color);
	text-decoration: none;
	transition: none;
}

.toc-level-3 .toc-link {
    font-size: 0.85rem;
	color: var(--primary-color);
	text-decoration: none;
}

.toc-level-4 .toc-link {
    font-size: 0.8rem;
    color: #666;
}

/* Mobile TOC Toggle Button */
.mobile-toc-toggle {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 1000;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.mobile-toc-toggle:hover {
    background: #d81b60;
    transform: scale(1.05);
}

.mobile-toc-toggle svg {
    display: block;
    margin: auto;
}

/* Icon switching */
.mobile-toc-toggle .toc-icon-close {
    display: none;
}

.mobile-toc-toggle.active .toc-icon-open {
    display: none;
}

.mobile-toc-toggle.active .toc-icon-close {
    display: block;
}

/* Back to Top Button */
.back-to-top {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
}

.back-to-top.visible {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    pointer-events: auto;
}

.back-to-top:hover {
    background: #0d1b3e;
    transform: scale(1.05);
}

.back-to-top svg {
    display: block;
    margin: auto;
}



/* Tablet and below - TOC moves to bottom */
@media (max-width: 1024px) {
    .post-content-wrapper {
        flex-direction: column;
    }

    .toc-container {
        order: 1; /* TOC 移到上方 */
        width: 100%;
        margin: 0 0 2rem 0;
        position: relative;
        top: auto;
        max-height: none;
    }

    .toc-toggle {
        display: block;
    }

    .toc-title {
        font-size: 1.1rem;
    }

    /* Collapsed state */
    .toc-container.toc-collapsed .toc-list {
        display: none;
    }

    .toc-container.toc-collapsed .toc-toggle svg {
        transform: rotate(-90deg);
    }

    .toc-list {
        max-height: 400px;
    }
}

/* Mobile styles */
@media (max-width: 768px) {
    /* 顯示手機版 toggle 按鈕 */
    .mobile-toc-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 隱藏桌面版 TOC toggle */
    .toc-toggle {
        display: none;
    }

    /* 顯示關閉按鈕 */
    .toc-close {
        display: block;
    }

    /* TOC 預設隱藏 */
    .toc-container {
        display: none;
        position: fixed;
        bottom: 140px;
        right: 20px;
        width: 90%;
        max-width: 400px;
        max-height: 77vh;
        margin: 0;
        padding: 1.5rem;
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
        z-index: 999;
        overflow-y: hidden;
    }

    /* TOC 顯示狀態 */
    .toc-container.toc-visible {
        display: block;
    }

    /* 背景遮罩 */
    .toc-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
    }

    .toc-overlay.active {
        display: block;
    }

    .toc-header {
        margin-bottom: 1.5rem;
    }

    .toc-list {
        max-height: calc(100vh - 100px);
    }

    .toc-link {
        font-size: 0.9rem;
        padding: 0.4rem 0.5rem;
    }

    .toc-nested {
        padding-left: 1rem;
    }
}
