/* ==============================
   General Page Layout
   ============================== */
html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #fdfcf0;
    color: #4a4a4a;
    font-size: 0.95rem;
    line-height: 1.5;
}

:root {
    --brand-purple: #8a3a8a;
    --dark-purple: #6a2a6a;
    --border-tan: #e0dbc5;
    --bg-parchment: #fdfcf0;
    --viewer-dark: #333333; /* Dark background for PDF area */
}

/* ==============================
   Headings & Links
   ============================== */
h1, h2, h3 {
    margin: 0;
    color: var(--dark-purple);
    font-weight: 600;
}

a {
    color: var(--brand-purple);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--dark-purple);
    text-decoration: underline;
}

/* ==============================
   Structure
   ============================== */
.container {
    display: flex;
    min-height: 100vh;
}

.toc {
    flex: 0 0 320px;
    background-color: var(--bg-parchment);
    border-right: 1px solid var(--border-tan);
    padding: 40px 30px;
    box-sizing: border-box;
    overflow-y: auto;
}

.toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc li { margin-bottom: 12px; }

.viewer-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: var(--bg-parchment);
}

.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-tan);
}

/* ==============================
   Controls & Search
   ============================== */
.viewer-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

#trigger-search {
    background-color: var(--bg-parchment);
    color: var(--brand-purple);
    border: 1px solid var(--border-tan);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

#trigger-search:hover {
    background-color: var(--brand-purple);
    color: #fff;
}

.language-switch button.active { font-weight: bold; }

/* ==============================
   Calendar (Left Aligned)
   ============================== */
.calendar-wrapper {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    margin: 25px 0;
}

.calendar-wrapper iframe {
    max-width: 450px;
    width: 100%;
    border: 1px solid var(--border-tan);
    border-radius: 8px;
}

/* ==============================
   The Dark PDF Viewer
   ============================== */
iframe#pdf-viewer {
    display: none;
    flex: 1;
    width: 100%;
    border: none;
    background-color: var(--viewer-dark); /* Dark Mode Background */
}

/* ==============================
   Mobile Responsiveness (Fixed Order & Sizing)
   ============================== */
@media (max-width: 768px) {
    .container {
        display: flex;
        flex-direction: column-reverse; /* Put TOC at the bottom, Viewer Body at top */
        height: auto;
    }

    .toc {
        width: 100%;
        max-height: 300px; /* Limit height so it doesn't push the viewer away */
        overflow-y: auto;
        padding: 20px;
        border-right: none;
        border-top: 2px solid var(--border-tan); /* Border moves to top */
        background-color: #fffdf5;
    }

    .viewer-body {
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    .viewer-header {
        display: flex;
        flex-direction: column; /* Stack Title and Buttons */
        align-items: flex-start;
        padding: 15px;
        gap: 15px;
    }

    .viewer-header h2 {
        font-size: 1.1rem;
        white-space: normal; /* Wrap long titles */
        line-height: 1.3;
    }

    .viewer-controls {
        width: 100%;
        display: flex;
        justify-content: space-between; /* Spread buttons out */
        align-items: center;
        gap: 5px;
    }

    /* CALENDAR FIX */
    .calendar-wrapper {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden; /* Prevent horizontal scroll */
        display: block;
    }

    .calendar-wrapper iframe {
        width: 100% !important; /* Force it to fit phone width */
        max-width: 450px;
        height: 400px;
    }

    iframe#pdf-viewer {
        height: 70vh; /* Viewport height */
    }
}