/*
 * Dark mode for every page with a layout (the visitor's switch, partials/theme-switch).
 * Plain CSS on purpose: the live server does not rebuild Tailwind, so the light pages keep their
 * own classes and these rules recolour them while <html> has the class "dark". Screen only:
 * printing and PDFs stay as they are. Dark-green and gold parts are left alone.
 */
@media screen {
    html.dark {
        color-scheme: dark;
        --dm-page: #0a231b;
        --dm-card: #11342a;
        --dm-raised: #184236;
        --dm-tint: #1b4a3b;
        --dm-line: #2f5f50;
        --dm-mint: #8ff0c9;
        --dm-text: #f1f7f3;
        --dm-soft: #d3e0d9;
        --dm-muted: #a9c0b5;
    }

    html.dark body,
    html.dark .bg-\[\#eef5f0\],
    html.dark .bg-\[\#eef2f1\] { background-color: var(--dm-page) !important; color: var(--dm-text); }

    /* a soft green light from the top, so the page is not one flat colour */
    html.dark body { background-image: radial-gradient(70rem 34rem at 50% -6rem, rgba(16, 122, 84, .3), transparent 70%); background-repeat: no-repeat; }

    /* home: the admin's picture behind the page is made for a light page, on dark it is only a stain */
    html.dark .home-watermark .hero-scene * { animation: none !important; }
    html.dark .home-watermark { opacity: .05 !important; }
    html.dark .premium-dots { background-image: radial-gradient(rgba(167, 243, 208, .08) 1px, transparent 1.4px); }

    /* pale blurred glows behind cards: on dark they turn into a grey haze */
    html.dark :is(.blur-2xl, .blur-3xl):is([class*="bg-emerald-200/"], [class*="bg-emerald-300/"], [class*="bg-amber-200/"], [class*="bg-rose-200/"]) { opacity: .2 !important; }

    /* surfaces */
    html.dark .bg-white,
    html.dark .bg-white\/95,
    html.dark .bg-white\/90,
    html.dark .bg-white\/80,
    html.dark .bg-white\/70,
    html.dark .bg-white\/75,
    html.dark .bg-white\/60,
    html.dark .bg-white\/50,
    html.dark .bg-white\/85,
    html.dark .bg-gray-50\/80,
    html.dark .bg-gray-50\/60,
    html.dark [style*="background:#fff;"],
    html.dark [style*="background: #fff;"] { background-color: var(--dm-card) !important; }

    html.dark .bg-gray-50,
    html.dark .bg-gray-100,
    html.dark .hover\:bg-gray-50:hover,
    html.dark .hover\:bg-gray-100:hover { background-color: var(--dm-raised) !important; }

    html.dark .bg-gray-200,
    html.dark .bg-gray-300 { background-color: #33594c !important; }

    /* light gradients behind cards and headings: exact classes only, so colour gradients, glass
       overlays and gold gradient-filled text are left alone */
    html.dark :is(.from-white, .from-gray-50, .from-\[\#eef5f0\], .from-emerald-50, .from-emerald-50\/70, .from-emerald-50\/80,
        .from-emerald-50\/90, .from-emerald-100, .from-emerald-100\/70, .from-green-50, .from-amber-50, .from-amber-50\/70,
        .from-amber-50\/90, .from-amber-100, .from-amber-100\/60, .from-yellow-100):not(.bg-clip-text) {
        background-image: none !important;
        background-color: var(--dm-card) !important;
    }

    /* tints: the same colour, dark ("/" keeps bg-emerald-50/70 apart from bg-emerald-500) */
    html.dark .bg-emerald-50,
    html.dark .bg-emerald-100,
    html.dark .bg-green-50,
    html.dark .bg-green-100,
    html.dark .hover\:bg-emerald-50:hover,
    html.dark [class*="bg-emerald-50/"],
    html.dark [class*="bg-emerald-100/"],
    html.dark [class*="bg-green-50/"],
    html.dark [class*="bg-gray-50/"],
    html.dark [class*="bg-gray-100/"] { background-color: var(--dm-tint) !important; }

    html.dark .bg-amber-50,
    html.dark .bg-amber-100,
    html.dark .bg-yellow-50,
    html.dark .bg-yellow-100,
    html.dark .bg-orange-50,
    html.dark .bg-orange-100,
    html.dark [class*="bg-amber-50/"],
    html.dark [class*="bg-amber-100/"],
    html.dark [class*="bg-yellow-50/"],
    html.dark [class*="bg-orange-50/"] { background-color: #3d3212 !important; }

    html.dark .bg-red-50,
    html.dark .bg-red-100,
    html.dark .bg-rose-50,
    html.dark .bg-rose-100,
    html.dark [class*="bg-red-50/"],
    html.dark [class*="bg-rose-50/"] { background-color: #3a1a1f !important; }

    html.dark .bg-sky-50,
    html.dark .bg-sky-100,
    html.dark .bg-blue-50,
    html.dark .bg-blue-100,
    html.dark .bg-indigo-50,
    html.dark .bg-indigo-100,
    html.dark .bg-violet-50,
    html.dark .bg-purple-50,
    html.dark [class*="bg-sky-50/"],
    html.dark [class*="bg-blue-50/"],
    html.dark [class*="bg-indigo-50/"] { background-color: #1a2740 !important; }

    html.dark [style*="background:#fffbeb"] { background-color: #3d3212 !important; }

    /* colours written on the element, with no light chip behind them */
    html.dark :is([style*="color:#047857"], [style*="color: #047857"]):not([style*="background"]) { color: var(--dm-mint) !important; }
    html.dark :is([style*="color:#b45309"], [style*="color: #b45309"]):not([style*="background"]) { color: #fcd34d !important; }
    html.dark :is([style*="color:#be123c"], [style*="color: #be123c"]):not([style*="background"]) { color: #fda4af !important; }

    /* text */
    html.dark .text-gray-900,
    html.dark .text-gray-800,
    html.dark .text-slate-900,
    html.dark .text-slate-800 { color: var(--dm-text) !important; }

    html.dark .text-gray-700,
    html.dark .text-gray-600 { color: var(--dm-soft) !important; }

    html.dark .text-gray-500,
    html.dark .text-gray-400 { color: var(--dm-muted) !important; }

    html.dark .text-emerald-950,
    html.dark .text-emerald-900,
    html.dark [class*="text-emerald-950/"],
    html.dark [class*="text-emerald-900/"] { color: var(--dm-text) !important; }

    html.dark .text-emerald-800,
    html.dark .text-emerald-700,
    html.dark .text-emerald-600,
    html.dark .text-green-800,
    html.dark .text-green-700,
    html.dark [class*="text-emerald-800/"],
    html.dark [class*="text-emerald-700/"] { color: var(--dm-mint) !important; }

    html.dark .text-amber-950,
    html.dark [class*="text-amber-950/"],
    html.dark [class*="text-amber-900/"],
    html.dark [class*="text-amber-800/"],
    html.dark .text-amber-900,
    html.dark .text-orange-900,
    html.dark .text-orange-800,
    html.dark .text-orange-700,
    html.dark .text-amber-800,
    html.dark .text-amber-700,
    html.dark .text-yellow-800 { color: #fcd34d !important; }

    html.dark .text-red-800,
    html.dark .text-red-700,
    html.dark .text-red-600,
    html.dark .text-rose-700,
    html.dark .text-rose-600 { color: #fda4af !important; }

    html.dark .text-sky-700,
    html.dark .text-blue-700,
    html.dark .text-indigo-700,
    html.dark .text-indigo-600,
    html.dark .text-violet-700,
    html.dark .text-violet-600,
    html.dark .text-purple-700 { color: #c4b5fd !important; }

    /* the fee totals are filled with a dark green gradient */
    html.dark .bg-clip-text.from-emerald-600.to-green-800 { background-image: linear-gradient(135deg, #bbf7d0, #34d399) !important; }

    /* words on gold stay dark, also when the gold part is a button around them */
    html.dark :is(.bg-amber-200, .bg-amber-300, .bg-amber-400, .bg-yellow-300, .bg-yellow-400,
        .from-amber-200, .from-amber-300, .from-amber-400, .from-amber-500, .from-yellow-300, .from-yellow-400):is(.text-emerald-950, .text-emerald-900, .text-gray-900, .text-gray-800, .text-amber-950, .text-amber-900),
    html.dark :is(.bg-amber-200, .bg-amber-300, .bg-amber-400, .bg-yellow-300, .bg-yellow-400,
        .from-amber-200, .from-amber-300, .from-amber-400, .from-amber-500, .from-yellow-300, .from-yellow-400) > :is(.text-emerald-950, .text-emerald-900, .text-gray-900, .text-gray-800, .text-amber-950, .text-amber-900) { color: #1c1a06 !important; }

    html.dark :is([class*="bg-amber-300/"], [class*="bg-amber-400/"]):is(.text-emerald-950, .text-emerald-900, .text-amber-950, .text-amber-900) { color: #1c1a06 !important; }

    /* a picture alone in a white box (a logo, a signature) keeps its paper */
    html.dark :is(.bg-white, .bg-white\/95, .bg-white\/90, .bg-white\/80):has(> img:only-child) { background-color: #fff !important; }

    /* lines */
    html.dark .border-gray-100,
    html.dark .border-gray-200,
    html.dark .border-gray-300,
    html.dark .border-emerald-100,
    html.dark .border-emerald-200,
    html.dark .divide-gray-100 > * + *,
    html.dark .divide-gray-200 > * + *,
    html.dark .divide-emerald-100 > * + * { border-color: var(--dm-line) !important; }

    html.dark .ring-gray-100,
    html.dark .ring-gray-200,
    html.dark .ring-gray-300,
    html.dark .ring-emerald-100,
    html.dark .ring-emerald-100\/80,
    html.dark .ring-emerald-200,
    html.dark .ring-amber-200,
    html.dark .ring-white { --tw-ring-color: var(--dm-line) !important; }

    /* forms */
    html.dark input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
    html.dark select,
    html.dark textarea {
        background-color: var(--dm-raised) !important;
        border-color: var(--dm-line) !important;
        color: var(--dm-text) !important;
    }

    html.dark input::placeholder,
    html.dark textarea::placeholder { color: var(--dm-muted) !important; }

    html.dark input:-webkit-autofill {
        -webkit-text-fill-color: var(--dm-text);
        box-shadow: 0 0 0 40px var(--dm-raised) inset;
    }

    /* the searchable lists of the admin panel */
    html.dark .ss-control,
    html.dark .ss-panel,
    html.dark .ss-search { background: var(--dm-raised) !important; border-color: var(--dm-line) !important; color: var(--dm-text) !important; }

    html.dark .ss-opt { color: var(--dm-soft); }
    html.dark .ss-opt:hover,
    html.dark .ss-opt.ss-active { background: var(--dm-tint) !important; color: var(--dm-text); }
    html.dark .ss-selected { color: var(--dm-mint); }
    html.dark .ss-none { color: var(--dm-muted); }

    /* home: the day's programme */
    html.dark .ps-card,
    html.dark .ps-pill { background: var(--dm-card) !important; }
    html.dark .ps-card { border-color: var(--dm-line) !important; }
    html.dark .ps-title { color: var(--dm-text); }
    html.dark .ps-desc { color: var(--dm-soft); }
    html.dark .ps-sess-range { color: #fcd34d; }
    html.dark .ps-loc { color: var(--dm-mint); }
    html.dark .ps-pill { color: var(--dm-soft); }
    html.dark .ps-num { color: rgba(167, 243, 208, .07); }

    /* the fixed top bar of the admin panel */
    html.dark .adm-topbar { background-color: rgba(17, 52, 42, .95) !important; border-color: var(--dm-line) !important; }

    /* calendar pop-up */
    html.dark .flatpickr-calendar,
    html.dark .flatpickr-weekdays,
    html.dark .flatpickr-months .flatpickr-month { background: var(--dm-raised); color: var(--dm-text); }

    html.dark .flatpickr-day,
    html.dark .flatpickr-weekday,
    html.dark .flatpickr-current-month input.cur-year { color: var(--dm-text); }

    /* pictures on white (signatures, logos in a white box, sample cards) and the sign-in picture keep their paper */
    html.dark [data-theme-keep],
    html.dark [data-theme-keep] * { color-scheme: light; }
}

/* the switch itself: in the top menu of every page ("dark": a green header, "light": the admin's
   white top bar); "corner": top right on a page with no menu. Nothing floats over the page any more. */
.theme-switch {
    display: inline-flex;
    flex: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 9999px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background-color .15s ease, color .15s ease;
}
.theme-switch--dark { background: rgba(255, 255, 255, .08); color: #fde68a; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16); }
.theme-switch--dark:hover { background: rgba(255, 255, 255, .16); }
.theme-switch--light { background: transparent; color: #065f46; }
.theme-switch--light:hover { background: #ecfdf5; }
html.dark .theme-switch--light { color: #fde68a; }
html.dark .theme-switch--light:hover { background: rgba(255, 255, 255, .08); }
.theme-switch--corner {
    position: fixed;
    top: .75rem;
    right: .75rem;
    z-index: 45;
    background: #0b4f2c;
    color: #fde68a;
    box-shadow: 0 8px 20px -8px rgba(2, 44, 34, .6), inset 0 0 0 1px rgba(253, 230, 138, .35);
}
.theme-switch--corner:hover { background: #0f6a3b; }
.theme-switch:focus-visible { outline: 2px solid #fbbf24; outline-offset: 2px; }
.theme-switch svg { width: 20px; height: 20px; }
.theme-switch .ts-sun { display: none; }
html.dark .theme-switch .ts-sun { display: block; }
html.dark .theme-switch .ts-moon { display: none; }

@media print { .theme-switch { display: none !important; } }
