/*
 * Common CSS Template for CMS Sites
 * This file contains all shared styles across sites.
 * Site-specific colors and variations are defined via CSS custom properties.
 */

/* ===== CSS CUSTOM PROPERTIES (set by individual sites) ===== */
:root {
    /* Primary colors - to be overridden by each site */
    --color-primary: #1b277b;
    --color-primary-light: #2f6f9e;
    --color-secondary: #def1f3;
    --color-section-bg: #def1f3;

    /* Gradients */
    --gradient-primary: linear-gradient(90deg, #1b277b, #2f6f9e);
    --gradient-sidebar: linear-gradient(180deg, #1b277b 0%, #2f6f9e 100%);
    --gradient-button: linear-gradient(135deg, #1b277b, #2f6f9e);
    --gradient-welcome: linear-gradient(135deg, #def1f3 0%, #e8f4f8 100%);

    /* Tooltip background (should match primary color with opacity) */
    --color-tooltip-bg: rgba(27, 39, 123, 0.95);

    /* Optional adjustments */
    --section-image-margin-right: 20px;
    --h3-font-size: 20px;
}

/* ===== BASE STYLES ===== */
body {
    padding: 0;
    margin: 0;
    font-family: Roboto, Arial, Helvetica, sans-serif;
    overflow-x: hidden;
}

h2 {
    font-size: 24px;
    font-family: 'Roboto Slab', 'Times New Roman', Times, serif;
}

h3 {
    font-size: var(--h3-font-size);
    font-family: 'Roboto Slab', 'Times New Roman', Times, serif;
}

hr {
    border-top: 1px solid #d0d0d0;
    border-bottom: none;
}

table {
    background-color: #f6f6f1;
}

.emoji {
    font-size: 1.2em;
}

/* ===== HEADER ===== */
.header {
    background-color: var(--color-primary);
    color: white;
    padding: 8px 40px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.header .logo {
    width: 50px;
    height: auto;
    margin: 0;
}

.site-title {
    font-size: 28px;
    font-weight: bold;
    margin: 0;
    text-align: center;
}

.tagline {
    font-size: 14px;
    font-style: italic;
    margin: 0;
    text-align: center;
    opacity: 0.9;
}

/* ===== CONTENT AREA ===== */
.content {
    max-width: 1200px;
    margin: 0 auto;
    overflow-x: hidden;
}

/* ===== SECTIONS ===== */
.section {
    padding: 20px 40px;
    background-color: var(--color-section-bg);
    border-bottom: 1px solid #d0d0d0;
    margin: 10px 0;
    border-radius: 10px;
}

.section-title {
    font-family: 'Roboto Slab', 'Times New Roman', Times, serif;
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 10px;
}

.section-content {
    overflow: hidden;
}

.section-content summary {
    display: block;
    cursor: pointer;
}

.section-text {
    font-size: 18px;
    line-height: 24px;
    margin: 0;
}

.section-image {
    width: 480px;
    height: auto;
    max-width: 100%;
    float: left;
    margin: 0 var(--section-image-margin-right) 20px 0;
}

.section-image.portrait {
    width: auto;
    height: 480px;
}

.section-image:not([src$=".jpg"]) {
    display: none;
}

.section:nth-child(even) .section-image {
    float: right;
    margin: 0 0 20px 20px;
}

/* ===== WELCOME BANNER ===== */
.welcome-banner {
    background: var(--gradient-welcome);
    border: 2px solid var(--color-primary);
    padding: 16px 40px;
}

.welcome-banner .section-title {
    font-size: 20px;
    color: var(--color-primary);
    margin-bottom: 8px;
}

/* ===== ARTICLE REVEAL/TOGGLE ===== */
.article-reveal {
    margin: 10px 0 0;
}

.article-reveal > .details-body {
    display: block;
    margin-top: 10px;
    position: relative;
    transition: max-height 0.35s ease;
    max-height: 3.5em;
    overflow: visible;
    clip-path: inset(0);
    -webkit-mask-image: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.3) 25%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.3) 25%, transparent 100%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.article-toggle-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.article-toggle {
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--gradient-primary);
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.2px;
    box-shadow: 0 4px 10px rgba(18, 41, 78, 0.25);
    margin-bottom: 8px;
    user-select: none;
    cursor: pointer;
}

.article-toggle::before {
    content: "";
    width: 7px;
    height: 7px;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
}

.article-toggle-input:checked + .article-toggle::before {
    transform: rotate(-135deg);
}

.article-toggle-input:focus-visible + .article-toggle {
    outline: 2px solid var(--color-primary);
    outline-offset: 3px;
}

.toggle-open {
    display: none;
}

.article-toggle-input:checked ~ .article-toggle .toggle-open {
    display: inline;
}

.article-toggle-input:checked ~ .article-toggle .toggle-closed {
    display: none;
}

.article-toggle-input:checked ~ .details-body {
    max-height: none;
    clip-path: none;
    -webkit-mask-image: none;
    mask-image: none;
}

/* ===== RESOURCE LIST ===== */
.resource-list {
    list-style-type: none;
    padding-left: 0;
}

.resource-list li {
    margin-bottom: 10px;
    padding: 8px 0;
    border-bottom: 1px dashed #ecf0f1;
}

.resource-list a {
    color: #1a5276;
    text-decoration: none;
    font-weight: bold;
}

.resource-list a:hover {
    color: #1abc9c;
    text-decoration: underline;
}

/* ===== TOC NAVIGATION SYSTEM ===== */

/* TOC Toggle Button */
.toc-toggle {
    position: fixed;
    top: -9999px;
    left: -9999px;
    opacity: 0;
    pointer-events: none;
}

.toc-toggle-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1001;
    background: var(--gradient-button);
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    user-select: none;
    animation: toc-bounce 2s ease-in-out 0.5s;
}

.toc-toggle-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Tooltip that appears during initial bounce */
.toc-toggle-btn::after {
    content: "Table of Contents";
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 18px;
    background: var(--color-tooltip-bg);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    font-size: 13px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    animation: toc-tooltip-fade 2s ease-in-out 0.5s;
}

/* Arrow for tooltip - creates a triangle pointing left */
.toc-toggle-btn::before {
    content: "";
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 8px 6px 0;
    border-color: transparent rgba(255, 255, 255, 0.9) transparent transparent;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
    z-index: 1001;
    animation: toc-arrow-fade 2s ease-in-out 0.5s;
}

@keyframes toc-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    10%, 30%, 50% {
        transform: translateY(-8px);
    }
    20%, 40% {
        transform: translateY(0);
    }
    60% {
        transform: translateY(-4px);
    }
    70% {
        transform: translateY(0);
    }
}

@keyframes toc-tooltip-fade {
    0% {
        opacity: 0;
    }
    15%, 75% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes toc-arrow-fade {
    0% {
        opacity: 0;
    }
    15%, 75% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* TOC Overlay */
.toc-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 850;
    cursor: pointer;
}

.toc-toggle:checked ~ .toc-overlay {
    display: block;
}

/* TOC Sidebar */
.toc-sidebar {
    position: fixed;
    left: -200px;
    top: 0;
    width: 200px;
    height: 100vh;
    background: var(--gradient-sidebar);
    color: white;
    overflow-y: auto;
    z-index: 900;
    transition: left 0.3s ease, visibility 0s 0.3s;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.2);
    padding: 60px 16px 16px;
    visibility: hidden;
}

.toc-toggle:checked ~ .toc-sidebar {
    left: 0;
    visibility: visible;
    transition: left 0.3s ease;
}

.toc-title {
    font-size: 20px;
    font-weight: bold;
    margin: 0 0 12px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

/* Show All Articles button */
.toc-show-all {
    display: block;
    padding: 10px 12px;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-align: center;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.toc-show-all:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.02);
}

/* Disable Show All button when All filter is already active */
body:has(#filter-all:checked) .toc-show-all {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

.toc-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toc-link {
    display: block;
    padding: 10px 12px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-size: 15px;
}

.toc-link:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(4px);
}

.toc-link.toc-sub {
    padding-left: 24px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
}

.toc-category {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 16px;
    margin-bottom: 4px;
    padding-left: 12px;
    letter-spacing: 0.5px;
}

/* ===== FILTER BAR ===== */

/* Quick Filter Bar */
.filter-container {
    position: sticky;
    top: 0;
    z-index: 100;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.filter-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.quick-filter-bar {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 40px 12px 60px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    background: #e8e8e8;
    color: #333;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.filter-chip:hover {
    background: #d0d0d0;
    transform: translateY(-1px);
}

.chip-count {
    background: rgba(27, 39, 123, 0.12);
    color: var(--color-primary);
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

/* Active filter chip - generic pattern that works for any filter ID */
.filter-input:checked ~ .quick-filter-bar label {
    /* Default unchecked state */
    background: #e8e8e8;
    color: #333;
}

/* Specific checked state - matches each input to its label */
#filter-all:checked ~ .quick-filter-bar label[for="filter-all"],
#filter-missions:checked ~ .quick-filter-bar label[for="filter-missions"],
#filter-rockets:checked ~ .quick-filter-bar label[for="filter-rockets"],
#filter-spacecraft:checked ~ .quick-filter-bar label[for="filter-spacecraft"],
#filter-science:checked ~ .quick-filter-bar label[for="filter-science"],
#filter-recipes:checked ~ .quick-filter-bar label[for="filter-recipes"],
#filter-tips:checked ~ .quick-filter-bar label[for="filter-tips"],
#filter-chocolate:checked ~ .quick-filter-bar label[for="filter-chocolate"],
#filter-festive:checked ~ .quick-filter-bar label[for="filter-festive"],
#filter-kidfriendly:checked ~ .quick-filter-bar label[for="filter-kidfriendly"],
#filter-humanoids:checked ~ .quick-filter-bar label[for="filter-humanoids"],
#filter-industrial:checked ~ .quick-filter-bar label[for="filter-industrial"],
#filter-culture:checked ~ .quick-filter-bar label[for="filter-culture"],
#filter-reviews:checked ~ .quick-filter-bar label[for="filter-reviews"],
#filter-physics:checked ~ .quick-filter-bar label[for="filter-physics"],
#filter-astronomy:checked ~ .quick-filter-bar label[for="filter-astronomy"],
#filter-biology:checked ~ .quick-filter-bar label[for="filter-biology"],
#filter-earth:checked ~ .quick-filter-bar label[for="filter-earth"] {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(27, 39, 123, 0.3);
}

#filter-all:checked ~ .quick-filter-bar label[for="filter-all"] .chip-count,
#filter-missions:checked ~ .quick-filter-bar label[for="filter-missions"] .chip-count,
#filter-rockets:checked ~ .quick-filter-bar label[for="filter-rockets"] .chip-count,
#filter-spacecraft:checked ~ .quick-filter-bar label[for="filter-spacecraft"] .chip-count,
#filter-science:checked ~ .quick-filter-bar label[for="filter-science"] .chip-count,
#filter-recipes:checked ~ .quick-filter-bar label[for="filter-recipes"] .chip-count,
#filter-tips:checked ~ .quick-filter-bar label[for="filter-tips"] .chip-count,
#filter-chocolate:checked ~ .quick-filter-bar label[for="filter-chocolate"] .chip-count,
#filter-festive:checked ~ .quick-filter-bar label[for="filter-festive"] .chip-count,
#filter-kidfriendly:checked ~ .quick-filter-bar label[for="filter-kidfriendly"] .chip-count,
#filter-humanoids:checked ~ .quick-filter-bar label[for="filter-humanoids"] .chip-count,
#filter-industrial:checked ~ .quick-filter-bar label[for="filter-industrial"] .chip-count,
#filter-culture:checked ~ .quick-filter-bar label[for="filter-culture"] .chip-count,
#filter-reviews:checked ~ .quick-filter-bar label[for="filter-reviews"] .chip-count,
#filter-physics:checked ~ .quick-filter-bar label[for="filter-physics"] .chip-count,
#filter-astronomy:checked ~ .quick-filter-bar label[for="filter-astronomy"] .chip-count,
#filter-biology:checked ~ .quick-filter-bar label[for="filter-biology"] .chip-count,
#filter-earth:checked ~ .quick-filter-bar label[for="filter-earth"] .chip-count {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Filtering Logic - hides all sections when a specific filter is active */
.filter-container:has(.filter-input:not(#filter-all):checked) ~ .content .section {
    display: none;
}

/* Animation for appearing sections */
.filter-container:has(.filter-input:checked) ~ .content .section {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== SMOOTH SCROLL ===== */
html {
    scroll-behavior: smooth;
    scroll-padding-top: 70px;
}

/* ===== RESPONSIVE DESIGN ===== */

@media (max-width: 1024px) {
    .section-title {
        font-size: 24px;
    }
    h2 {
        font-size: 22px;
    }
    h3 {
        font-size: 18px;
    }
    .section-image {
        width: 320px;
        height: auto;
    }
    .section:nth-child(even) .section-image {
        width: 320px;
        height: auto;
    }
    .section-image.portrait {
        width: auto;
        height: 320px;
    }
    .section-text {
        font-size: 16px;
        line-height: 21px;
    }
    .section-text h2 {
        line-height: 24px;
    }
}

@media (max-width: 768px) {
    html {
        scroll-padding-top: 90px;
    }

    .header {
        padding: 6px 20px;
        gap: 10px;
    }

    .header .logo {
        width: 40px;
    }

    .site-title {
        font-size: 22px;
    }

    .tagline {
        font-size: 12px;
    }

    .section {
        padding: 20px 20px;
    }

    .section-title {
        font-size: 22px;
    }

    .section-image {
        width: 480px;
        height: auto;
        float: none;
        margin: 5px 0 20px 0;
    }

    .section:nth-child(even) .section-image {
        float: none;
        margin: 5px 0 20px 0;
    }

    .section-image.portrait {
        width: auto;
        height: 480px;
    }

    .section-text {
        font-size: 16px;
        line-height: 18px;
    }

    .section-text h2 {
        line-height: 24px;
    }

    /* TOC mobile adjustments */
    .toc-toggle-btn {
        top: 8px;
        left: 8px;
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Adjust tooltip for mobile - position below button, aligned to left */
    .toc-toggle-btn::after {
        left: 0;
        top: 100%;
        transform: none;
        margin-left: 0;
        margin-top: 20px;
        font-size: 12px;
    }

    .toc-toggle-btn::before {
        left: 20px;
        top: calc(100% + 4px);
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 0 8px 8px 8px;
        border-color: transparent transparent rgba(255, 255, 255, 0.9) transparent;
        transform: none;
        margin-left: 0;
        margin-top: 0;
    }

    .quick-filter-bar {
        padding: 10px 20px 10px 50px;
        gap: 6px;
    }

    /* Narrower TOC on mobile */
    .toc-sidebar {
        width: 200px;
        left: -200px;
    }

    .toc-title {
        font-size: 18px;
        margin-bottom: 10px;
        padding-bottom: 8px;
    }

    .toc-show-all {
        padding: 8px 10px;
        margin-bottom: 12px;
        font-size: 13px;
    }

    .toc-link {
        padding: 8px 10px;
        font-size: 14px;
    }

    .toc-link.toc-sub {
        padding-left: 20px;
        font-size: 13px;
    }

    .toc-category {
        font-size: 12px;
        margin-top: 12px;
        padding-left: 10px;
    }

    .filter-chip {
        padding: 6px 12px;
        font-size: 13px;
    }

    .chip-count {
        padding: 1px 6px;
        font-size: 11px;
    }

    .welcome-banner {
        padding: 12px 20px;
    }

    .welcome-banner .section-title {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .section-image.portrait {
        width: 320px;
        height: auto;
    }
}
