/* Colors & Typography variables */
:root {
    --bg-main: #171B17;
    --bg-card: #242B24;
    --bg-card-hover: #2e352e;
    --border-color: #323b32;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --color-primary: #cad400; /* Lime green */
    --color-primary-dark: #8a9100;
    --color-accent: #F5F2E9; /* Off-white/cream */
    --color-error: #ef4444;

    --font-body: 'Work Sans', system-ui, -apple-system, sans-serif;
    --font-heading: 'Work Sans', system-ui, -apple-system, sans-serif;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-body);
    overflow: hidden; /* Hide scrollbars for entrance screen */
    width: 100vw;
    height: 100vh;
}

/* Screen Wrapper */
.screen-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    padding: 1.5rem;
}

/* Header styling */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
    height: 10%;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 1.25rem; /* Beautiful spacing between brand icon and brand logo */
}

.brand-icon {
    height: 42px; /* Uniform height matching the brand logo */
    width: auto;
    display: block;
}

.brand-logo {
    height: 42px; /* Perfect height for highly readable entrance-screen branding */
    width: auto;
    display: block;
}

.header-datetime {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-clock {
    font-size: 1.4rem;
    font-weight: 600;
    font-family: monospace;
    color: var(--color-accent);
}

.header-clock::before {
    content: "•";
    margin-right: 1rem;
    color: var(--text-muted);
    font-family: var(--font-family);
}

.header-date {
    font-size: 1.4rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: capitalize;
}

/* Grid Layout */
.app-grid {
    display: grid;
    grid-template-columns: 4fr 3.5fr 4.5fr; /* SEM, Lib/News, Slideshow */
    gap: 1.5rem;
    height: 87%;
    min-height: 0; /* Allow grid items to shrink */
}

/* Grid Columns */
.grid-col {
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex/grid inner scroll */
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
}

.section-title {
    font-family: var(--font-heading);
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-left: 5px solid var(--color-primary);
    padding-left: 0.85rem;
}

.section-title .icon {
    font-size: 1.55rem;
}

/* Left Column: Smart Event Manager (SEM) Events */
.sem-column {
    background-color: transparent;
}

.events-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
    padding-right: 0.5rem;
    flex-grow: 1;
}

/* Hide standard scrollbars for a clean kiosk look */
.events-list::-webkit-scrollbar,
.news-list::-webkit-scrollbar {
    width: 6px;
}
.events-list::-webkit-scrollbar-thumb,
.news-list::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 8px;
}

/* Event Card */
.event-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.35rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    transition: transform 0.2s ease, background-color 0.2s ease;
    height: auto; /* Dynamic height adapted to content */
}

.event-card:hover {
    background-color: var(--bg-card-hover);
}

.event-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.event-time {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--color-accent);
    letter-spacing: 0.05em;
    white-space: nowrap;
    flex-shrink: 0;
}

.event-room {
    background-color: #cad400;
    color: #525b52;
    border: 1px solid #cad400;
    padding: 0.3rem 0.85rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.event-room-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
}

.room-direction,
.event-direction {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-primary);
    background-color: rgba(202, 212, 0, 0.15);
    padding: 0.25rem 0.6rem;
    border-radius: 8px;
    white-space: nowrap;
}

.dir-icon {
    width: 15px;
    height: 15px;
    display: inline-block;
    stroke: currentColor;
}

.event-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.35;
}

.event-relation {
    font-size: 1.1rem;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.event-relation::before {
    content: "👥";
    font-size: 1.05rem;
}

/* Middle Column: Library & News */
.middle-column {
    gap: 1.5rem;
}

/* Library Hours Box */
.lib-section {
    flex-shrink: 0;
}

.lib-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.lib-hours-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.hours-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
    border: 1px solid transparent;
}

/* Today active styling for library opening */
.hours-row.active-today {
    background-color: rgba(202, 212, 0, 0.1);
    border-color: rgba(202, 212, 0, 0.3);
}

.hours-row.active-today .day-name {
    color: var(--color-primary);
    font-weight: 600;
}

.day-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.hours-val {
    font-size: 0.9rem;
    color: var(--text-primary);
    text-align: right;
}

.hours-val small {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Library exceptions */
.lib-exceptions {
    border-top: 1px dashed var(--border-color);
    padding-top: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.exception-title {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.15rem;
}

.exception-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.exception-val.closed {
    color: var(--color-error);
    font-weight: 600;
}

/* News Section */
.news-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex-grow: 1;
}

.news-list {
    position: relative;
    flex-grow: 1;
    min-height: 200px; /* Secure enough vertical space for text */
}

.news-card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    opacity: 0;
    z-index: 1;
    transition: opacity 1s ease-in-out;
    pointer-events: none;
}

.news-card.active {
    opacity: 1;
    z-index: 2;
    pointer-events: auto;
}

.news-card-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
}

.news-card-body {
    width: 100%; /* Force full width to prevent nested flex column collapse */
    flex-grow: 1;
    overflow-y: hidden; /* Hide scrollbars; we scroll dynamically with JS */
    margin-bottom: 0.5rem;
}

.news-scroll-content {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%; /* Force full width */
}

.news-card-desc {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary); /* Highlight the lead description in lime green */
    line-height: 1.4;
    word-break: break-word;
    overflow-wrap: break-word;
    width: 100%; /* Force full width */
}

.news-card-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
    white-space: pre-wrap; /* Support multi-line strapi content beautifully */
    word-break: break-word;
    overflow-wrap: break-word;
    width: 100%; /* Force full width */
}

/* Stacked News Layout with Image underneath */
.news-body-stacked {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.news-image-row {
    width: 100%;
    height: 140px; /* Perfect horizontal landscape height */
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background-color: var(--bg-main);
}

.news-article-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 8px;
}

.news-card-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Right Column: Slideshow / Gallery Gallery */
.gallery-column {
    height: 100%;
}

.slideshow-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    border: none;
    background-color: var(--bg-main);
}

.slideshow-container {
    width: 100%;
    height: 100%;
    position: relative;
    background-color: var(--bg-main);
}

.slide-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: top center;
    background-color: var(--bg-main);
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
    z-index: 1;
}

.slide-img.active {
    opacity: 1;
    z-index: 2;
}

.slide-img.leaving {
    opacity: 0;
    z-index: 1; /* Keep underneath the new active slide during the crossfade */
}

/* Dynamic News QR Code & Footer styling */
.news-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto; /* Push the footer to the very bottom */
    padding-top: 0.6rem;
    border-top: 1px dashed var(--border-color);
    width: 100%;
}

.news-qr-container {
    background-color: #fff;
    padding: 0.25rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    width: 64px; /* Perfectly compact for a neat footer presentation */
    height: 64px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.news-qr-code {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Loading & Empty State States */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-style: italic;
    background-color: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    text-align: center;
}

.empty-state {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
    background-color: var(--bg-card);
    border-radius: 8px;
    border: 1px dashed var(--border-color);
    text-align: center;
    gap: 0.75rem;
}

.empty-state-icon {
    font-size: 2.5rem;
}

.empty-state-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

.empty-state-subtitle {
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Portrait Orientation / Vertical Screen Support */
@media (orientation: portrait) {
    body {
        overflow: hidden; /* Lock layout to exactly 100vh so slideshow is always 100% visible */
    }

    .screen-container {
        padding: 1.5rem;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .app-header {
        flex-shrink: 0;
        height: auto;
        padding-bottom: 1.25rem;
        margin-bottom: 1.5rem;
        flex-direction: column;
        gap: 1rem;
        align-items: center;
        text-align: center;
    }

    .header-logo {
        gap: 1.5rem;
    }

    .header-clock {
        font-size: 2rem;
    }

    .brand-icon {
        height: 60px;
        max-height: none;
    }

    .brand-logo {
        height: 60px;
        max-height: none;
        max-width: 100%;
    }

    .app-grid {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
        overflow: hidden;
        height: 100%;
    }

    /* Left Column: SEM Events ("Vandaag in de Essenburcht") - base styles, dynamically scaled by JS based on content */
    .sem-column {
        flex: 1 1 auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transition: flex-basis 0.35s ease;
    }

    .sem-column .section-title {
        flex-shrink: 0;
    }

    .events-list {
        flex: 1;
        min-height: 0;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr)); /* 2-column grid for balanced layout on portrait/4K displays */
        grid-auto-rows: auto;
        align-content: start; /* Prevent grid rows from artificially stretching and causing dead space in cards */
        gap: 1.25rem;
        overflow: hidden;
        padding-right: 0.25rem;
        scrollbar-width: none; /* Hide scrollbars for clean kiosk presentation */
        -ms-overflow-style: none;
    }

    .events-list::-webkit-scrollbar {
        display: none;
    }

    /* Side-by-side layout for bieb and news in portrait - dynamically scaled by JS based on content */
    .middle-column {
        flex: 0 0 auto;
        min-height: 0;
        display: grid;
        grid-template-columns: 1fr 1.2fr;
        gap: 1.5rem;
        overflow: hidden;
        transition: flex-basis 0.35s ease;
    }

    .middle-column .lib-section {
        display: flex;
        flex-direction: column;
        min-height: 0;
        height: 100%;
    }

    .middle-column .lib-card {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        gap: 0.75rem;
    }

    .middle-column .lib-hours-list {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        gap: 0.45rem;
        flex: none;
    }

    .middle-column .lib-exceptions {
        margin-top: 0.25rem;
    }

    .middle-column .news-section {
        display: flex;
        flex-direction: column;
        min-height: 0;
        height: 100%;
    }

    .middle-column .news-list {
        position: relative;
        flex: 1;
        min-height: 0;
        height: 100%;
    }

    /* Slideshow expands dynamically to occupy remaining screen space */
    .gallery-column {
        flex: 1 1 0px;
        min-height: 25vh;
        height: auto;
    }
}

/* Extra support for extremely small vertical displays or extreme heights */
@media (orientation: portrait) and (max-width: 640px) {
    .events-list {
        grid-template-columns: 1fr; /* Single column on narrow phone screens */
    }

    .middle-column {
        grid-template-columns: 1fr; /* Collapse bieb and news fully to 1 col on narrow screens */
    }
}

/* Large-Screen (4K / 1440p) scaling optimization */
@media (min-width: 2000px), (min-height: 2500px) {
    html {
        font-size: 30px; /* Scale up rem-based typography and layout padding proportionally on giant 4K displays */
    }

    .screen-container {
        padding: 3rem;
    }

    .app-header {
        margin-bottom: 3rem;
        padding-bottom: 2rem;
        gap: 1.5rem;
    }

    .header-clock {
        font-size: 3rem;
    }

    .header-date {
        font-size: 2.6rem;
    }

    .brand-icon {
        height: 100px;
        max-height: none;
    }

    .brand-logo {
        height: 100px;
        max-height: none;
    }

    .events-list {
        gap: 2rem;
    }

    .event-card {
        padding: 1.75rem 2rem;
        gap: 1rem;
    }
}

/* Targeted optimization for 1580x2810 portrait resolution */
@media (orientation: portrait) and (max-width: 1800px) and (min-height: 2500px) {
    html {
        font-size: 24px; /* Proportional scaling for ~1580px width compared to 30px on 2160px 4K */
    }

    .screen-container {
        padding: 2rem;
    }

    .app-header {
        margin-bottom: 2rem;
        padding-bottom: 1.5rem;
        gap: 1.25rem;
    }

    .brand-icon, .brand-logo {
        height: 75px;
    }

    .header-clock {
        font-size: 2.5rem;
    }

    .header-date {
        font-size: 2.1rem;
    }

    .events-list {
        gap: 1.25rem;
        align-content: start;
        grid-auto-rows: auto;
    }

    .event-card {
        padding: 1.25rem 1.5rem;
        gap: 0.65rem;
        height: auto;
    }
}

/* Night Mode / Blackout Overlay */
.blackout-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000000;
    z-index: 999999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.5s ease-in-out;
}

.blackout-overlay.active {
    opacity: 1;
    pointer-events: all;
    cursor: none;
}
