/* ========================================
   Sub Page Styles - Modern Edition
   Matching the new client design
   ======================================== */

/* CSS Variables (inherits from style.css when available) */
:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --theme-color-alpha: rgba(99, 102, 241, 0.1);
    
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}

body {
    background: var(--bg-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    color: var(--text-primary);
    line-height: 1.6;
    max-width: 800px;
    margin: 0 auto;
    min-height: 100vh;
    overflow-x: hidden;
}

/* 移动端铺满屏幕并居中 */
@media (max-width: 768px) {
    body {
        max-width: 100%;
        margin: 0 auto;
    }
}

/* ========================================
   文字子页面文章标题（背景色和文字色由后台配置，JS 内联覆盖）
   ======================================== */
.sub-article-title-header {
    min-height: 44px;
    height: auto;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: #ffffff;
    padding: 12px 16px;
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md, 12px);
    margin: 12px 12px 0;
    overflow-wrap: break-word;
    word-break: break-word;
    overflow: hidden;
}

.sub-article-title-text {
    margin: 0;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* ========================================
   Fixed Content Containers (above/below title and periods)
   ======================================== */
.fixed-title-above {
    /* Outside main content, needs margin */
    margin: 0 12px 16px 12px;
}

.fixed-above-periods {
    /* Inside sub-page-content which has padding, no extra margin */
    margin-bottom: 16px;
}

.fixed-below-periods {
    /* Inside sub-page-content which has padding, no extra margin */
    margin-top: 16px;
}

/* Feature page content area already has padding */
.feature-page-content .fixed-title-above {
    margin: 0 0 16px 0;
}

/* ========================================
   Page Header (same width as periods list)
   ======================================== */
.sub-page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    /* Background is set by JS inline style */
    margin: 0 12px 0 12px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--primary-color);
    color: #fff;
    text-decoration: none;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 600;
    transition: var(--transition-normal);
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}

.back-btn:hover {
    background: var(--primary-dark);
    transform: translateX(-4px);
    box-shadow: var(--shadow-md);
}

.sub-page-title {
    flex: 1;
    font-size: 1.25rem;
    color: var(--text-primary);
    margin: 0;
    font-weight: 700;
    text-align: center;
}

/* ========================================
   Content Area
   ======================================== */
.sub-page-content {
    padding: 0 12px 12px;
    min-height: 50vh;
}

/* ========================================
   Periods List - small consistent gap (same as backend)
   ======================================== */
.periods-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ========================================
   Period Card
   ======================================== */
.period-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    transition: var(--transition-normal);
}

.period-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.period-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: #fff;
    position: relative;
    overflow: hidden;
}

.period-card-header::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1));
}

.period-number {
    font-size: 1rem;
    font-weight: 700;
    position: relative;
    z-index: 1;
}

.period-date {
    font-size: 0.85rem;
    opacity: 0.9;
    position: relative;
    z-index: 1;
}

.period-card-body {
    padding: 20px;
}

/* Period Title - 期数标题条，支持字体放大不溢出 */
.period-title {
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    overflow: hidden;
}

/* Period Item: background wraps content tightly, content full width of block */
.period-item {
    padding: 8px 12px;
    border-radius: var(--radius-md, 8px);
    transition: var(--transition-normal);
    box-sizing: border-box;
    min-width: 0;
    overflow: hidden;
}

.period-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.period-item-row {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.period-item .period-content {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-wrap: break-word;
    word-break: break-word;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Alignment classes */
.period-content.align-left {
    text-align: left !important;
}

.period-content.align-center {
    text-align: center !important;
}

.period-content.align-right {
    text-align: right !important;
}

.period-content.align-center-left {
    text-align: left !important;
}

/* Single image display */
.period-image-single {
    width: 100%;
    margin-bottom: 12px;
}

.period-image-single img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius-md, 8px);
}

.period-content {
    line-height: 1.9;
    width: 100%;
    min-width: 0;
    text-align: center;
    overflow-wrap: break-word;
    word-break: break-word;
    /* Don't override color - preserve CKEditor content colors */
}

.period-content p {
    margin: 0;
}

.period-content img {
    max-width: 100%;
    height: auto;
    margin: 12px 0;
}

/* Ensure tables fill full width and preserve inline styles */
.period-content table,
.period-content .table,
.period-content figure.table,
.period-content figure.table > table {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse !important;
}

.period-content figure {
    margin: 0 !important;
    width: 100% !important;
}

/* Default table borders for all tables */
.period-content table,
.period-content figure.table > table {
    border-collapse: collapse !important;
}

.period-content table td,
.period-content table th,
.period-content figure.table td,
.period-content figure.table th {
    /* Default gray border for visibility on dark backgrounds */
    border: solid 1px #555;
    padding: 5px 10px;
}

/* Fixed content areas */
.fixed-content-area table,
.fixed-content-area figure.table > table {
    width: 100% !important;
    border-collapse: collapse !important;
}

.fixed-content-area table td,
.fixed-content-area table th {
    border: solid 1px #555;
    padding: 5px 10px;
}

/* ========================================
   Image Gallery for Feature Pages
   ======================================== */
.period-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.period-image-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.period-image-item:hover {
    transform: scale(1.03);
    box-shadow: var(--shadow-md);
}

.period-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.period-image-item .image-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12px;
    opacity: 0;
    transition: var(--transition-normal);
}

.period-image-item:hover .image-overlay {
    opacity: 1;
}

.period-image-item .image-overlay i {
    color: #fff;
    font-size: 1.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* ========================================
   Image Viewer (Feature Page - same as backend)
   ======================================== */
.feature-page-content {
    padding: 0 12px 12px;
}

.scroll-image-viewer {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    border-radius: 15px;
    overflow: visible;
    position: relative;
    z-index: 10;
    margin-bottom: -15px;
}

.viewer-header {
    min-height: 45px;
    height: auto;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    text-align: center;
    padding: 12px 10px 8px 10px;
    font-size: 22px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 15px 15px 0 0;
    position: relative;
    z-index: 2;
    overflow-y: hidden;
}

.period-scroll-container {
    background: #e8e8e8;
    padding: 10px 15px 78px 15px;
    display: flex;
    align-items: center;
    overflow: visible;
    position: relative;
    margin-bottom: 0;
    z-index: 1;
}

.period-scroll-container::before,
.period-scroll-container::after {
    content: '';
    position: absolute;
    bottom: 0;
    width: 15px;
    height: 15px;
    background: inherit;
}

.period-scroll-container::before {
    left: 0;
    border-radius: 0 0 15px 0;
}

.period-scroll-container::after {
    right: 0;
    border-radius: 0 0 0 15px;
}

.period-scroll {
    display: flex;
    gap: 8px;
    width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    padding: 0 5px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.period-scroll::-webkit-scrollbar {
    display: none;
}

/* Period Button - for image viewer slider (feature page) */
.period-btn {
    flex-shrink: 0;
    width: 120px;
    height: 28px;
    padding: 0;
    margin: 0 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid #333;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: normal;
    font-size: 15px;
    white-space: nowrap;
    color: #333;
    letter-spacing: 3px;
}

.period-btn:hover {
    background: #f0f0f0;
}

.period-btn.active {
    color: #fff;
    width: 140px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 15px rgba(255, 255, 255, 0.5);
    border: 2px solid #fff;
    animation: borderGlow 1.5s ease-in-out infinite;
}

@keyframes borderGlow {
    0%, 100% {
        border-color: #fff;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 10px rgba(255, 255, 255, 0.5);
    }
    50% {
        border-color: #ffeb3b;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 235, 59, 0.8);
    }
}

.image-display-area {
    width: 100%;
    overflow: visible;
    position: relative;
    margin-top: -65px;
    z-index: 100;
    background: transparent;
    min-height: 200px;
}

.image-slider {
    position: relative;
    width: 100%;
    min-height: 200px;
}

/* Swiper container (left/right slide effect) */
.image-slider.swiper {
    overflow: hidden;
}

.image-slider .swiper-slide {
    width: 100%;
    min-height: 200px;
}

.image-slider .swiper-slide img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 15px;
    position: relative;
    z-index: 100;
}

.image-slider .swiper-slide .slide-empty,
.image-slider .swiper-slide .slide-error {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 200px;
    background: #f0f0f0;
    border-radius: 15px;
    color: #999;
    font-size: 14px;
}

/* Legacy fade-based slides (kept for any non-Swiper fallback) */
.image-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.image-slide.active {
    position: relative;
    opacity: 1;
    pointer-events: auto;
}

.image-slide img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 15px;
    position: relative;
    z-index: 100;
}

.image-slide .slide-empty,
.image-slide .slide-error {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 200px;
    background: #f0f0f0;
    border-radius: 15px;
    color: #999;
    font-size: 14px;
}

/* Content Display Area (same as backend) */
.content-display-area {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    min-height: 20px;
    padding: 78px 15px 15px 15px;
    background: #f8f9fa;
    border-radius: 0 0 15px 15px;
    position: relative;
    margin-top: -63px;
    z-index: 1;
    display: none;
}

.content-display-area.has-content {
    display: block;
}

.content-display-area .period-text-content {
    line-height: 1.8;
}

/* ========================================
   Fixed Content Area (same as backend preview)
   ======================================== */
/* Fixed Block - same as main page .fixed-content-card */
.fixed-block {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 10px 15px;
    margin-bottom: 8px;
}

/* Fixed Content Inner - inside card, full width */
.fixed-content-inner {
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 8px;
}

/* Legacy class for compatibility */
.fixed-content-area {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    border-left: 4px solid var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.fixed-content-area:empty {
    display: none;
}

.fixed-content-area.above {
    border-left-color: #10b981;
    background: linear-gradient(to right, rgba(16, 185, 129, 0.05), var(--bg-secondary));
}

.fixed-content-area.below {
    border-left-color: #f59e0b;
    background: linear-gradient(to right, rgba(245, 158, 11, 0.05), var(--bg-secondary));
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 1rem;
}

/* ========================================
   Image Modal
   ======================================== */
.image-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
}

.image-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(8px);
}

.image-modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.image-modal-close {
    position: absolute;
    top: -50px;
    right: 0;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 12px;
    border-radius: 50%;
    transition: var(--transition-fast);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.image-modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.25rem;
    padding: 16px;
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition-fast);
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.image-modal-nav.prev {
    left: -70px;
}

.image-modal-nav.next {
    right: -70px;
}

.image-modal-counter {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.8);
    font-size: 0.9rem;
    font-weight: 500;
}

/* ========================================
   News Scroll Animation (replaces deprecated marquee)
   ======================================== */
.news-scroll {
    overflow: hidden;
    white-space: nowrap;
    width: 100%;
}

.news-text {
    display: inline-block;
    padding-left: 100%;
    animation: news-scroll-animation 20s linear infinite;
}

.news-scroll:hover .news-text {
    animation-play-state: paused;
}

@keyframes news-scroll-animation {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(-100%);
    }
}

/* ========================================
   Loading States
   ======================================== */
.content-loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.content-loading i {
    font-size: 1.5rem;
    margin-bottom: 12px;
    display: block;
    color: var(--primary-color);
}

.content-loading.hidden {
    display: none;
}

/* ========================================
   Footer (if used on sub pages)
   ======================================== */
.footer {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: rgba(255,255,255,0.9);
    text-align: center;
    padding: 24px 20px;
    margin-top: 16px;
    font-size: 0.85rem;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    .sub-page-header {
        padding: 16px;
        gap: 12px;
    }
    
    .sub-page-title {
        font-size: 1.1rem;
        text-align: center;
    }
    
    .back-btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
    
    .period-images {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }

    .image-modal-nav.prev {
        left: 10px;
    }

    .image-modal-nav.next {
        right: 10px;
    }
}

@media (max-width: 480px) {
    .sub-page-header {
        flex-direction: column;
        align-items: center;
        gap: 12px;
        margin: 8px;
    }
    
    .sub-page-title {
        font-size: 1rem;
    }
    
    .sub-page-content {
        padding: 0 8px 8px;
    }
    
    .period-images {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .image-modal-nav.prev {
        left: 10px;
    }
    
    .image-modal-nav.next {
        right: 10px;
    }
    
    .period-card-header {
        padding: 12px 16px;
    }
    
    .period-card-body {
        padding: 16px;
    }
}

/* 子页面内容防溢出 - 字体放大时防止超出容器 */
.period-content,
.period-card-content,
.period-card-body,
.fixed-content-card,
.fixed-block,
.fixed-content-inner {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overflow-wrap: break-word;
    word-break: break-word;
}

.periods-section,
.periods-list {
    min-width: 0;
}

.period-content img,
.period-card-content img,
.period-card-body img {
    max-width: 100%;
    height: auto;
}

.period-content table,
.period-card-content table,
.period-card-body table {
    max-width: 100%;
}

/* 子页面间距优化 */
.periods-section {
    padding: 0 8px;
}

@media (min-width: 481px) {
    .periods-section {
        padding: 0 12px;
    }
}
