/**
 * Tile Box Calculator — front-end styles.
 * All colours/spacing are exposed as CSS custom properties so Elementor's
 * native style controls can override them per-widget-instance without any
 * inline style attributes.
 */

.tbc-woo-calculator {
	--tbc-accent: #1f8a3b;
	--tbc-header-bg: #232e3f;
	--tbc-openings-accent: #d6336c;
	--tbc-radius: 14px;
	--tbc-text: #1a1a1a;
	--tbc-muted: #6b7280;
	--tbc-border: #e5e7eb;
	--tbc-bg: #ffffff;
	--tbc-surface: #f8fafc;
	font-family: var(--tbc-font, inherit);
	color: var(--tbc-text);
	box-sizing: border-box;
	line-height: 1.4;
}

.tbc-woo-calculator *,
.tbc-woo-calculator *::before,
.tbc-woo-calculator *::after {
	box-sizing: inherit;
}

/*
 * Host themes frequently ship broad, high-specificity rules for bare
 * `input`/`button`/`label` elements (e.g. full-width form fields). The
 * declarations below are the ones that actively define this widget's
 * layout, so they carry `!important` to stay correct regardless of the
 * surrounding theme's stylesheet.
 */

/* ---------- Compact trigger row ---------- */

.tbc-trigger {
	display: flex !important;
	flex-direction: column !important;
	gap: 16px;
	padding: 20px 0;
	border-top: 1px solid var(--tbc-border);
	border-bottom: 1px solid var(--tbc-border);
	width: auto !important;
}

.tbc-trigger-row {
	display: flex !important;
	align-items: center !important;
	flex-wrap: wrap;
	gap: 20px;
	width: auto !important;
}

.tbc-trigger-price {
	font-size: 1.5rem;
	font-weight: 800;
	color: var(--tbc-header-bg);
	white-space: nowrap;
	flex: 0 0 auto;
}

.tbc-trigger-price-unit {
	font-weight: 500;
	color: var(--tbc-muted);
	font-size: 1rem;
}

.tbc-trigger-field {
	display: inline-flex !important;
	align-items: center !important;
	gap: 8px;
	flex: 0 0 auto;
}

.tbc-trigger-field input {
	display: block !important;
	width: 70px !important;
	max-width: 70px !important;
	min-height: 46px !important;
	height: 46px !important;
	padding: 0 8px !important;
	margin: 0 !important;
	font-size: 16px !important; /* stops iOS Safari auto-zooming the page on focus */
	text-align: center;
	border: 1.5px solid var(--tbc-border) !important;
	border-radius: 10px !important;
	background: var(--tbc-bg);
	box-shadow: none !important;
}

.tbc-trigger-field input:focus-visible {
	outline: none;
	border-color: var(--tbc-accent) !important;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--tbc-accent) 25%, transparent) !important;
}

.tbc-trigger-unit {
	font-weight: 700;
	font-size: 0.95rem;
	white-space: nowrap;
}

/*
 * The required quantity can be a compound result ("1 Pallet + 3 Boxes"),
 * not just a bare number, so this is a box that sizes to its content
 * rather than a fixed-width input like the area field.
 */
.tbc-trigger-qty {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: auto !important;
	min-height: 46px !important;
	padding: 0 14px !important;
	margin: 0 !important;
	font-size: 16px;
	font-weight: 700;
	white-space: nowrap;
	text-align: center;
	border: 1.5px solid var(--tbc-border);
	border-radius: 10px;
	background: var(--tbc-surface);
	color: var(--tbc-text);
}

.tbc-trigger-link,
.tbc-trigger-link:hover,
.tbc-trigger-link:focus,
.tbc-trigger-link:active {
	display: inline-flex !important;
	flex-wrap: nowrap !important;
	align-items: center !important;
	gap: 8px;
	margin-left: auto;
	background: none !important;
	border: none !important;
	padding: 4px !important;
	cursor: pointer;
	color: var(--tbc-header-bg) !important;
	font-weight: 600;
	font-size: 0.95rem;
	text-decoration: underline;
	text-underline-offset: 3px;
	flex: 0 0 auto;
	width: auto !important;
	min-width: max-content;
}

.tbc-trigger-link:hover,
.tbc-trigger-link:focus-visible {
	color: var(--tbc-accent) !important;
}

.tbc-trigger-link:focus-visible {
	outline: 2px solid var(--tbc-accent);
	outline-offset: 3px;
	border-radius: 4px;
}

.tbc-trigger-icon {
	display: inline-flex !important;
	flex: 0 0 auto;
	color: var(--tbc-header-bg);
}

.tbc-trigger-link-text {
	white-space: nowrap;
	display: inline-block !important;
}

.tbc-trigger-cart {
	width: 100%;
}

/* ---------- Waste toggle ---------- */

.tbc-waste-toggle {
	display: flex !important;
	align-items: center !important;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 12px 16px;
	margin: 0 0 20px;
	padding: 14px 16px;
	background: var(--tbc-surface);
	border-radius: calc(var(--tbc-radius) * 0.5);
	cursor: pointer;
	width: auto !important;
}

.tbc-trigger .tbc-waste-toggle {
	margin: 0;
}

.tbc-waste-toggle-text {
	font-size: 0.9rem;
	color: var(--tbc-text);
}

.tbc-waste-toggle-text strong {
	color: var(--tbc-header-bg);
}

.tbc-waste-toggle-control {
	display: inline-flex !important;
	align-items: center !important;
	gap: 10px;
	flex-shrink: 0;
}

.tbc-waste-percent {
	font-weight: 700;
	font-size: 0.9rem;
	white-space: nowrap;
}

.tbc-waste-switch {
	position: relative;
	display: inline-flex !important;
	width: 44px;
	height: 24px;
	flex-shrink: 0;
}

.tbc-waste-switch input {
	position: absolute !important;
	inset: 0;
	margin: 0 !important;
	width: 44px !important;
	height: 24px !important;
	opacity: 0;
	cursor: pointer;
	z-index: 1;
}

.tbc-waste-switch-track {
	position: absolute;
	inset: 0;
	border-radius: 999px;
	background: var(--tbc-border);
	transition: background-color 0.15s ease;
	pointer-events: none;
}

.tbc-waste-switch-track::before {
	content: '';
	position: absolute;
	top: 3px;
	left: 3px;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
	transition: transform 0.15s ease;
}

.tbc-waste-switch input:checked ~ .tbc-waste-switch-track {
	background: var(--tbc-accent);
}

.tbc-waste-switch input:checked ~ .tbc-waste-switch-track::before {
	transform: translateX(20px);
}

.tbc-waste-switch input:focus-visible ~ .tbc-waste-switch-track {
	outline: 2px solid var(--tbc-accent);
	outline-offset: 2px;
}

/* ---------- Modal ---------- */

.tbc-modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(15, 15, 30, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	z-index: 100000;
}

.tbc-modal-overlay[hidden] {
	display: none;
}

body.tbc-modal-open {
	overflow: hidden;
}

.tbc-modal {
	width: 100%;
	max-width: 640px;
	max-height: calc(100vh - 48px);
	background: var(--tbc-bg);
	border-radius: var(--tbc-radius);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.tbc-modal-header {
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	position: relative;
	background: var(--tbc-header-bg) !important;
	color: #fff !important;
	padding: 20px 56px !important;
	min-height: 64px;
	flex-shrink: 0;
}

.tbc-modal-title {
	margin: 0 !important;
	padding: 0 !important;
	font-size: 1.3rem !important;
	line-height: 1.3 !important;
	font-weight: 800 !important;
	text-align: center;
	color: #fff !important;
}

.tbc-modal-close,
.tbc-modal-close:hover,
.tbc-modal-close:focus,
.tbc-modal-close:active {
	position: absolute;
	top: 50%;
	right: 16px;
	transform: translateY(-50%);
	width: 36px;
	height: 36px;
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	background: transparent !important;
	border: none !important;
	color: #fff !important;
	font-size: 1.4rem;
	line-height: 1;
	cursor: pointer;
	border-radius: 50%;
}

.tbc-modal-close:hover,
.tbc-modal-close:focus-visible {
	background: rgba(255, 255, 255, 0.15) !important;
}

.tbc-modal-close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.tbc-modal-body {
	padding: 24px 28px 28px;
	overflow-y: auto;
}

.tbc-modal-subtitle {
	margin: 0 0 18px;
	font-size: 1.1rem;
	font-weight: 800;
	color: var(--tbc-header-bg);
}

/* Row blocks (shared between Wall/Floor and Window/Door) */

.tbc-rows-header {
	display: grid;
	grid-template-columns: 1fr 76px 20px 76px 20px 76px 32px;
	gap: 8px;
	padding: 0 0 8px;
}

.tbc-rows-header span {
	grid-column: 2 / 4;
	font-size: 0.8rem;
	color: var(--tbc-muted);
	text-align: center;
}

.tbc-rows-header span:nth-child(2) {
	grid-column: 4 / 6;
}

.tbc-rows-header span:nth-child(3) {
	grid-column: 6 / 7;
}

.tbc-rows {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.tbc-row {
	display: grid;
	grid-template-columns: 1fr auto 32px;
	align-items: center;
	gap: 8px;
}

.tbc-row-label {
	font-size: 0.92rem;
	font-weight: 600;
	color: var(--tbc-text);
}

.tbc-row-fields {
	display: grid;
	grid-template-columns: 76px 20px 76px 20px 76px;
	align-items: center;
	gap: 8px;
	justify-self: end;
}

.tbc-row-input {
	width: 76px;
	min-height: 44px;
	padding: 0 8px;
	text-align: center;
	font-size: 16px; /* stops iOS Safari auto-zooming the page on focus */
	border: 1.5px solid var(--tbc-border);
	border-radius: 8px;
	background: var(--tbc-bg);
}

.tbc-row-input[aria-invalid='true'] {
	border-color: #dc2626;
}

.tbc-row-input:focus-visible {
	outline: none;
	border-color: var(--tbc-accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--tbc-accent) 25%, transparent);
}

.tbc-row-op {
	text-align: center;
	color: var(--tbc-muted);
	font-weight: 600;
}

.tbc-row-area {
	display: block;
	width: 76px;
	text-align: center;
	font-weight: 700;
}

.tbc-row-remove,
.tbc-row-remove:hover,
.tbc-row-remove:focus,
.tbc-row-remove:active {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	box-sizing: border-box !important;
	width: 28px !important;
	height: 28px !important;
	min-width: 28px !important;
	max-width: 28px !important;
	margin: 0 !important;
	padding: 0 !important;
	border-radius: 50% !important;
	border: none !important;
	background: var(--tbc-surface) !important;
	color: var(--tbc-muted) !important;
	font-size: 1rem;
	line-height: 1;
	cursor: pointer;
	justify-self: center;
}

.tbc-row-remove:hover,
.tbc-row-remove:focus-visible {
	background: #fee2e2 !important;
	color: #b91c1c !important;
}

.tbc-row-remove:disabled {
	visibility: hidden;
}

.tbc-rows-footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 12px;
	margin-top: 14px;
}

.tbc-add-row,
.tbc-add-row:hover,
.tbc-add-row:focus,
.tbc-add-row:active {
	display: inline-flex !important;
	align-items: center !important;
	gap: 6px;
	width: auto !important;
	background: none !important;
	border: none !important;
	padding: 4px 0 !important;
	margin: 0 !important;
	color: var(--tbc-accent) !important;
	font-weight: 700;
	font-size: 0.92rem;
	cursor: pointer;
}

.tbc-add-row-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: var(--tbc-accent);
	color: #fff;
	font-size: 0.9rem;
	line-height: 1;
}

.tbc-add-row:focus-visible {
	outline: 2px solid var(--tbc-accent);
	outline-offset: 3px;
	border-radius: 4px;
}

.tbc-rows-total {
	font-weight: 700;
	color: var(--tbc-header-bg);
}

.tbc-divider {
	margin: 20px 0;
	border: none;
	border-top: 1px solid var(--tbc-border);
}

/* Subtract Window/Door accordion */

.tbc-accordion-toggle,
.tbc-accordion-toggle:hover,
.tbc-accordion-toggle:focus,
.tbc-accordion-toggle:active {
	width: 100% !important;
	display: flex !important;
	align-items: center !important;
	justify-content: space-between !important;
	background: none !important;
	border: none !important;
	padding: 4px 0 !important;
	margin: 0 !important;
	font-size: 1rem;
	font-weight: 700;
	color: var(--tbc-text) !important;
	cursor: pointer;
}

.tbc-accordion-toggle:focus-visible {
	outline: 2px solid var(--tbc-accent);
	outline-offset: 3px;
	border-radius: 4px;
}

.tbc-accordion-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: var(--tbc-openings-accent);
	color: #fff;
	font-size: 1rem;
	transition: transform 0.15s ease;
}

.tbc-accordion-toggle[aria-expanded='true'] .tbc-accordion-icon {
	transform: rotate(90deg);
}

.tbc-accordion-body {
	margin-top: 18px;
}

.tbc-accordion-body[hidden] {
	display: none;
}

/* Warnings */

.tbc-warnings:not(:empty) {
	padding: 12px 16px;
	border-radius: calc(var(--tbc-radius) * 0.4);
	background: #fffbeb;
	border: 1px solid #fbbf24;
	color: #92400e;
	font-size: 0.85rem;
	margin-bottom: 16px;
}

/* Footer */

.tbc-modal-footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 16px;
}

.tbc-modal-summary {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.tbc-modal-summary-label {
	font-size: 0.85rem;
	color: var(--tbc-muted);
}

.tbc-modal-summary-value {
	font-size: 1.7rem;
	font-weight: 800;
	color: var(--tbc-header-bg);
}

.tbc-modal-summary-qty {
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--tbc-accent);
}

.tbc-btn {
	appearance: none;
	border: 1.5px solid transparent;
	border-radius: 10px;
	font-size: 1rem;
	font-weight: 700;
	cursor: pointer;
	min-height: 54px;
	padding: 0 24px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	transition: transform 0.1s ease, opacity 0.15s ease;
}

.tbc-btn:focus-visible {
	outline: 3px solid color-mix(in srgb, var(--tbc-accent) 50%, transparent);
	outline-offset: 2px;
}

.tbc-btn:active {
	transform: translateY(1px);
}

.tbc-btn:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.tbc-btn-primary {
	background: var(--tbc-header-bg);
	border-color: var(--tbc-header-bg);
	color: #fff;
}

.tbc-cart-notice {
	margin-top: 14px;
	padding: 12px 16px;
	border-radius: calc(var(--tbc-radius) * 0.4);
	background: color-mix(in srgb, var(--tbc-accent) 12%, transparent);
	color: var(--tbc-accent);
	font-weight: 600;
	font-size: 0.9rem;
}

.tbc-cart-notice[data-type='error'] {
	background: #fee2e2;
	color: #b91c1c;
}

/* Admin notice */

.tbc-woo-admin-notice {
	padding: 14px 18px;
	border-radius: 8px;
	background: #fef3c7;
	border: 1px solid #f59e0b;
	color: #78350f;
	font-size: 0.9rem;
}

.tbc-debug-table {
	margin-top: 10px;
	border-collapse: collapse;
	font-size: 0.75rem;
	width: 100%;
}

.tbc-debug-table th,
.tbc-debug-table td {
	text-align: left;
	padding: 4px 8px;
	border-bottom: 1px solid rgba(120, 53, 15, 0.2);
}

.tbc-debug-missing {
	color: #b91c1c;
	font-weight: 700;
}

.tbc-debug-ok {
	color: #15803d;
	font-weight: 600;
}

.tbc-debug-hint {
	margin: 8px 0 0;
	font-size: 0.75rem;
	opacity: 0.85;
}

/* Responsive */

@media (max-width: 640px) {
	.tbc-trigger {
		gap: 16px;
	}

	.tbc-trigger-qty {
		font-size: 15px;
		padding: 0 10px !important;
		white-space: normal;
		text-align: center;
	}

	.tbc-trigger-link {
		margin-left: 0;
		width: 100% !important;
		justify-content: center !important;
		padding: 10px 0 !important;
	}

	.tbc-modal-overlay {
		padding: 0;
	}

	.tbc-modal {
		max-width: none;
		max-height: 100vh;
		height: 100%;
		border-radius: 0;
	}

	.tbc-rows-header {
		display: none;
	}

	.tbc-row {
		grid-template-columns: 1fr 28px;
		grid-template-areas: 'label remove' 'fields fields';
		row-gap: 8px;
	}

	.tbc-row-label {
		grid-area: label;
	}

	.tbc-row-remove {
		grid-area: remove;
	}

	.tbc-row-fields {
		grid-area: fields;
		justify-self: start;
		grid-template-columns: 1fr 20px 1fr 20px 1fr;
		width: 100%;
	}

	.tbc-row-input,
	.tbc-row-area {
		width: 100%;
	}

	.tbc-modal-footer {
		flex-direction: column;
		align-items: stretch;
	}

	.tbc-btn-primary {
		width: 100%;
	}
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.tbc-woo-calculator * {
		transition: none !important;
		animation: none !important;
	}
}

/* Print */
@media print {
	.tbc-modal-overlay,
	.tbc-trigger-link {
		display: none !important;
	}
}
