/*
 * Component styles: cards, hero extras, search panel, newsletter,
 * single/page layouts, topics grid, theme toggle icon states.
 * Depends on custom properties defined in style.css (loaded first).
 */

/* =========================================================
   Theme toggle icon swap — driven by [data-theme] on <body>,
   set in header.php.
   ========================================================= */
.tpm-icon-sun { display: none; }
.tpm-icon-moon { display: block; }
[data-theme="dark"] .tpm-icon-sun { display: block; }
[data-theme="dark"] .tpm-icon-moon { display: none; }

/* =========================================================
   Search panel — #tpm-search-panel toggled via [hidden] by main.js
   ========================================================= */
.tpm-search-panel {
	border-bottom: 1px solid var(--tpm-color-border);
	background: var(--tpm-color-bg);
	padding: var(--tpm-space-3) 0;
}
.tpm-search-panel[hidden] { display: none; }
.tpm-search-input {
	width: 100%;
	padding: var(--tpm-space-2) var(--tpm-space-3);
	border: 1px solid var(--tpm-color-border);
	border-radius: var(--tpm-radius);
	background: var(--tpm-color-surface);
	color: var(--tpm-color-text);
	font-size: 1rem;
}
.tpm-search-results {
	margin-top: var(--tpm-space-2);
	max-height: min(320px, 60vh);
	overflow-y: auto;
}
.tpm-search-results:empty { display: none; }
.tpm-search-result {
	display: block;
	padding: var(--tpm-space-2) var(--tpm-space-3);
	border-radius: var(--tpm-radius);
	color: var(--tpm-color-text);
}
.tpm-search-result:hover, .tpm-search-result:focus {
	background: var(--tpm-color-bg-alt);
	text-decoration: none;
}
.tpm-search-result-type {
	display: inline-block;
	font-size: 0.75rem;
	text-transform: uppercase;
	color: var(--tpm-color-text-muted);
	margin-left: var(--tpm-space-2);
}

/* =========================================================
   Card grid — .tpm-card used by template-parts/content.php
   and woocommerce/content-product.php
   ========================================================= */
.tpm-card-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--tpm-space-4);
	list-style: none;
	margin: var(--tpm-space-5) 0;
	padding: 0;
}
.tpm-card {
	background: var(--tpm-color-surface);
	border: 1px solid var(--tpm-color-border);
	border-radius: var(--tpm-radius-lg);
	overflow: hidden;
	box-shadow: var(--tpm-shadow);
	display: flex;
	flex-direction: column;
}
.tpm-card-thumb { position: relative; aspect-ratio: 3 / 2; overflow: hidden; }
.tpm-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tpm-card-body { padding: var(--tpm-space-3); display: flex; flex-direction: column; gap: var(--tpm-space-2); flex: 1; }
.tpm-card-badge {
	align-self: flex-start;
	background: var(--tpm-color-bg-alt);
	color: var(--tpm-color-primary);
	font-size: 0.75rem;
	font-weight: 700;
	padding: 2px var(--tpm-space-2);
	border-radius: 999px;
}
.tpm-badge-sale { background: var(--tpm-color-danger); color: #fff; position: absolute; top: var(--tpm-space-2); left: var(--tpm-space-2); }
.tpm-card-title { font-size: 1.05rem; margin: 0; }
.tpm-card-title a { color: var(--tpm-color-text); }
.tpm-card-meta {
	display: flex;
	align-items: center;
	gap: var(--tpm-space-2);
	margin-top: var(--tpm-space-2);
	font-size: 0.8125rem;
	color: var(--tpm-color-text-muted);
}
.tpm-card-author { display: flex; align-items: center; gap: var(--tpm-space-1); }
.tpm-card-author img { border-radius: 50%; }
.tpm-card-price { font-weight: 700; color: var(--tpm-color-text); }

/* =========================================================
   Topics grid
   ========================================================= */
.tpm-topics { padding: var(--tpm-space-6) 0; }
.tpm-topics-grid {
	display: flex;
	flex-wrap: wrap;
	gap: var(--tpm-space-2);
	margin-top: var(--tpm-space-3);
}
.tpm-topic-pill {
	padding: var(--tpm-space-2) var(--tpm-space-4);
	border: 1px solid var(--tpm-color-border);
	border-radius: 999px;
	color: var(--tpm-color-text);
}
.tpm-topic-pill:hover, .tpm-topic-pill:focus {
	border-color: var(--tpm-color-primary);
	color: var(--tpm-color-primary);
	text-decoration: none;
}

/* =========================================================
   Newsletter
   ========================================================= */
.tpm-newsletter {
	background: var(--tpm-color-bg-alt);
	padding: var(--tpm-space-6) 0;
	text-align: center;
}
.tpm-newsletter-form {
	display: flex;
	gap: var(--tpm-space-2);
	justify-content: center;
	max-width: 480px;
	margin: var(--tpm-space-3) auto 0;
	flex-wrap: wrap;
}
.tpm-newsletter-form input[type="email"] {
	flex: 1;
	min-width: 220px;
	padding: var(--tpm-space-2) var(--tpm-space-3);
	border: 1px solid var(--tpm-color-border);
	border-radius: var(--tpm-radius);
}
.tpm-newsletter-status { width: 100%; font-size: 0.875rem; margin-top: var(--tpm-space-2); }
.tpm-newsletter-status.is-success { color: var(--tpm-color-success); }
.tpm-newsletter-status.is-error { color: var(--tpm-color-danger); }

/* =========================================================
   Single post / Page layout
   ========================================================= */
.tpm-single-layout {
	display: grid;
	grid-template-columns: 1fr 300px;
	gap: var(--tpm-space-5);
	padding: var(--tpm-space-6) 0;
	align-items: start;
}
.tpm-single-article { grid-column: 1; }
.tpm-single-sidebar { grid-column: 2; }
.tpm-single-meta { display: flex; align-items: center; gap: var(--tpm-space-2); color: var(--tpm-color-text-muted); font-size: 0.875rem; margin: var(--tpm-space-2) 0 var(--tpm-space-4); }
.tpm-single-thumb { margin-bottom: var(--tpm-space-4); border-radius: var(--tpm-radius-lg); overflow: hidden; }
.tpm-single-content { max-width: 720px; line-height: 1.75; }
.tpm-single-content img { border-radius: var(--tpm-radius); }
.tpm-tags { display: flex; gap: var(--tpm-space-2); flex-wrap: wrap; margin-top: var(--tpm-space-4); }

.tpm-page-hero { aspect-ratio: 16 / 6; overflow: hidden; }
.tpm-page-hero img { width: 100%; height: 100%; object-fit: cover; }
.tpm-page-header { padding: var(--tpm-space-5) 0 var(--tpm-space-3); }

/* =========================================================
   Archive / search / 404
   ========================================================= */
.tpm-archive-header { padding: var(--tpm-space-6) 0 var(--tpm-space-3); }
.tpm-no-results { text-align: center; padding: var(--tpm-space-7) 0; }
.tpm-social-links { list-style: none; display: flex; gap: var(--tpm-space-3); padding: 0; margin: var(--tpm-space-3) 0 0; }

@media (max-width: 1024px) {
	.tpm-card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 782px) {
	.tpm-card-grid { grid-template-columns: 1fr; }
	.tpm-single-layout { grid-template-columns: 1fr; }
	.tpm-single-sidebar { grid-column: 1; }
}
@media (max-width: 480px) {
	.tpm-card-grid { gap: var(--tpm-space-3); margin: var(--tpm-space-4) 0; }
}

/* =========================================================
   Layout-utility selectors — small display/spacing rules
   consumed directly by template class names (index.php,
   home.php, archive.php, search.php, 404.php, single.php,
   the WooCommerce templates, and template-parts/content.php).
   ========================================================= */
.tpm-icon { width: 20px; height: 20px; }

.tpm-main { display: block; }
.tpm-single, .tpm-archive, .tpm-search, .tpm-blog-index, .tpm-page, .tpm-404, .tpm-featured { display: block; }
.tpm-shop-main { display: block; }

.tpm-archive-description { color: var(--tpm-color-text-muted); margin-top: var(--tpm-space-2); }

.tpm-card-date, .tpm-card-reading-time {
	color: var(--tpm-color-text-muted);
	font-size: 0.8125rem;
}

.tpm-single-header { margin-bottom: var(--tpm-space-4); }
.tpm-single-footer { margin-top: var(--tpm-space-5); padding-top: var(--tpm-space-4); border-top: 1px solid var(--tpm-color-border); }
.tpm-single-footer.has-tags .tpm-tags { display: flex; flex-wrap: wrap; gap: var(--tpm-space-2); }

.tpm-page-links { margin-top: var(--tpm-space-4); }

.tpm-menu-item--has-children { position: relative; }

/* =========================================================
   MEGA MENU (nav redesign)
   Emitted by TechProMaster_Nav_Walker (inc/walkers.php):
   .tpm-mega-panel > .tpm-mega-panel-inner > ul.tpm-mega-grid
     > li.tpm-mega-col > a.tpm-mega-col-head (+ optional
       ul.tpm-mega-col-links > li.tpm-mega-link-item > a.tpm-mega-link)
   ========================================================= */
.tpm-mega-panel {
	position: fixed;
	top: var(--tpm-header-height);
	left: 50%;
	width: min(1100px, calc(100vw - 32px));
	margin: 0;
	padding: 8px 0 0;
	opacity: 0;
	pointer-events: none;
	transform: translate(-50%, -8px) scale(0.98);
	transform-origin: top center;
	transition: opacity 0.18s ease, transform 0.18s ease;
	z-index: 100;
}
.tpm-mega-panel.is-open {
	opacity: 1;
	pointer-events: auto;
	transform: translate(-50%, 0) scale(1);
}
.tpm-mega-panel-inner {
	background: var(--tpm-color-surface);
	border: 1px solid var(--tpm-color-border);
	border-radius: 16px;
	box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12), 0 4px 12px rgba(15, 23, 42, 0.06);
	padding: var(--tpm-space-5);
	max-height: calc(100vh - var(--tpm-header-height) - 32px);
	overflow-y: auto;
}
.tpm-mega-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: var(--tpm-space-5);
	list-style: none;
	margin: 0;
	padding: 0;
}
.tpm-mega-col {
	display: flex;
	flex-direction: column;
	gap: var(--tpm-space-2);
	min-width: 0;
}
.tpm-mega-col-head {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: var(--tpm-space-2);
	padding: var(--tpm-space-3);
	border-radius: 12px;
	text-decoration: none;
	transition: background-color 0.15s ease;
}
.tpm-mega-col-head:hover,
.tpm-mega-col-head:focus-visible {
	background: var(--tpm-color-bg-alt);
	text-decoration: none;
}
.tpm-mega-col-head:focus-visible {
	outline: 2px solid var(--tpm-color-primary);
	outline-offset: 2px;
}
.tpm-mega-col-icon {
	width: 36px;
	height: 36px;
	padding: 8px;
	box-sizing: border-box;
	border-radius: 10px;
	background: var(--tpm-color-bg-alt);
	color: var(--tpm-color-primary);
	flex-shrink: 0;
}
.tpm-mega-col-title {
	font-weight: 600;
	font-size: 0.9375rem;
	color: var(--tpm-color-text);
	white-space: nowrap;
}
.tpm-mega-col-desc {
	font-size: 0.8125rem;
	color: var(--tpm-color-text-muted);
	line-height: 1.4;
}
/* Grouped columns (have children): head becomes a compact section label. */
.tpm-mega-col--grouped .tpm-mega-col-head {
	flex-direction: row;
	align-items: center;
	padding: var(--tpm-space-2) var(--tpm-space-3);
}
.tpm-mega-col--grouped .tpm-mega-col-title {
	font-size: 0.8125rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--tpm-color-text-muted);
}
.tpm-mega-col--grouped .tpm-mega-col-icon {
	width: 24px;
	height: 24px;
	padding: 4px;
	background: transparent;
}
.tpm-mega-col-links {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
}
.tpm-mega-link {
	display: block;
	padding: 10px 12px;
	border-radius: 10px;
	color: var(--tpm-color-text);
	font-size: 0.9375rem;
	white-space: nowrap;
	transition: background-color 0.15s ease, color 0.15s ease;
}
.tpm-mega-link:hover,
.tpm-mega-link:focus-visible {
	background: var(--tpm-color-bg-alt);
	color: var(--tpm-color-primary);
	text-decoration: none;
}
.tpm-mega-link:focus-visible {
	outline: 2px solid var(--tpm-color-primary);
	outline-offset: 2px;
}
.tpm-mega-link[aria-current="page"] {
	color: var(--tpm-color-primary);
}

@media (prefers-reduced-motion: reduce) {
	.tpm-mega-panel,
	.tpm-hamburger-line,
	.tpm-primary-nav,
	.tpm-add-to-cart {
		transition: none !important;
	}
}

/* Tablet: simplified single-column dropdown instead of the full grid. */
@media (min-width: 783px) and (max-width: 1024px) {
	.tpm-mega-panel {
		position: absolute;
		top: 100%;
		left: 0;
		width: 320px;
		transform: translateY(-4px) scale(0.98);
	}
	.tpm-mega-panel.is-open {
		transform: translateY(4px) scale(1);
	}
	.tpm-mega-grid {
		grid-template-columns: 1fr;
	}
	.tpm-mega-col--grouped .tpm-mega-col-head {
		padding-top: var(--tpm-space-3);
	}
}

/* Mobile: mega panel collapses into an inline expandable section within the off-canvas nav. */
@media (max-width: 782px) {
	.tpm-mega-panel {
		position: static;
		width: 100%;
		opacity: 1;
		pointer-events: auto;
		transform: none;
		max-height: 0;
		overflow: hidden;
		padding: 0;
		transition: max-height 0.25s ease;
	}
	.tpm-mega-panel.is-open {
		max-height: 2000px;
	}
	.tpm-mega-panel-inner {
		border: none;
		border-radius: 0;
		box-shadow: none;
		padding: 0 var(--tpm-space-3) var(--tpm-space-3);
	}
	.tpm-mega-grid {
		grid-template-columns: 1fr;
		gap: var(--tpm-space-3);
	}
	.tpm-mega-col-head { padding-left: var(--tpm-space-2); min-height: 44px; }
	.tpm-mega-link { min-height: 44px; display: flex; align-items: center; }
	.tpm-menu-link[aria-expanded] .tpm-menu-chevron { margin-left: auto; }
	.tpm-menu-link[aria-expanded] {
		width: 100%;
		justify-content: space-between;
	}
}

.tpm-widget { margin-bottom: var(--tpm-space-4); }
.tpm-widget-title { font-size: 0.9375rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--tpm-color-text-muted); }

.tpm-footer-col--brand { grid-column: span 1; }
.tpm-footer-tagline { color: var(--tpm-color-text-muted); margin: 0 0 var(--tpm-space-2); }
.tpm-footer-widget-row { display: block; }

.tpm-download-btn { margin-top: var(--tpm-space-4); }

.tpm-hero.has-bg-image { color: #fff; }
.tpm-hero.has-bg-image h1,
.tpm-hero.has-bg-image p { color: #fff; }
.tpm-hero.has-bg-image .tpm-hero-eyebrow { color: var(--tpm-color-primary-light); }
.tpm-hero.has-bg-image .tpm-hero-stats { color: rgba(255, 255, 255, 0.85); }
.tpm-hero.has-bg-image .tpm-hero-stats strong { color: #fff; }
