/* RESET Y CONFIGURACIÓN BASE */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    min-height: 100vh;
    padding: 0;
}

/* TOPBAR FIJA */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
}

.datetime-widget {
    text-align: left;
    display: flex; /* CAMBIO: Añadir display flex y column para apilar hora/fecha */
    flex-direction: column; 
}

.time {
    font-size: 1.8rem;
    font-weight: 300;
}

.date {
    font-size: 1rem;
    opacity: 0.8;
}

.weather-widget {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 25px;
    backdrop-filter: blur(10px);
}

.weather-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.weather-temp {
    font-size: 1.4rem;
    font-weight: 600;
}

.weather-desc {
    font-size: 0.9rem;
    opacity: 0.9;
}

.weather-location {
    font-size: 0.8rem;
    opacity: 0.7;
}

/* CONTENEDOR PRINCIPAL CON 80% DE ANCHO */
.container {
    width: 80%;
    max-width: 1600px;
    margin: 120px auto 0 auto;
    padding: 0 20px;
}

/* BARRA DE BÚSQUEDA */
.search-container {
    display: flex;
    justify-content: center;
    margin: 40px 0 50px 0;
}

.search-box {
    display: flex;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50px;
    padding: 5px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 800px;
}

#searchEngine {
    border: none;
    background: transparent;
    padding: 0 15px;
    border-radius: 25px 0 0 25px;
    outline: none;
    color: #333;
    min-width: 120px;
}

#searchInput {
    flex: 1;
    border: none;
    padding: 15px;
    font-size: 1.1rem;
    outline: none;
    background: transparent;
    color: #333;
}

#searchBtn {
    background: #3366cc;
    border: none;
    color: white;
    padding: 15px 25px;
    border-radius: 0 25px 25px 0;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.3s;
    min-width: 80px;
}

#searchBtn:hover {
    background: #254eaf;
}

/* 8 COLUMNAS PARA ACCESOS DIRECTOS - OCUPANDO TODO EL ANCHO */
#shortcutsContainer { /* CAMBIO: Usar ID para mayor especificidad si se aplica grid-template-columns inline */
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 15px;
    max-height: 65vh;
    overflow-y: auto;
    padding: 20px 0;
    width: 100%;
}

/* MEJORAS EN ACCESOS DIRECTOS */
.shortcut-item {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    aspect-ratio: 1;
    user-select: none; /* Prevenir selección de texto durante drag */
}

.shortcut-item:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-3px);
}

/* BOTÓN DE OPCIONES (3 PUNTOS VERTICALES) */
.shortcut-options {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s ease;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.shortcut-item:hover .shortcut-options {
    opacity: 1;
    transform: scale(1);
}

.shortcut-options:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.options-dots {
    color: white;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    transform: rotate(90deg);
}

/* MENÚ CONTEXTUAL */
.options-menu {
    position: absolute;
    top: 35px;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
    min-width: 120px;
    overflow: hidden;
    display: none;
}

.options-menu.show {
    display: block;
}

.menu-item {
    padding: 10px 15px;
    color: #333;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.menu-item:hover {
    background: #f5f5f5;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item.delete {
    color: #e74c3c;
}

.menu-item.delete:hover {
    background: #ffeaea;
}

/* BOTÓN AÑADIR */
.shortcut-item.add-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    font-size: 2rem;
}

.shortcut-item.add-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.shortcut-icon {
    width: 35px;
    height: 35px;
    margin-bottom: 8px;
    border-radius: 6px;
}

.shortcut-name {
    font-size: 0.8rem;
    word-break: break-word;
    max-width: 100%;
    color: white;
}

/* BOTÓN CONFIGURACIÓN */
.settings-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    color: white;
    z-index: 900;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* MODAL DE AÑADIR/EDITAR SHORTCUT */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 1500; /* Alto, pero menor que el de configuración */
    justify-content: center;
    align-items: center;
}

/* CRÍTICO: Regla de visibilidad para el modal de shortcut */
.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    color: #333;
    padding: 30px;
    border-radius: 20px;
    min-width: 400px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.modal-content input {
    width: 100%;
    padding: 15px;
    margin: 10px 0;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    color: #333;
}

.modal-content input:focus {
    border-color: #3366cc;
    outline: none;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s;
}

#saveShortcut {
    background: #3366cc;
    color: white;
}

#saveShortcut:hover {
    background: #254eaf;
}

#cancelShortcut {
    background: #f0f0f0;
    color: #666;
}

#cancelShortcut:hover {
    background: #e0e0e0;
}

/* SCROLLBAR PERSONALIZADO */
#shortcutsContainer::-webkit-scrollbar {
    width: 8px;
}

#shortcutsContainer::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

#shortcutsContainer::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

#shortcutsContainer::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* RESPONSIVE */
@media (min-width: 1600px) {
    .container {
        width: 85%;
    }
    
    #shortcutsContainer {
        grid-template-columns: repeat(8, 1fr);
    }
}

@media (max-width: 1599px) {
    #shortcutsContainer {
        grid-template-columns: repeat(8, 1fr);
    }
}

@media (max-width: 1400px) {
    #shortcutsContainer {
        grid-template-columns: repeat(7, 1fr);
    }
}

@media (max-width: 1200px) {
    #shortcutsContainer {
        grid-template-columns: repeat(6, 1fr);
    }
}

@media (max-width: 992px) {
    #shortcutsContainer {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .container {
        width: 90%;
    }
}

@media (max-width: 768px) {
    #shortcutsContainer {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .container {
        width: 95%;
    }
    
    .topbar {
        padding: 10px 15px;
    }
    
    .time {
        font-size: 1.4rem;
    }
    
    .weather-info {
        gap: 10px;
    }
}

@media (max-width: 576px) {
    #shortcutsContainer {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .search-box {
        flex-direction: column;
        border-radius: 20px;
    }
    
    #searchEngine {
        border-radius: 20px 20px 0 0;
        padding: 10px;
    }
    
    #searchInput {
        border-radius: 0;
    }
    
    #searchBtn {
        border-radius: 0 0 20px 20px;
    }
}

@media (max-width: 480px) {
    #shortcutsContainer {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .container {
        width: 98%;
    }
}

/* MODAL DE CONFIGURACIÓN */
.config-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

/* CRÍTICO: Regla de visibilidad para el modal de configuración */
.config-modal.active {
    display: flex;
}

.config-content {
    background: white;
    color: #333;
    border-radius: 20px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

.config-header {
    background: linear-gradient(135deg, #3366cc, #764ba2);
    color: white;
    padding: 25px 30px;
    border-radius: 20px 20px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.config-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.close-config {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
}

.close-config:hover {
    background: rgba(255, 255, 255, 0.2);
}

.config-tabs {
    display: flex;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    padding: 0 30px;
}

.config-tab {
    padding: 15px 25px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.config-tab.active {
    color: #3366cc;
    border-bottom-color: #3366cc;
    background: white;
}

.config-tab:hover {
    color: #254eaf;
    background: rgba(51, 102, 204, 0.1);
}

.config-body {
    padding: 30px;
}

.config-section {
    margin-bottom: 30px;
    display: none;
}

.config-section.active {
    display: block;
}

.config-section h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.3rem;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
}

/* FORMULARIOS DE CONFIGURACIÓN */
.config-group {
    margin-bottom: 20px;
}

.config-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.config-select, .config-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.config-select:focus, .config-input:focus {
    border-color: #3366cc;
    outline: none;
}

/* SELECTOR DE COLORES */
.color-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-top: 10px;
}

.color-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 10px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s;
}

.color-option:hover {
    transform: scale(1.05);
}

.color-option.selected {
    border-color: #333;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* GRADIENTES PREDEFINIDOS */
.gradient-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 10px;
}

.gradient-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 10px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s;
}

.gradient-option:hover {
    transform: scale(1.05);
}

.gradient-option.selected {
    border-color: #333;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* SUBIDA DE IMÁGENES */
.upload-area {
    border: 2px dashed #ddd;
    border-radius: 10px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 10px;
}

.upload-area:hover {
    border-color: #3366cc;
    background: #f8f9ff;
}

.upload-area.dragover {
    border-color: #3366cc;
    background: #e8f0fe;
}

.upload-icon {
    font-size: 3rem;
    color: #666;
    margin-bottom: 15px;
}

.upload-text {
    color: #666;
    margin-bottom: 10px;
}

.upload-btn {
    background: #3366cc;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    transition: background 0.3s;
}

.upload-btn:hover {
    background: #254eaf;
}

/* IMÁGENES PREDETERMINADAS */
.default-images {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-top: 10px;
}

.default-image {
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: 10px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s;
    object-fit: cover;
}

.default-image:hover {
    transform: scale(1.05);
}

.default-image.selected {
    border-color: #3366cc;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* CONFIGURACIÓN DE UBICACIÓN */
.location-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 10px;
}

.location-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: white;
}

.location-option:hover {
    border-color: #3366cc;
    background: #f8f9ff;
}

.location-option.selected {
    border-color: #3366cc;
    background: #e8f0fe;
    box-shadow: 0 2px 8px rgba(51, 102, 204, 0.2);
}

.location-option input[type="radio"] {
    margin: 0;
    width: 18px;
    height: 18px;
}

.location-option label {
    margin: 0;
    font-weight: 600;
    color: #333;
    cursor: pointer;
}

.manual-location-container {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    border-left: 4px solid #3366cc;
    margin-top: 15px;
    display: none; /* Asegurar que está oculto por defecto si no es manual */
}

/* BOTONES DE CONFIGURACIÓN */
.config-buttons {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
}

.config-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s;
}

.config-btn.primary {
    background: #3366cc;
    color: white;
}

.config-btn.primary:hover {
    background: #254eaf;
}

.config-btn.secondary {
    background: #6c757d;
    color: white;
}

.config-btn.secondary:hover {
    background: #545b62;
}

/* PREVIEW EN TIEMPO REAL */
.background-preview {
    width: 100%;
    height: 120px;
    border-radius: 10px;
    margin-top: 15px;
    border: 2px solid #e9ecef;
    overflow: hidden;
}

/* SWITCH TOGGLE */
.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #3366cc;
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* ESTILOS PARA DRAG & DROP */
.shortcut-item[draggable="true"] {
    cursor: grab;
}

.shortcut-item[draggable="true"]:active {
    cursor: grabbing;
}

.shortcut-item.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.shortcut-item.drag-over {
    border: 2px dashed #3366cc;
    background: rgba(51, 102, 204, 0.1);
}

.shortcuts-container.drag-over {
    background: rgba(51, 102, 204, 0.05);
    border-radius: 12px;
}

.shortcut-item[draggable="true"]::after {
    content: "⃟";
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    opacity: 0;
    transition: opacity 0.3s;
}

.shortcut-item[draggable="true"]:hover::after {
    opacity: 1;
}

.shortcut-item.add-btn.drag-over {
    border-color: #2ecc71;
    background: rgba(46, 204, 113, 0.1);
}

.config-group small {
    color: #666;
    font-size: 0.8rem;
    display: block;
    margin-top: 5px;
}

.shortcut-item.locked {
    cursor: not-allowed;
    opacity: 0.7;
}

.shortcut-item.locked:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.1);
}

.shortcut-item:not(.locked) {
    cursor: pointer;
}

.shortcut-item.dragging {
    cursor: grabbing !important;
}