/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1a472a;
    --secondary-color: #2c5f2d;
    --accent-color: #c9a961;
    --text-color: #333;
    --light-bg: #f5f5f5;
    --white: #ffffff;
    --header-height: 80px;
    --footer-height: 60px;
}

body {
    font-family: 'Prompt', 'Sarabun', 'Tahoma', sans-serif;
    color: var(--text-color);
    background: var(--white);
    line-height: 1.8;
    margin: 0;
    padding: 0;
    font-weight: 400;
}

/* Sidebar Menu Styles */
.sidebar-menu {
    position: fixed;
    left: 0;
    top: 0;
    width: 260px;
    height: 100vh;
    background: linear-gradient(180deg, var(--primary-color) 0%, #0d2415 100%);
    color: var(--white);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 15px rgba(0,0,0,0.3);
    transition: transform 0.3s ease;
}

.sidebar-menu.hidden {
    transform: translateX(-260px);
}

.menu-header {
    padding: 25px 20px;
    border-bottom: 2px solid var(--accent-color);
    background: rgba(0,0,0,0.2);
}

.menu-header h3 {
    margin: 0;
    font-size: 22px;
    color: var(--accent-color);
    letter-spacing: 1px;
}

.menu-items {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    color: var(--white);
    text-decoration: none;
    transition: all 0.3s;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.menu-item:hover {
    background: rgba(255,255,255,0.1);
    border-left-color: var(--accent-color);
}

.menu-item.active {
    background: rgba(201,169,97,0.2);
    border-left-color: var(--accent-color);
}

.menu-item .icon {
    font-size: 20px;
    margin-right: 12px;
    min-width: 24px;
}

.menu-item .label {
    font-size: 15px;
}

.menu-actions {
    padding: 15px;
    border-top: 1px solid rgba(255,255,255,0.2);
}

.menu-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 15px;
    margin-bottom: 10px;
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    font-family: 'Prompt', sans-serif;
    font-weight: 400;
}

.menu-button:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.menu-button.primary {
    background: var(--accent-color);
    color: var(--primary-color);
    border-color: var(--accent-color);
    font-weight: 600;
}

.menu-button.primary:hover {
    background: #d4b76e;
    box-shadow: 0 4px 12px rgba(201,169,97,0.4);
}

.menu-button .icon {
    margin-right: 8px;
}

.menu-footer {
    padding: 15px 20px;
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.2);
}

.menu-footer small {
    color: var(--accent-color);
    font-size: 13px;
}

/* Content Wrapper */
.content-wrapper {
    margin-left: 260px;
    padding: 2rem 1rem;
    transition: margin-left 0.3s ease;
    background: #f5f5f5;
    min-height: 100vh;
}

.content-wrapper.menu-hidden {
    margin-left: 0;
}

/* Toggle Button (when menu is hidden) */
.menu-toggle-fab {
    position: fixed;
    left: 20px;
    top: 20px;
    width: 50px;
    height: 50px;
    background: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 1999;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.3s;
}

.menu-toggle-fab:hover {
    background: var(--secondary-color);
    transform: scale(1.1);
}

.menu-toggle-fab.visible {
    display: flex;
}

/* Page Structure */
.page {
    position: relative;
    width: 8.5in;
    min-height: 11in;
    margin: 0 auto 2rem auto;
    background: var(--white);
    page-break-after: always;
    padding-top: var(--header-height);
    padding-bottom: var(--footer-height);
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Fixed Header */
.fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--primary-color);
    color: var(--white);
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 8.5in;
    margin: 0 auto;
    padding: 20px 40px;
    height: 100%;
}

.logo h1 {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--accent-color);
}

.header-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 14px;
}

.issue-number {
    margin-top: 5px;
    color: var(--accent-color);
}

/* Fixed Footer */
.fixed-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background: var(--primary-color);
    color: var(--white);
    z-index: 1000;
    border-top: 3px solid var(--accent-color);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 8.5in;
    margin: 0 auto;
    padding: 15px 40px;
    height: 100%;
    font-size: 12px;
}

.footer-center {
    text-align: center;
}

.footer-right {
    text-align: right;
}

/* Cover Page Styles */
.cover-page {
    background: linear-gradient(to bottom, var(--white) 0%, var(--light-bg) 100%);
}

.cover-content {
    padding: 40px;
    max-width: 100%;
}

.hero-section {
    margin-bottom: 40px;
}

.featured-image {
    width: 100%;
    height: 400px;
    overflow: hidden;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    margin-bottom: 30px;
}

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

.cover-headline {
    text-align: center;
    padding: 20px;
}

.cover-headline h2 {
    font-size: 42px;
    color: var(--primary-color);
    margin-bottom: 15px;
    line-height: 1.4;
    font-weight: 600;
}

.cover-subheadline {
    font-size: 20px;
    color: var(--secondary-color);
    font-style: normal;
    font-weight: 400;
}

.cover-stories {
    background: var(--white);
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.cover-stories h3 {
    color: var(--primary-color);
    font-size: 24px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 10px;
    font-weight: 600;
}

.cover-stories ul {
    list-style: none;
}

.cover-stories li {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    font-size: 16px;
}

.cover-stories li:before {
    content: "▸ ";
    color: var(--accent-color);
    font-weight: bold;
    margin-right: 10px;
}

.cover-highlights {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.highlight-card {
    background: var(--white);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s;
}

.highlight-card:hover {
    transform: translateY(-5px);
}

.highlight-card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.highlight-card h4 {
    padding: 15px 15px 5px;
    color: var(--primary-color);
    font-size: 16px;
    font-weight: 600;
}

.highlight-card p {
    padding: 0 15px 15px;
    font-size: 13px;
    color: #666;
}

/* Letter Page Styles */
.letter-page {
    background: var(--white);
}

.letter-content {
    padding: 40px 60px;
    max-width: 100%;
}

.letterhead {
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 3px solid var(--accent-color);
}

.company-info h2 {
    color: var(--primary-color);
    font-size: 24px;
    margin-bottom: 10px;
    font-weight: 600;
}

.company-info p {
    color: #666;
    font-size: 14px;
}

.letter-meta {
    margin-top: 20px;
}

.letter-date-full {
    font-size: 14px;
    color: #666;
}

.letter-body {
    font-size: 15px;
    line-height: 1.8;
}

.letter-body h3 {
    color: var(--primary-color);
    font-size: 20px;
    margin: 30px 0 15px;
    font-weight: 600;
}

.letter-body h4 {
    color: var(--secondary-color);
    font-size: 17px;
    margin: 25px 0 12px;
    font-weight: 500;
}

.letter-body p {
    margin-bottom: 15px;
    text-align: justify;
}

.letter-body ul, .letter-body ol {
    margin: 15px 0 15px 30px;
}

.letter-body li {
    margin-bottom: 8px;
}

.greeting {
    margin-bottom: 20px;
    font-style: italic;
}

.closing {
    margin-top: 40px;
}

.signature {
    margin-top: 50px;
}

.signature-name {
    font-weight: bold;
    color: var(--primary-color);
}

.signature-title {
    font-style: italic;
    color: #666;
    font-size: 14px;
}

/* Data Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 14px;
}

.data-table th {
    background: var(--primary-color);
    color: var(--white);
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #ddd;
}

.data-table tr:nth-child(even) {
    background: var(--light-bg);
}

.data-table tr:hover {
    background: #e8f5e9;
}

/* PDF Container */
.pdf-page {
    background: var(--white);
}

.pdf-canvas-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.pdf-canvas-container canvas {
    max-width: 100%;
    height: auto;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* PDF Advertisement Pages (Full Page) */
.pdf-ad-page {
    background: var(--white);
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pdf-ad-canvas-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.pdf-ad-canvas-container canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* PDF Error Display */
.pdf-error {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff3e0;
}

.pdf-error .error-message {
    text-align: center;
    padding: 3rem;
    color: #e65100;
}

.pdf-error .error-message h3 {
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.pdf-error .error-message p {
    font-size: 0.9rem;
    color: #666;
    word-break: break-all;
}

/* Print Styles */
@media print {
    body {
        background: white;
        margin: 0;
        padding: 0;
    }

    .sidebar-menu,
    .menu-toggle-fab {
        display: none !important;
    }

    .content-wrapper {
        margin-left: 0 !important;
        padding: 0 !important;
        background: white !important;
    }

    .page {
        width: 100%;
        height: 100vh;
        min-height: 11in;
        margin: 0;
        padding: 0;
        page-break-after: always;
        page-break-inside: avoid;
        position: relative;
        display: flex;
        flex-direction: column;
        border: none !important;
        box-shadow: none !important;
    }

    .page:last-child {
        page-break-after: auto;
    }

    /* Headers - fixed at top of each page */
    .fixed-header {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: var(--header-height);
        background: white;
        z-index: 100;
    }

    /* Footers - fixed at bottom of each page */
    .fixed-footer {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--footer-height);
        background: white;
        z-index: 100;
    }

    /* Main content area with proper spacing */
    .cover-content,
    .letter-content {
        margin-top: var(--header-height);
        margin-bottom: var(--footer-height);
        padding: 2rem;
        flex: 1;
        overflow: visible;
    }

    /* Prevent breaking inside important elements */
    .highlight-card,
    .story-item,
    .letter-body h3,
    .letter-body h4 {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .letter-body h3,
    .letter-body h4 {
        page-break-after: avoid;
        break-after: avoid;
    }

    .letter-body p,
    .letter-body ul,
    .letter-body ol {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Cover page specific */
    .cover-page .cover-content {
        padding: 2rem 3rem;
    }

    .featured-image img {
        max-width: 100%;
        height: auto;
        page-break-inside: avoid;
    }

    /* Hide interactive elements in print */
    button,
    .menu-toggle-btn {
        display: none !important;
    }

    /* PDF Advertisement pages - full page display */
    .pdf-ad-page {
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }

    .pdf-ad-canvas-container {
        padding: 0 !important;
    }

    .pdf-ad-canvas-container canvas {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
    }

    @page {
        size: letter portrait;
        margin: 0;
    }

    /* Ensure proper page dimensions */
    @page :first {
        margin: 0;
    }
}

/* Screen-only Styles */
@media screen {
    body {
        padding: 20px 0;
        background: #e0e0e0;
    }

    .content-wrapper {
        padding-right: 20px;
    }

    .page {
        margin: 20px auto;
        box-shadow: 0 0 20px rgba(0,0,0,0.3);
    }

    .fixed-header,
    .fixed-footer {
        position: absolute;
    }

    .page .fixed-header {
        position: absolute;
        top: 0;
    }

    .page .fixed-footer {
        position: absolute;
        bottom: 0;
    }
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.bold {
    font-weight: bold;
}

.italic {
    font-style: italic;
}

.accent-text {
    color: var(--accent-color);
}

.highlight-box {
    background: var(--light-bg);
    padding: 20px;
    border-left: 4px solid var(--accent-color);
    margin: 20px 0;
}

/* Error Banner Styles */
.error-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f44336;
    color: white;
    z-index: 3000;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.error-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 15px;
}

.error-icon {
    font-size: 24px;
}

.error-text {
    flex: 1;
    font-size: 14px;
}

.error-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
}

.error-close:hover {
    background: rgba(255,255,255,0.2);
}

/* Mobile Responsiveness */
@media screen and (max-width: 1024px) {
    .sidebar-menu {
        width: 220px;
    }
    
    .content-wrapper {
        margin-left: 220px;
    }
    
    .page {
        width: 100%;
        max-width: 8.5in;
    }
}

@media screen and (max-width: 768px) {
    .sidebar-menu {
        transform: translateX(-260px);
    }
    
    .sidebar-menu.visible {
        transform: translateX(0);
    }
    
    .content-wrapper {
        margin-left: 0;
        padding: 1rem 0.5rem;
    }
    
    .menu-toggle-fab {
        display: flex;
    }
    
    .page {
        width: 100%;
        margin: 10px auto;
    }
    
    .header-content,
    .footer-content {
        padding: 15px 20px;
    }
    
    .logo h1 {
        font-size: 20px;
    }
    
    .header-info {
        font-size: 12px;
    }
    
    .cover-content {
        padding: 20px;
    }
    
    .cover-headline h2 {
        font-size: 28px;
    }
    
    .cover-subheadline {
        font-size: 16px;
    }
    
    .cover-highlights {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .letter-content {
        padding: 30px 30px;
    }
    
    .menu-items {
        padding: 5px 0;
    }
    
    .menu-item {
        padding: 12px 15px;
    }
    
    .menu-item .icon {
        font-size: 18px;
    }
    
    .menu-item .label {
        font-size: 14px;
    }
}

@media screen and (max-width: 480px) {
    .content-wrapper {
        padding: 0.5rem 0;
    }
    
    .page {
        margin: 5px auto;
    }
    
    .cover-content {
        padding: 15px;
    }
    
    .cover-headline h2 {
        font-size: 22px;
    }
    
    .letter-content {
        padding: 20px 20px;
    }
    
    .data-table {
        font-size: 12px;
    }
    
    .data-table th,
    .data-table td {
        padding: 8px 6px;
    }
}
