.treeview-container {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    max-width: 450px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.treeview-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    font-weight: bold;
    font-size: 16px;
}

.search-container {
    padding: 15px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
    position: relative;
}

.search-box {
    width: 100%;
    padding: 10px 15px 10px 40px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.search-box:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    pointer-events: none;
}

.treeview-content {
    max-height: 500px;
    overflow-y: auto;
    padding: 10px;
}

.tree-node {
    margin: 2px 0;
}

.tree-folder {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.tree-folder.expanded {
    background: #fff;
}

.folder-header {
    padding: 12px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    color: #495057;
    transition: all 0.3s ease;
}

.folder-header:hover {
    background: #e9ecef;
}

.tree-folder.expanded .folder-header {
    background: #667eea;
    color: white;
}

.folder-icon {
    margin-right: 10px;
    transition: transform 0.3s ease;
}

.tree-folder.expanded .folder-icon {
    transform: rotate(90deg);
}

.folder-children {
    display: none;
    padding: 10px 0px 0px 10px;
    background: #fff;
}

.tree-folder.expanded .folder-children {
    display: block;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    margin: 3px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    flex-direction: column;
    align-items: stretch;
}

.tree-item:hover {
    background: #f8f9fa;
    border-color: #dee2e6;
}

.tree-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.item-main {
    display: flex;
    align-items: center;
    width: 100%;
}

.item-toggle {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    margin-left: 10px;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.tree-item.active .item-toggle {
    background: white;
    border-color: white;
    color: #667eea;
}

.item-toggle:hover {
    border-color: #667eea;
}

.item-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.item-actions {
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tree-item:hover .item-actions,
.tree-item.active .item-actions {
    opacity: 1;
}

.action-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: #6c757d;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 12px;
}

.action-btn:hover {
    transform: scale(1.1);
}

.action-btn.info {
    background: #17a2b8;
    box-shadow: none !important;
}

.action-btn.download {
    background: #28a745;
    margin: 0 !important;
}

.action-btn.settings {
    background: #6f42c1;
}

.action-btn:disabled {
    background: #6c757d;
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.tree-item.active .action-btn {
    background: rgba(255,255,255,0.2);
    color: white;
}

.tree-item.active .action-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.3);
}

.tree-item.active .action-btn:disabled {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.5);
}

.opacity-control {
    display: none;
    margin-top: 10px;
    padding: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.2);
}

.tree-item.active .opacity-control {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
}

.opacity-control.show {
    display: block;
}

.opacity-label {
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 8px;
    color: #495057;
}

.tree-item.active .opacity-label {
    color: white;
}

.opacity-slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.opacity-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.opacity-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.tree-item.active .opacity-slider {
    background: rgba(255,255,255,0.3);
}

.tree-item.active .opacity-slider::-webkit-slider-thumb {
    background: white;
    border-color: rgba(255,255,255,0.8);
}

.tree-item.active .opacity-slider::-moz-range-thumb {
    background: white;
    border-color: rgba(255,255,255,0.8);
}

.opacity-value {
    font-size: 12px;
    font-weight: 600;
    min-width: 35px;
    text-align: center;
    color: #495057;
}

.tree-item.active .opacity-value {
    color: white;
}

.no-results {
    text-align: center;
    padding: 30px;
    color: #6c757d;
    font-style: italic;
}

.controls-container {
    padding: 15px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.control-btn {
    padding: 8px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    background: white;
    color: #495057;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.highlight {
    background: yellow;
    font-weight: bold;
}

/* Responsive para móviles */
@media (max-width: 768px) {
    .folder-children {
        padding: 8px 0 0 3px; /* Reducido aún más para móviles */
    }
}

@media (max-width: 480px) {
    .folder-children {
        padding: 6px 0 0 2px; /* Mínimo padding para pantallas muy pequeñas */
    }
}

@media (max-width: 768px) {
    .treeview-container {
        max-width: 100%;
        width: 100%;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        border-left: none;
        border-right: none;
    }
    
    .treeview-header {
        padding: 12px 15px;
        font-size: 14px;
    }
    
    .search-container {
        padding: 10px 15px;
    }
    
    .search-box {
        padding: 8px 12px 8px 35px;
        font-size: 16px; /* Evita zoom en iOS */
    }
    
    .search-icon {
        left: 25px;
    }
    
    .treeview-content {
        max-height: calc(100vh - 200px); /* Altura dinámica basada en viewport */
        overflow-y: auto;
        overflow-x: hidden;
        padding: 8px;
        -webkit-overflow-scrolling: touch; /* Scroll suave en iOS */
    }
    
    .folder-header {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .folder-children {
        padding: 8px 12px 12px 12px;
    }
    
    .tree-item {
        padding: 8px 12px;
        margin: 2px 0;
    }
    
    .item-main {
        flex-wrap: wrap;
    }
    
    .item-name {
        font-size: 13px;
        word-break: break-word;
        overflow-wrap: break-word;
    }
    
    .item-actions {
        opacity: 1;
        margin-top: 8px;
        width: 100%;
        justify-content: flex-end;
    }
    
    .action-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
        margin-left: 5px;
    }
    
    .opacity-controls {
        margin-top: 8px;
        width: 100%;
    }
    
    .opacity-slider {
        height: 8px;
    }
    
    .opacity-slider::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }
    
    .opacity-slider::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }
    
    .controls-container {
        padding: 10px 15px;
        justify-content: center;
    }
    
    .control-btn {
        padding: 10px 15px;
        font-size: 14px;
        min-width: 80px;
    }
    
    .legend-container {
        margin-top: 8px;
        padding: 8px;
    }
    
    .legend-content {
        max-height: 120px;
        padding: 6px;
    }
}

@media (max-width: 480px) {
    .treeview-container {
        font-size: 14px;
    }
    
    .treeview-header {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .search-container {
        padding: 8px 12px;
    }
    
    .search-box {
        padding: 6px 10px 6px 30px;
        font-size: 16px;
    }
    
    .search-icon {
        left: 20px;
        font-size: 14px;
    }
    
    .treeview-content {
        max-height: calc(100vh - 180px);
        padding: 6px;
    }
    
    .folder-header {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .folder-children {
        padding: 6px 10px 10px 10px;
    }
    
    .tree-item {
        padding: 6px 10px;
    }
    
    .item-name {
        font-size: 12px;
    }
    
    .action-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .controls-container {
        padding: 8px 12px;
        flex-direction: column;
    }
    
    .control-btn {
        width: 100%;
        margin-bottom: 5px;
        padding: 12px;
    }
    
    .opacity-value {
        font-size: 11px;
        min-width: 30px;
    }
}

/* Mejoras adicionales para scroll y touch */
.treeview-content {
    /* Mejora el scroll en dispositivos táctiles */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Scrollbar personalizado para móviles */
@media (max-width: 768px) {
    .treeview-content::-webkit-scrollbar {
        width: 8px;
    }
    
    .treeview-content::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 4px;
    }
    
    .treeview-content::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 4px;
    }
    
    .treeview-content::-webkit-scrollbar-thumb:hover {
        background: #a8a8a8;
    }
}

/* Asegurar que el contenedor padre permita scroll */
.treeview-container {
    position: relative;
    overflow: visible;
}

@media (max-width: 768px) {
    .treeview-container {
        height: auto;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    .treeview-content {
        flex: 1;
        min-height: 0; /* Importante para que funcione el scroll en flex */
    }
}

@keyframes pulse {
    0% { background-color: rgba(102, 126, 234, 0.3); }
    50% { background-color: rgba(102, 126, 234, 0.6); }
    100% { background-color: transparent; }
}

/* Estilos para la leyenda de capas */
.legend-container {
    margin-top: 10px;
    padding: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.2);
}

.legend-label {
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 8px;
    color: white;
}

.legend-content {
    max-height: 150px;
    overflow-y: auto;
    background: white;
    border-radius: 4px;
    padding: 8px;
    text-align: center;
}

.legend-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.legend-error {
    color: #6c757d;
    font-size: 12px;
    font-style: italic;
    padding: 10px;
    text-align: center;
}

/* Scrollbar personalizado para la leyenda */
.legend-content::-webkit-scrollbar {
    width: 6px;
}

.legend-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.legend-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.legend-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.download-format-link {
    transition: all 0.2s ease;
    cursor: pointer;
}

.download-format-link:hover {
    background-color: #f5f5f5;
    text-decoration: none;
}

.download-format-link i {
    margin-right: 10px;
    width: 20px;
    text-align: center;
}

.download-format-link strong {
    display: inline-block;
    width: 100px;
}

/* Estilos para multiniveles SIN indentación */
.tree-folder[data-level="0"],
.tree-folder[data-level="1"],
.tree-folder[data-level="2"],
.tree-folder[data-level="3"] {
    margin-left: 0;
    border-left: none;
    padding-left: 0;
}

.tree-item[data-level="0"],
.tree-item[data-level="1"],
.tree-item[data-level="2"],
.tree-item[data-level="3"] {
    margin-left: 0;
    padding-left: 0;
}

/* ELIMINAR todos los ::before que crean los símbolos "L" */
.tree-item[data-level="1"]::before,
.tree-item[data-level="2"]::before,
.tree-item[data-level="3"]::before {
    display: none !important;
}

.tree-folder[data-level="1"]::before,
.tree-folder[data-level="2"]::before,
.tree-folder[data-level="3"]::before {
    display: none !important;
}

/* Estilos uniformes para todos los niveles SIN indentación */
.tree-folder[data-level="1"] .folder-header,
.tree-folder[data-level="2"] .folder-header,
.tree-folder[data-level="3"] .folder-header {
    font-size: 14px;
    padding: 10px 12px;
    background: rgba(0,0,0,0.01);
    border-radius: 4px;
    margin-bottom: 3px;
    /* Asegurar que el texto no se salga */
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    max-width: 100%;
    box-sizing: border-box;
}

/* Mejorar la visualización de carpetas expandidas */
.tree-folder.expanded .folder-children {
    margin-top: 5px;
    padding-top: 3px;
}

/* Asegurar que el texto de los items no se salga del contenedor */
.item-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    /* Prevenir que el texto se salga */
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* Asegurar que los contenedores principales manejen el overflow correctamente */
.tree-item {
    display: flex;
    align-items: flex-start;
    padding: 10px 15px;
    margin: 3px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    flex-direction: column;
    align-items: stretch;
    /* Asegurar que el contenedor maneje el overflow */
    overflow: hidden;
    word-wrap: break-word;
    box-sizing: border-box;
}

.item-main {
    display: flex;
    align-items: center;
    width: 100%;
    /* Asegurar que el contenedor principal maneje el overflow */
    overflow: hidden;
    box-sizing: border-box;
}

/* Responsive optimizado para móviles SIN indentación */
@media (max-width: 768px) {
    .tree-folder[data-level="1"],
    .tree-folder[data-level="2"],
    .tree-folder[data-level="3"] {
        margin-left: 0;
        border-left: none;
        padding-left: 0;
    }
    
    .tree-item[data-level="1"],
    .tree-item[data-level="2"],
    .tree-item[data-level="3"] {
        margin-left: 0;
        padding-left: 0;
    }
    
    .tree-folder[data-level="1"] .folder-header,
    .tree-folder[data-level="2"] .folder-header,
    .tree-folder[data-level="3"] .folder-header {
        font-size: 13px;
        padding: 6px 8px;
        /* Asegurar manejo de texto en móviles */
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
    }
    
    .item-name {
        font-size: 13px;
        word-break: break-word;
        overflow-wrap: break-word;
        line-height: 1.3;
    }
    
    /* Asegurar que NO aparezcan símbolos en móviles */
    .tree-item[data-level="1"]::before,
    .tree-item[data-level="2"]::before,
    .tree-item[data-level="3"]::before,
    .tree-folder[data-level="1"]::before,
    .tree-folder[data-level="2"]::before,
    .tree-folder[data-level="3"]::before {
        display: none !important;
        content: none !important;
    }
}

/* Animaciones suaves para la expansión */
.folder-children {
    transition: all 0.2s ease;
    overflow: hidden;
}

.tree-folder:not(.expanded) .folder-children {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding-top: 0;
}

.tree-folder.expanded .folder-children {
    max-height: none;
    opacity: 1;
}

/* ELIMINAR la diferenciación de colores por nivel */
/* Comentar o eliminar estas reglas:
.tree-folder[data-level="1"] {
    border-left-color: #007bff;
}

.tree-folder[data-level="2"] {
    border-left-color: #28a745;
}

.tree-folder[data-level="3"] {
    border-left-color: #ffc107;
}
*/