/**
 * ElectronicsDIY Tools - shared design system.
 *
 * Every selector is scoped to .ediy-tool so the theme (header, footer,
 * sidebar, typography, Elementor widgets) is never affected. Selectors use
 * two classes, which is enough to win over typical theme element selectors
 * such as `input[type="text"]` or `.elementor-kit-1 button` inside the tool.
 */

.ediy-tool {
	--ediy-primary: #990099;
	--ediy-primary-hover: #770077;
	--ediy-primary-contrast: #ffffff;
	--ediy-text: #1d2733;
	--ediy-muted: #4b5664;
	--ediy-bg: #ffffff;
	--ediy-surface: #f5f7fa;
	--ediy-border: #d7dde5;
	--ediy-border-strong: #a9b3bf;
	--ediy-error: #b42318;
	--ediy-error-bg: #fef3f2;
	--ediy-warning: #7a4d00;
	--ediy-warning-bg: #fff7e0;
	--ediy-warning-border: #f0c75e;
	--ediy-focus: rgba(153, 0, 153, 0.45);
	--ediy-radius: 10px;
	--ediy-radius-sm: 6px;
	--ediy-gap: 1rem;
	--ediy-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

	position: relative;
	display: block;
	max-width: 100%;
	margin: 1.5em 0;
	padding: clamp(1rem, 3vw, 1.5rem);
	border: 1px solid var(--ediy-border);
	border-radius: var(--ediy-radius);
	background: var(--ediy-bg);
	color: var(--ediy-text);
	font-size: 1rem;
	line-height: 1.55;
	text-align: left;
	overflow-wrap: break-word;
}

.ediy-tool *,
.ediy-tool *::before,
.ediy-tool *::after {
	box-sizing: border-box;
}

/* Themes sometimes force display on elements; keep the hidden attribute reliable inside the tool. */
.ediy-tool [hidden] {
	display: none !important;
}

/* ---------- Headings & text ---------- */

.ediy-tool .ediy-tool__title {
	margin: 0 0 1rem;
	padding: 0;
	font-size: 1.35em;
	line-height: 1.3;
	color: inherit;
}

.ediy-tool .ediy-intro {
	margin: 0 0 1rem;
	color: var(--ediy-muted);
}

.ediy-tool .ediy-sr-only {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- Layout ---------- */

.ediy-tool .ediy-form {
	margin: 0;
}

.ediy-tool .ediy-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
	gap: var(--ediy-gap);
	margin: 0 0 var(--ediy-gap);
}

.ediy-tool fieldset {
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.ediy-tool legend {
	float: none;
	width: auto;
	margin: 0 0 0.4rem;
	padding: 0;
	border: 0;
	font-size: 0.95em;
	font-weight: 600;
	color: inherit;
}

/* ---------- Fields ---------- */

.ediy-tool .ediy-field {
	min-width: 0;
	margin: 0;
}

.ediy-tool .ediy-label {
	display: block;
	margin: 0 0 0.35rem;
	padding: 0;
	font-size: 0.95em;
	font-weight: 600;
	line-height: 1.35;
	color: inherit;
}

.ediy-tool .ediy-input-group {
	display: flex;
	align-items: stretch;
	gap: 0.5rem;
}

.ediy-tool .ediy-input,
.ediy-tool .ediy-select {
	display: block;
	width: 100%;
	height: auto;
	min-height: 2.75rem;
	margin: 0;
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--ediy-border-strong);
	border-radius: var(--ediy-radius-sm);
	background-color: #ffffff;
	box-shadow: none;
	color: var(--ediy-text);
	font-family: inherit;
	font-size: 1rem;
	font-weight: 400;
	line-height: 1.4;
	letter-spacing: normal;
	text-transform: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ediy-tool .ediy-input-group .ediy-input {
	flex: 1 1 auto;
	min-width: 0;
}

.ediy-tool .ediy-select {
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	padding-right: 2.1rem;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%234b5664' stroke-width='1.8' d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.7rem center;
	background-size: 12px 8px;
	cursor: pointer;
}

.ediy-tool .ediy-select--unit {
	flex: 0 0 auto;
	width: auto;
	min-width: 5.5rem;
}

.ediy-tool .ediy-unit-fixed {
	display: inline-flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	min-width: 3rem;
	padding: 0 0.75rem;
	border: 1px solid var(--ediy-border);
	border-radius: var(--ediy-radius-sm);
	background: var(--ediy-surface);
	color: var(--ediy-muted);
	font-weight: 600;
}

.ediy-tool .ediy-input:hover,
.ediy-tool .ediy-select:hover {
	border-color: var(--ediy-muted);
}

.ediy-tool .ediy-input:focus,
.ediy-tool .ediy-select:focus {
	border-color: var(--ediy-primary);
	outline: 3px solid var(--ediy-focus);
	outline-offset: 0;
	box-shadow: none;
}

.ediy-tool .ediy-input::placeholder {
	color: #6b7684;
	opacity: 1;
}

.ediy-tool .ediy-help {
	margin: 0.35rem 0 0;
	font-size: 0.85em;
	line-height: 1.45;
	color: var(--ediy-muted);
}

/* ---------- Validation ---------- */

.ediy-tool .ediy-field.is-invalid .ediy-input,
.ediy-tool .ediy-field.is-invalid .ediy-select:not(.ediy-select--unit) {
	border-color: var(--ediy-error);
	box-shadow: inset 0 0 0 1px var(--ediy-error);
}

.ediy-tool .ediy-field-error {
	margin: 0.35rem 0 0;
	font-size: 0.875em;
	font-weight: 600;
	line-height: 1.4;
	color: var(--ediy-error);
}

.ediy-tool .ediy-field-error::before,
.ediy-tool .ediy-form-error::before {
	content: "\26A0\FE0E\00a0";
}

.ediy-tool .ediy-form-error {
	margin: 0 0 var(--ediy-gap);
	padding: 0.75rem 1rem;
	border: 1px solid var(--ediy-error);
	border-left-width: 4px;
	border-radius: var(--ediy-radius-sm);
	background: var(--ediy-error-bg);
	color: var(--ediy-error);
	font-weight: 600;
}

/* ---------- Buttons ---------- */

.ediy-tool .ediy-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	margin: 0.25rem 0 0;
}

.ediy-tool .ediy-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	width: auto;
	height: auto;
	min-height: 2.75rem;
	margin: 0;
	padding: 0.55rem 1.35rem;
	border: 1px solid transparent;
	border-radius: var(--ediy-radius-sm);
	box-shadow: none;
	font-family: inherit;
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: normal;
	text-align: center;
	text-decoration: none;
	text-transform: none;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ediy-tool .ediy-btn--primary {
	border-color: var(--ediy-primary);
	background: var(--ediy-primary);
	color: var(--ediy-primary-contrast);
}

.ediy-tool .ediy-btn--primary:hover {
	border-color: var(--ediy-primary-hover);
	background: var(--ediy-primary-hover);
	color: var(--ediy-primary-contrast);
}

.ediy-tool .ediy-btn--secondary,
.ediy-tool .ediy-btn--ghost {
	border-color: var(--ediy-border-strong);
	background: #ffffff;
	color: var(--ediy-text);
}

.ediy-tool .ediy-btn--secondary:hover,
.ediy-tool .ediy-btn--ghost:hover {
	border-color: var(--ediy-muted);
	background: var(--ediy-surface);
	color: var(--ediy-text);
}

.ediy-tool .ediy-btn--small {
	min-height: 2.25rem;
	padding: 0.35rem 0.8rem;
	font-size: 0.875rem;
}

.ediy-tool .ediy-btn:focus-visible {
	outline: 3px solid var(--ediy-focus);
	outline-offset: 2px;
}

/* ---------- Segmented radio control ---------- */

.ediy-tool .ediy-segmented {
	margin: 0 0 var(--ediy-gap);
}

.ediy-tool .ediy-segmented__options {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 0.25rem;
	padding: 0.25rem;
	border: 1px solid var(--ediy-border);
	border-radius: var(--ediy-radius-sm);
	background: var(--ediy-surface);
}

.ediy-tool .ediy-segmented__option {
	position: relative;
	margin: 0;
}

.ediy-tool .ediy-segmented__option input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	opacity: 0;
	cursor: pointer;
}

.ediy-tool .ediy-segmented__option span {
	display: block;
	padding: 0.45rem 0.9rem;
	border: 1px solid transparent;
	border-radius: 4px;
	font-size: 0.95em;
	font-weight: 600;
	line-height: 1.3;
	color: var(--ediy-muted);
}

.ediy-tool .ediy-segmented__option input:checked + span {
	border-color: var(--ediy-border);
	background: #ffffff;
	color: var(--ediy-primary);
	box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

.ediy-tool .ediy-segmented__option input:checked + span::before {
	content: "\2713\00a0";
}

.ediy-tool .ediy-segmented__option input:focus-visible + span {
	outline: 3px solid var(--ediy-focus);
	outline-offset: 1px;
}

/* ---------- Results ---------- */

.ediy-tool .ediy-results {
	margin: 1.25rem 0 0;
	padding: 1rem;
	border: 1px solid var(--ediy-border);
	border-left: 4px solid var(--ediy-primary);
	border-radius: var(--ediy-radius-sm);
	background: var(--ediy-surface);
}

.ediy-tool .ediy-results__header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	margin: 0 0 0.75rem;
}

.ediy-tool .ediy-results__title {
	margin: 0;
	padding: 0;
	font-size: 1.1em;
	line-height: 1.3;
	color: inherit;
}

.ediy-tool .ediy-results__list {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
	gap: 0.75rem;
	margin: 0;
	padding: 0;
}

.ediy-tool .ediy-result {
	margin: 0;
	padding: 0.65rem 0.8rem;
	border: 1px solid var(--ediy-border);
	border-radius: var(--ediy-radius-sm);
	background: #ffffff;
}

.ediy-tool .ediy-result__label {
	margin: 0 0 0.15rem;
	padding: 0;
	font-size: 0.8em;
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	color: var(--ediy-muted);
}

.ediy-tool .ediy-result__value {
	margin: 0;
	padding: 0;
	font-family: var(--ediy-mono);
	font-size: 1.15em;
	font-weight: 700;
	line-height: 1.3;
	color: var(--ediy-text);
	font-variant-numeric: tabular-nums;
}

.ediy-tool .ediy-results__note {
	margin: 0.75rem 0 0;
	font-size: 0.9em;
	color: var(--ediy-muted);
}

.ediy-tool .ediy-warnings {
	margin: 0.75rem 0 0;
	padding: 0;
	list-style: none;
}

.ediy-tool .ediy-warnings li {
	margin: 0.5rem 0 0;
	padding: 0.6rem 0.8rem;
	border: 1px solid var(--ediy-warning-border);
	border-left-width: 4px;
	border-radius: var(--ediy-radius-sm);
	background: var(--ediy-warning-bg);
	color: var(--ediy-warning);
	font-size: 0.925em;
}

.ediy-tool .ediy-warnings li::before {
	content: "\26A0\FE0E\00a0";
	font-weight: 700;
}

/* ---------- Info / explanation sections ---------- */

.ediy-tool .ediy-info {
	margin: 1.5rem 0 0;
	padding: 1.25rem 0 0;
	border-top: 1px solid var(--ediy-border);
}

.ediy-tool .ediy-info h3 {
	margin: 1.25rem 0 0.5rem;
	padding: 0;
	font-size: 1.1em;
	line-height: 1.3;
	color: inherit;
}

.ediy-tool .ediy-info h3:first-child {
	margin-top: 0;
}

.ediy-tool .ediy-info p {
	margin: 0 0 0.75rem;
}

.ediy-tool .ediy-info ul,
.ediy-tool .ediy-info ol {
	margin: 0 0 0.75rem;
	padding: 0 0 0 1.25rem;
}

.ediy-tool .ediy-info ul {
	list-style: disc;
}

.ediy-tool .ediy-info ol {
	list-style: decimal;
}

.ediy-tool .ediy-info li {
	margin: 0 0 0.3rem;
}

.ediy-tool .ediy-formula {
	margin: 0.5rem 0 0.75rem;
	padding: 0.65rem 0.85rem;
	border: 1px solid var(--ediy-border);
	border-radius: var(--ediy-radius-sm);
	background: var(--ediy-surface);
	font-family: var(--ediy-mono);
	font-size: 0.95em;
	line-height: 1.6;
	overflow-x: auto;
	white-space: nowrap;
}

.ediy-tool .ediy-formula code {
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	font-family: inherit;
	font-size: inherit;
}

.ediy-tool .ediy-formula sub,
.ediy-tool .ediy-formula sup {
	font-size: 0.75em;
	line-height: 0;
}

.ediy-tool .ediy-formula sub {
	vertical-align: sub;
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
	.ediy-tool .ediy-actions .ediy-btn {
		flex: 1 1 auto;
	}

	.ediy-tool .ediy-results__list {
		grid-template-columns: 1fr 1fr;
	}

	.ediy-tool .ediy-formula {
		white-space: normal;
	}
}

@media (max-width: 340px) {
	.ediy-tool .ediy-results__list {
		grid-template-columns: 1fr;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ediy-tool .ediy-input,
	.ediy-tool .ediy-select,
	.ediy-tool .ediy-btn {
		transition: none;
	}
}
