/**
 * MadTheme Dark Mode Stylesheet
 *
 * Implements the data-scheme override layer and progressive fallbacks
 * for MadTheme preset colors and gradients.
 *
 * @package MadTheme_One
 * @version 1.0.6
 */

@media screen {
	/* Explicit dark mode override */
	html[data-scheme="dark"],
	:root[data-scheme="dark"],
	html.is-dark-theme,
	body.is-dark-theme {
		color-scheme: dark !important;
		--wp--preset--color--base: #121212 !important;
		--wp--preset--color--base-2: #1d1d1f !important;
		--wp--preset--color--base-3: #20202b !important;
		--wp--preset--color--contrast: #f0f0f1 !important;
		--wp--preset--color--contrast-2: #ffffff !important;
		--wp--preset--color--accent: #8f96f7 !important;

		/* Accent gradients adjusted for dark background legibility */
		--wp--preset--gradient--accent: linear-gradient(
			180deg,
			oklch(from var(--wp--preset--color--accent) calc(l + .22) c h),
			var(--wp--preset--color--accent)
		);
		--wp--preset--gradient--accent-diagonal: linear-gradient(
			135deg,
			oklch(from var(--wp--preset--color--accent) calc(l + .22) c h),
			var(--wp--preset--color--accent)
		);
	}

	html[data-scheme="dark"] body,
	html.is-dark-theme body,
	body.is-dark-theme {
		background-color: var(--wp--preset--color--base, #121212) !important;
		color: var(--wp--preset--color--contrast, #f0f0f1) !important;
	}

	html[data-scheme="dark"] .wp-site-blocks,
	html.is-dark-theme .wp-site-blocks,
	body.is-dark-theme .wp-site-blocks {
		background-color: var(--wp--preset--color--base, #121212);
		color: var(--wp--preset--color--contrast, #f0f0f1);
	}

	html[data-scheme="dark"] .has-base-background-color,
	html.is-dark-theme .has-base-background-color,
	body.is-dark-theme .has-base-background-color {
		background-color: #121212 !important;
	}

	html[data-scheme="dark"] .has-contrast-color,
	html.is-dark-theme .has-contrast-color,
	body.is-dark-theme .has-contrast-color {
		color: #f0f0f1 !important;
	}

	/* Explicit light mode override */
	html[data-scheme="light"],
	:root[data-scheme="light"] {
		color-scheme: light !important;
		--wp--preset--color--base: #ffffff !important;
		--wp--preset--color--base-2: #f5f5f7 !important;
		--wp--preset--color--base-3: #e5e6fa !important;
		--wp--preset--color--contrast: #101012 !important;
		--wp--preset--color--contrast-2: #000000 !important;
		--wp--preset--color--accent: #3740b9 !important;

		--wp--preset--gradient--accent: linear-gradient(
			180deg,
			oklch(from var(--wp--preset--color--accent) calc(l - .22) c h),
			var(--wp--preset--color--accent)
		);
		--wp--preset--gradient--accent-diagonal: linear-gradient(
			135deg,
			oklch(from var(--wp--preset--color--accent) calc(l - .22) c h),
			var(--wp--preset--color--accent)
		);
	}

	/* Progressive fallback for browsers without light-dark() support */
	@supports not (color: light-dark(#fff, #000)) {
		@media (prefers-color-scheme: dark) {
			:root:not([data-scheme="light"]) {
				color-scheme: dark;
				--wp--preset--color--base: #121212;
				--wp--preset--color--base-2: #1d1d1f;
				--wp--preset--color--base-3: #20202b;
				--wp--preset--color--contrast: #f0f0f1;
				--wp--preset--color--contrast-2: #ffffff;
				--wp--preset--color--accent: #8f96f7;

				--wp--preset--gradient--accent: linear-gradient(
					180deg,
					oklch(from var(--wp--preset--color--accent) calc(l + .22) c h),
					var(--wp--preset--color--accent)
				);
				--wp--preset--gradient--accent-diagonal: linear-gradient(
					135deg,
					oklch(from var(--wp--preset--color--accent) calc(l + .22) c h),
					var(--wp--preset--color--accent)
				);
			}
		}
	}

	/* Frontend Core Elements: Comment Form & Password Protected Post */
	html[data-scheme="dark"] .wp-block-post-comments-form input[type="text"],
	html[data-scheme="dark"] .wp-block-post-comments-form input[type="email"],
	html[data-scheme="dark"] .wp-block-post-comments-form input[type="url"],
	html[data-scheme="dark"] .wp-block-post-comments-form textarea,
	html[data-scheme="dark"] .post-password-form input[type="password"],
	html.is-dark-theme .wp-block-post-comments-form input[type="text"],
	html.is-dark-theme .wp-block-post-comments-form input[type="email"],
	html.is-dark-theme .wp-block-post-comments-form input[type="url"],
	html.is-dark-theme .wp-block-post-comments-form textarea,
	html.is-dark-theme .post-password-form input[type="password"] {
		background-color: var(--wp--preset--color--base-2, #1d1d1f) !important;
		border: 1px solid var(--wp--preset--color--tertiary, #3f3f46) !important;
		color: var(--wp--preset--color--contrast, #f0f0f1) !important;
		border-radius: 6px;
	}

	html[data-scheme="dark"] .wp-block-post-comments-form input[type="text"]:focus,
	html[data-scheme="dark"] .wp-block-post-comments-form input[type="email"]:focus,
	html[data-scheme="dark"] .wp-block-post-comments-form input[type="url"]:focus,
	html[data-scheme="dark"] .wp-block-post-comments-form textarea:focus,
	html[data-scheme="dark"] .post-password-form input[type="password"]:focus,
	html.is-dark-theme .wp-block-post-comments-form input[type="text"]:focus,
	html.is-dark-theme .wp-block-post-comments-form textarea:focus {
		border-color: var(--wp--preset--color--accent, #8f96f7) !important;
		outline: none;
		box-shadow: 0 0 0 2px rgba(143, 150, 247, 0.25);
	}

	/* Code & Preformatted Blocks */
	html[data-scheme="dark"] .wp-block-code,
	html[data-scheme="dark"] pre.wp-block-preformatted,
	html[data-scheme="dark"] code,
	html.is-dark-theme .wp-block-code,
	html.is-dark-theme pre.wp-block-preformatted,
	html.is-dark-theme code {
		background-color: var(--wp--preset--color--base-2, #1d1d1f) !important;
		color: var(--wp--preset--color--contrast, #f0f0f1) !important;
		border-color: var(--wp--preset--color--tertiary, #3f3f46) !important;
	}

	/* Navigation Submenu Dropdown Container */
	html[data-scheme="dark"] .wp-block-navigation .wp-block-navigation__submenu-container,
	html.is-dark-theme .wp-block-navigation .wp-block-navigation__submenu-container {
		background-color: var(--wp--preset--color--base-2, #1d1d1f) !important;
		border: 1px solid var(--wp--preset--color--tertiary, #3f3f46) !important;
		box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6) !important;
		color: var(--wp--preset--color--contrast, #f0f0f1) !important;
	}

	html[data-scheme="dark"] .wp-block-navigation .wp-block-navigation__submenu-container .wp-block-navigation-item a,
	html.is-dark-theme .wp-block-navigation .wp-block-navigation__submenu-container .wp-block-navigation-item a {
		color: var(--wp--preset--color--contrast, #f0f0f1) !important;
	}

	html[data-scheme="dark"] .wp-block-navigation .wp-block-navigation__submenu-container .wp-block-navigation-item a:hover,
	html.is-dark-theme .wp-block-navigation .wp-block-navigation__submenu-container .wp-block-navigation-item a:hover {
		background-color: color-mix(in srgb, currentColor 8%, transparent) !important;
		color: var(--wp--preset--color--accent, #8f96f7) !important;
	}

	/* Table Subtle Note Backgrounds (core light-only colors, dark equivalents) */
	html[data-scheme="dark"] .wp-block-table .has-subtle-light-gray-background-color,
	html.is-dark-theme .wp-block-table .has-subtle-light-gray-background-color,
	body.is-dark-theme .wp-block-table .has-subtle-light-gray-background-color {
		background-color: #2b2b31 !important;
	}

	html[data-scheme="dark"] .wp-block-table .has-subtle-pale-green-background-color,
	html.is-dark-theme .wp-block-table .has-subtle-pale-green-background-color,
	body.is-dark-theme .wp-block-table .has-subtle-pale-green-background-color {
		background-color: #20301e !important;
	}

	html[data-scheme="dark"] .wp-block-table .has-subtle-pale-blue-background-color,
	html.is-dark-theme .wp-block-table .has-subtle-pale-blue-background-color,
	body.is-dark-theme .wp-block-table .has-subtle-pale-blue-background-color {
		background-color: #1d2b3a !important;
	}

	html[data-scheme="dark"] .wp-block-table .has-subtle-pale-pink-background-color,
	html.is-dark-theme .wp-block-table .has-subtle-pale-pink-background-color,
	body.is-dark-theme .wp-block-table .has-subtle-pale-pink-background-color {
		background-color: #37232b !important;
	}

	/* Table subtle notes combined with striped rows */
	html[data-scheme="dark"] .wp-block-table.is-style-stripes.has-subtle-light-gray-background-color tbody tr:nth-child(odd),
	html.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-light-gray-background-color tbody tr:nth-child(odd),
	body.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-light-gray-background-color tbody tr:nth-child(odd) {
		background-color: #2b2b31 !important;
	}

	html[data-scheme="dark"] .wp-block-table.is-style-stripes.has-subtle-pale-green-background-color tbody tr:nth-child(odd),
	html.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-pale-green-background-color tbody tr:nth-child(odd),
	body.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-pale-green-background-color tbody tr:nth-child(odd) {
		background-color: #20301e !important;
	}

	html[data-scheme="dark"] .wp-block-table.is-style-stripes.has-subtle-pale-blue-background-color tbody tr:nth-child(odd),
	html.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-pale-blue-background-color tbody tr:nth-child(odd),
	body.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-pale-blue-background-color tbody tr:nth-child(odd) {
		background-color: #1d2b3a !important;
	}

	html[data-scheme="dark"] .wp-block-table.is-style-stripes.has-subtle-pale-pink-background-color tbody tr:nth-child(odd),
	html.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-pale-pink-background-color tbody tr:nth-child(odd),
	body.is-dark-theme .wp-block-table.is-style-stripes.has-subtle-pale-pink-background-color tbody tr:nth-child(odd) {
		background-color: #37232b !important;
	}

	/* Calendar Block */
	html[data-scheme="dark"] .wp-block-calendar table,
	html.is-dark-theme .wp-block-calendar table,
	body.is-dark-theme .wp-block-calendar table {
		color: var(--wp--preset--color--contrast, #f0f0f1) !important;
	}

	html[data-scheme="dark"] .wp-block-calendar table td,
	html[data-scheme="dark"] .wp-block-calendar table th,
	html.is-dark-theme .wp-block-calendar table td,
	html.is-dark-theme .wp-block-calendar table th {
		border-color: var(--wp--preset--color--tertiary, #3f3f46) !important;
	}

	html[data-scheme="dark"] .wp-block-calendar table th,
	html.is-dark-theme .wp-block-calendar table th {
		background-color: var(--wp--preset--color--base-3, #20202b) !important;
	}

	html[data-scheme="dark"] .wp-block-calendar a,
	html.is-dark-theme .wp-block-calendar a {
		color: var(--wp--preset--color--accent, #8f96f7) !important;
	}

	html[data-scheme="dark"] .wp-block-calendar caption,
	html.is-dark-theme .wp-block-calendar caption {
		color: var(--wp--preset--color--secondary, #a1a1aa) !important;
	}

	/* Search Block Button Border (outside the inside-wrapper pattern) */
	html[data-scheme="dark"] .wp-block-search .wp-block-search__button,
	html.is-dark-theme .wp-block-search .wp-block-search__button,
	body.is-dark-theme .wp-block-search .wp-block-search__button {
		border-color: var(--wp--preset--color--tertiary, #3f3f46) !important;
	}
}
