/**
 * Mapa del Sitio - Vista Pública
 * Diseño moderno tipo árbol visual
 * Inspirado en arquitecturas de sitio modernas
 * 
 * @package Fiscalia
 * @since 1.0.0
 */

/* =================================
   VARIABLES Y RESET
   ================================= */
.fiscalia-sitemap-public {
	--color-primary: #1e3a5f;
	--color-primary-light: #2c5282;
	--color-accent: #c9a227;
	--color-bg-light: #f8f9fa;
	--color-bg-white: #ffffff;
	--color-text-dark: #1a202c;
	--color-text-medium: #4a5568;
	--color-text-light: #718096;
	--color-border: #e2e8f0;
	--color-border-hover: var(--color-primary);
	--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
	--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
	--radius-base: 0.75rem;
	--radius-lg: 1rem;
}

/* =================================
   CONTENEDOR PRINCIPAL
   ================================= */
.fiscalia-sitemap-public {
	width: 100%;
	max-width: 1200px;
	margin: 0 auto;
	padding: 40px 20px;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	color: var(--color-text-dark);
	line-height: 1.6;
}

.fiscalia-sitemap-public * {
	box-sizing: border-box;
}

/* =================================
   ENCABEZADO Y CONTROLES
   ================================= */
.sitemap-header {
	display: flex;
	flex-direction: column;
	gap: 20px;
	margin-bottom: 40px;
}

.sitemap-title-section {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.sitemap-title-section h2 {
	color: var(--color-text-dark);
	font-size: 2.25rem;
	font-weight: 800;
	margin: 0;
	line-height: 1.2;
	letter-spacing: -0.02em;
}

.sitemap-subtitle {
	color: var(--color-text-light);
	font-size: 1rem;
	margin: 0;
}

/* =================================
   BARRA DE BÚSQUEDA Y FILTROS
   ================================= */
.sitemap-controls {
	display: flex;
	gap: 16px;
	padding: 16px;
	background: var(--color-bg-white);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-sm);
	flex-wrap: wrap;
}

.sitemap-search-container {
	flex: 1;
	min-width: 280px;
	margin: 0;
}

.sitemap-search-wrapper {
	position: relative;
	width: 100%;
}

.sitemap-search-icon {
	position: absolute;
	left: 16px;
	top: 50%;
	transform: translateY(-50%);
	color: var(--color-text-light);
	pointer-events: none;
	font-size: 20px;
}

.sitemap-search {
	width: 100%;
	padding: 12px 16px 12px 48px;
	border: 1px solid transparent;
	background: var(--color-bg-light);
	border-radius: var(--radius-base);
	font-size: 14px;
	color: var(--color-text-dark);
	transition: all 0.2s ease;
}

.sitemap-search:focus {
	outline: none;
	background: var(--color-bg-white);
	border-color: var(--color-primary);
	box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.1);
	font-family: inherit;
	background: #fff url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%231e3a5f" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>') no-repeat 18px center;
	transition: all 0.3s ease;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sitemap-search:focus {
	outline: none;
	border-color: #1e3a5f;
	box-shadow: 0 4px 16px rgba(30, 58, 95, 0.15);
}

.sitemap-search::placeholder {
	color: var(--color-text-light);
}

/* Botones de acción */
.sitemap-action-buttons {
	display: flex;
	gap: 8px;
}

.sitemap-btn {
	padding: 10px 20px;
	border: 1px solid var(--color-border);
	background: var(--color-bg-white);
	color: var(--color-text-medium);
	font-size: 14px;
	font-weight: 600;
	border-radius: var(--radius-base);
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	gap: 8px;
}

.sitemap-btn:hover {
	background: var(--color-bg-light);
	border-color: var(--color-primary);
	color: var(--color-primary);
}

.sitemap-btn:active {
	transform: scale(0.98);
}

.sitemap-btn-primary {
	background: var(--color-primary);
	color: white;
	border-color: var(--color-primary);
}

.sitemap-btn-primary:hover {
	background: var(--color-primary-light);
	border-color: var(--color-primary-light);
	color: white;
}

/* =================================
   MENSAJES
   ================================= */
.sitemap-empty,
.sitemap-no-results {
	text-align: center;
	padding: 48px 32px;
	background: var(--color-bg-white);
	border-radius: var(--radius-lg);
	border: 2px dashed var(--color-border);
	margin: 24px 0;
}

.sitemap-empty p,
.sitemap-no-results p {
	margin: 0;
	font-size: 16px;
	color: var(--color-text-medium);
}

.sitemap-no-results {
	background: #fff3cd;
	border-color: #ffc107;
}

.sitemap-no-results p {
	color: #856404;
}

/* =================================
   ESTRUCTURA DEL ÁRBOL VISUAL
   ================================= */
.sitemap-level {
	list-style: none;
	margin: 0;
	padding: 0;
}

/* Contenedor del árbol */
.sitemap-tree-container {
	margin-top: 32px;
}

/* Nivel raíz */
.sitemap-level-1 {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

/* Niveles anidados - Árbol visual con líneas */
.sitemap-level:not(.sitemap-level-1) {
	margin-top: 16px;
	margin-left: 40px;
	padding-left: 32px;
	border-left: 2px solid var(--color-border);
	position: relative;
}

/* =================================
   ITEMS DEL MAPA - DISEÑO TARJETA
   ================================= */
.sitemap-item {
	position: relative;
	margin-bottom: 0;
}

/* Línea horizontal conectora (para items anidados) */
.sitemap-level:not(.sitemap-level-1) > .sitemap-item::after {
	content: '';
	position: absolute;
	left: -32px;
	top: 20px;
	width: 32px;
	height: 2px;
	background-color: var(--color-border);
}

/* =================================
   TARJETA DEL NODO
   ================================= */
.sitemap-link,
.sitemap-item > span {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 16px;
	background: var(--color-bg-white);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-base);
	color: var(--color-text-dark);
	text-decoration: none;
	font-weight: 600;
	font-size: 14px;
	transition: all 0.2s ease;
	position: relative;
	box-shadow: var(--shadow-sm);
}

/* Diferentes cursores según tenga URL o no */
.sitemap-link[href] {
	cursor: pointer;
}

.sitemap-item > span {
	cursor: default;
}

.sitemap-item > span.has-children {
	cursor: pointer;
}

/* Nivel 1 - Tarjetas destacadas */
.sitemap-level-1 > .sitemap-item > .sitemap-link,
.sitemap-level-1 > .sitemap-item > span {
	padding: 16px 20px;
	font-size: 16px;
	font-weight: 700;
	border-width: 2px;
	box-shadow: var(--shadow-md);
}

/* Nivel 1 con borde especial si es raíz */
.sitemap-level-1 > .sitemap-item:first-child > .sitemap-link,
.sitemap-level-1 > .sitemap-item:first-child > span {
	border-color: rgba(30, 58, 95, 0.3);
	background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
}

/* Hover states */
.sitemap-link:hover,
.sitmap-item > span:hover {
	border-color: var(--color-border-hover);
	box-shadow: 0 4px 12px rgba(30, 58, 95, 0.1);
	transform: translateX(4px);
}

.sitemap-level-1 > .sitemap-item > .sitemap-link:hover,
.sitemap-level-1 > .sitemap-item > span:hover {
	transform: translateY(-2px);
	box-shadow: 0 8px 16px rgba(30, 58, 95, 0.12);
}

/* Focus state para accesibilidad */
.sitemap-link:focus,
.sitemap-item > span:focus {
	outline: 3px solid var(--color-accent);
	outline-offset: 2px;
}

/* Active state */
.sitemap-link:active {
	transform: scale(0.98);
}

/* =================================
   ICONOS TIPO ENLACE
   ================================= */
.sitemap-icon {
	flex-shrink: 0;
	width: 32px;
	height: 32px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--color-bg-light);
	border-radius: var(--radius-base);
	transition: all 0.2s ease;
	color: var(--color-text-medium);
}

/* Iconos de nivel 1 */
.sitemap-level-1 .sitemap-icon {
	width: 40px;
	height: 40px;
	font-size: 24px;
}

/* Iconos por tipo de enlace */
.sitemap-link-internal .sitemap-icon {
	background: rgba(30, 58, 95, 0.1);
	color: var(--color-primary);
}

.sitemap-link-external .sitemap-icon {
	background: rgba(16, 185, 129, 0.1);
	color: #10b981;
}

.sitemap-link-pdf .sitemap-icon {
	background: rgba(239, 68, 68, 0.1);
	color: #ef4444;
}

.sitemap-link-dropdown .sitemap-icon {
	background: rgba(139, 92, 246, 0.1);
	color: #8b5cf6;
}

.sitemap-link:hover .sitemap-icon,
span.has-children:hover .sitemap-icon {
	transform: scale(1.05);
}

/* =================================
   TÍTULO DEL ENLACE
   ================================= */
.sitemap-title {
	flex: 1;
	font-size: inherit;
	font-weight: inherit;
	color: inherit;
	line-height: 1.4;
	word-break: break-word;
	min-width: 0;
}

/* =================================
   BADGES Y ETIQUETAS
   ================================= */
.sitemap-badge {
	padding: 4px 10px;
	border-radius: 6px;
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	flex-shrink: 0;
}

.sitemap-badge-pages {
	background: var(--color-bg-light);
	color: var(--color-text-medium);
}

.sitemap-badge-new {
	background: rgba(16, 185, 129, 0.15);
	color: #047857;
}

.sitemap-badge-external::after {
	content: '↗';
	margin-left: 4px;
	font-size: 12px;
}

/* =================================
   TOGGLE (Expandir/Contraer) 
   ================================= */
.sitemap-toggle {
	flex-shrink: 0;
	width: 24px;
	height: 24px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 4px;
	font-size: 18px;
	color: var(--color-text-light);
	transition: all 0.2s ease;
	margin-left: 8px;
	cursor: pointer;
	user-select: none;
	position: relative;
	z-index: 10; /* Para asegurar que esté por encima del enlace */
}

.sitemap-toggle:hover {
	color: var(--color-primary);
	background: var(--color-bg-light);
	transform: scale(1.1);
}

.sitemap-toggle:active {
	transform: scale(0.95);
}

.expanded > .sitemap-link .sitemap-toggle,
.expanded > span .sitemap-toggle {
	/* No rotar, el texto cambia de ▼ a ▶ */
}

/* =================================
   ESTADOS VISUALES
   ================================= */

/* Item expandido */
.sitemap-item.expanded > .sitemap-link,
.sitemap-item.expanded > span {
	background: var(--color-bg-light);
}

/* Item filtrado (búsqueda) */
.sitemap-item.filtered-out {
	display: none;
}

.sitemap-item.search-match > .sitemap-link,
.sitemap-item.search-match > span {
	background: #fffbeb;
	border-color: var(--color-accent);
}

/* =================================
   ANIMACIONES
   ================================= */
@keyframes fadeIn {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

@keyframes slideDown {
	from {
		opacity: 0;
		transform: translateY(-10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.sitemap-level:not(.sitemap-level-1) {
	animation: slideDown 0.3s ease-out;
}

/* =================================
   BREADCRUMB (Ruta de navegación)
   ================================= */
/* =================================
   ACCESIBILIDAD
   ================================= */

/* Focus visible mejorado */
.sitemap-link:focus-visible {
	outline: 3px solid var(--color-accent);
	outline-offset: 3px;
	z-index: 1;
}

/* Alto contraste */
@media (prefers-contrast: high) {
	.sitemap-link,
	.sitemap-item > span {
		border-width: 2px;
	}
}

/* Movimiento reducido */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}

/* =================================
   RESPONSIVE DESIGN
   ================================= */

@media (max-width: 768px) {
	.fiscalia-sitemap-public {
		padding: 24px 16px;
	}
	
	.sitemap-title-section h2 {
		font-size: 1.75rem;
	}
	
	.sitemap-controls {
		flex-direction: column;
		gap: 12px;
	}
	
	.sitemap-search-container {
		min-width: 100%;
	}
	
	.sitemap-action-buttons {
		width: 100%;
		flex-wrap: wrap;
	}
	
	.sitemap-btn {
		flex: 1;
		min-width: 120px;
	}
	
	/* Árbol más compacto en móvil */
	.sitemap-level:not(.sitemap-level-1) {
		margin-left: 24px;
		padding-left: 20px;
	}
	
	.sitemap-level:not(.sitemap-level-1) > .sitemap-item::after {
		left: -20px;
		width: 20px;
	}
	
	.sitemap-link,
	.sitemap-item > span {
		padding: 10px 12px;
		font-size: 13px;
		gap: 10px;
	}
	
	.sitemap-level-1 > .sitemap-item > .sitemap-link,
	.sitemap-level-1 > .sitemap-item > span {
		padding: 14px 16px;
		font-size: 15px;
	}
	
	.sitemap-icon {
		width: 28px;
		height: 28px;
		font-size: 18px;
	}
	
	.sitemap-level-1 .sitemap-icon {
		width: 36px;
		height: 36px;
		font-size: 20px;
	}
}

@media (max-width: 480px) {
	.sitemap-title-section h2 {
		font-size: 1.5rem;
	}
	
	.sitemap-subtitle {
		font-size: 0.875rem;
	}
	
	.sitemap-header {
		gap: 16px;
		margin-bottom: 24px;
	}
	
	.sitemap-tree-container {
		margin-top: 24px;
	}
}

/* =================================
   PRINT STYLES
   ================================= */
@media print {
	.sitemap-header,
	.sitemap-controls,
	.sitemap-toggle {
		display: none !important;
	}
	
	.fiscalia-sitemap-public {
		padding: 0;
	}
	
	.sitemap-level:not(.sitemap-level-1) {
		border-left: 1px solid #000;
	}
	
	.sitemap-item {
		page-break-inside: avoid;
		break-inside: avoid;
	}
	
	.sitemap-link,
	.sitemap-item > span {
		color: #000 !important;
		background: none !important;
		border: none !important;
		box-shadow: none !important;
		padding: 4px 0;
	}
	
	.sitemap-link[href]::after {
		content: " (" attr(href) ")";
		font-size: 10px;
		color: #666;
		font-weight: normal;
	}
}

/* =================================
   UTILIDADES Y ESTADOS ESPECIALES
   ================================= */

/* Loading state */
.sitemap-loading {
	text-align: center;
	padding: 60px 20px;
	color: var(--color-text-light);
}

.sitemap-loading::before {
	content: '';
	display: block;
	width: 48px;
	height: 48px;
	border: 4px solid var(--color-border);
	border-left-color: var(--color-primary);
	border-radius: 50%;
	animation: spin 1s linear infinite;
	margin: 0 auto 16px;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* Highlighted item (para scroll automático) */
.sitemap-item.highlighted > .sitemap-link,
.sitemap-item.highlighted > span {
	animation: pulse 1.5s ease-in-out 3;
}

@keyframes pulse {
	0%, 100% {
		box-shadow: var(--shadow-sm);
		border-color: var(--color-border);
	}
	50% {
		box-shadow: 0 0 0 4px rgba(201, 162, 39, 0.3);
		border-color: var(--color-accent);
	}
}

/* Error state */
.sitemap-error {
	padding: 24px;
	background: #fef2f2;
	border: 1px solid #fecaca;
	border-radius: var(--radius-base);
	color: #991b1b;
	margin: 20px 0;
}

.sitemap-error-title {
	font-weight: 700;
	margin-bottom: 8px;
}

/* =================================
   URL DISPLAY (para debug)
   ================================= */
.sitemap-url-display {
	display: none;
	font-size: 11px;
	color: var(--color-text-light);
	margin-top: 4px;
	font-family: monospace;
}

.fiscalia-sitemap-public[data-show-urls="true"] .sitemap-url-display {
	display: block;
}
