/* Estructura Base de Formularios */
.form-card {
	background: transparent;
	border-radius: 8px;
	box-shadow: none;
	border: none;
	display: flex;
	flex-direction: column;
	height: 100%;
	min-height: 0;
	overflow: hidden;
}

:has(> .form-card) {
	overflow: hidden !important;
}

.form-main {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
	overflow: hidden;
}

.form-scroll-area {
	flex: 1;
	overflow-y: auto;
	min-height: 0;
	/* Ocultar barra de scroll en Firefox y Edge */
	scrollbar-width: none;
}

/* Ocultar barra de scroll en Chrome, Safari y Opera */
.form-scroll-area::-webkit-scrollbar {
	display: none;
}

.form-fieldset {
	border: 1px solid rgba(255, 255, 255, 0.2);
	border-radius: 12px;
	padding: 0;
	background: rgba(var(--textoClaro-rgb), 0.7);
	backdrop-filter: blur(20px);
	margin: 1rem 0;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
	position: relative;
	z-index: 10;
	transition: z-index 0s;
}

.form-fieldset:focus-within {
	z-index: 100;
}

.form-legend {
	display: block;
	width: calc(100% + 2px);
	background: var(--fondo1);
	color: var(--textoClaro);
	padding: 0.6rem 1rem;
	font-weight: 600;
	font-size: 0.9rem;
	margin: -1px -1px 0 -1px;
	box-sizing: border-box;
	text-transform: capitalize;
	border-radius: 12px 12px 0 0;
}

.form-group-container {
	padding: 1rem;
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 1rem 2rem;
	overflow: visible;
	box-sizing: border-box;
}

/* Wrappers y Etiquetas */
.input-wrapper {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0.3rem;
	padding: 0.5rem 0;
}



/* Controles de Entrada */
.form-input,
.form-select,
.custom-combo-selected {
	width: 100%;
	padding: 0.6rem 0.75rem;
	border: 1px solid rgba(0, 0, 0, 0.1);
	border-radius: 6px;
	background-color: var(--textoClaro);
	color: var(--textoOscuro);
	font-size: 0.9rem;
	transition: all 0.2s ease;
	outline: none;
	box-sizing: border-box;
	min-height: 42px;
	display: flex;
	align-items: center;
}

.form-input:focus,
.form-select:focus,
.custom-combo-selected:hover {
	border-color: var(--color1);
	background-color: var(--textoClaro);
	box-shadow: 0 0 0 3px rgba(var(--color1-rgb), 0.1);
}

.form-input[readonly],
.is-readonly .custom-combo-selected,
.is-readonly .selector-id-box,
.is-readonly .selector-desc-box {
	background-color: #f8f9fa !important;
	cursor: not-allowed;
	opacity: 0.8;
}

.form-input[type="color"] {
	height: 42px;
	padding: 5px;
	cursor: pointer;
	background-color: var(--textoClaro);
}

.form-input[type="color"]::-webkit-color-swatch-wrapper {
	padding: 0;
}

.form-input[type="color"]::-webkit-color-swatch {
	border: 1px solid rgba(0, 0, 0, 0.1);
	border-radius: 3px;
}

/* Botones de Acción */
.form-actions {
	background: rgba(var(--textoClaro-rgb), 0.7);
	backdrop-filter: blur(20px);
	padding: 0.8rem 1rem;
	padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
	display: flex;
	justify-content: center;
	gap: 2rem;
	border: 1px solid rgba(255, 255, 255, 0.2);
	border-radius: 12px;
	margin: 0.5rem;
	margin-top: 0;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
	position: sticky;
	bottom: 0.5rem;
	z-index: 100;
	box-sizing: border-box;
}

.btn-cancel,
.btn-save-form {
	flex: 0 1 auto;
	text-align: center;
	min-width: 120px;
}

.btn-custom {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 0.6rem 1.2rem;
	border-radius: 6px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.2s;
	border: none;
	min-height: 42px;
}

.btn-cancel {
	padding: 0.5rem 1.2rem;
	background: #e74c3c;
	color: var(--textoClaro);
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-size: 0.85rem;
	font-weight: 600;
	transition: all 0.2s ease;
}

.btn-cancel:hover {
	background: #c0392b;
}

.btn-save-form {
	padding: 0.5rem 2rem;
	background: var(--color2);
	color: var(--textoClaro);
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-size: 0.85rem;
	font-weight: 700;
	transition: all 0.2s ease;
}

.btn-save-form:hover {
	filter: brightness(1.1);
	transform: translateY(-1px);
}

.btn-save-form:active,
.btn-cancel:active {
	transform: scale(0.96);
}

/* Feedback para peticiones HTMX en botones de formulario */
.htmx-request .btn-save-form,
.htmx-request .btn-cancel,
.btn-save-form.htmx-request,
.btn-cancel.htmx-request {
	opacity: 0.8;
	pointer-events: none;
	cursor: not-allowed;
	position: relative;
	color: transparent !important;
	transform: scale(0.96);
}

.htmx-request .btn-save-form::after,
.htmx-request .btn-cancel::after,
.btn-save-form.htmx-request::after,
.btn-cancel.htmx-request::after {
	content: "\f1ce";
	/* fa-circle-notch */
	font-family: "Font Awesome 6 Free";
	font-weight: 900;
	position: absolute;
	left: 50%;
	top: 50%;
	width: 1.2rem;
	height: 1.2rem;
	margin-left: -0.6rem;
	margin-top: -0.6rem;
	color: white;
	animation: spin 1s linear infinite;
	font-size: 1.2rem;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* Utilidades de Controles */
.full-width-item {
	grid-column: 1 / -1 !important;
}

.form-row {
	display: flex;
	flex-wrap: wrap;
	gap: 1rem;
	align-items: flex-end;
	width: 100%;
	margin: 0;
	box-sizing: border-box;
}

.form-row>.input-wrapper {
	flex: 1 1 0;
	min-width: 80px;
	padding: 0;
}

.form-row>.input-wrapper:has(.switch-toggle),
.form-row>.input-wrapper:has(.btn-custom) {
	flex: 0 0 auto;
	min-width: 0;
}

.btn-set-now {
	background: var(--color1);
	color: var(--textoClaro);
	border: none;
	border-radius: 4px;
	padding: 2px 10px;
	font-size: 0.7rem;
	cursor: pointer;
	font-weight: 600;
	transition: background 0.2s;
	display: inline-block;
	white-space: nowrap;
	width: auto;
	flex: 0 0 auto;
}

.btn-set-now:hover {
	background: var(--fondo1);
}

/* HtmlSelector */
.html-selector-container {
	width: 100%;
	position: relative;
}

.selector-input-group {
	display: flex;
	gap: 6px;
	/* Separación elegante como otros botones de acción */
	align-items: stretch;
	min-height: 42px;
}

.selector-id-box {
	width: 60px;
	padding: 0.6rem 0.2rem;
	border: 1px solid rgba(0, 0, 0, 0.1);
	border-radius: 6px;
	background-color: #f1f3f5;
	color: #495057;
	font-size: 0.85rem;
	text-align: center;
	font-weight: 700;
	outline: none;
	cursor: default;
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
}

.selector-desc-wrapper {
	flex: 1;
	position: relative;
	display: flex;
}

.selector-desc-box {
	width: 100%;
	padding: 0.6rem 0.75rem;
	border: 1px solid rgba(0, 0, 0, 0.1);
	border-radius: 6px;
	background-color: var(--textoClaro);
	color: var(--textoOscuro);
	font-size: 0.9rem;
	transition: all 0.2s ease;
	outline: none;
	box-sizing: border-box;
	height: 100%;
	min-height: 42px;
}

.selector-desc-box:focus {
	border-color: var(--color1);
	background-color: var(--textoClaro);
	box-shadow: 0 0 0 3px rgba(var(--color1-rgb), 0.1);
	z-index: 2;
}

.btn-clear-selector {
	background: #e74c3c;
	color: var(--textoClaro);
	border: none;
	border-radius: 6px;
	width: 42px;
	height: 42px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1rem;
	cursor: pointer;
	transition: all 0.2s ease;
	opacity: 1;
	line-height: 1;
	flex-shrink: 0;
}

.btn-clear-selector:hover {
	background: #c0392b;
	transform: none;
}

.btn-search-selector {
	background: var(--color1);
	color: var(--textoClaro);
	border: none;
	border-radius: 6px;
	width: 42px;
	height: 42px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1rem;
	cursor: pointer;
	transition: all 0.2s ease;
	opacity: 1;
	line-height: 1;
	flex-shrink: 0;
}

.btn-search-selector:hover {
	background: var(--fondo1);
	transform: none;
}

.btn-insert-selector {
	background: #2ecc71;
	color: var(--textoClaro);
	border: none;
	border-radius: 6px;
	width: 42px;
	height: 42px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1rem;
	cursor: pointer;
	transition: all 0.2s ease;
	opacity: 1;
	line-height: 1;
	flex-shrink: 0;
	margin-left: 5px;
}

.btn-insert-selector:hover {
	background: #27ae60;
	transform: none;
}

.selector-dropdown {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	background: var(--textoClaro);
	border: 1px solid rgba(0, 0, 0, 0.15);
	border-radius: 0 0 8px 8px;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
	z-index: 1000;
	margin-top: 2px;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	animation: selectorFadeIn 0.2s ease-out;
}

@keyframes selectorFadeIn {
	from {
		opacity: 0;
		transform: translateY(-5px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.selector-options-list {
	list-style: none;
	padding: 0;
	margin: 0;
	max-height: 250px;
	overflow-y: auto;
}

.selector-option {
	padding: 10px 15px;
	font-size: 0.9rem;
	cursor: pointer;
	transition: all 0.15s;
	color: var(--textoOscuro);
	border-bottom: 1px solid rgba(0, 0, 0, 0.02);
}

.selector-option:hover,
.selector-option.highlighted {
	background: rgba(var(--color1-rgb), 0.15);
	color: var(--color1);
	padding-left: 20px;
}

.selector-option.active {
	background: var(--color1);
	color: var(--textoClaro);
}

.selector-option-insert {
	padding: 10px 15px;
	cursor: pointer;
	transition: opacity 0.2s;
	font-size: 0.95rem;
}

.selector-option-insert:hover {
	opacity: 0.9;
}

.selector-option.no-results {
	padding: 10px;
	color: #999;
	font-style: italic;
	cursor: default;
}

.selector-option.no-results:hover {
	background: transparent;
	color: #999;
	padding-left: 10px;
}





/* Responsive */
@media (max-width: 1100px) {
	.form-group-container {
		grid-template-columns: 1fr;
		gap: 1rem;
	}
}

@media (max-width: 768px) {
	.form-card {
		margin: 0;
		border-radius: 0;
	}

	.form-fieldset {
		margin: 0.5rem 0;
		border-radius: 8px;
	}

	.form-legend {
		border-radius: 8px 8px 0 0;
	}

	.form-group-container {
		padding: 0.8rem;
		gap: 0.75rem;
	}

	.form-actions {
		justify-content: space-between;
		padding: 0.8rem;
		border-radius: 5px;
		margin-top: 0;
	}

	.btn-cancel,
	.btn-save-form {
		flex: 1;
		min-width: 0;
	}

	.input-wrapper {
		padding: 0.2rem 0;
	}
}

/* --- Modales de Alta Rápida y Diálogos --- */
.modal-overlay {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.7);
	z-index: 2000;
	align-items: center;
	justify-content: center;
}

.modal-card {
	width: 100%;
	max-width: 600px;
	padding: 0;
	border-radius: 8px;
	overflow: hidden;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
	animation: scaleIn 0.2s ease-out;
	background: var(--fondo1);
	height: auto;
	display: block;
}

.modal-header {
	background: rgba(0, 0, 0, 0.2);
	color: var(--textoClaro);
	padding: 5px 20px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-header h3 {
	margin: 0;
	font-size: 1.1rem;
	display: flex;
	align-items: center;
	gap: 8px;
}

.modal-close-btn {
	background: none;
	border: none;
	font-size: 1.5rem;
	cursor: pointer;
	color: var(--textoClaro);
	opacity: 0.7;
	transition: opacity 0.2s;
	line-height: 1;
}

.modal-close-btn:hover {
	opacity: 1;
}

.modal-body {
	padding: 5px 10px;
	height: auto;
	display: block;
}

.modal-scroll-area {
	max-height: 60vh;
	overflow-y: auto;
	margin-bottom: 15px;
	padding-right: 5px;
	height: auto;
	display: block;
}

/* Overrides para formularios dentro de modales oscuros */
.modal-overlay .form-fieldset {
	margin-bottom: 0;
	box-shadow: none !important;
	border: 1px solid rgba(255, 255, 255, 0.1) !important;
	background: transparent !important;
	backdrop-filter: none !important;
}

.modal-overlay .input-label {
	color: var(--textoClaro) !important;
}

@keyframes scaleIn {
	from {
		opacity: 0;
		transform: scale(0.95);
	}

	to {
		opacity: 1;
		transform: scale(1);
	}
}