/* ==========================================================================
   Boekweit Weerstation - een stylesheet, thema via design tokens.

   Het thema wordt gezet met data-theme op <html>:
     data-theme="light"  -> altijd licht
     data-theme="dark"   -> altijd donker
     geen attribuut      -> volgt prefers-color-scheme (stand "automatisch")
   ========================================================================== */

/* --- Tokens: licht ------------------------------------------------------- */
:root {
    color-scheme: light;

    --bg:              #eef2f7;
    --bg-accent:       #dce8f7;
    --surface:         #ffffff;
    --surface-hover:   rgba(15, 33, 55, 0.05);
    --border:          #d7dfea;
    --border-strong:   #bcc8d8;

    --text:            #16202b;
    --text-muted:      #4d5f73;
    --text-subtle:     #5c6b7d;
    --accent:          #1668d6;
    --accent-graphic:  #1e83ef;
    --warning:         #8a5c00;
    --warning-border:  #d4a017;
    --warning-surface: #fdf7e6;

    --header-bg:       rgba(255, 255, 255, 0.78);
    --overlay:         rgba(12, 20, 30, 0.55);
    --shadow-sm:       0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow:          0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 16px rgba(16, 24, 40, 0.07);
    --shadow-lg:       0 12px 40px rgba(16, 24, 40, 0.22);

    /* Typografie */
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --fs-xs:    0.75rem;
    --fs-sm:    0.8125rem;
    --fs-base:  1rem;
    --fs-lg:    1.125rem;
    --fs-title: clamp(1.0625rem, 0.8rem + 1.1vw, 1.4rem);
    --fs-value: clamp(1.375rem, 1.05rem + 1.5vw, 1.9rem);

    /* Ruimte en vorm */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --radius-sm: 8px;
    --radius:    14px;
    --radius-lg: 20px;
    --content:   1240px;
}

/* --- Tokens: donker ----------------------------------------------------- */
/* Twee blokken met dezelfde waarden: het media-blok dekt de stand
   "automatisch" (geen data-theme), het attribuut-blok de expliciete keuze. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg:              #0d1117;
        --bg-accent:       #121b26;
        --surface:         #171d26;
        --surface-hover:   rgba(255, 255, 255, 0.07);
        --border:          #262f3b;
        --border-strong:   #384252;

        --text:            #e6edf3;
        --text-muted:      #a4b1c0;
        --text-subtle:     #8593a3;
        --accent:          #6cb0ff;
        --accent-graphic:  #58a6ff;
        --warning:         #e3b341;
        --warning-border:  #8a6d1f;
        --warning-surface: #1e1a10;

        --header-bg:       rgba(13, 17, 23, 0.82);
        --overlay:         rgba(0, 0, 0, 0.68);
        --shadow-sm:       0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow:          0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 16px rgba(0, 0, 0, 0.35);
        --shadow-lg:       0 12px 40px rgba(0, 0, 0, 0.6);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg:              #0d1117;
    --bg-accent:       #121b26;
    --surface:         #171d26;
    --surface-hover:   rgba(255, 255, 255, 0.07);
    --border:          #262f3b;
    --border-strong:   #384252;

    --text:            #e6edf3;
    --text-muted:      #a4b1c0;
    --text-subtle:     #8593a3;
    --accent:          #6cb0ff;
    --accent-graphic:  #58a6ff;
    --warning:         #e3b341;
    --warning-border:  #8a6d1f;
    --warning-surface: #1e1a10;

    --header-bg:       rgba(13, 17, 23, 0.82);
    --overlay:         rgba(0, 0, 0, 0.68);
    --shadow-sm:       0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow:          0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg:       0 12px 40px rgba(0, 0, 0, 0.6);
}

/* --- Basis -------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background-color: var(--bg);
    background-image: radial-gradient(120% 55% at 50% 0%, var(--bg-accent) 0%, var(--bg) 62%);
    background-repeat: no-repeat;
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font);
    font-size: var(--fs-base);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

img {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Nodig omdat de regels hieronder op id selecteren en dus zwaarder wegen
   dan de standaard display:none van [hidden]. */
[hidden] {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* --- Header ------------------------------------------------------------- */
#header {
    position: sticky;
    top: 0;
    z-index: 98;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 3.75rem;
    padding: var(--space-2) var(--space-4);
    margin-bottom: var(--space-5);
    background-color: var(--header-bg);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

#logo {
    display: block;
    width: 2.5rem;
    height: auto;
    flex-shrink: 0;
}

#headertext {
    flex: 1;
    min-width: 0;
    font-size: var(--fs-title);
    font-weight: 600;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Header: thema- en taalkeuze ---------------------------------------- */
#header-controls {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-shrink: 0;
}

#theme-switcher,
#lang-switcher {
    position: relative;
    display: flex;
}

#theme-btn,
#lang-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

#theme-btn:hover,
#lang-btn:hover,
#theme-switcher.open #theme-btn,
#lang-switcher.open #lang-btn {
    background-color: var(--surface-hover);
    border-color: var(--border);
    color: var(--text);
}

#theme-btn svg,
#lang-btn svg {
    width: 18px;
    height: 18px;
}

#theme-menu,
#lang-menu {
    display: none;
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    flex-direction: column;
    gap: 2px;
    min-width: 11rem;
    padding: var(--space-1);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 100;
}

#theme-menu.open,
#lang-menu.open {
    display: flex;
}

#theme-menu a,
#lang-menu a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--fs-sm);
    white-space: nowrap;
    text-decoration: none;
}

#theme-menu a svg,
#lang-menu a svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-subtle);
}

#theme-menu a:hover,
#lang-menu a:hover {
    background-color: var(--surface-hover);
    text-decoration: none;
}

#theme-menu a.active,
#lang-menu a.active {
    font-weight: 600;
    color: var(--accent);
}

#theme-menu a.active svg {
    color: var(--accent);
}

/* --- Live tegels -------------------------------------------------------- */
.live {
    max-width: var(--content);
    margin: 0 auto var(--space-5);
    padding: 0 var(--space-4);
}

.livegroup {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--space-3);
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-2);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    text-align: center;
    transition: box-shadow 0.18s, transform 0.18s, border-color 0.18s;
}

.tile:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.tile-label {
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-subtle);
}

.tile-icon {
    width: clamp(3rem, 5.5vw, 4.5rem);
    height: auto;
    margin-top: auto;
}

.tile-value {
    margin-top: auto;
    font-size: var(--fs-value);
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* --- Grafieken ---------------------------------------------------------- */
.charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(560px, 100%), 1fr));
    gap: var(--space-4);
    max-width: var(--content);
    margin: 0 auto;
    padding: 0 var(--space-4);
}

.chartitem {
    width: 100%;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.chart-expand-btn {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.875rem;
    height: 1.875rem;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-subtle);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.chart-expand-btn:hover {
    background-color: var(--surface-hover);
    border-color: var(--border);
    color: var(--text);
}

/* --- Stationlinks, subfooter, footer ------------------------------------ */
#stationlinks {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-2) var(--space-5);
    max-width: var(--content);
    margin: var(--space-6) auto 0;
    padding: 0 var(--space-4);
    font-size: var(--fs-sm);
    color: var(--text-muted);
}

.stationlink {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-variant-numeric: tabular-nums;
}

.stationlink a {
    display: flex;
    line-height: 0;
    border-radius: var(--radius-sm);
}

.menuitemimgsmall {
    width: 1.75rem;
    height: auto;
}

#subfooter {
    max-width: var(--content);
    margin: var(--space-5) auto 0;
    padding: 0 var(--space-4);
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--text-subtle);
}

#subfooter p {
    margin: 0;
}

#subfooter-notice {
    margin-top: var(--space-1);
    color: var(--warning);
    font-weight: 600;
}

#footer {
    margin-top: var(--space-4);
    padding: var(--space-4);
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--text-subtle);
}

#footer p {
    margin: 0;
}

/* --- Grafiek in het groot ----------------------------------------------- */
#chart-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--overlay);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

#chart-modal {
    position: relative;
    width: min(960px, 100%);
    padding: var(--space-6) var(--space-4) var(--space-4);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

#chart-modal-container {
    width: 100%;
}

/* --- Melding: offline of verouderde gegevens ---------------------------- */
#notice-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 210;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--overlay);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

#notice-card {
    position: relative;
    max-width: 28rem;
    padding: var(--space-6) var(--space-5) var(--space-5);
    background-color: var(--warning-surface);
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    text-align: center;
    color: var(--text);
}

#notice-icon {
    line-height: 0;
    margin-bottom: var(--space-3);
    color: var(--warning);
}

#notice-icon svg {
    width: 32px;
    height: 32px;
}

#notice-card h2 {
    margin: 0 0 var(--space-2);
    font-size: var(--fs-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
}

#notice-card p {
    margin: 0 0 var(--space-2);
    font-size: var(--fs-sm);
    line-height: 1.6;
    color: var(--text-muted);
}

#notice-last {
    margin-bottom: 0;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* --- Sluitknoppen in overlays ------------------------------------------- */
#chart-modal-close,
#notice-close {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-subtle);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

#chart-modal-close:hover,
#notice-close:hover {
    background-color: var(--surface-hover);
    border-color: var(--border);
    color: var(--text);
}

#chart-modal-close svg,
#notice-close svg {
    width: 18px;
    height: 18px;
}

/* --- Offline-pagina ----------------------------------------------------- */
.api-error {
    max-width: 32rem;
    margin: 0 auto;
    padding: var(--space-6) var(--space-4);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    text-align: center;
    color: var(--text-muted);
}

.api-error p {
    margin: 0 0 var(--space-2);
}

.api-error p:last-child {
    margin-bottom: 0;
}

/* --- Responsief --------------------------------------------------------- */
/* Tablet: 3 per rij geeft een nette 3x2 opstelling. */
@media (max-width: 1100px) {
    .livegroup {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Mobiel: 2 per rij, zodat label en waarde leesbaar blijven. */
@media (max-width: 640px) {
    :root {
        --space-5: 1.125rem;
        --space-6: 1.5rem;
    }

    #header {
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
    }

    #logo {
        width: 2rem;
    }

    .live,
    .charts,
    #subfooter,
    #stationlinks {
        padding: 0 var(--space-3);
    }

    .livegroup {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-2);
    }

    .tile {
        padding: var(--space-3) var(--space-2);
    }

    .chartitem {
        min-height: 22rem;
    }

    #chart-modal {
        padding: var(--space-5) var(--space-2) var(--space-2);
    }
}
