/* =============================================================================
   VARIABLES CSS Y RESET
   ============================================================================= */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --accent-primary: #0d6efd;
    --accent-hover: #0b5ed7;
    --accent-light: #e7f1ff;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --header-height: 60px;
    --toolbar-height: 50px;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1d21;
        --bg-secondary: #212529;
        --bg-tertiary: #2d333b;
        --text-primary: #c9d1d9;
        --text-secondary: #8b949e;
        --border-color: #30363d;
        --accent-primary: #58a6ff;
        --accent-hover: #79b8ff;
        --accent-light: #1f6feb33;
        --shadow: 0 2px 8px rgba(0,0,0,0.4);
        --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
                 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: var(--shadow);
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand .logo {
    font-size: 28px;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* =============================================================================
   TOGGLE DE VISTAS
   ============================================================================= */
.view-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    padding: 4px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.view-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.view-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.view-btn.active {
    background: var(--bg-primary);
    color: var(--accent-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-weight: 500;
}

.view-btn .icon {
    font-size: 1.1rem;
    line-height: 1;
}

/* =============================================================================
   TOOLBAR Y MIGAS DE PAN
   ============================================================================= */
.toolbar {
    height: var(--toolbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    gap: 16px;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}

.breadcrumbs::-webkit-scrollbar {
    display: none;
}

.crumb {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.crumb:hover {
    background: var(--bg-secondary);
    color: var(--accent-primary);
}

.crumb:not(:last-child)::after {
    content: '›';
    margin-left: 8px;
    color: var(--text-secondary);
    opacity: 0.5;
}

.crumb.root {
    font-weight: 500;
}

.actions {
    display: flex;
    gap: 8px;
}

/* =============================================================================
   BOTONES
   ============================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

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

.btn-danger:hover {
    background: #c82333;
    border-color: #bd2130;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
}

/* =============================================================================
   ÁREA DE CONTENIDO
   ============================================================================= */
.main-content {
    flex: 1;
    overflow: auto;
    padding: 24px;
    background: var(--bg-secondary);
}

#fileContainer {
    display: grid;
    gap: 16px;
    min-height: 100%;
}

/* =============================================================================
   VISTA DE CUADRÍCULA (GRID)
   ============================================================================= */
.view-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    align-content: start;
}

.view-grid .file-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    text-align: center;
}

.view-grid .file-item:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: var(--accent-light);
}

.view-grid .file-icon {
    font-size: 48px;
    line-height: 1;
    margin-bottom: 12px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.view-grid .file-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    word-break: break-word;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.view-grid .file-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* =============================================================================
   MENÚ DE ACCIONES EN GRID - SIEMPRE VISIBLE
   ============================================================================= */
.file-actions-menu {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 100;
}

.btn-action-menu {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1 !important; /* FORZAR VISIBILIDAD */
    visibility: visible !important;
    color: var(--text-secondary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    padding: 0;
    margin: 0;
}

.btn-action-menu:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.action-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 120px;
    display: none;
    overflow: hidden;
    z-index: 1000;
}

.action-dropdown.active {
    display: block;
    animation: fadeIn 0.15s ease;
}

.action-item {
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 0.8125rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
    margin: 0;
}

.action-item:hover {
    background: var(--bg-secondary);
}

.action-item.delete-action {
    color: var(--danger);
}

.action-item.delete-action:hover {
    background: var(--danger);
    color: white;
}

.action-item span {
    font-size: 14px;
    width: 16px;
    text-align: center;
}

/* =============================================================================
   VISTA DE LISTA (LIST) - COMPACTA
   ============================================================================= */
.view-list {
    grid-template-columns: 1fr;
    gap: 2px;
}

.view-list .file-item {
    display: grid;
    grid-template-columns: 28px 1fr 80px 120px 60px;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    gap: 10px;
    min-height: 40px;
}

.view-list .file-item:hover {
    background: var(--accent-light);
    border-color: var(--accent-primary);
}

.view-list .file-icon {
    font-size: 18px;
    text-align: center;
    line-height: 1;
}

.view-list .file-name {
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

.view-list .file-size {
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.view-list .file-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* BOTONES PEQUEÑOS EN LISTA */
.view-list .file-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
    justify-content: flex-end;
}

.view-list .file-item:hover .file-actions {
    opacity: 1;
}

.btn-icon {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
    line-height: 1;
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

.btn-icon.delete-btn:hover {
    background: var(--danger);
    color: white;
}

.btn-icon.download-btn:hover {
    background: var(--accent-primary);
    color: white;
}

/* =============================================================================
   ESTADOS ESPECIALES
   ============================================================================= */
.file-item.folder .file-icon {
    color: var(--warning);
}

.file-item.file .file-icon {
    color: var(--text-secondary);
}

.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state .icon {
    font-size: 64px;
    opacity: 0.5;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 1.125rem;
}

/* =============================================================================
   OVERLAY DE SUBIDA
   ============================================================================= */
.upload-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity var(--transition-normal);
}

.upload-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.upload-progress {
    background: var(--bg-primary);
    padding: 24px 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 320px;
    max-width: 90vw;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-weight: 500;
}

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--accent-primary);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

.progress-status {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* =============================================================================
   MODAL
   ============================================================================= */
.modal {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0;
    background: var(--bg-primary);
    min-width: 320px;
}

.modal::backdrop {
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    padding: 24px;
}

.modal-content h3 {
    margin-bottom: 16px;
    font-size: 1.125rem;
}

.modal-content input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 20px;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.modal-content p {
    margin-bottom: 20px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* =============================================================================
   NOTIFICACIONES
   ============================================================================= */
.notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 0.875rem;
    z-index: 10000;
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 380px;
    word-wrap: break-word;
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.notification.success {
    border-left: 3px solid var(--success);
}

.notification.error {
    border-left: 3px solid var(--danger);
}

.notification.warning {
    border-left: 3px solid var(--warning);
}

.notification.info {
    border-left: 3px solid var(--accent-primary);
}

.notification-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.notification-text {
    line-height: 1.4;
}

/* =============================================================================
   ANIMACIONES
   ============================================================================= */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
@media (max-width: 768px) {
    .view-btn .label {
        display: none;
    }
    
    .actions {
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 6px 10px;
        font-size: 0.8125rem;
    }
    
    .view-list .file-item {
        grid-template-columns: 28px 1fr 60px;
        gap: 8px;
        padding: 6px 10px;
    }
    
    .view-list .file-size,
    .view-list .file-date {
        display: none;
    }
    
    .view-list .file-actions {
        opacity: 1;
    }
    
    .btn-action-menu {
        width: 22px;
        height: 22px;
        font-size: 12px;
    }
    
    .notification {
        left: 12px;
        right: 12px;
        max-width: none;
        font-size: 0.8125rem;
    }
    
    .main-content {
        padding: 12px;
    }
    
    .view-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }
}

.hidden {
    display: none !important;
}