/*
 * Apex Builder - Frontend CSS
 * Styles for the public-facing frontend output.
 *
 * @package ApexBuilder
 */

/* ==========================================================================
   CSS VARIABLES (overridden by theme-options global vars in <head>)
   ========================================================================== */

:root {
	--apex-primary: #2563eb;
	--apex-secondary: #7c3aed;
	--apex-text: #1f2937;
	--apex-container-width: 1200px;
	--apex-btn-radius: 6px;
	--apex-space-xs: 4px;
	--apex-space-sm: 8px;
	--apex-space-md: 16px;
	--apex-space-lg: 32px;
	--apex-space-xl: 64px;
}

/* ==========================================================================
   BASE RESET (scoped to builder content)
   ========================================================================== */

.apex-builder-content *,
.apex-builder-content *::before,
.apex-builder-content *::after {
	box-sizing: border-box;
}

/* ==========================================================================
   BUILDER CONTENT WRAPPER
   ========================================================================== */

.apex-builder-content {
	width: 100%;
}

/* ==========================================================================
   SECTION
   ========================================================================== */

.apex-section {
	width: 100%;
}

.apex-section-inner {
	width: 100%;
}

/* ==========================================================================
   CONTAINER
   ========================================================================== */

.apex-container {
	width: 100%;
}

/* ==========================================================================
   COLUMNS / GRID
   ========================================================================== */

.apex-columns {
	display: grid;
}

/* Responsive: collapse columns on mobile */
@media ( max-width: 768px ) {
	.apex-columns {
		grid-template-columns: 1fr !important;
	}
}

/* ==========================================================================
   HEADING
   ========================================================================== */

.apex-heading {
	margin: 0 0 0.5em;
	line-height: 1.2;
	font-weight: 700;
}

/* ==========================================================================
   TEXT
   ========================================================================== */

.apex-text {
	line-height: 1.7;
}

.apex-text p {
	margin: 0 0 1em;
}

.apex-text p:last-child {
	margin-bottom: 0;
}

/* ==========================================================================
   BUTTON
   ========================================================================== */

.apex-button-wrap {
	display: block;
}

.apex-button {
	display: inline-block;
	text-decoration: none;
	font-weight: 600;
	cursor: pointer;
	transition: opacity 0.2s, transform 0.1s;
	border: none;
	line-height: 1.4;
}

.apex-button:hover {
	opacity: 0.88;
	transform: translateY(-1px);
}

/* ==========================================================================
   IMAGE
   ========================================================================== */

.apex-image-wrap {
	display: block;
}

.apex-image {
	display: block;
	max-width: 100%;
}

/* ==========================================================================
   SPACER
   ========================================================================== */

.apex-spacer {
	display: block;
}

/* ==========================================================================
   DIVIDER
   ========================================================================== */

.apex-divider {
	display: block;
}

/* ==========================================================================
   SITE HEADER (default theme header, non-builder)
   ========================================================================== */

.apex-site-header {
	background: #fff;
	border-bottom: 1px solid #e5e7eb;
	padding: 0 var(--apex-space-lg);
}

.apex-header-inner {
	max-width: var(--apex-container-width);
	margin: 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 64px;
	gap: 16px;
}

.apex-site-logo a {
	text-decoration: none;
	font-size: 20px;
	font-weight: 700;
	color: var(--apex-text);
}

.apex-site-logo img {
	height: 40px;
	width: auto;
}

/* Primary nav */
.apex-primary-nav ul {
	list-style: none;
	display: flex;
	gap: 24px;
	margin: 0;
	padding: 0;
}

.apex-primary-nav a {
	text-decoration: none;
	color: var(--apex-text);
	font-size: 14px;
	font-weight: 500;
	transition: color 0.15s;
}

.apex-primary-nav a:hover {
	color: var(--apex-primary);
}

/* ==========================================================================
   SITE FOOTER (default theme footer, non-builder)
   ========================================================================== */

.apex-site-footer {
	border-top: 1px solid #e5e7eb;
	padding: 32px var(--apex-space-lg);
	margin-top: auto;
}

.apex-footer-inner {
	max-width: var(--apex-container-width);
	margin: 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 16px;
}

.apex-footer-credits {
	font-size: 13px;
	color: #6b7280;
}

.apex-footer-nav ul {
	list-style: none;
	display: flex;
	gap: 16px;
	margin: 0;
	padding: 0;
}

.apex-footer-nav a {
	text-decoration: none;
	color: #6b7280;
	font-size: 13px;
	transition: color 0.15s;
}

.apex-footer-nav a:hover {
	color: var(--apex-primary);
}

/* ==========================================================================
   MAIN CONTENT AREA
   ========================================================================== */

.apex-site-main {
	flex: 1;
}

.site {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
}

/* ==========================================================================
   DEFAULT PAGE CONTENT (non-builder pages)
   ========================================================================== */

.apex-page-content {
	max-width: var(--apex-container-width);
	margin: 0 auto;
	padding: var(--apex-space-xl) var(--apex-space-lg);
}

.apex-page-title {
	font-size: 2rem;
	font-weight: 700;
	margin: 0 0 var(--apex-space-lg);
	color: var(--apex-text);
	line-height: 1.2;
}

/* ==========================================================================
   404 PAGE
   ========================================================================== */

.apex-404-page {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 80px 20px;
	text-align: center;
}

.apex-404-page h1 {
	font-size: 5rem;
	font-weight: 800;
	color: #d1d5db;
	margin: 0;
}

.apex-404-page h2 {
	font-size: 1.5rem;
	margin: 8px 0 16px;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media ( max-width: 1024px ) {
	.apex-header-inner {
		padding: 0 var(--apex-space-md);
	}
}

@media ( max-width: 768px ) {
	.apex-header-inner {
		height: auto;
		flex-wrap: wrap;
		padding: var(--apex-space-sm) var(--apex-space-md);
	}

	.apex-primary-nav ul {
		gap: 12px;
	}

	.apex-site-main {
		padding: var(--apex-space-md);
	}

	.apex-footer-inner {
		flex-direction: column;
		text-align: center;
	}
}

/* ==========================================================================
   PHASE 2 — DYNAMIC ELEMENT STYLES
   ========================================================================== */

/* ── Site Logo ──────────────────────────────────────────────────────────────── */
.apex-site-logo img,
.apex-custom-header .apex-site-logo img { height: auto; display: block; }
.apex-logo-text-link,
.apex-logo-text { font-size: 1.25rem; font-weight: 700; text-decoration: none; color: inherit; }

/* ── Site Title ─────────────────────────────────────────────────────────────── */
.apex-site-title a { text-decoration: none; color: inherit; }
.apex-site-tagline { font-size: .875rem; color: #6b7280; margin: 4px 0 0; }

/* ── Navigation Menu ────────────────────────────────────────────────────────── */
.apex-nav-menu { display: flex; align-items: center; }
.apex-nav-menu.align-center { justify-content: center; }
.apex-nav-menu.align-right  { justify-content: flex-end; }

.apex-nav-menu ul {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0;
}
.apex-nav-menu ul li { position: relative; }
.apex-nav-menu ul li a {
	display: block;
	padding: 10px 16px;
	text-decoration: none;
	color: inherit;
	font-size: .9375rem;
	font-weight: 500;
	transition: color .15s;
}
.apex-nav-menu ul li a:hover { color: var(--apex-primary); }

/* Sub-menus */
.apex-nav-menu ul ul {
	display: none;
	position: absolute;
	top: 100%;
	left: 0;
	background: #fff;
	border: 1px solid #e2e8f0;
	border-radius: 6px;
	box-shadow: 0 4px 16px rgba(0,0,0,.1);
	min-width: 180px;
	z-index: 999;
	flex-direction: column;
}
.apex-nav-menu ul li:hover > ul { display: flex; }
.apex-nav-menu ul ul li a { padding: 8px 16px; }

/* ── Search Form ────────────────────────────────────────────────────────────── */
.apex-search-form { display: flex; gap: 0; }
.apex-search-field {
	flex: 1;
	padding: 8px 12px;
	border: 1px solid #d1d5db;
	border-right: 0;
	border-radius: 6px 0 0 6px;
	font-size: .9375rem;
	outline: none;
	transition: border-color .15s;
}
.apex-search-field:focus { border-color: var(--apex-primary); }
.apex-search-submit {
	padding: 8px 16px;
	background: var(--apex-primary);
	color: #fff;
	border: none;
	border-radius: 0 6px 6px 0;
	cursor: pointer;
	font-size: .9375rem;
	font-weight: 500;
	transition: background .15s;
}
.apex-search-submit:hover { background: #1d4ed8; }

/* ── Post Title ─────────────────────────────────────────────────────────────── */
.apex-post-title { margin: 0 0 var(--apex-space-md); line-height: 1.2; }
.apex-post-title a { text-decoration: none; color: inherit; }
.apex-post-title a:hover { color: var(--apex-primary); }

/* ── Featured Image ─────────────────────────────────────────────────────────── */
.apex-featured-image { margin-bottom: var(--apex-space-md); }
.apex-featured-image img,
.apex-featured-img { width: 100%; height: auto; display: block; border-radius: 6px; }

/* ── Post Content ───────────────────────────────────────────────────────────── */
.apex-post-content { line-height: 1.7; }
.apex-post-content img { max-width: 100%; height: auto; }
.apex-post-content a { color: var(--apex-primary); }

/* ── Post Meta ──────────────────────────────────────────────────────────────── */
.apex-post-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
	font-size: .875rem;
	color: #6b7280;
	margin-bottom: var(--apex-space-md);
}
.apex-post-meta a { color: inherit; text-decoration: underline; }
.apex-post-meta a:hover { color: var(--apex-primary); }
.apex-meta-sep { color: #d1d5db; }
.apex-post-meta .dashicons { font-size: 14px; vertical-align: text-bottom; }

/* ── Author Box ─────────────────────────────────────────────────────────────── */
.apex-author-box {
	display: flex;
	gap: 16px;
	padding: 24px;
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	margin-top: var(--apex-space-lg);
}
.apex-author-avatar img { border-radius: 50%; display: block; }
.apex-author-name { font-weight: 700; text-decoration: none; color: var(--apex-text); font-size: 1rem; }
.apex-author-name:hover { color: var(--apex-primary); }
.apex-author-bio { font-size: .9rem; color: #6b7280; margin: 6px 0 0; }

/* ── Comments ───────────────────────────────────────────────────────────────── */
.apex-comments-wrap { margin-top: var(--apex-space-xl); }

/* ── Archive Title ──────────────────────────────────────────────────────────── */
.apex-archive-title { margin: 0 0 var(--apex-space-md); }

/* ── Archive Description ────────────────────────────────────────────────────── */
.apex-archive-description { color: #6b7280; margin-bottom: var(--apex-space-lg); }

/* ── Posts Grid ─────────────────────────────────────────────────────────────── */
.apex-posts-grid {
	display: grid;
	gap: 24px;
}
.apex-posts-grid.cols-1 { grid-template-columns: 1fr; }
.apex-posts-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.apex-posts-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.apex-posts-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.apex-post-card {
	background: #fff;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	overflow: hidden;
	transition: box-shadow .15s;
}
.apex-post-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.08); }
.apex-post-card-thumb a { display: block; }
.apex-post-card .apex-post-thumb { width: 100%; height: 200px; object-fit: cover; display: block; }
.apex-post-card-body { padding: 16px; }
.apex-post-card-title {
	font-size: 1rem;
	font-weight: 600;
	margin: 0 0 6px;
	line-height: 1.3;
}
.apex-post-card-title a { text-decoration: none; color: inherit; }
.apex-post-card-title a:hover { color: var(--apex-primary); }
.apex-post-card-meta { font-size: .8125rem; color: #9ca3af; margin-bottom: 8px; }
.apex-post-card-excerpt { font-size: .875rem; color: #6b7280; margin: 0; line-height: 1.5; }
.apex-no-posts { color: #9ca3af; font-style: italic; padding: 20px 0; }

/* ── Pagination ─────────────────────────────────────────────────────────────── */
.apex-pagination { margin-top: var(--apex-space-xl); }
.apex-pagination .nav-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.apex-pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 36px;
	height: 36px;
	padding: 0 8px;
	border: 1px solid #e2e8f0;
	border-radius: 6px;
	text-decoration: none;
	font-size: .875rem;
	color: var(--apex-text);
	transition: background .15s, border-color .15s;
}
.apex-pagination .page-numbers:hover { background: #f1f5f9; border-color: #d1d5db; }
.apex-pagination .page-numbers.current { background: var(--apex-primary); color: #fff; border-color: var(--apex-primary); }

/* ── Breadcrumb ─────────────────────────────────────────────────────────────── */
.apex-breadcrumb {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	font-size: .875rem;
	color: #6b7280;
	margin-bottom: var(--apex-space-md);
}
.apex-breadcrumb a { color: inherit; text-decoration: underline; }
.apex-breadcrumb a:hover { color: var(--apex-primary); }
.apex-crumb-sep { margin: 0 6px; }
.apex-crumb-current { color: var(--apex-text); }

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.apex-sidebar { min-width: 0; }
.apex-sidebar .widget { margin-bottom: var(--apex-space-lg); }

/* ── Custom header/footer wrapper resets ────────────────────────────────────── */
.apex-custom-header .apex-builder-content,
.apex-custom-footer .apex-builder-content {
	width: 100%;
	max-width: 100%;
}

/* ── Placeholder text (builder preview) ─────────────────────────────────────── */
.apex-placeholder {
	color: #94a3b8;
	font-style: italic;
	padding: 16px;
	border: 2px dashed #e2e8f0;
	border-radius: 6px;
	text-align: center;
}

/* ── Responsive: posts grid & nav menu collapse ─────────────────────────────── */
@media ( max-width: 900px ) {
	.apex-posts-grid.cols-3,
	.apex-posts-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}

@media ( max-width: 600px ) {
	.apex-posts-grid.cols-2,
	.apex-posts-grid.cols-3,
	.apex-posts-grid.cols-4 { grid-template-columns: 1fr; }

	.apex-nav-menu nav { display: none; } /* Basic mobile hide — Phase 3 handles mobile menu toggle */
	.apex-search-form { flex-direction: column; }
	.apex-search-field { border-right: 1px solid #d1d5db; border-radius: 6px; margin-bottom: 4px; }
	.apex-search-submit { border-radius: 6px; }
}
