/*
Theme Name: Canvas Builder
Theme URI: https://example.com/canvas-builder
Author: Junaid Ahmed
Author URI: https://portfolio.thejunaid.in
Description: A minimal, lightweight blank canvas WordPress theme for shortcode-based plugins and custom HTML pages. Build pages entirely with shortcodes, raw HTML, or plugin-generated content — with zero theme interference.
Version: 1.0.0
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 7.4
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: canvas-builder
Tags: full-width-template, custom-background, custom-colors, custom-logo, editor-style, featured-images, flexible-header, footer-widgets, theme-options, threaded-comments, translation-ready, block-styles, wide-blocks
*/

/* ==========================================================================
   CSS Reset & Base
   ========================================================================== */

*, *::before, *::after {
	box-sizing: border-box;
}

/* ── Horizontal overflow fix ────────────────────────────────────────────────
   The browser quirk: if BOTH html and body have overflow-x:hidden they
   cancel each other out. The correct pattern is:
     html  → overflow-x: clip  (hard clip, cannot be scrolled into)
     body  → overflow-x: hidden (creates the clipping context for children)
   Together they trap any plugin / shortcode content that is wider than 100vw.
   ─────────────────────────────────────────────────────────────────────────── */
html {
	font-size: 16px;
	-webkit-text-size-adjust: 100%;
	/* clip, not hidden — clip does not create a scroll container on html */
	overflow-x: clip;
}

/* WP admin bar injects margin-top via inline !important style in wp_head().
   Our !important here beats it. Padding-0 stops any plugin resetting it. */
html,
body {
	margin: 0 !important;
	padding: 0;
}

body {
	/* hidden on body = creates a clipping scroll container that traps children */
	overflow-x: hidden;
	/* Never wider than the viewport — stops 100vw elements adding scroll */
	max-width: 100vw;
	font-family: var(--cb-font-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif);
	font-size: var(--cb-font-size, 16px);
	line-height: var(--cb-line-height, 1.6);
	color: var(--cb-color-text, #333333);
	background-color: var(--cb-color-bg, #ffffff);
}

/* ==========================================================================
   CSS Custom Properties (overridden by Customizer)
   ========================================================================== */

:root {
	--cb-font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	--cb-font-heading: inherit;
	--cb-font-size: 16px;
	--cb-line-height: 1.6;
	--cb-color-text: #333333;
	--cb-color-bg: #ffffff;
	--cb-color-link: #0073aa;
	--cb-color-link-hover: #005177;
	--cb-color-btn: #0073aa;
	--cb-color-btn-text: #ffffff;
	--cb-color-heading: #111111;
	--cb-container-width: 1200px;
	--cb-site-padding: 0px;
	--cb-site-margin: 0px;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.cb-site-wrapper {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	/* min-width:0 on flex children prevents them from overflowing the flex
	   container when content inside is wider than the available space */
	min-width: 0;
	/* Contain any child that is wider than the viewport */
	overflow-x: hidden;
	width: 100%;
	max-width: 100vw;
}

.cb-main-content {
	flex: 1;
	min-width: 0;   /* critical for flex overflow containment */
	width: 100%;
	/* display:flow-root prevents margin-top of first child (hero) collapsing
	   through this wrapper and showing as white space — safe on iOS Safari */
	display: flow-root;
}

.cb-container {
	width: 100%;
	max-width: var(--cb-container-width);
	margin-left: auto;
	margin-right: auto;
	/* Use max() so padding is never less than 0 even if custom prop is 0 */
	padding-left: max(var(--cb-site-padding), 0px);
	padding-right: max(var(--cb-site-padding), 0px);
}

.cb-layout-full .cb-container {
	max-width: 100%;
	padding: 0;
}

/* ==========================================================================
   Header
   ========================================================================== */

.cb-site-header {
	position: relative; /* Anchor for mobile nav dropdown absolute positioning */
	width: 100%;
	padding: 20px 0;
	background-color: var(--cb-color-bg, #ffffff);
	border-bottom: var(--cb-header-border, none);
	z-index: 100;
}

/* Hamburger hidden on desktop — only shown via mobile media query */
.cb-menu-toggle {
	display: none;
}

.cb-header-inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 16px;
}

.cb-site-branding .cb-site-title {
	margin: 0;
	padding: 0;
	font-size: 1.5rem;
	font-weight: 700;
	line-height: 1.2;
}

.cb-site-branding .cb-site-title a {
	color: var(--cb-color-heading, #111111);
	text-decoration: none;
}

.cb-site-branding .cb-site-description {
	margin: 2px 0 0;
	padding: 0;
	font-size: 0.85rem;
	color: #777;
	line-height: 1.3;
}

/* ==========================================================================
   Navigation
   ========================================================================== */

.cb-main-nav ul {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	gap: 24px;
	flex-wrap: wrap;
}

.cb-main-nav ul li a {
	color: var(--cb-color-text, #333);
	text-decoration: none;
	font-size: 0.95rem;
	transition: color 0.2s ease;
}

.cb-main-nav ul li a:hover {
	color: var(--cb-color-link, #0073aa);
}

/* ==========================================================================
   Page Content
   ========================================================================== */

.cb-page-title {
	margin: 0 0 24px;
	font-family: var(--cb-font-heading, inherit);
	color: var(--cb-color-heading, #111111);
	font-size: 2rem;
}

.cb-entry-content {
	width: 100%;
}

.cb-entry-content img {
	max-width: 100%;
	height: auto;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.cb-content-area {
	display: flex;
	gap: 40px;
	align-items: flex-start;
}

.cb-primary {
	flex: 1;
	min-width: 0;
}

.cb-sidebar {
	width: 300px;
	flex-shrink: 0;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.cb-site-footer {
	padding: 24px 0;
	background-color: #f9f9f9;
	border-top: 1px solid #eeeeee;
	font-size: 0.875rem;
	color: #777;
	text-align: center;
}

/* ==========================================================================
   Links & Buttons
   ========================================================================== */

a {
	color: var(--cb-color-link, #0073aa);
	transition: color 0.2s ease;
}

a:hover {
	color: var(--cb-color-link-hover, #005177);
}

.cb-btn,
button,
input[type="submit"],
input[type="button"] {
	display: inline-block;
	background-color: var(--cb-color-btn, #0073aa);
	color: var(--cb-color-btn-text, #ffffff);
	padding: 10px 20px;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-size: 1rem;
	text-decoration: none;
	transition: opacity 0.2s ease;
}

.cb-btn:hover,
button:hover,
input[type="submit"]:hover {
	opacity: 0.85;
}

/* ==========================================================================
   Headings
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
	font-family: var(--cb-font-heading, inherit);
	color: var(--cb-color-heading, #111111);
	line-height: 1.3;
	margin: 0 0 16px;
}

/* ==========================================================================
   Blank Canvas Mode
   ========================================================================== */

.cb-blank-canvas body,
body.cb-blank-canvas {
	background: #ffffff;
}

.template-blank-canvas .cb-site-header,
.template-blank-canvas .cb-site-footer,
.template-blank-canvas .cb-page-title,
.template-blank-canvas .cb-sidebar,
body.cb-hide-header .cb-site-header,
body.cb-hide-footer .cb-site-footer,
body.cb-hide-title .cb-page-title,
body.cb-hide-sidebar .cb-sidebar {
	display: none !important;
}

.template-blank-canvas .cb-main-content,
.template-blank-canvas .cb-entry-content,
.template-blank-canvas .cb-content-area {
	margin: 0 !important;
	padding: 0 !important;
}

/* ==========================================================================
   Full Width Mode
   ========================================================================== */

.cb-full-width .cb-container,
body.cb-full-width .cb-container {
	max-width: 100%;
	padding: 0;
	margin: 0;
}

/* Full-width / blank-canvas page content wrapper.
   This is the DIRECT parent of plugin/shortcode output when no-wrapper
   mode is active. It must not constrain width in any way — the plugin's
   own CSS handles its internal layout. */
.cb-page-content-full {
	display: block;
	width: 100%;
	max-width: 100%;
	margin: 0;
	padding: 0;
}

/* Ensure all direct block children of the full-width wrapper
   can safely use width:100% relative to the viewport */
.cb-page-content-full > * {
	max-width: 100%;
	box-sizing: border-box;
}

/* ==========================================================================
   Widgets
   ========================================================================== */

.cb-widget-area .widget {
	margin-bottom: 32px;
}

.cb-widget-area .widget-title {
	font-size: 1.1rem;
	font-weight: 600;
	margin-bottom: 12px;
	padding-bottom: 8px;
	border-bottom: 2px solid var(--cb-color-link, #0073aa);
}

/* ==========================================================================
   WooCommerce Basic Support
   ========================================================================== */

.woocommerce,
.woocommerce-page {
	width: 100%;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.cb-hide { display: none !important; }
.cb-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0,0,0,0);
	white-space: nowrap;
	border: 0;
}

/* ==========================================================================
   Alignment (Gutenberg)
   ========================================================================== */

.alignwide {
	margin-left: -40px;
	margin-right: -40px;
}

.alignfull {
	margin-left: calc(-50vw + 50%);
	margin-right: calc(-50vw + 50%);
	max-width: 100vw;
	width: 100vw;
}

img.alignleft, .alignleft { float: left; margin-right: 20px; margin-bottom: 10px; }
img.alignright, .alignright { float: right; margin-left: 20px; margin-bottom: 10px; }
img.aligncenter, .aligncenter { display: block; margin: 0 auto 10px; }

/* ==========================================================================
   Overflow / Content Containment
   ========================================================================== */

/* Targeted containment — only on elements we control.
   We do NOT put max-width:100% on * because it breaks plugin/page-builder
   layouts that intentionally size their children in specific ways. */
.cb-container,
.cb-content-area,
.cb-primary,
.cb-entry-content {
	max-width: 100%;
}

/* Media: hard cap at 100% of their container (not 100vw) */
img,
video,
audio,
iframe,
embed,
object {
	max-width: 100%;
	height: auto;
}

/* Tables can scroll horizontally inside their container if too wide */
table {
	max-width: 100%;
	overflow-x: auto;
	display: block; /* allows table to scroll without breaking page layout */
	white-space: nowrap;
}

/* Restore inline-table for WooCommerce and other plugins that need it */
.woocommerce table,
.wc-block-cart table,
.wc-block-checkout table {
	display: table;
	white-space: normal;
}

/* Pre and code blocks: scroll within, not overflow the page */
pre,
code {
	max-width: 100%;
	overflow-x: auto;
	white-space: pre-wrap;
	word-break: break-all;
}

/* ==========================================================================
   Responsive — Tablet  (max-width: 1024px)
   ========================================================================== */

@media (max-width: 1024px) {
	.cb-container {
		padding-left: 24px;
		padding-right: 24px;
	}

	.cb-sidebar {
		width: 260px;
	}

	.cb-content-area {
		gap: 28px;
	}

	.cb-main-nav ul {
		gap: 16px;
	}

	.cb-page-title {
		font-size: 1.75rem;
	}

	.alignwide {
		margin-left: -16px;
		margin-right: -16px;
	}
}

/* ==========================================================================
   Responsive — Mobile  (max-width: 768px)
   ========================================================================== */

@media (max-width: 768px) {

	/* -- Container: breathing room on mobile -- */
	.cb-container {
		padding-left: 16px;
		padding-right: 16px;
	}

	/* -- Header -- */
	.cb-site-header {
		padding: 12px 0;
	}

	.cb-header-inner {
		position: relative;
		flex-wrap: nowrap;      /* keep logo and hamburger on same line */
		align-items: center;
		justify-content: space-between;
		gap: 0;
	}

	/* -- Hamburger button -- */
	.cb-menu-toggle {
		display: flex;
		align-items: center;
		justify-content: center;
		background: transparent;
		border: none;
		cursor: pointer;
		padding: 8px;
		color: var(--cb-color-heading, #111);
		z-index: 1001;
		order: 3;                /* always last item in flex row */
		border-radius: 4px;
		transition: background 0.15s ease;
	}

	.cb-menu-toggle:hover {
		background: rgba(0,0,0,0.06);
	}

	.cb-menu-toggle svg {
		display: block;
		width: 24px;
		height: 24px;
		fill: currentColor;
	}

	/* Hide the close icon by default; show hamburger */
	.cb-menu-toggle .cb-icon-close { display: none; }
	.cb-menu-toggle .cb-icon-open  { display: block; }

	/* When nav is open: swap icons */
	.cb-menu-toggle[aria-expanded="true"] .cb-icon-close { display: block; }
	.cb-menu-toggle[aria-expanded="true"] .cb-icon-open  { display: none; }

	/* -- Mobile nav panel -- */
	.cb-main-nav {
		display: none;             /* hidden by default */
		position: absolute;
		top: 100%;
		left: 0;
		right: 0;
		background: var(--cb-color-bg, #ffffff);
		z-index: 1000;
		box-shadow: 0 8px 24px rgba(0,0,0,0.12);
		border-top: 1px solid rgba(0,0,0,0.08);
		max-height: calc(100svh - 60px);  /* svh = small viewport height, safe on mobile */
		overflow-y: auto;
		-webkit-overflow-scrolling: touch; /* iOS momentum scroll */
	}

	/* Open state — toggled by JS */
	.cb-main-nav.is-open {
		display: block;
	}

	.cb-main-nav ul {
		flex-direction: column;
		gap: 0;
		padding: 8px 0;
	}

	.cb-main-nav ul li {
		border-bottom: 1px solid rgba(0,0,0,0.05);
	}

	.cb-main-nav ul li:last-child {
		border-bottom: none;
	}

	.cb-main-nav ul li a {
		display: block;
		padding: 14px 20px;
		font-size: 1rem;
	}

	/* Sub-menus */
	.cb-main-nav ul ul {
		padding-left: 16px;
		border-top: 1px solid rgba(0,0,0,0.05);
	}

	/* -- Content layout -- */
	.cb-content-area {
		flex-direction: column;
		gap: 32px;
	}

	.cb-sidebar {
		width: 100%;
	}

	/* -- Typography -- */
	.cb-page-title,
	h1 {
		font-size: 1.6rem;
		word-break: break-word;
		overflow-wrap: break-word;
	}

	h2 { font-size: 1.35rem; }
	h3 { font-size: 1.15rem; }

	/* -- Alignment blocks — remove negative margins on mobile -- */
	.alignwide {
		margin-left: 0;
		margin-right: 0;
		width: 100%;
	}

	.alignfull {
		margin-left: -16px;
		margin-right: -16px;
		max-width: calc(100% + 32px);
		width: calc(100% + 32px);
	}

	/* -- Floats: kill them on mobile -- */
	.alignleft,
	.alignright,
	img.alignleft,
	img.alignright {
		float: none;
		display: block;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 16px;
		max-width: 100%;
	}

	/* -- Footer -- */
	.cb-site-footer {
		padding: 20px 0;
		font-size: 0.8rem;
	}

	.cb-footer-menu ul {
		flex-direction: column;
		gap: 8px;
	}

	/* -- Buttons -- */
	.cb-btn,
	button,
	input[type="submit"],
	input[type="button"] {
		padding: 12px 20px;   /* larger tap target */
		font-size: 1rem;
		min-height: 44px;     /* WCAG 2.5.5 minimum touch target */
	}
}

/* ==========================================================================
   Responsive — Small Mobile  (max-width: 480px)
   ========================================================================== */

@media (max-width: 480px) {
	.cb-container {
		padding-left: 12px;
		padding-right: 12px;
	}

	.cb-page-title,
	h1 {
		font-size: 1.4rem;
	}

	.cb-site-branding .cb-site-title {
		font-size: 1.1rem;
	}
}
