/* Colour preferences are independent of the seasonal theme on <body>. */
.portal-mode-toggle[hidden], .portal-mode-sun, [data-portal-mode="dark"] .portal-mode-moon {
    display: none;
}
[data-portal-mode="dark"] .portal-mode-sun { display: inline; }
.portal-mode-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

@media (prefers-reduced-motion: no-preference) {
    .portal-switching-mode::view-transition-old(root),
    .portal-switching-mode::view-transition-new(root) { animation-duration: 150ms; }
}

html[data-portal-mode="dark"] {
    color-scheme: dark;
    --pd-canvas: #101820;
    --pd-surface: #19242f;
    --pd-raised: #223140;
    --pd-inset: #111d27;
    --pd-border: #415467;
    --pd-text: #ecf2f6;
    --pd-muted: #b3c3d1;
    --pd-accent: #8cd5ed;
    --pd-brand: #ffd478;
    --pd-brand-bg: #503a15;
    --pd-good: #99e8c3;
    --pd-good-bg: #173c32;
    --pd-info: #a0d7ff;
    --pd-info-bg: #19394f;
    --pd-danger: #ffb3c2;
    --pd-danger-bg: #4b2635;
    --pd-violet: #d7c4ff;
    --pd-violet-bg: #342c50;
    --portal-canvas: 16 24 32;
    --portal-surface: 25 36 47;
    --portal-surface-subtle: 34 49 64;
    --portal-ink: 236 242 246;
    --portal-ink-soft: 210 221 230;
    --portal-muted: 179 195 209;
    --portal-line: 65 84 103;
    --portal-brand-ink: 255 212 120;
    --portal-accent-soft: 80 58 21;
    --portal-success: 153 232 195;
    --portal-danger: 255 179 194;
    --portal-scrollbar-thumb: 79 99 117;
    --portal-scrollbar-thumb-hover: 105 128 149;
    --portal-scrollbar-thumb-active: 126 147 166;
    --portal-scrollbar-track: 21 31 42;
}

/* Django admin supplies its own dark surfaces and uses the shared widget tokens. */
html[data-portal-mode="dark"]:not([data-theme]) {
    color: var(--pd-text);
    background-color: var(--pd-canvas);

    & body { color: var(--pd-text); background-color: var(--pd-canvas); }
    & :is(.portal-sidebar-brand, .portal-frame) img[alt="iCloud Portal"],
    & .portal-festive-logo {
        filter: url("../icons/portal-dark-logo.ff234f6acc4a.svg#light-ink");
    }
    & :is(input:not([type]), input:is([type=text], [type=number], [type=password], [type=email], [type=tel], [type=date], [type=datetime-local], [type=month], [type=time], [type=url], [type=search]), select, textarea, option) {
        background-color: var(--pd-inset);
        color: var(--pd-text);
        border-color: var(--pd-border);
    }
    & :is(input, textarea)::placeholder { color: #a4b7c8; opacity: 1; }
    & :is(input, select, textarea):disabled { color: var(--pd-muted); }
    & :is(input[type=checkbox], input[type=radio], progress) { accent-color: var(--pd-brand); }
    & input::file-selector-button { color: var(--pd-text); background: var(--pd-raised); border-color: var(--pd-border); }
    & :focus-visible { outline-color: var(--pd-brand); }
    & ::selection { background: #6b4c22; color: white; }

    & .bg-white, & :is(.bg-white\/95, .bg-white\/90, .bg-white\/80, .bg-white\/75, .bg-white\/70, .bg-white\/60) { background-color: var(--pd-surface); }
    & :is(.bg-zinc-50, .bg-slate-50, .bg-zinc-50\/40, .bg-zinc-50\/60, .bg-zinc-50\/70, .bg-zinc-50\/80, .bg-zinc-50\/90) { background-color: var(--pd-inset); }
    & :is(.bg-zinc-100, .bg-zinc-100\/95, .bg-slate-100, .bg-zinc-200, .bg-zinc-300) { background-color: var(--pd-raised); }
    & body.bg-zinc-100 { background-color: var(--pd-canvas); }
    & :is(.text-slate-700, .text-slate-800, .text-slate-900, .text-slate-950, .text-zinc-700) { color: var(--pd-text); }
    & :is(.text-slate-400, .text-slate-500, .text-slate-600, .text-zinc-400, .text-zinc-500, .text-zinc-600) { color: var(--pd-muted); }
    & :is(.border-zinc-100, .border-zinc-200, .border-zinc-300, .border-slate-200, .border-white) { border-color: var(--pd-border); }
    & :is(.divide-zinc-100, .divide-zinc-200, .divide-rose-100\/70) > :not([hidden]) ~ :not([hidden]) { border-color: var(--pd-border); }
    & :is(.ring-white, .ring-zinc-200) { --tw-ring-color: var(--pd-border); }
    & :is(.hover\:bg-zinc-50, .hover\:bg-zinc-50\/70, .hover\:bg-zinc-100, .hover\:bg-slate-100, .hover\:bg-white):hover { background-color: var(--pd-raised); }
    & :is(.hover\:text-slate-700, .hover\:text-slate-800, .hover\:text-slate-900, .hover\:text-slate-950, .hover\:text-zinc-700):hover { color: #fff; }
    & :is(.from-white, .from-orange-100, .from-rose-50) { --tw-gradient-from: var(--pd-raised) var(--tw-gradient-from-position); }
    & .via-amber-50 { --tw-gradient-stops: var(--tw-gradient-from), var(--pd-brand-bg) var(--tw-gradient-via-position), var(--tw-gradient-to); }
    & :is(.to-white, .to-amber-50, .to-emerald-50, .to-emerald-50\/80, .to-rose-50, .to-sky-50, .to-sky-50\/70, .to-violet-50, .to-violet-50\/70) { --tw-gradient-to: var(--pd-surface) var(--tw-gradient-to-position); }

    & :is(.text-brandInk, .text-accent, .text-amber-700, .text-amber-700\/70, .text-amber-800, .text-amber-900, .text-amber-950, .text-orange-500, .text-orange-600, .text-orange-700, .text-orange-800, .text-orange-900) { color: var(--pd-brand); }
    & :is(.text-emerald-600, .text-emerald-700, .text-emerald-700\/70, .text-emerald-700\/80, .text-emerald-800, .text-emerald-900, .text-emerald-950, .text-teal-700, .text-teal-800) { color: var(--pd-good); }
    & :is(.text-blue-600, .text-blue-700, .text-blue-800, .text-blue-900, .text-cyan-700, .text-sky-600, .text-sky-700, .text-sky-800, .text-sky-900) { color: var(--pd-info); }
    & :is(.text-rose-500, .text-rose-600, .text-rose-700, .text-rose-700\/70, .text-rose-800, .text-rose-900, .text-rose-950, .text-red-600, .text-red-700) { color: var(--pd-danger); }
    & :is(.text-violet-600, .text-violet-700, .text-violet-700\/70, .text-violet-800, .text-violet-900, .text-indigo-700) { color: var(--pd-violet); }
    & :is(.bg-accent-soft, .bg-amber-100, .bg-amber-50, .bg-amber-50\/70, .bg-orange-50, .bg-orange-50\/70) { background-color: var(--pd-brand-bg); }
    & :is(.bg-emerald-100, .bg-emerald-50, .bg-emerald-50\/40, .bg-emerald-50\/60, .bg-green-50, .bg-teal-50) { background-color: var(--pd-good-bg); }
    & :is(.bg-blue-50, .bg-sky-100, .bg-sky-50, .bg-sky-50\/35, .bg-sky-50\/50, .bg-sky-50\/60, .bg-sky-50\/70) { background-color: var(--pd-info-bg); }
    & :is(.bg-rose-100, .bg-rose-50, .bg-rose-50\/30, .bg-rose-50\/40, .bg-rose-50\/50) { background-color: var(--pd-danger-bg); }
    & :is(.bg-violet-100, .bg-violet-50, .bg-violet-50\/35, .bg-violet-50\/60, .bg-indigo-50) { background-color: var(--pd-violet-bg); }
    & :is(.border-emerald-100, .border-emerald-200, .border-emerald-300, .border-green-200, .border-teal-200, .border-teal-300) { border-color: #416b5b; }
    & :is(.border-sky-100, .border-sky-200, .border-sky-300, .border-blue-200) { border-color: #42677e; }
    & :is(.border-amber-100, .border-amber-200, .border-amber-300, .border-orange-100, .border-orange-200, .border-orange-200\/80, .border-orange-300) { border-color: #82653a; }
    & :is(.border-rose-100, .border-rose-200, .border-rose-300) { border-color: #84515f; }
    & :is(.border-violet-100, .border-violet-200, .border-violet-300, .border-indigo-200) { border-color: #675883; }
    & :is(.hover\:bg-accent-soft, .hover\:bg-amber-100, .hover\:bg-orange-50, .hover\:bg-orange-50\/30, .hover\:bg-orange-50\/40, .hover\:bg-orange-100):hover { background-color: #624722; }
    & .hover\:bg-emerald-100:hover { background-color: #244d40; }
    & :is(.hover\:bg-sky-50, .hover\:bg-sky-50\/50, .hover\:bg-sky-100):hover { background-color: #274b60; }
    & .hover\:bg-rose-100:hover { background-color: #58323d; }
    & .hover\:bg-violet-100:hover { background-color: #44385d; }
    & :is(.hover\:text-accent, .hover\:text-accent-dark, .hover\:text-orange-900, .hover\:text-amber-900):hover { color: var(--pd-brand); }
    & :is(.hover\:text-rose-700, .hover\:text-rose-800):hover { color: var(--pd-danger); }
    & .hover\:text-sky-700:hover { color: var(--pd-info); }
    & .group:hover .group-hover\:text-accent { color: var(--pd-brand); }
    & .group:has(:checked) .group-has-\[\:checked\]\:bg-accent { background-color: var(--pd-brand-bg); }
    & .group:has(:checked) .group-has-\[\:checked\]\:text-white { color: var(--pd-brand); }
    & .group:has(:checked) .group-has-\[\:checked\]\:border-accent,
    & .focus\:border-accent:focus, & .focus-within\:border-accent:focus-within { border-color: var(--pd-brand); }
    & .focus\:ring-accent-soft:focus { --tw-ring-color: var(--pd-brand); }
    & :is(.focus\:ring-emerald-100, .focus\:ring-emerald-200):focus { --tw-ring-color: #528d75; }
    & .focus\:ring-sky-200:focus { --tw-ring-color: #5f9db8; }
    & .focus\:ring-violet-100:focus { --tw-ring-color: #8d7fac; }
    & :is(.disabled\:bg-zinc-100, .disabled\:bg-zinc-300):disabled { background-color: var(--pd-raised); }
    & .disabled\:text-zinc-400:disabled { color: var(--pd-muted); }
    & .disabled\:border-zinc-200:disabled { border-color: var(--pd-border); }

    /* Keep filled actions distinguishable from their muted status surfaces. */
    & .bg-accent { background-color: var(--pd-brand-bg); color: var(--pd-brand); }
    & :is(button, a, label).bg-accent { box-shadow: inset 0 0 0 1px #886b3c; }
    & .hover\:bg-accent-dark:hover { background-color: #654b23; color: var(--pd-brand); }
    & :is(.bg-emerald-500, .bg-emerald-600).text-white { background-color: #23654c; }
    & :is(.bg-sky-500, .bg-sky-600, .bg-cyan-500).text-white { background-color: #265f7b; }
    & :is(.bg-rose-500, .bg-rose-600).text-white { background-color: #91415a; }
    & .portal-mode-toggle:focus-visible { outline-color: var(--pd-brand); }

    /* The flowers, artwork and seasonal accent still come from the campaign. */
    & body.theme-womens_day {
        --pd-brand: #ffc2dd;
        --pd-brand-bg: #492b3c;
        --portal-accent-soft: 73 43 60;
        --portal-brand-ink: 255 194 221;
        background: radial-gradient(ellipse at 95% 0, #3a263a 0, transparent 38%), var(--pd-canvas);
    }
    & .theme-womens_day::before, & .theme-womens_day::after,
    & .theme-womens_day #appSidebar::before, & .theme-womens_day #appSidebar::after,
    & .theme-womens_day .portal-aurora::before, & .theme-womens_day .portal-aurora::after { opacity: .12; }
    & .theme-womens_day :is(.portal-frame, #appSidebar, #navbarNotificationsList, .portal-sidebar-role-card, .portal-sidebar-botanical, #sidebarClose, #sidebarToggle) {
        background: var(--pd-surface); color: var(--pd-text); border-color: var(--pd-border); box-shadow: none;
    }
    & .theme-womens_day :is(.portal-sidebar-nav p, .portal-sidebar-botanical-caption) { color: var(--pd-brand); }
    & .theme-womens_day .portal-sidebar-nav a:hover { background: var(--pd-raised); }
    & .theme-womens_day .portal-sidebar-nav a.bg-accent.text-white, & .theme-womens_day .bg-accent.text-white {
        background: var(--pd-brand-bg); color: var(--pd-brand); box-shadow: inset 0 0 0 1px #865673;
    }
    & :is(.portal-ribbon, .portal-festive-dialog, .cele-hero, .cele-panel, .cele-card) {
        background: linear-gradient(135deg, #362638, #212735); color: var(--pd-text); border-color: #67475c; box-shadow: none;
    }
    & :is(.portal-ribbon-chip, .portal-ribbon-cta, .portal-ribbon-cta-arrow, .portal-festive-chip, .portal-festive-button, .portal-festive-close) {
        background: #492c40; border-color: #7b5269; color: #ffd0e4; box-shadow: none;
    }
    & :is(.portal-festive-title, .portal-festive-copy, .portal-festive-signature) { color: #f5e4ec; }
}
