/*
Theme Name: KNXHUB
Theme URI: https://www.knxhub.com/
Author: KNXHUB
Description: Lightweight block theme for KNXHUB: a fast, structured KNX and DALI learning and reference hub. Replaces the Elementor build. No page builder, no jQuery, self-hosted fonts, automatic dark mode.
Requires at least: 6.6
Tested up to: 6.8
Requires PHP: 7.4
Version: 0.1.3
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: knxhub
Tags: blog, education, block-patterns, full-site-editing, wide-blocks, accessibility-ready
*/

/* ---------- Dark mode: re-map the palette, everything else follows ---------- */
@media (prefers-color-scheme: dark) {
	:root body {
		--wp--preset--color--base: #0d1117;
		--wp--preset--color--surface: #161b22;
		--wp--preset--color--border: #2b333e;
		--wp--preset--color--muted: #9aa6b5;
		--wp--preset--color--contrast: #e8edf3;
		--wp--preset--color--brand: #6ea8ff;
		--wp--preset--color--brand-soft: #14233b;
		--wp--preset--color--knx: #6ea8ff;
		--wp--preset--color--dali: #fb923c;
		--wp--preset--color--protocols: #b794f6;
		--wp--preset--color--devices: #2dd4bf;
		--wp--preset--color--tip: #12291b;
		--wp--preset--color--warning: #2e2311;
		color-scheme: dark;
	}
	:root body .wp-element-button,
	:root body .wp-block-button__link { color: #0d1117; }
}

/* ---------- Base ---------- */
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
:where(code, kbd, samp) { font-family: var(--wp--preset--font-family--mono); font-size: 0.9em; }
:where(p, li) code {
	background: var(--wp--preset--color--surface);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: 4px;
	padding: 0.1em 0.35em;
}
:focus-visible { outline: 2px solid var(--wp--preset--color--brand); outline-offset: 2px; }
img { height: auto; }
.screen-reader-text:not(:focus) { position: absolute !important; clip: rect(1px,1px,1px,1px); width: 1px; height: 1px; overflow: hidden; }

/* ---------- Header ---------- */
.knx-header {
	position: sticky; top: 0; z-index: 50;
	background: color-mix(in srgb, var(--wp--preset--color--base) 92%, transparent);
	backdrop-filter: saturate(1.4) blur(10px);
	border-bottom: 1px solid var(--wp--preset--color--border);
}
.admin-bar .knx-header { top: 32px; }
@media (max-width: 782px) { .admin-bar .knx-header { top: 0; position: relative; } }
.knx-header .wp-block-site-logo img { max-height: 40px; width: auto; }
.knx-header .wp-block-navigation__submenu-container {
	border: 1px solid var(--wp--preset--color--border) !important;
	border-radius: 10px;
	padding: 0.4rem !important;
	box-shadow: 0 12px 32px rgb(0 0 0 / 0.08);
	min-width: 240px !important;
}
.knx-header .wp-block-navigation__submenu-container .wp-block-navigation-item__content { padding: 0.45rem 0.7rem !important; border-radius: 6px; }
.knx-header .wp-block-navigation__submenu-container .wp-block-navigation-item__content:hover { background: var(--wp--preset--color--surface); }
.knx-header .wp-block-search__input { border-radius: 8px; border-color: var(--wp--preset--color--border); background: var(--wp--preset--color--surface); color: inherit; }

/* ---------- Cards ---------- */
.knx-card {
	background: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: 12px;
	overflow: hidden;
	height: 100%;
	transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.knx-card:hover { border-color: var(--wp--preset--color--brand); box-shadow: 0 8px 24px rgb(0 0 0 / 0.06); }
.knx-card .wp-block-post-featured-image { margin: 0; aspect-ratio: 16/9; background: var(--wp--preset--color--surface); }
.knx-card .wp-block-post-featured-image img { width: 100%; height: 100%; object-fit: cover; }
.knx-card .wp-block-post-title { font-size: 1.0625rem; line-height: 1.35; }
.knx-card .wp-block-post-title a::after { content: ""; position: absolute; inset: 0; }
.knx-card { position: relative; }
.knx-card .wp-block-post-terms a { position: relative; z-index: 1; }
.wp-block-post-template.is-layout-grid > li { margin: 0; }

/* Entry-point tiles on the homepage */
.knx-entry {
	position: relative;
	border: 1px solid var(--wp--preset--color--border);
	border-radius: 14px;
	background: var(--wp--preset--color--base);
	height: 100%;
	transition: border-color .15s ease, transform .15s ease;
}
.knx-entry:hover { border-color: var(--wp--preset--color--brand); transform: translateY(-2px); }
.knx-entry h3 a { color: inherit; text-decoration: none; }
.knx-entry h3 a::after { content: ""; position: absolute; inset: 0; }
.knx-entry .knx-entry__icon {
	width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
	background: var(--wp--preset--color--brand-soft); color: var(--wp--preset--color--brand);
	font-family: var(--wp--preset--font-family--mono); font-weight: 700; font-size: 0.9rem;
}
.knx-count { font-family: var(--wp--preset--font-family--mono); font-size: 0.8125rem; color: var(--wp--preset--color--muted); }

/* Topic colour chips (category slug classes added by post-terms) */
.knx-chip, .taxonomy-category.wp-block-post-terms a {
	color: var(--wp--preset--color--brand);
}
.wp-block-post-terms a[href*="/category/dali"] { color: var(--wp--preset--color--dali); }
.wp-block-post-terms a[href*="/category/protocol"] { color: var(--wp--preset--color--protocols); }
.wp-block-post-terms a[href*="devices"] { color: var(--wp--preset--color--devices); }

/* ---------- Article ---------- */
.knx-article-layout { align-items: flex-start; }
.knx-toc {
	position: sticky; top: 96px;
	font-size: 0.875rem;
	border-left: 1px solid var(--wp--preset--color--border);
	padding-left: 1rem;
	max-height: calc(100vh - 120px); overflow: auto;
}
.knx-toc:empty { display: none; }
.knx-toc__title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--wp--preset--color--muted); margin: 0 0 .6rem; }
.knx-toc ol { list-style: none; margin: 0; padding: 0; }
.knx-toc li { margin: 0 0 .45rem; line-height: 1.35; }
.knx-toc a { color: var(--wp--preset--color--muted); text-decoration: none; }
.knx-toc a:hover, .knx-toc a.is-active { color: var(--wp--preset--color--brand); }
@media (max-width: 1024px) { .knx-toc-col { display: none; } }

.knx-meta { color: var(--wp--preset--color--muted); font-size: var(--wp--preset--font-size--small); }
.knx-meta > * { margin: 0 !important; }
.knx-meta .wp-block-post-author-name a { color: inherit; }

.entry-content table, .wp-block-table table { border-collapse: collapse; width: 100%; }
.entry-content th, .entry-content td, .wp-block-table th, .wp-block-table td { border: 1px solid var(--wp--preset--color--border) !important; padding: .55rem .75rem; text-align: left; vertical-align: top; }
.entry-content thead th, .wp-block-table thead th { background: var(--wp--preset--color--surface); font-weight: 600; }
.wp-block-table { overflow-x: auto; }
.entry-content h2, .entry-content h3 { scroll-margin-top: 96px; }

/* ---------- Callouts (block styles on core/group) ---------- */
.is-style-knx-callout-tip,
.is-style-knx-callout-warning,
.is-style-knx-callout-ets,
.is-style-knx-key-facts {
	border-radius: 10px;
	padding: 1rem 1.25rem !important;
	border: 1px solid var(--wp--preset--color--border);
	border-left-width: 4px;
}
.is-style-knx-callout-tip { background: var(--wp--preset--color--tip); border-left-color: #16a34a; }
.is-style-knx-callout-warning { background: var(--wp--preset--color--warning); border-left-color: #d97706; }
.is-style-knx-callout-ets { background: var(--wp--preset--color--surface); border-left-color: var(--wp--preset--color--brand); }
.is-style-knx-callout-ets :where(p, li) { font-family: var(--wp--preset--font-family--mono); font-size: .875rem; }
.is-style-knx-key-facts { background: var(--wp--preset--color--brand-soft); border-left-color: var(--wp--preset--color--brand); }
.is-style-knx-key-facts ul { margin: 0; padding-left: 1.1rem; }
.is-style-knx-key-facts li + li { margin-top: .3rem; }
[class*="is-style-knx-"] > :first-child { margin-top: 0; }
[class*="is-style-knx-"] > :last-child { margin-bottom: 0; }

/* ---------- Sponsor slot: fixed size, never shifts the layout ---------- */
.knx-sponsor {
	min-height: 120px;
	border: 1px dashed var(--wp--preset--color--border);
	border-radius: 10px;
	display: grid; place-items: center;
	position: relative;
	color: var(--wp--preset--color--muted);
	font-size: var(--wp--preset--font-size--small);
}
.knx-sponsor::before {
	content: "Sponsored";
	position: absolute; top: .5rem; left: .75rem;
	font-size: .6875rem; text-transform: uppercase; letter-spacing: .08em;
}
.knx-sponsor--rail { min-height: 250px; }

/* ---------- Newsletter ---------- */
.knx-newsletter { border-radius: 16px; }
.knx-newsletter form { display: flex; gap: .5rem; flex-wrap: wrap; }
.knx-newsletter input[type="email"] {
	flex: 1 1 220px; min-height: 44px; padding: 0 .9rem;
	border: 1px solid var(--wp--preset--color--border); border-radius: 8px;
	background: var(--wp--preset--color--base); color: inherit; font: inherit;
}

/* ---------- Pagination & misc ---------- */
.wp-block-query-pagination { gap: .4rem; }
.wp-block-query-pagination-numbers .page-numbers {
	display: inline-grid; place-items: center; min-width: 2.25rem; height: 2.25rem;
	border: 1px solid var(--wp--preset--color--border); border-radius: 8px; text-decoration: none;
}
.wp-block-query-pagination-numbers .page-numbers.current { background: var(--wp--preset--color--brand); color: #fff; border-color: var(--wp--preset--color--brand); }
.knx-breadcrumbs { font-size: var(--wp--preset--font-size--small); color: var(--wp--preset--color--muted); }
.knx-breadcrumbs a { color: inherit; }

.knx-footer a { color: var(--wp--preset--color--muted); text-decoration: none; }
.knx-footer a:hover { color: var(--wp--preset--color--brand); }
.knx-footer ul { list-style: none; padding: 0; margin: 0; }
.knx-footer li { margin: 0 0 .45rem; }

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Related articles (end of article) ---------- */
.knx-related { margin-top: var(--wp--preset--spacing--50); }
.knx-related__grid { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.knx-related .knx-card__body { padding: .9rem 1rem 1rem; }
.knx-related .wp-block-post-title { font-size: .9375rem; margin: 0; }
.knx-related .wp-block-post-title a { color: var(--wp--preset--color--contrast); text-decoration: none; }

/* ---------- Plugin templates that use get_header()/get_footer() (device pages) ---------- */
.knx-classic {
	max-width: var(--wp--style--global--wide-size, 1200px);
	margin: 0 auto;
	padding: var(--wp--preset--spacing--40) clamp(1rem, 4vw, 2rem) 0;
}
.knx-classic h1 { font-size: var(--wp--preset--font-size--xx-large); }
.knx-classic table { border-collapse: collapse; width: 100%; }
.knx-classic th, .knx-classic td { border: 1px solid var(--wp--preset--color--border); padding: .55rem .75rem; text-align: left; }

/* Phones: the homepage hero has its own search, so the header keeps just logo + menu. */
@media (max-width: 600px) {
	.knx-header .knx-header-search { display: none; }
}

/* ---------- Calculator posts ----------
   Each calculator carries its own inline <style> written for a white page and a
   fixed 700px box (body, h2 and button rules leak to the whole page). These rules
   win on specificity, so the calculators fit phones and follow light/dark mode. */
html body { background: var(--wp--preset--color--base); font-family: var(--wp--preset--font-family--sans); }
html h2 { color: var(--wp--preset--color--contrast); }
html .entry-content h2 { margin-top: 2.5rem; }
.entry-content .container {
	box-sizing: border-box; width: auto; max-width: 100%; margin: 1.5rem 0;
	background: var(--wp--preset--color--surface); color: var(--wp--preset--color--contrast);
	border: 1px solid var(--wp--preset--color--border); border-radius: 12px; padding: 1.25rem;
}
html .entry-content .container h2 { margin-top: 0; }
.entry-content .container table { width: 100%; border-collapse: collapse; border: 0; }
.entry-content .container td { border: 0; padding: 6px 4px; vertical-align: middle; }
.entry-content .container input,
.entry-content .container select {
	box-sizing: border-box; width: 100%; padding: .55rem .7rem; font: inherit;
	background: var(--wp--preset--color--base); color: var(--wp--preset--color--contrast);
	border: 1px solid var(--wp--preset--color--border); border-radius: 6px;
}
.entry-content .container button {
	background: var(--wp--preset--color--brand); color: #fff; border: 0; border-radius: 8px;
	padding: .65rem 1.15rem; font: inherit; font-weight: 600; cursor: pointer;
}
.entry-content .container button:hover { background: var(--wp--preset--color--contrast); color: var(--wp--preset--color--base); }
.entry-content .container .result {
	background: var(--wp--preset--color--base); color: var(--wp--preset--color--contrast);
	border: 1px solid var(--wp--preset--color--border); border-radius: 8px; overflow-x: auto;
}
.entry-content .container .result h3 { margin-top: 0; }
.entry-content .container .pass { color: #16a34a; }
.entry-content .container .fail { color: #dc2626; }
.entry-content .container .warning { color: #d97706; }
@media (max-width: 600px) {
	.entry-content .container td { display: block; width: auto; padding: 4px 0; }
	.entry-content .container td[colspan] { padding-top: 10px; text-align: left; }
}

/* The theme builds its own "On this page" list, so hide the Easy Table of Contents box
   (it also ignores dark mode). Turn the plugin off once nothing else needs it. */
.entry-content #ez-toc-container, .entry-content .ez-toc-container { display: none; }
